Analysis of data access layer technology under. Net (III.)

Source: Internet
Author: User
Tags reference
access | data u/r Mapping

The full name of the O/R Mapping is: Object Relational Mapping, the main purpose is to build a mapping relationship between the traditional RDBMS and OO language, thus leaving the developer completely disconnected from the data.

About O/R Mapping or recent popular o/x Mapping (you can refer to "programmer, 2004.01,p86"), may need special articles for detailed discussion, the purpose of this article is to make a simple analysis of the advantages and disadvantages of existing schemes and provide some reference information in practice.

Compared to the Java platform,. NET of O ' mapping is no history, so far there has not been tested mature available programs. However, with the attention of major manufacturers and open source projects in full swing, the pace of the. NET O/R mapping began to slowly follow, so that this belongs to the Java-EE territory to join a new competitor (will not allow more developers to invest in the. NET Camp?) J) has also made many of the DAL developers who are struggling to run back and forth in SQL clause or ado.net to see the "Path of Light".



Next, let's take a look at some of the solution that are worth exploring in this more expansive land than ado.net.

Øopen Source

Open source has been with. NET to maintain a certain distance, o ' mapping is very few, but the author's download trial and source analysis, personally think that the following two solutions or have a certain reference value: OPF,OJB.

For a brief introduction to these two open source projects, you can refer to "programmer, 2004.01,p13".

Opf's full name is: Object persistent Framework.

OJB's full name is: ObJect Relational bridge.



In the implementation of the methods, the two ideas are completely different, with their own representativeness.

The Opf route is somewhat similar to the typed dataset or Borland ECO (please refer to the introduction below) to achieve simpler, more source-level control, while the OJB implementation is similar to the Microsoft ObjectSpaces (refer to the following description). The way the configuration file is used is relatively complex.



The basic framework for these two programmes is as follows:

OPF:




It is not difficult to see from the diagram:

(1) Persistent class plays the role of DataSet, in addition to the normal object data manipulation, you can also set the relationship between different objects (such as master-slave relationship, set relationship, etc., in the code generated by Borland Eco can also be seen slightly one or two), which is also said above " The reason for providing more source-level control;



(2) Persistentsqldatamanager plays the role of DataAdapter and performs real database operations through pre-set commands; In the employee data manager that is actually written, Developers do need to provide basic SQL statements, as set in Sqlcommond (Borland Eco goes further, using OCL instead of SQL);



(3) The function of ObjectBroker is very important, it is the bridge between the object and the data, and the Registerpersistent method establishes the relationship between the virtual (object) and the reality (RDBMS).



(4) In the statement of Employee business object, the corresponding relationship between the objects attribute and the database field is embodied by the. NET attribute mechanism, so it is more convenient to modify it, although the way of configuration file is not flexible (please refer to the introduction of OJB) , such as: the need to recompile, developers have to focus on database fields, and so on.



OJB:




It is not difficult to see from the diagram:

(1) The implementation of the program is more complex, but the user needs to write the actual code less (only need to write employee business object), which is the key to the introduction of the configuration file, and because of the introduction of the configuration file, we in Hello World There is also no need to invoke a similar Opf solution (refer to the Opf class diagram above) in the application, all of which (even including database connection information), the system is already at your fingertips!



(2) In this scenario, the SQL command is completely replaced by the criteria class, while Queryfacade acts as the adapter function and communicates with the database by persistencebroker this real command;



(3) Whether it is Repository.xml configuration file, or criteria, Queryfacade class, we can be in objectspaces (please refer to the introduction below) to find a similar implementation (is it a coincidence?) At the same time, the author personally think that this way is more in line with the spirit of O ' mapping, reducing the burden on developers!



(4) OJB also has a very cool tool "Repositorygen.exe", can be used to generate Repository.xml configuration file (the same, the source code to serve J), this point, not even objectspaces can do (think about so many fields, attributes, associations, mappings, can be a crazy person. J!





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.