INSIDE LIBERATOR JDO & JDO2

xiaoxiao2021-03-06  70

1. Liberator JDO uses the method generated by the compile period bytecode to enhance Pojo. We know that Pojo (Plain Old Java Object) is a simple Java Bean that does not do special processing is unable to implement various operations of O / R mapping. Therefore, Java Beans need to be so-called enhancements. Enhanced is actually very simple, that is, add state management to Java Bean, such as each getter / setter increase status judgment, if the Field corresponding to getter has not been loaded from the data, then initiate SQL to load this field. These newly added operations need to be added to POJO in some way. There are three ways to add: Automatically add source code, generate Interface in the Runtime implementation status by dynamic bytecode, inserted in the BYTECode in Bytecode in Bytecode.

Automatically add source code Since the risk and maintenance work of potential error changes, it is rarely adopted by the O / R mapping tool. By dynamic Bytecode is an ideal way to add a status processing process, the famous open source O / R mapping tool Hiberante adopts (through open source CGLIB). The benefits of dynamic Bytecode generation are simple, and the enhancement process is completely impossible to developers. The disadvantage is that the startup time is long (because the dynamic generating bytecode) and memory occupancy is more in the first load of Pojo Class to VM (bytecode is generated).

Liberator JDO is the third compile period bytecode generation. The advantage of this approach is that static enhancement is high and less memory, and the disadvantage is that developers who are used to use Debugger need to compile multiple steps. Not used to, but developers who habits to drive development will not have problems.

JDO1.0 specification The reason for the generation of compile period Bytecode is mainly to make specifications to realize the reinforcement of vendors to enhance the replacement of post-code. In addition, since JDO is not just an O / R mapping framework, more is the enterprise data access framework, considering the JDO implementation that needs to be Memory Footprint as much as possible, such as XML or Flash Memory-based JDO developed by PDA. Implementation, such JDO implementation requires as little Memory Footpring as much as possible, using dynamic BYTECODE generation does not apply. Consider these factors, JDO chose the compile period bytecode generation.

The latest CGLIB2 adds a Code Transformation API to enhance the JDO style bytecode, which can be easily compiled or dynamic bytecode. JDO Enhancer. The Red Plant will implement EJB3.0 in the first quarter of the year to increase the enhanced way of dynamic Bytecode generated, and users can choose according to their needs.

2. Liberaot JDO uses two-layer cache design. The first layer cache is a readable write cache for the PersistenceManager (PM), which caches only the objects operating in the PM lifecycle. Readable write cache In addition to reducing read operations for databases, it is more important to delay all write operations in the transaction (INSERT, UPDATE, DELETE) to actually execute, so that you can operate (Batch Update) ) To achieve a reduction in network communication burden between databases.

The second layer cache is read-only cache, and only two read-only cache features:

1. Provides a target cache across PM.

2. Provide a distributed object cache.

The read-only cache can greatly improve the performance of the application (special read operating application). When the cached object is written, the objects in the read-only cache immediately will be abolished, then the next load is required to be read from the database. The maximum advantage of read-only cache is easy to achieve distributed support, simple and reliable, and do not need to consider data synchronization issues in the same object in multiple caches in a distributed environment. 3. Liberatorjdo plane flush design.

In JDO, there are two main objects in PersistenceManagerImpl and StoreManager. StoreManger is responsible for the specific database operation. Since JDO needs to support Persistence Reachablity, it means that when we save Object Graph, you need to be traversed in the traversal of the map, when this traversal has a great impact on the architecture of JDO implementation. A obvious sign is when the Persistecemangaer is submitted to the StoreManager, it is related to the StoreManger. If there is, it means that it is necessary to recurs in the StoreManager's database operation. If not, it is true to recursive within the PersistenceManager. For StoreManger, all POs that need to be saved are indispensable, which is like PersistenceManager and StoreManager. There is a relationship between the two clear cuts. Sun's JDO RI adopts the former design, and JDO Ri-based TJDO is also the same design. Such a design is likely to cause logic related to the StoreManager, troubleshooting and generating redundant code in PersistenceManager and StoreManager. The latter is clear. The Liberator JDO uses the latter architecture, which has not changed from JDO1 to JDO2, which proves that the architecture of Liberator JDO is excellent.

4. Detach / attach in Liberato. Detach / Attach has great superiority in the multilayer architecture of J2EE. Detach / attach is an important feature of JDO2 learning from Hibernate. But because JDO itself supports Persistence by Reachablity, JDO2 is able to carry out this feature. Since Hiberante does not support the default persistence by Reachbility, you need to explicitly Update each object when updating multiple associated objects of SESSION:

// in The First Session

