Analysis of the data access layer technology under the .NET (3)

zhaozj2021-02-16  61

u o / r mapping

O / R Mapping's full name is: Object Relational mapping, main purpose is to build a mapping relationship between traditional RDBMS and Oo Language, so that developers completely detach the data for a long-lasting sea.

About O / R mapping or recently comparing O / X mapping (You can refer to "programmer, 2004.01, p86"), may require a special article to discuss, this paper is mainly for the advantages and disadvantages of existing programs. Simple profiles and provide reference information in some practices.

Comparison of J2EE platforms, O / R mapping under .NET can be described as there is no history, and has not yet been tested programs. However, with the attention of major manufacturers, the pace of .Net O / R mapping has begun to keep up with the steps of this item to join the J2EE, and will not make more Many developers put .NET camp? J), which also makes numerous fatigates who come back and forth in SQL CLAUSE or ADO.NET to see "Light Road".

Next, let's take a look at the Solution of this slogan to discuss more than ADO.net.

Ø Open Source

Open source has always been with .NET keeps a certain distance, O / R mapping is even more than, but in terms of the author's download trial and source analysis, individuals think that the following two solutions still have a certain reference value: OPF, OJB.

Introduction to these two open source projects, you can refer to "Programmer, 2004.01, P13".

The full name of OPF is: Object Persistent Framework.

The full name of OJB is: Object Relational Bridge.

In implementation, the idea of ​​these two programs is completely different, with respective representation.

The route of the OPF is a bit similar to Typed DataSet or Borland Eco (please refer to the following description), the implementation is relatively simple, providing more source level control; and the OJB implementation is similar to Microsoft Objectspaces (please refer to the following introduction), use The way the configuration file is complicated, relatively complicated.

The basic framework of these two programs is as follows:

OPF:

It is not difficult to see from the figure:

(1) The Persistent class plays a DataSet role. In addition to the regular object data operations, the PersisTent operation can also set the relationship between different objects (such as the primary relationship, collection relationship, etc.) in the code generated by the Borland ECO. Slightly one or two), this is also the reason why the above say "provide more source level control";

(2) PersistentSqldataManager played the role of DataAdapter, performs real database operations by pre-set Commands; in actually written Employee Data Manager, developers do need to provide basic SQL statements, just like setting in SQLCommond (Borland ECO is further, replacing SQL with OCL);

(3) ObjectBroker's role is very important, it is the bridge between objects and data, and the registerpersistent method establishes the relationship between this virtual (Object) and reality (RDBMS); (4) In the declaration of Employee Business Object, object properties The correspondence with the database field is reflected in the .NET Attribute mechanism, so modified or more convenient, although it is not flexible than the configuration file (please refer to OJB introduction), such as: need to recompile, developers must not Don't pay attention to the database field, etc.

OJB:

It is not difficult to see from the figure:

(1) The implementation of the scheme is more complicated, but the user needs to be actually written (only written EMPLOYEE Business Object), the key is to introduce the configuration file; at the same time, we are There is no need to call the RegisterObject method in similar OPF solutions (please refer to the OPF class diagram above), all of which (even database connection information), the system is as good!

(2) In this scenario, the SQL command is thoroughly replaced by the Criteria class, while QueryFacade acts as an Adapter functionality, communicating with the database through the true Command of PersistenceBroker;

(3) Whether it is a repository.xml configuration file, or the Criteria, QueryFacade class, we can find similar implementations in ObjectSpaces (please refer to the following introduction), at the same time, the author believes that this way It is also more in line with the spirit of O / R mapping, reducing the burden of developers!

(4) OJB has a very cool tool "repositorygen.exe", can be used to generate the repository.xml configuration file (the same, source code is unpaid J), this, even ObjectSpaces can not do (want Think so many fields, attributes, associations, mapping, simply let people go crazy J)!

About the Author:

"Zhang Xuefeng, this article, is the senior development engineer of Bibo Global Development Center. He currently works in the Core / Eai department of China Shanghai Bibo Global Development Center, engaged in .NET technology research and related projects. You can pass xuefeng.zhang@bearingpoint .com Contact him. "

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

New Post(0)