Select JDO or CMP?

Source: Internet
Author: User
Tags inheritance object model
Select JDO or CMP.

Translated from Sun Bin to http://www.onjava.com/pub/a/onjava/2003/05/21/jdo.html

Author: David Jordan and Craig Russell
The book "Java Data Objects"
May 21, 2003

The authors note: The JDO and CMP-style ejbs are moving forward at the same time, but taking different routes. JDO's core idea is to store traditional Java objects (Plain old Java Objects, hereinafter called POJOs) at different levels of the enterprise application architecture, while the CMP solution is based on the container environment and specific requirements.

The similarities and differences between the two have become the subject of controversy at the beginning of the regulation. You can see this kind of controversy on the jdocentral.com, and there will be demonstrations and explanations to compare the two different technologies at the 2003 JavaOne conference, which will be opened in San Francisco in mid-June.

At this JavaOne conference, the technical dialogue No. 3368 will discuss the feasibility and practical experience of JDO and struts (open source software for a well-known Web application architecture design); No. 3236 Special research on the combination of JDO and EJB container; 1289th Topics will compare the use of JDO, The application of design patterns in the development of JDBC and EJB.

In our 17th chapter of Java Data Objects, a short paragraph describes the use of JDO and CMP balance points. --craig Russell

JDO or CMP.

CMP entity beans and JDO are the ways to consider before you decide on a project development strategy.

JDO is suitable for coarse-grained and fine-grained data object design, specifically in an application server environment, typically used behind Sessionbean. When CMP is used for Sessionbean, its remote calls are rarely used directly.

JDO-written classes are only compiled once and can be used in any tier of the distributed architecture, and can be debugged in a single or two-tier manner before being integrated into the Web or application server. CMP can only be debugged after it has been published to a specific application server.

JDO does not directly define remote behavior, which is different from servlet, JSP, and EJB components. All distributed processing, transaction, and security policies are based on isolated Storage manager, which handles all class instances in your object model. This also means that you can use JDO at any level in a distributed environment, and that its remote behavior is implemented by the container, not by the JDO vendor.

The CMP component provides a high degree of portability, and the Bean class and its descriptors are normalized. Most incompatibilities exist only where the specification fails, including how to map a class to a specific database (not limited to a relational database), optional features similar to read-only classes, and vendor extensions for other aspects. JDO products differ depending on the optional features supported by the specific vendor.

In CMP, the relationships between objects are controlled, meaning that one end change affects the other and is visible to the application. JDO does not support the management of relationships, but some vendors provide similar functionality in an extended manner.

Inheritance is a common concept when modeling real objects, but CMP does not support it. CMP is inconsistent in the definition and implementation of a component, and when implementing a Entitybean interface, the implemented class can have an inheritance relationship, but not when defining this entitybean. The relationships between classes are also just between interfaces, not between implementation classes, so there is no polymorphism in these relationships. For example, a CMP bean class named Mediaitem cannot directly contact a class named Mediacontent because Mediacontent is abstract and there are no concrete instances of the class. To establish such a connection, you can only convert it to two relationships: one is Mediaitem and movie, one is Modiaitem and game, and in each of the related methods, you have to discriminate against two relationships.

CMP and JDO are also poorly accessed on object properties. In a CMP bean, all property and object relationships are defined as abstract get and set methods in descriptors, and access to actual properties can only be done by specific implementation classes generated by the relevant tools. In Jdo, the properties and relationships that can be saved are declared in the descriptor and can be accessed directly from the code, including the code generated by the JDO product. The JDO intensifier will appropriately transform the code when it is enhanced.

Both JDOQL and EJBQL provide similar methods for querying data. Both can query and access data objects in the program, all take the "read-change-write" strategy, are not complete data manipulation language (such as no data update statements), they are only used to find data objects and access in code.

CMP requires that all access operations are in a transactional environment, and that non transactional access is not supported. JDO allows you to decide whether to adopt a transactional approach. For places where data needs to be updated, JDO requires transactions, but only read code, including buffering, that JDO supports non transactional access.

Table 17-1 is a comparison of the CMP bean and JDO storage classes

table 17-1 CMP beans comparison with jdo

characteristic CMP Beans JDO can store classes
Environmental aspects
Application portability Basic can, few negative effects The principle of the definition of the code can be transplanted
Application environment Application Server Single-tier, two-tier, Web server, Application server
The independence of the storage class relative to the environment Low: The class must implement the EJB interface and execute in the EJB container High: Classes do not need to implement any specific interfaces and can be executed in any environment
Meta data (metadata)
To mark a storage class Publish descriptor to indicate all storage classes Meta data identifies all storage classes
To mark a stored property The publication descriptor marks all the stored properties and relationships Most of the default storage properties and relationships in metadata (concise)
Modeling
Modeling objects for domain classes CMP beans (abstract underlying database) can store class
Inheritance between domain classes does not support Full support
Property access The Get/set method of abstraction Access in any way, including direct access and Get/set methods
Collection, Set Support Support
List, Array, Map does not support Optional features
Relationship As a reference to the CMP local interface As a reference to the JDO storage class or interface
Polymorphism does not support Support
Programming
Query Language SQL-like EJBQL JDOQL based on Java Boolean judgment
Remote method call Support does not support
Life-cycle management requirements for class methods

Setentitycontext
Unsetentitycontext
Ejbactivate
Ejbpassivate
Ejbload
Ejbstore
Ejbremove

Non-parametric constructor (can be private)
Optional callback method Ejbcreate
Ejbpostcreate
Ejbfind
Jdopostload
Jdoprestore
Jdopreclear
Jdopredelete
relational database Mapping Vendor-related Vendor-related
Method Security Policy Support does not support
Transaction policy for a method Support does not support
Non-transactional access Non-standard Support
Required Classes/Interfaces

Ejblocalhome, local interface (if local access is supported)

EJBHome, remote interface (if remote access is supported)

Abstract class must implement Entitybean

Identifies the class (if not the original type)

can store class

Identity class (for custom identities only)

Transaction Synchronization Callback does not support Support

David Jordan created Object Identity, Inc., which provides consulting and training services for Java Data Objects (JDO). David is also one of the authors of the Java Data Objects, and the other author is Craig Russell.

Craig Russell is the JDO specification leader of the Sun Microsystems Company.

O ' Reilly and his association published the Java Data Objects recently (April 2003). Chapter One overview, free download You can also view the book's catalog, index and full description of the above two parts of the Chinese version: CSDN version, or Javaresearch version (by Sun Bin translation) more information or buy the book, please see here.

The copyright of this article belongs to the author, but welcome to reprint, the premise is to indicate the source and original author. In addition, you are welcome to view my other articles in my column and make valuable comments.

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.