Show TOC Start of Content Area

Object documentation Persistence Capable Classes  Locate the document in its SAP Library structure

Definition

According to the JDO standard, a persistence capable class is one that implements the javax.jdo.PersistenceCapable interface.

Persistence capable classes define objects that can be stored in and retrieved from the persistent data store. These objects are managed by a Persistent Manager.

Structure

Defining the Persistence Capable Classes

Typically, you create a persistence capable class by using a byte code enhancement tool (JDO Enhancer) to add an implementation of the PersistenceCapable interface to a Java class. The superclass and the subclasses of a persistence capable class are not necessarily persistence capable.

The persistence capable class defines persistent fields. If a relational database is used, as in the SAP implementation, the persistent fields represent columns of the database table used for storing the data for the relevant object. The persistent fields can hold references to the following types:

·        Primitive types – the value of the persistent fields can be boolean, byte, short, int, long, char, float, and double.

·        Immutable object classes – the persistent fields may contain reference instances of immutable object classes, such as the ones from the java.lang package (Boolean, Character, Byte, Short, Integer, Long, Float, Double, and String), java.util.Locale, java.math.BigDecimal and java.math.BigInteger.

·        Mutable object classes – the persistent fields may refer instances of classes from the java.util package, such as Date, HashSet, ArrayList, and so on.

·        Persistence capable classes

·        Collection and other interface types

·        Arrays

In addition to the persistent fields, a persistence capable class is also required to define a no-args constructor. It is used by the JDO implementation at runtime to create empty instances of the class before retrieving the data from the data store.

Neither the persistent fields, nor the no-arg constructor are required to be declared public. They should only be reachable by the subclasses of the persistence capable class (if any).

See also:

Defining the Persistence Capable Classes

 

Defining the Object Identity

The JDO identity guarantees that there is a single JDO instance associated to a PersistenceManager that represents a particular data store object.

The JDO standard defines three types of identity:

·        Application identity – the JDO identity is managed by the application and enforced by the data store. The instance’s identity is often its primary key – that is, a persistent field value defines the identity.

·        Data store identity – the data store manages the object identity, which is not associated to the instance’s field values.

·        Nondurable identity – this type of object identity is managed by the JDO implementation and does not guarantee uniqueness in the data store but in the JVM only.

The type of identity is set as a property of the persistence capable class at enhancement time.

The SAP JDO implementation supports application identity only. Therefore, it requires an internal object ID public static class to be implemented in the persistence capable class as well. The ID class corresponds to the primary key field of the JDO instance. During the enhancement the object ID class is compiled into a separate class file.

See also:

Defining the Object Identity Classes

 

FCO and SCO

The JDO standard introduces the concept of first-class objects (FCOs) and second-class objects (SCOs).

The FCOs are the instances of the persistence capable classes. They are user-defined and are stored in the data store.

The SCOs are referenced by the FCOs and usually exist as a part of the latter. They represent a particular instance stored in the data store, which is either a user-defined persistence capable class, or a system-defined supported classes. Each FCO creates its own representation of a referenced instance in the database. The SCOs are made persistent by reachability.

Integration

If you have chosen to not implement the PersistenceCapable interface yourself, you have to enhance the class using the JDO Enhancer. To do this, you also have to provide the JDO metadata.

 

 

End of Content Area