Are you or mapping?

xiaoxiao2021-03-06  22

In the software development, O / R mapping is increasingly lifted by people. What is o / r mapping? Simply, Object / Relation Mapping, object to the relationship mapping. What is this name and concept come out? Why do we need o / r mapping in the development? First let's see the object-oriented development. Object-Oriented development has been widely popular in recent years and has become the most basic method of software development. The development language also has a programming language specifically for object-oriented development, like the mainstream Java, C # is based on programming languages ​​for face-to-face development design. Practice has proved object-oriented, an development method that effectively improves development quality, easy management and conforming to human thinking. Whether it is a process / structure development method or an object-oriented development method, almost all projects and product software development must involve data access updates such as relational databases. And relational databases are the first need to face all project product development. The current development technology needs to develop a data access layer (Data Access Layer) for each project as the basis for commercial logic code.

In object-oriented development, the most basic database operation of the data access layer includes insertion objects, deleting objects, updating objects, and query objects. Almost all project development needs to first need to implement these atomic operations. These operations are similar in almost all project development, which transforms inserted objects, deleting objects, update objects, and query-level operations to underlying relational data supported by SQL operations such as INSERT, DELETE, UPDATE, and SELECT. . Look at a basic example insert object, here we add a user object Account.

Public void addaccount (Final Account Account) Throws DaoException,

AccountAlReadyexistexception {

Final connection conn;

CONN = getConnection ();

Final prepaaredStatement Stat

= conn.preparestatement ("INSERT INTO"

PersistentAccount.property_account_table

"(" "

PersistentAccount.property_user_name ","

PersistentAccount.property_password ","

PersistentAccount.property_Email ","

Persistentaccount.property_column_writer ")"

"VALUES"

Account.getusername () "','"

Account.getPassword () "" ""

Account.Getemail () "','"

(Account.iscolumnWriter ()? "y": "n") ")");

Stat.execute ();

Stat.close ();

CONN.CLOSE ();

Return;

}

This operation is simple, which is to convert an object logic of an Account object into an Insert action, which implements the simplest ACCOUNT object to the map of database table Account. In the example, it is implemented by developers manually writing JDBC code. If there is another object Person, we also want to write similar code to achieve a Person's operation. Similar examples and code exist in a large number of items. From 1996, JDBC has appeared in 200 years, a large number of project development is still repeated to write such code to implement basic fucks needed for each project. The development of data access layer (development and testing) is great, and the requirements for developers are also very high. The most unfortunate thing is to repeat the development of this complicated data access layer in a large number of project development, resulting in a large number of human labor financial resources to waste in this human intensive data access layer repeated development and database operations are precise. It is the most prone to errors and consume a lot of time in project development. If you need to face different databases in your project, you also need to develop a specialized data access layer for each database. Obviously this type of code is repeated but has the same mode of code is a significant waste. This gave birth to the production of O / R mapping technology. ORM, Object-RelationL mapping, its role is to make an automatic mapping between the relational database and objects, so that we do not need to go and complicate SQL statements when we do not need to go to the complex SQL statement when specific operational databases. Objects can be, the O / R mapping tool automatically converts the object's operation to the SQL statement operation. This way we only need to pay attention to the object architecture in business logic, rather than the database SQL and JDBC code of the underlying repetitive. Let's take a look at what the original code is different after using O / R mapping technology. Here we use JDO. Public void addaccount (Final Account Account) Throws DaoException,