Cat Cat = (CAT) FirstSession.Load (Cat.class, Catid);

Cat potentialmate = new cat ();

Firstsession.save (potentialmate);

// in a higher tier of the application

Cat.SetMate (PotentialMate);

// Later, in a new session

SecondSession.Update (cat); // update cat

SecondSession.Update (Mate); // Update Mate

In jdo

/

Cat cat = (cat) firstpm.getObjectByid (Cat.class, Catid);

Cat potentialmate = new cat ();

Firstpm.makepersistent (potentialmate);

Cat.SetMate (PotentialMate);

Secondpm.attach (cat); // Update Cat and PotentialMate

Persistence by Reachabilty In a slightly complex relationship, whether it is PERSIST, DETTACH or ATTACH can reduce programmers' workload and programming complexity. 5. JDO2 not only learns many of the advantages of Hiberante, but also learns the advantages of SQL Mapping like Ibatas, which can be said to be a bit set. A very similar SQL mapping feature is also available in JDO2. Users can directly define SQL and mapping results objects directly in the mapping file. JDO2 can not only make static SQL mapping, but also dynamically SQL mapping, that is, write SQL and mapping objects in the code.

Query Query = PM.NewQuery ("javax.jdo.query.sql", "select id, name from person where id = 2");

Query.SetClass (Person.class);

Such DBA can be able to optimize SQL (which can be a very complex SQL), and perform such SQL directly in JDO, while using the benefits of Project, this receives one / multiple Result objects (rather than usually JDBC's ResultSet). Since JDO's Query Interface takes into account extensions, we can easily support a variety of unused query languages, such as SQL, JDOQL, and even QL of Hibernate's HQL and EJB 3.

6. Dynamic Fetch Group. Dynamic FECTCH Group allows users to change the delayed load plan of the PO object Field (Fetch Plan) in the run. For example, in the O / R mapping application, there are often some big tables. For example, one device list has up to 30 attributes, we need to first be a brief list, just need to display a few attributes in the brief list, and All information is required in the detailed page. In this case, dynamically change the delay load loading of each Field of the Device object to improve the efficiency of display, avoid unnecessary network data transmission.

7. The workshop also develops industry-leading dynamic table mapping. In a large amount of data, multiple scales of single objects are supported, and actually specify the actual mapping table name in operation, solve the performance problem of large data query, update, deletion.

8. Liberator JDO 1.2 supports various operations and statistics for Aggregation.

9 LIBERATOR JDO can operate in two modes for each PO, one is a pure JDO mode, one is the mode of O / R mapping. JDO models can completely depend on JDO to complete the establishment and maintenance of the database table. This is extremely simple in mapping.

Public class account {

Private string dimstname;

PRIVATE STRING LASTNAME;

PRIVATE STRING Password;

PRIVATE STRING EMAIL;

/ **

......

}

Her mapping can be:

Saving JDO mode can not consider mapping issues, it is suitable for rapid development of prototypes or small projects. The O / R mapping mode is suitable for use in a larger item. 10 LIBERATOR JDO supports Eager Fetching in all versions. Eager fectching is loaded with related properties or associated objects that may be loaded, reducing SQL, executing the number of SQL. Among some similar products abroad, similar features are additional to advanced features.

The new features of the official version of the Liberator PE 1.2 include:

Fully support JSR-243 standards. Support aggregation / projection. Support SQL MApping, you can define, execute and projection mapping, and execute. Use Eager Fectching, Bulk Load database access policies to avoid N 1 problem. The leading dynamic table name map. In a large amount of data, multiple scales of single objects are supported, and actually specify the actual mapping table name in operation, solve the performance problem of large data query, update, deletion. Support SimpleIdentity. When the table is used to customize the primary key and only one primary key, SimpleIdentity is automatically adopted, the user simplifies the development of the Identity Class object. Allow users to use standard syntax to define the column type of object properties, support standard O / R mapping mapping, can map one-to-one, one-to -man, man-to-one, can map MAP and Collection. The mapping method of JSR-243 and other mainstream O / R mapping products (EJB 3 JSR-220, Hiberante, Toplink) are similar, and a large number of attributes make mapping easy to learn and easier. A multi-table mapping that supports individual objects. When mapping Java.util.map, Key and Value can be a simple Java type or a PersistenceCapable. When mapping Java.util.Collection, Element can be a simple Java type or a storage object type (PersistenceCapable). Object Reference Map When supporting Inner Join and Outer Join. Support for bulk deletion, associated batch deletion adds the Paging function of the query data set, which can define the result set of composite query conditions for a range to support all mainstream foreign databases, support the domestic database, including China Oscar, Easoft OpenBase support Damn database.

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

New Post(0)