public interface Persistable
This interface defines methods that allow the implementation to manage the instances. It also defines methods that allow a DataNucleus aware application to examine the runtime state of instances. For example, an application can discover whether the instance is persistent, transactional, dirty, new, deleted, or detached; and to get its associated ExecutionContext, object identity, and version if it has one.
The Persistable interface is designed to avoid name conflicts in the scope of user-defined classes. All of its declared method names are prefixed with 'dn'.
Modifier and Type | Interface and Description |
---|---|
static interface |
Persistable.ObjectIdFieldConsumer
This interface is used to store fields from the Object id instance.
|
static interface |
Persistable.ObjectIdFieldManager
This interface is a convenience interface that allows an instance to implement both
ObjectIdFieldSupplier and ObjectIdFieldConsumer . |
static interface |
Persistable.ObjectIdFieldSupplier
This interface is used to provide fields to the Object id instance.
|
Modifier and Type | Field and Description |
---|---|
static byte |
CHECK_READ
dnFieldFlags for a field includes CHECK_READ, then the field has been enhanced to call the StateManager on read if the dnFlags setting is not READ_OK or READ_WRITE_OK
|
static byte |
CHECK_WRITE
dnFieldFlags for a field includes CHECK_WRITE, then the field has been enhanced to call the StateManager on write if the dnFlags setting is not READ_WRITE_OK
|
static byte |
LOAD_REQUIRED
dnFlags == LOAD_REQUIRED, then the fields in the default fetch group cannot be accessed for read or write without notifying the StateManager.
|
static byte |
MEDIATE_READ
dnFieldFlags for a field includes MEDIATE_READ, then the field has been enhanced to always call the StateManager on all reads
|
static byte |
MEDIATE_WRITE
dnFieldFlags for a field includes MEDIATE_WRITE, then the field has been enhanced to always call the StateManager on all writes
|
static byte |
READ_OK
dnFlags == READ_OK, then the fields in the default fetch group can be accessed for read without notifying the StateManager
|
static byte |
READ_WRITE_OK
dnFlags == READ_WRITE_OK, then the fields in the default fetch group can be accessed for read or write without notifying the StateManager.
|
static byte |
SERIALIZABLE
dnFieldFlags for a field includes SERIALIZABLE, then the field is not declared as TRANSIENT.
|
Modifier and Type | Method and Description |
---|---|
void |
dnCopyFields(Object other,
int[] fieldNumbers)
Copy field values from another instance of the same class to this instance.
|
void |
dnCopyKeyFieldsFromObjectId(Persistable.ObjectIdFieldConsumer fm,
Object oid)
Copy fields to an outside consumer from the key fields in the ObjectId.
|
void |
dnCopyKeyFieldsToObjectId(Object oid)
Copy fields from this Persistable instance to the Object Id instance.
|
void |
dnCopyKeyFieldsToObjectId(Persistable.ObjectIdFieldSupplier fm,
Object oid)
Copy fields from an outside source to the key fields in the ObjectId.
|
ExecutionContextReference |
dnGetExecutionContext()
Return the associated ExecutionContext if there is one.
|
Object |
dnGetObjectId()
Return a copy of the identity associated with this instance.
|
Object |
dnGetTransactionalObjectId()
Return a copy of the identity associated with this instance.
|
Object |
dnGetVersion()
Return the version of this instance.
|
boolean |
dnIsDeleted()
Tests whether this object has been deleted.
|
boolean |
dnIsDetached()
Tests whether this object has been detached.
|
boolean |
dnIsDirty()
Tests whether this object is dirty.
|
boolean |
dnIsNew()
Tests whether this object has been newly made persistent.
|
boolean |
dnIsPersistent()
Tests whether this object is persistent.
|
boolean |
dnIsTransactional()
Tests whether this object is transactional.
|
void |
dnMakeDirty(String fieldName)
Explicitly mark this instance and this field dirty.
|
Persistable |
dnNewInstance(StateManager sm)
Return a new instance of this class, with the StateManager set to the parameter, and dnFlags set to LOAD_REQUIRED.
|
Persistable |
dnNewInstance(StateManager sm,
Object oid)
Return a new instance of this class, with the StateManager set to the parameter, key fields
initialized to the values in the oid, and dnFlags set to LOAD_REQUIRED.
|
Object |
dnNewObjectIdInstance()
Create a new instance of the ObjectId class for this Persistable class and initialize the key
fields from the instance on which this method is called.
|
Object |
dnNewObjectIdInstance(Object o)
Create a new instance of the class used for identity, using the key constructor of the object id
class.
|
void |
dnProvideField(int fieldNumber)
The owning StateManager uses this method to ask the instance to provide the value of the single field identified by fieldNumber.
|
void |
dnProvideFields(int[] fieldNumbers)
The owning StateManager uses this method to ask the instance to provide the values of the multiple fields identified by fieldNumbers.
|
void |
dnReplaceField(int fieldNumber)
The owning StateManager uses this method to ask the instance to replace the value of the single field identified by number.
|
void |
dnReplaceFields(int[] fieldNumbers)
The owning StateManager uses this method to ask the instance to replace the values of the multiple fields identified by number.
|
void |
dnReplaceFlags()
The owning StateManager uses this method to ask the instance to replace the value of the flags by
calling back the StateManager replacingFlags method.
|
void |
dnReplaceStateManager(StateManager sm)
This method sets the StateManager instance that manages the state of this instance.
|
static final byte READ_WRITE_OK
static final byte LOAD_REQUIRED
static final byte READ_OK
static final byte CHECK_READ
static final byte MEDIATE_READ
static final byte CHECK_WRITE
static final byte MEDIATE_WRITE
static final byte SERIALIZABLE
ExecutionContextReference dnGetExecutionContext()
void dnReplaceStateManager(StateManager sm) throws SecurityException
sm
- The StateManager which will own this instance, or null to reset the instance to transient stateSecurityException
- if the caller does not have JDOPermissionvoid dnProvideField(int fieldNumber)
fieldNumber
- the field whose value is to be provided by a callback to the StateManager's providedXXXField methodvoid dnProvideFields(int[] fieldNumbers)
fieldNumbers
- the fields whose values are to be provided by multiple callbacks to the StateManager's providedXXXField methodvoid dnReplaceField(int fieldNumber)
fieldNumber
- the field whose value is to be replaced by a callback to the StateManager's replacingXXXField methodvoid dnReplaceFields(int[] fieldNumbers)
fieldNumbers
- the fields whose values are to be replaced by multiple callbacks to the StateManager's replacingXXXField methodvoid dnReplaceFlags()
void dnCopyFields(Object other, int[] fieldNumbers)
This method will throw an exception if the other instance is not managed by the same StateManager as this instance.
other
- the PC instance from which field values are to be copiedfieldNumbers
- the field numbers to be copied into this instancevoid dnMakeDirty(String fieldName)
The field name should be the fully qualified name, including package name and class name of the class declaring the field. This allows unambiguous identification of the field to be marked dirty. If multiple classes declare the same field, and if the package and class name are not provided by the parameter in this API, then the field marked dirty is the field declared by the most derived class.
Transient instances ignore this method.
fieldName
- the name of the field to be marked dirty.Object dnGetObjectId()
Persistent instances of Persistable classes have an identity managed by the ExecutionContext. This method returns a copy of the ObjectId that represents the identity.
Transient instances return null.
The ObjectId may be serialized and later restored, and used with a ExecutionContext from the same DataNucleus instance to locate a persistent instance with the same data store identity.
If the identity is managed by the application, then the ObjectId may be used with a ExecutionContext from DataNucleus that supports the Persistable class.
If the identity is not managed by the application or the data store, then the ObjectId returned is only valid within the current transaction.
If the identity is being changed in the transaction, this method returns the object id as of the beginning of the current transaction.
Object dnGetTransactionalObjectId()
If the identity is being changed in the transaction, this method returns the current object id as modified in the current transaction.
dnGetObjectId()
Object dnGetVersion()
boolean dnIsDirty()
Transient instances return false.
boolean dnIsTransactional()
boolean dnIsPersistent()
boolean dnIsNew()
boolean dnIsDeleted()
boolean dnIsDetached()
Persistable dnNewInstance(StateManager sm)
This method is used as a performance optimization as an alternative to using reflection to construct a new instance. It is used by the JDOImplHelper class method newInstance.
sm
- the StateManager that will own the new instance.Persistable dnNewInstance(StateManager sm, Object oid)
This method is used as a performance optimization as an alternative to using reflection to construct a new instance of a class that uses application identity. It is used by the JDOImplHelper class method newInstance.
sm
- the StateManager that will own the new instance.oid
- an instance of the object id class (application identity).Object dnNewObjectIdInstance()
For classes using single field identity, this method must be called on an instance of a persistence-capable class with its primary key field initialized (not null), or an exception is thrown.
The instance returned is initialized with the value(s) of the primary key field(s) of the instance on which the method is called.
Object dnNewObjectIdInstance(Object o)
For classes that use single field identity, if the parameter is of one of the following types, the behavior must be as specified:
Number
or Character
: the parameter must be the single field type or the
wrapper class of the primitive field type; the parameter is passed to the single field identity
constructorObjectIdFieldSupplier
: the field value is fetched from the
ObjectIdFieldSupplier
and passed to the single field identity constructorString
: the String is passed to the single field identity constructoro
- the object identity constructor parametervoid dnCopyKeyFieldsToObjectId(Object oid)
JDOUserException
.oid
- the ObjectId target of the key fieldsvoid dnCopyKeyFieldsToObjectId(Persistable.ObjectIdFieldSupplier fm, Object oid)
Persistable
class to generate a call to the field manager for each key field in the
ObjectId. For example, an ObjectId class that has three key fields (int id,
String name, and Float salary)
would have the method generated:
void dnCopyKeyFieldsToObjectId(ObjectIdFieldSupplier fm, Object objectId)
{
EmployeeKey oid = (EmployeeKey)objectId;
oid.id = fm.fetchIntField (0);
oid.name = fm.fetchStringField (1);
oid.salary = fm.fetchObjectField (2);
}
The implementation is responsible for implementing the ObjectIdFieldSupplier
to produce
the values for the key fields.
For classes using single field identity, this method always throws JDOUserException
.
oid
- the ObjectId target of the copy.fm
- the field supplier that supplies the field values.void dnCopyKeyFieldsFromObjectId(Persistable.ObjectIdFieldConsumer fm, Object oid)
Persistable
class to generate a call to the field manager for each key field in the
ObjectId. For example, an ObjectId class that has three key fields (int id,
String name, and Float salary)
would have the method generated:
void copyKeyFieldsFromObjectId(ObjectIdFieldConsumer fm, Object objectId)
{
EmployeeKey oid = (EmployeeKey)objectId;
fm.storeIntField (0, oid.id);
fm.storeStringField (1, oid.name);
fm.storeObjectField (2, oid.salary);
}
The implementation is responsible for implementing the ObjectIdFieldConsumer
to store the
values for the key fields.
oid
- the ObjectId source of the copy.fm
- the field manager that receives the field values.Copyright © 2018. All rights reserved.