AccountAlReadyexistexception {

Final PersistenceManager PM = pmf.getPersistenceManager ();

PM.currentTransaction (). Begin ();

PM.makePersistent (Account);

Pm.currentTransaction (). Commit ();

After contrast, we can understand the huge differences in the amount of code. And this is just a situation in which a single object is inserted. Insert multiple objects, especially inserting multiple associated objects, more advantages of O / R mapping can be seen. In the Liberator JDO frame, Persistence by Reachability is supported, and all objects referenced by the object can be automatically saved to the appropriate data table when saving objects, without having to save each object. After contrast, we can understand the huge differences in the amount of code. And this is just a situation in which a single object is inserted. Insert multiple objects, especially inserting multiple associated objects, more advantages of O / R mapping can be seen. In the Liberator JDO frame, Persistence by Reachability is supported, and all objects referenced by the object can be automatically saved to the appropriate data table when saving objects, without having to save each object. The following example saves a department, all of the student objects contained, and each student profile (Profiel). final PersistenceManager pm = pmf.getPersistenceManager (); final Profile myProfile1 = new Profile (180, "foo1", "fooLast1", 19); final Student student1 = new Student (1, myProfile1); final Profile myProfile2 = new Profile (181 , "foo2", "fooLast2", 19); final Student student2 = new Student (2, myProfile2); final Department department = new Department ( "Computer"); department.addStudent (student1); department.addStudent (student2); Pm.currentTransAction (). Begin (); PM.makePersistent (department); pm.currentTransAction (). Commit (); If you use traditional manual SQL, JDBC mode encoding, code amount can be nearly 5 times. In calculating the test saving time, you can use O / R mapping technology to greatly improve the development efficiency and development time, while the development quality is also easier to ensure. Here we only show a small part of the O / R mapping technology, and more very attractive features worthy of our trial. The benefits of using O / R mapping: 1) Improve learning and development efficiency, greatly reduce development costs. Using ORM can greatly reduce learning and development costs, the development of modern technology, makes we need to learn. We must not only learn knowledge-oriented, UML, design models, etc., but also need to learn SQL, JDBC, and even knowledge of various databases (DB2, Oracle, SQL Server, etc.). In actual development, it is really a unique business function for customers. The current status is that we spend a lot of time in writing data access, including BUG lookups, maintenance, etc. will cost more. Time is on data processing. That is to say, we have been wasted at all non-business incidents that do not create value in actual development.

After using ORM, we will not need to waste too much time in the development and testing of SQL statements, JDBC. The ORM frame has converted the underlying database operation into our familiar object operation, we will only need to understand the development of the database application to be able to develop database applications. 2) Simplify the code and reduce the number of bugs. By establishing an ORM framework, it is possible to reduce the program development code, and the development of the data layer is relatively simple, greatly reduces the chance of error. 3) Simplify the test. Simply test the class and behavior of business logic, avoid duplicate JDBC test 4) Improve performance object-level cache (cache objects and their relationships) can avoid unnecessary data inventory, greatly improve the performance of data read and write. We can also save time and workload for system tuning. 5) Isolation data source, it can be easily converted to the actual data store ORM, and the developer does not need to care about the actual storage. If we need to convert the SQL Server database to an Oracle database, only need to modify The configuration file can be, and the business logic code does not need to be modified. The huge advantage of O / R mapping technology makes it a mainstream development model in object-oriented development. In the Java community, Java Data Object is initiated by Sun, and many manufacturers have developed the Java's O / R mapping standard, and the next generation of Enterprise Java Bean standards will also fusion JDO technology, and O / R mapping technology as EJB 3.0 technology. Core technology of specifications. Microsoft also does not show weakness, providing an O / R mapping framework called ObjectSpaces in the next generation .NET development framework. It can be foreseen that in the near future, O / R mapping technology will be widely used in software project development, becoming a rocket booth for software development. Public void addaccount (Final Account Account) Throws DaoException,

AccountAlReadyexistexception {

Final connection conn;

CONN = getConnection ();

Final prepaaredStatement Stat

= conn.preparestatement ("INSERT INTO"

PersistentAccount.property_account_table

"(" "

PersistentAccount.property_user_name ","

PersistentAccount.property_password ","

PersistentAccount.property_Email ","

Persistentaccount.property_column_writer ")"

"VALUES"

Account.getusername () "','"

Account.getPassword () "" ""

Account.Getemail () "','"

(Account.iscolumnWriter ()? "y": "n") ")");

Stat.execute ();

Stat.close ();

CONN.CLOSE ();

Return;

}

