Object Relational ing (ORM) is a technology designed to solve the mismatch between objects and relational databases. To put it simply, Orm automatically persists the objects in Java programs to relational databases by using metadata describing the ing between objects and databases. In essence, data is converted from one form to another. This also implies additional execution overhead. However, if ORM is implemented as a middleware, there will be many opportunities for optimization, which do not exist in the handwritten persistence layer. More importantly, the metadata used to control the conversion needs to be provided and managed; however, these costs are less than the manual maintenance solution; in addition, even object databases that comply with the ODMG specifications still need class-level metadata.
Object/Relation Mapping (ORM) is generated with the development of object-oriented software development methods. Object-Oriented development is the mainstream development method in today's enterprise-level application development environment. Relational databases are the mainstream data storage systems that permanently store data in enterprise-level application environments. Objects and relational data are two forms of business entities. business entities are represented as objects in the memory and relational data in the database. Objects in the memory have associations and inheritance relationships. In the database, relational data cannot directly express many-to-many associations and inheritance relationships. Therefore, the object-relational ing (ORM) system generally exists in the form of middleware, mainly to map program objects to relational database data.
Object-Oriented development is based on the basic principles of Software Engineering (such as coupling, aggregation, and encapsulation), while relational databases are developed from mathematical theories, there are significant differences between the two sets of theories. To solve this mismatch, the object link ing technology emerged.
Let's start with O/R. The letter O originated from "object", while R came from "relational ). Objects and relational databases exist in almost all programs. In the business logic layer and user interface layer, We are object-oriented. When the object information changes, we need to save the object information in the relational database.
When you develop an application (without O/R Mapping), you may write a lot of data access layer code to save, delete, and read object information from the database. You have written many methods in the Dal to read object data, change State objects, and so on. These codes are always repeated.
If you open your recent program and look at the Dal code, you will certainly see many similar general patterns. Let's take the method of saving objects as an example. You pass in an object, add sqlparameter to the sqlcommand object, map all attributes to the object, set the commandtext attribute of sqlcommand as the stored procedure, and then run sqlcommand. This code must be repeatedly written for each object.
In addition, is there a better way? Yes. Introduce an O/R Mapping. Essentially, an O/R Mapping will generate a dal for you. It is better to use o/R Mapping than to write the Dal code by yourself. You use o/R Mapping to save, delete, and read objects. O/R Mapping is responsible for generating SQL statements. You only need to care about objects.
Object relationship ing is successfully applied to different object-oriented persistence layer products, such as torque, OJB, hibernate, toplink, Castor JDO, and tjdo.
The general ORM includes the following four parts:
An API for performing crud operations on persistent class objects;
A language or API is used to specify queries related to classes and class attributes;
A tool that specifies mapping metadata;
One technology allows the implementation of ORM to perform dirty checking, lazy Association fetching, and other optimization operations together with the transaction object.
I. currently popular ORM Products
At present, many manufacturers and open-source communities have provided implementation of the persistent layer framework. Common implementations include:
Apache OJB (http://db.apache.org/ojb)
Cayenne (http://objectstyle.org/cayenne)
Jaxor (http://jaxor.sourceforge.net)
Hibernate (the http://www.hibernate.org)
IBM (http://www.ibatis.com)
Jrelationalframework (http://ijf.sourceforge.net)
Mirage, http://itor.cq2.org/en/oss/mirage/toon)
Http://www.drjava.de/smyle (smyle)
Toplink (http://otn.oracle.com/products/ias/toplink/index.html)
Among them, toplink is a commercial Oracle product, and others are open-source projects.
Among them, Hibernate's lightweight ORM model gradually establishes a leading position in the Java ORM architecture, and even replaces the complex and complicated EJB model to become the de facto Java ORM industrial standard. Many of these designs have been absorbed by J2EE standards organizations and become the latest EJB 3.0 standard, which is also a strong witness to the impact of open-source projects on industrial standards.
Ii. Object-link ing mode
The contents extracted from Chapter 8th of "public warehouse meta-model: Development Guide" are used to implement the public warehouse meta-model (CWM) UML ing from a UML diagram to a Microsoft SQL Server database is a way to map object hierarchies into a relational structure. I personally think it can be used as a reference to store ontology files in relational databases.
Basic information: the common warehouse metadata model (CWM) is an object management organization (OMG) metadata model standard related to the Data Warehouse. It adopts the object hierarchy represented by UML, because of the imperfect Object-Oriented Database Technology (neither theoretical nor commercial applications are mainstream ), therefore, the author of this book tends to use mature relational databases for storage-this is also a problem encountered when storing the ontology.
Usage method: convert various elements in the UML Model and save them as the database mode. Because CWM is a metadata model, the instance of the model is also a model that stores such instances as database data. Improve development and execution efficiency by using mature stored procedures in databases.
1. Data Type ing mode
1.1 simple data type mode: Create a ing table for simple data types in UML and relational databases to guide ing.
1.2 enumeration data type mode: Each Enumeration type corresponds to a table, and only one column (_ enumliteral) represents the enumeration value.
1.3 class-based data type mode: use foreign key constraints to associate basic columns with class-based type instances.
2. Class ing model
Each class corresponds to a table. Single-value attributes, multi-value attributes, and inheritance relationships can be mapped using the following methods, and referenced attributes are described in the associated ing mode.
2.1 single-Value Attribute mode: it is the attribute with the upper bound of cardinality 1, which is mapped to the column of the table corresponding to the class. If its lower bound is also 1 (mandatory), the column attribute is not null.
2.2 multi-value attribute mode: Each multi-value attribute is mapped to an independent table, and a foreign key is used to connect to the table corresponding to the class.
2.3 inheritance mode: When a class instance is added, the class objects are generated from top to bottom based on their inheritance relationships. These objects have the same ID (the primary key of the root object corresponding to the record ). When deleting an object instance, data is deleted from the bottom up. What should I do if I delete data from the center? How to deal with multi-inheritance? (Jin longfei)
3. Associated ing mode
3.1 one-to-one association mode: Add a column to each end of the association.
3.2 One-to-Multiple Association mode: Same as 3.1. If multiple ends are ordered, you must add a column to indicate the sequence number.
3.3 Multi-to-Multi-join mode: Separate the join table.
3.4 combined Association mode: Pay attention to cascading deletion.
3.5 reverse Association mode: The types at the two ends of the Association point to the correlation type, which is the same as the common association.
3.6 paired Association mode: The Association records the relationship between two classes, and uses the intersection class to indicate Association, representing a separate table. Each association corresponds to a table, foreign keys are used to represent the relationships between them.
3.7 The associated OCL needs to be analyzed into the corresponding stored procedure code.
3.8 Ensure that the associated cardinality needs to be analyzed into the corresponding stored procedure code.
4. Reference ing mode
A mof feature that does not exist in UML is an instance declared as a reference type. Use stored procedures.