Show TOC Start of Content Area

Function documentation JDO Life Cycle and State Transitions  Locate the document in its SAP Library structure

Use

The JDO standard introduces the concept of object life cycle, which enables the manageability of the JDO instances and ensures persistent data consistency and integrity. The state transitions allow for the efficient usage of the JDO instances. In addition, the JDO life cycle contract enables the co-existence of several PersistenceManagers sharing the same persistence capable classes, although a JDO instance can be associated to a single PM at a time.

Features

JDO States

Generally, the JDO instances can be either transient or persistent. Persistent objects are linked to the transactional data store and require specific management by the JDO implementation. The support for transient transactional object management is optional.

The JDO standard defines the following JDO states:

·        Transient – an instance of a persistence capable class created using the “new” operator is transient. It is not associated with a persistent object in the data store, has no object identity, and is not influenced by transactional calls. If not declared transactional, its behavior does not differ much from the one of an unenhanced class instance.

·        Persistent-new – a transient instance transitions to the persistent-new state when the PersistentManager.makePersistent() method is invoked. An object identity is assigned to the instance, and all objects reachable from the persistent fields are made provisionally persistent-new.

·        Persistent-new-deleted – if you delete a persistent-new object using PersistentManager.deletePersistent() method, the instance transitions to persistent-new-deleted state. It can be changed only upon transaction termination, and in this case the instance becomes transient.

·        Persistent-clean – this is an instance that holds data that has not yet been modified during the current transaction.

·        Persistent-dirty – an instance typically transitions from persistent-clean to persistent-dirty state when the data it holds has been modified in the current transaction. Restoring the initial values does not bring the instance back into persistent-clean state.

·        Persistent-deleted – after an invocation of the PersistenceManager.deletePersistent() method on a persistent instance, it becomes persistent-deleted. The deletion can only be undone if the transaction is rolled back. The transaction termination turns the persistent-deleted instance into transient.

·        Hollow – this is a JDO instance that represents specific persistent data in the data store, but the values of the fields have not been loaded into the instance. The hollow instances have JDO identity. However, if the application does not maintain a strong reference to them, they can be garbage-collected. The hollow state is actually invisible to the applications. It is used to ensure the uniqueness of the object between transactions.

·        Persistent-nontransactional (optional) – an instance that represents persistent data in the data store, whose values are loaded but are not transactionally consistent, is persistent-nontransactional. The application may change the values of the data in the instance but this does not affect the state of the instance unless it is made transactional.

·        Transient-clean (optional) – a transient instance transitions to the transient-clean state when a reference to the instance is passed as argument to the PersistenceManager’s makeTransient() method. An instance in the state transient-clean is transaction and has not yet been changed in the current transaction.

·        Transient-dirty (optional) – when a managed field of a transient-clean instance is modified, the instance transitions to the transient-dirty state.

The SAP JDO implementation supports the three optional states.

State Transitions

A transition to particular states may be invoked by the application itself, or may be the result of a transaction start or termination. In managed environments, such as the J2EE Engine, external to the JDO implementation transaction controllers typically invoke the state transitions.

Some operations can directly change the state of a JDO instance, while others, such as read and write operations, indirectly lead to state transitions. The following operations change the state of the JDO instances:

·        makePersistent()

·        makeTransient()

·        makeTransactional()

·        makeNontransactional()

·        deletePersistent()

·        evict()

·        refresh()

·        retrieve()

·        reload()

·        commit()/rollback()

·        readField()/writeField()

·        makeDirty()

For more information about the transitions that occur as a result of these operations, see JDO State Transitions.

Activities

Finding Out the Instance State

The application can obtain information about the state of the JDO instances using the javax.jdo.JDOHelper class. It provides the following methods for checking the state of the instances:

·        isDeleted()

·        isDirty()

·        isNew()

·        isPersistent()

·        isTransactional()

For more information about the return values of the methods for each life cycle state, see JDO State Checks.

 

End of Content Area