Design of ORM Framework

Source: Internet
Author: User

(Start with an ORM introduction from the Internet) what is ORM?
ORM, the Object-relational Mapping (object-relational mapping), acts as a mapping between a relational database and a business entity object. ORM can also be understood as a specification, and the specific ORM framework can be used as a bridge for applications and databases. In this way, we do not need to deal with complex SQL statements when we operate the business objects, simply manipulate the object's properties and methods.
Why ORM is required
The object-oriented programming language, which represents the mainstream and trend of the current programming language, has many advantages, such as:
1, object-oriented modeling, operation.
2, polymorphism, inheritance.
3, abandon the difficult to understand the process.
4, easy to use, easy to understand.
However, the development of the database is not synchronized with the programming language, and some advantages of the relational database system are not solved by object-oriented language at present. Like what:
1, a large number of data operations to find, sort.
2, collection data connection operation, mapping.
3. Concurrency and transactions for database access.
4, the database constraints, isolation.
Faced with the coexistence of object-oriented language and relational database system, the use of ORM becomes a necessity. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What is ORM's core purpose?

is to let us not care about the database, only care about our object, the collection of all object-oriented knowledge points

How do I design an ORM framework on my own?

Altogether consists of two parts:

First, the Mapping section (provides an XML file that can be configured by the user)

Second, framework core section (providing APIs for user use)

The first part

The mapping section, which is called an ORM. Responsible for mapping between objects and database tables, and this part is divided into three parts.

Part 1th, Entity section (Object)

Part 2nd, Database section (relational database relationship)

3rd part, Mapping section (Mapping)

So how do they work together?

Mapping section to access the Object section and the Relationship section, and then complete the mapping between them

How to map?

The corresponding fields and properties are mapped through the XML file through the mapping operation.

Part II

The core part of the framework is the operation of a collection or object that you receive.

What do you want to do with your core class?

In the first step, the core class parses the XML file according to your mapping rules, matches the table of the object, and the column of the object's property corresponding to the table.

In the second step, the core class generates the corresponding SQL statement based on the operation of the object (add and revise).

The third step, the core class to access the database through ADO, execute SQL statements.

Fourth step, return the result. (if it is a query operation, it is converted from the core class to the corresponding object or collection and returns the result)

Depending on what class you have now, say you have a user object now, and the user object corresponds to a user table, then you find that it is the add operation that builds the INSERT statement in the core class, which table does the INSERT statement insert? Based on the mapping between the object and the table, the corresponding table, the values of which columns? This is then taken from the properties of this object, which corresponds to that column, which is taken out in turn, through the core class to complete an SQL statement, through the core class to complete such a transformation. Finally, this SQL statement requests a specific database to complete the operation through our framework. How to request? Here we can directly access the database via ADO, and finally return the result.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The first step, the core class to parse the XML file according to your mapping rules, match the object corresponding to the table, the object property corresponding to the table column.

In the second step, the core class generates the corresponding SQL statement based on the operation of the object (add and revise).

The third step, the core class to access the database through ADO, execute SQL statements.

1

Fourth step, return the result. (if it is a query operation, it is converted from the core class to the corresponding object or collection and returns the result)

  

Design of ORM Framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.