Java Data Objects JSR000012, Version 0.8 Public Review Draft Specification Lead: Craig Russell, Sun Microsystems Inc. Lubomír Bulej
Introduction Data access: different techniques for different data types different API for each data source type Persistent storage: serialization (preserves relations, no sharing among users) JDBC (explicit management & mapping into tables) Increased productivity: data represented by native classes mappings done by EIS expert Main objectives: pluggable implementation of data stores into application servers provide Java-centric view of persistent data Java Data Objects 2
Introduction, continued Contract types: programmer / JDO vendor focused on instances of persistence capable classes JDO vendor / application server J2EE CA: instance, connection & transaction management integration of EIS using JCA Interface types: application developer oriented container provider /JDO vendor oriented Typical scenarios: managed (application server) non-managed (local storage), does not require CA Java Data Objects 3
Overview: Definitions Common interfaces JDO Instance: implements application functions, represents data in the store single or multiple data store entities (object, row, query result) implements PersistenceCapable interface JDO Implementation: classes implementing JDO contracts, provided by JDO vendor provides PersistenceManager, Query and Transaction interfaces JDO Enhancer: enhances byte-code of classes implementing application component enables transparency for loading/storing of instance fields binary compatibility between reference/compliant enhancers required Java Data Objects 4
Overview: Definitions, continued Managed Environment: Enterprise Information System (provides infrastructure) EIS Resource (EIS-specific functionality) Resource Manager (shared resources, requested by clients) Connection (connectivity to RM, [non-]transactional) Application Component (EJB, JSP, servlet) Session Beans (do not represent data, execute on behalf of client) Entity Beans (do represent data, allow shared access) Helper Objects (for use by local session/entity beans) Container (deployment/runtime support for application compoments) Non-managed Environment: does not rely on mid-tier services for security, transaction and connection JDO hides EIS specific issues (data type/relationship mapping, etc.) Java Data Objects 5
Overview: Rationale, Goals JDO Architecture Rationale: No standard architecture for persistent transactional storage JDO presents consistent view of data from existing systems Standardized data access interface to different EISes Allows for plug-n-play and extend once, exploit many times JDO Architecture Goals: store data without learning new data-access language simplify development of JDO implementations suitability for wide range of uses allow direct use of JDO implementation in non-managed environment Java Data Objects 6
JDO Architecture: Overview Non-managed JDO architecture Managed JDO architecture transparent distributed transaction, security, connection management hides contracts between application server and JDO implementation Java Data Objects 7
JDO Architecture: Usage types Two-tier usage: javax.jdo.persistencemanager query, transaction, life cycle management services javax.jdo.persistencecapable instance life cycle state interrogation Application server usage: JDO persistence manager is caching manager as defined in J2EE CA uses native or third party resource adapter native must implement system-level contracts as specified by J2EE CA PersistenceManager must implement Synchronization Resource adapter: used to connect to resource manager JDO vendor specific interface Java Data Objects 8
JDO Architecture: AS usage Pooling: persistence managers (optional, not standardized) connections to data stores (governed by CA contracts) Contracts: JDO specifies contract between components and PersistenceManager J2EE CA specifies contracts between servers and EIS connector: connection management (implemented by JDO native resource adapter) transaction management (transaction manager - connection manager) security contract Java Data Objects 9
JDO Architecture: Contracts Contracts between server and native JDO resource adapter Java Data Objects 10
JDO Architecture: Contracts Contracts between server and layered JDO implementation Java Data Objects 11
Roles and Scenarios Roles: JDO Vendor expert in technology related to specific data store, provides JDO implementation requires EIS vendor to implement J2EE Connector Architecture JDO role: synchronization adapter to connector architecture Connector Provider typically vendor of EIS or data store, must satisfy resource adapter interface Connector: separate component, supplied by JDO/EIS vendor or 3rd party Application Server Vendor provides implementation of J2EE compliant application server typically OS/middleware/database vendor role usually same as that of Container Provider Container Provider container provides components with services of managed server platform Java Data Objects 12
Roles and Scenarios, continued Application Component Provider provides application functionality JDO transparent components: typically helper classes JDO non-transparent components: direct users of JDO API Application Assembler takes jar files from application providers, produces jars with deployment descriptions Deployer configures assembled components into operating environment defines security roles, transactions and connection pooling protocols System Administrator configuration and administration of multiple containers, resource adapters, EISs... Java Data Objects 13
Roles and Scenarios, continued Scenario: Embedded calendar management system Java Data Objects 14
Roles and Scenarios, continued Scenario: Enterprise Calendar Manager Java Data Objects 15
Life Cycle of JDO Instances JDO Instance transient: no difference in behavior compared to unenhanced class persistent: tracks changes, preserves transactional integrity transitions among various states until garbage collected dirty instance - inconsistent with data store transactional transient instances (optional) persistent nontransactional instances (optional) Persistent instance environment with PersistenceManager reference to StateManager JDO State Manager maintains state changes of JDO Instance interfaces with PersistenceManager to manage data store values Java Data Objects 16
Life Cycle of JDO Instances, cont. JDO Identity extends Java concepts of identity/equality preserve application s implementation of equality ensure only one instance associated with PersistenceManager representing persistent state of data store object defines object identity different from Java object identity and application equality, represented via object id, fixed at enhancement time Application identity primary key, managed by application, enforced by data store Data store identity managed by data store, not tied to any instance values Non-data store identity managed by implementation to guarantee uniqueness in JVM only Java Data Objects 17
Life Cycle of JDO Instances, cont. Life Cycle States Data Store Transactions (required) Transient (no object id, transaction boundaries, exceptions) Persistent-new (result of makepersistent, assigned JDO identity) Persistent-dirty (changed in transaction) Hollow (data store values not present in instance) Persistent-clean Persistent-deleted (result of deletepersistent) Persistent-new-deleted (newly made, deleted in current transaction) Nontransactional (optional) Persistent-nontransactional Transactional transient (optional) Transient-clean Transient-dirty Java Data Objects 18
Life Cycle of JDO Instances, cont. JDO Instance State Transitions Java Data Objects 19
The Persistent Object Model Overview classes highly interconnected small number of instances at a time transparent data access required instances instantiated when following references Goals support all Java supported field types support all class/field modifiers allow all user-defined classes to be persistence-capable allow some system-defined classes to be persistence-capable Java Data Objects 20
The Persistent Object Model, cont. Architecture persistence capable classes (independent on inaccessible/remote objects) persistence incapable classes (java.lang, java.io, etc. unless specified) First Class Objects persistence capable classes, have identity stored in data store with associated Second Class Object only one instance representing FCO managed by the same PM Second Class Objects no JDO identity, track changes made to them & report to FCOs stored only as part of FCO, Java identity lost with FCO flush Arrays stored only as part of FCO, no JDO identity, Java identity lost with FCO flush Primitives stored only as part of FCO, no Java/data store identity Java Data Objects 21
PersistenceCapable Public interface implemented by classes managed by PersistenceManager allows JDO implementation to examine & manage instances JDO Enhancer modifies classes prior to loading into runtime adds code to implement PersistenceCapable methods recommended approach: use class JDOHelper PersistenceCapable PersistenceManager jdogetpersistencemanager(); void jdomakedirty (String fieldname); Object jdogetobjectid(); Object jdogetobjectid(); boolean jdoispersistent(); Object jdogetobjectid(); boolean jdoisdeleted(); boolean jdoisnew(); Java Data Objects 22
Instance Callbacks InstanceCallbacks interface required by classes including derived fields executed by PersistenceManager must be explicitly declared Methods void jdopostload(); initialization of non-persistent fields, not enhanced void jdoprestore(); update data store fields affected by non-persistent fields enhanced to reflect changes to persistent fields void jdopreclear(); clear non-persistent fields & associations with other instances during transition to hollow, not enhanced Java Data Objects 23
PersistenceManagerFactory PersistenceManagerFactory class implementing the interface provided by JDO vendor provides PersistenceManager constructor[s] Instantiating PM in managed environment JNDI lookup, cast to javax.jdo.persistencemanagerfactory call PMF s getpersistencemanager Instantiating PM in non-managed environment lookup + call as above construction & configuration of PersistenceManagerFactory + call direct construction of PersistenceManager (vendorspecific) ConnectionFactory in managed environment implements javax.resource Java Data Objects 24
PersistenceManager Overview primary interface for JDO aware componets methods for managing persistent instances factory for Query interface Goals no change to applications when changing vendors use in managed and non-managed environments without changes Provides cache & extent management ObjectId, JDO identity & life cycle management Query & Transaction factory interfaces Java Data Objects 25
Conclusion Topics not covered (by me) Transactions, Connections & Query Enterprise Java Beans JDO Exceptions & XML Metadata Portability guidelines JDO Reference enhancer Looks interesting and well thought out (after brief reading :) Lack of experience did not allow deeper analysis Complicated enough for the unvary to get lost Still some topics on TODO list Java Data Objects 26