This operation is simple, which is to convert an object logic of an Account object into an Insert action, which implements the simplest ACCOUNT object to the map of database table Account. In the example, it is implemented by developers manually writing JDBC code. If there is another object Person, we also want to write similar code to achieve a Person's operation. Similar examples and code exist in a large number of items. From 1996, JDBC has appeared in 200 years, a large number of project development is still repeated to write such code to implement basic fucks needed for each project. The development of data access layer (development and testing) is great, and the requirements for developers are also very high. The most unfortunate thing is to repeat the development of this complicated data access layer in a large number of project development, resulting in a large number of human labor financial resources to waste in this human intensive data access layer repeated development and database operations are precise. It is the most prone to errors and consume a lot of time in project development. If you need to face different databases in your project, you also need to develop a specialized data access layer for each database. Obviously this type of code is repeated but has the same mode of code is a significant waste. This gave birth to the production of O / R mapping technology. ORM, Object-RelationL mapping, its role is to make an automatic mapping between the relational database and objects, so that we do not need to go and complicate SQL statements when we do not need to go to the complex SQL statement when specific operational databases. Objects can be, the O / R mapping tool automatically converts the object's operation to the SQL statement operation. This way we only need to pay attention to the object architecture in business logic, rather than the database SQL and JDBC code of the underlying repetitive. Let's take a look at what the original code is different after using O / R mapping technology. Here we use JDO. Public void addaccount (Final Account Account) Throws DaoException,

AccountAlReadyexistexception {

Final PersistenceManager PM = pmf.getPersistenceManager ();

PM.currentTransaction (). Begin ();

PM.makePersistent (Account);

Pm.currentTransaction (). Commit ();

After contrast, we can understand the huge differences in the amount of code. And this is just a situation in which a single object is inserted. Insert multiple objects, especially inserting multiple associated objects, more advantages of O / R mapping can be seen. In the Liberator JDO frame, Persistence by Reachability is supported, and all objects referenced by the object can be automatically saved to the appropriate data table when saving objects, without having to save each object. After contrast, we can understand the huge differences in the amount of code. And this is just a situation in which a single object is inserted. Insert multiple objects, especially inserting multiple associated objects, more advantages of O / R mapping can be seen. In the Liberator JDO frame, Persistence by Reachability is supported, and all objects referenced by the object can be automatically saved to the appropriate data table when saving objects, without having to save each object. The following example saves a department, all of the student objects contained, and each student profile (Profiel). final PersistenceManager pm = pmf.getPersistenceManager (); final Profile myProfile1 = new Profile (180, "foo1", "fooLast1", 19); final Student student1 = new Student (1, myProfile1); final Profile myProfile2 = new Profile (181 , "foo2", "fooLast2", 19); final Student student2 = new Student (2, myProfile2); final Department department = new Department ( "Computer"); department.addStudent (student1); department.addStudent (student2); Pm.currentTransAction (). Begin (); PM.makePersistent (department); pm.currentTransAction (). Commit (); If you use traditional manual SQL, JDBC mode encoding, code amount can be nearly 5 times. In calculating the test saving time, you can use O / R mapping technology to greatly improve the development efficiency and development time, while the development quality is also easier to ensure. Here we only show a small part of the O / R mapping technology, and more very attractive features worthy of our trial. The benefits of using O / R mapping: 1) Improve learning and development efficiency, greatly reduce development costs. Using ORM can greatly reduce learning and development costs, the development of modern technology, makes we need to learn. We must not only learn knowledge-oriented, UML, design models, etc., but also need to learn SQL, JDBC, and even knowledge of various databases (DB2, Oracle, SQL Server, etc.). In actual development, it is really a unique business function for customers. The current status is that we spend a lot of time in writing data access, including BUG lookups, maintenance, etc. will cost more. Time is on data processing. That is to say, we have been wasted at all non-business incidents that do not create value in actual development.

转载请注明原文地址:https://www.9cbs.com/read-40464.html

New Post(0)