Class StateManagerImpl
- All Implemented Interfaces:
StateManager, DNStateManager<Persistable>
- Direct Known Subclasses:
ReferentialStateManagerImpl
Embedded/Serialised Objects
An object that is being embedded/serialised in an owning object will NOT have an identity unless the object is subject to a makePersistent() call also. When an object is embedded/serialised and a field is changed, the field will NOT be marked as dirty (unless it is also an object in its own right with an identity). When a field is changed any owning objects are updated so that they can update their tables accordingly.Performance and Memory
StateManagers are very performance-critical, because for each Persistable object made persistent, there will be one StateManager instance, adding up to the total memory footprint of that object. In heap profiling analysis (cerca 2008), StateManagerImpl showed to consume bytes 169 per StateManager by itself and about 500 bytes per StateManager when taking PC-individual child-object (like the id) referred by the StateManager into account. With small Java objects this can mean a substantial memory overhead and for applications using such small objects can be critical. For this reason the StateManager should always be minimal in memory consumption. Any fields that are only present for some cases should, in general, either be offloaded to the ExecutionContext, or to a separate object if multiple fields. The fields loadedFields and dirtyFields could, arguably, be made BitSet but it isn't clear of the benefit in the typical use-case of smaller array sizes (number of fields in a class), as per https://www.baeldung.com/java-boolean-array-bitset-performanceCommit/Rollback
When the managed object is changed it is saved as savedPC and its state as savedPersistenceFlags and savedLoadedFields. These fields allow it to be rolled-back to an earlier state. Refer to the saveFields and restoreFields methods.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AbstractClassMetaDatathe metadata for the class.protected FieldManagerCurrent FieldManager.protected booleanIndicator for whether the persistable instance is dirty.protected boolean[]indicators for which fields are currently dirty in the persistable instance.protected static final intFlag forflagswhether we are in the process of attaching the object.protected static final intprotected static final intprotected static final intWhether we are in the process of DELETING the object from persistence.protected static final intFlag forflagswhether we are in the process of detaching the object.protected static final intFlag forflagswhether we are in the process of disconnecting the object.protected static final intWhether we are managing an embedded object.protected static final intif the persistable object is new and was flushed to the datastore.protected static final intFlag forflagswhether we are in the process of flushing changes to the object.protected static final intWhether we are in the process of INSERTING the object to persistence.protected static final intWhether we are in the process of INSERTING the object from persistence, running callbacks.protected static final intprotected static final intFlag forflagswhether we are in the process of making transient the object.protected static final intWhether the managed object needs the inheritance level validating before loading fields.protected static final intprotected static final intprotected static final intFlag forflagswhether we are resetting the detached state.protected static final intWhether to restore values at StateManager.protected static final intFlag forflagswhether we are retrieving detached state from the detached object.protected static final intFlag to signify that we are currently storing the persistable object, so we don't detach it on serialisation.protected static final intFlag whether this SM is updating the ownership of its embedded/serialised field(s).protected static final intWhether we are currently validating the object in the datastore.protected intBit-packed flags for operational settings (packed into "int" for memory benefit).private static final EnhancementHelperprotected static final SingleTypeFieldManagerprotected boolean[]indicators for which fields are currently loaded in the persistable instance.protected ExecutionContextThe ExecutionContext for this StateManagerprotected FetchPlanForClassFetch plan for the class of the managed object.protected ObjectThe object identity in the datastoreprotected ObjectThe object identity in the JVM.protected LifeCycleStateThe actual LifeCycleState for the persistable instanceprotected PersistableThe persistable instance managed by this StateManager.protected ObjectOptimistic version, when starting any transaction.protected byteFlags for state stored with the object.(package private) boolean[]Copy of the "loadedFields" just before delete was started to avoid reload during deleteprotected SavedStateSaved state, for use during any rollback for reinstating the object.protected ObjectOptimistic version, after insert/update but not yet committed (i.e incremented).Fields inherited from interface DNStateManager
MEMBER_VALUE_STORED_PREFIX, ORIGINAL_FIELD_VALUE_KEY_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for object of specified type managed by the provided ExecutionContext. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanareFieldsLoaded(int[] fieldNumbers) Accessor for whether all of the specified field numbers are loaded.voidattach(boolean embedded) Method to attach the object managed by this StateManager.voidattach(Persistable detachedPC) Method to attach the provided detached object into the managed instance.attachCopy(Persistable detachedPC, boolean embedded) Method to attach a copy of the detached persistable instance and return the (attached) copy.booleanWhether this object is moving to a deleted state.voidDeprecated.Dont use this, to be removedprotected voidMethod to clear all dirty flags on the object.protected voidclearDirtyFlags(int[] fieldNumbers) Method to clear all dirty flags on the object.voidMethod to clear all fields of the object.protected voidclearFieldsByNumbers(int[] fieldNumbers) voidMethod to clear all loaded flags on the object.voidMethod to clear all fields that are not part of the primary key of the object.voidMethod to clear all saved fields on the object.voidconnect(ExecutionContext ec, AbstractClassMetaData cmd) Method to (re)connect this StateManager to the specified ExecutionContext and object type.booleanAccessor for whether the specified associated value key is present.private static StringconvertPCToString(Object pc, AbstractClassMetaData cmd) Method to convert the persistable object into String form.voidMethod to delete the object from persistence.voiddetach(FetchPlanState state) Method to detach this object.detachCopy(FetchPlanState state) Method to make detached copy of this instance If the object is detachable then the copy will be migrated to DETACHED state, otherwise will migrate the copy to TRANSIENT.voidDisconnect from the ExecutionContext and persistable object.protected booleanMethod to disconnect any cloned persistence capable objects from their StateManager.voidMethod to enlist the managed object in the current transaction.voidevict()Method to change the object state to evicted.voidMethod to evict the managed object from the current transaction.voidflush()Flushes any outstanding changes to the object to the datastore.booleanReturns whether all fields are loaded.getAssociatedValue(Object key) Accessor for the value of an external field.protected CallbackHandlerAccessor for the ClassMetaData for this persistable object.String[]Convenience accessor for the names of the fields that are dirty.int[]Accessor for the field numbers of all dirty fields.boolean[]Creates a copy of thedirtyFieldsbitmap.Return theExecutionContextthat owns this instance.Return an object id that the user can use.Accessor for the FetchPlan for this class.protected int[]getFieldNumbersOfLoadedOrDirtyFields(boolean[] loadedFields, boolean[] dirtyFields) Convenience accessor to return the field numbers for the input loaded and dirty field arrays.private int[]Return an array of field numbers that must be included in the detached objectAccessor for the internal object id of the object we are managing.Accessor for the LifeCycleState of this persistable object.String[]Convenience accessor for the names of the fields that are loaded.int[]Accessor for the field numbers of all loaded fields in this managed instance.boolean[]Accessor for the fieldsAccessor for the persistable object being managed.Returns a printable form of the managed object.Return the object representing the persistent identity of the calling instance.Accessor for the referenced PC object when we are attaching or detaching.Return the object representing the persistent identity of the calling instance.Return the transactional version of the managed object.Return the object representing the transactional version of the calling instance.Method to return the current version of the managed object.Return the object representing the version of the calling instance.voidinitialiseForCachedPC(CachedPC cachedPC, Object id) Initialise StateManager, assigning the specified id to the object.voidinitialiseForDetached(Persistable pc, Object id, Object version) Initialises the StateManager to manage a Persistable object in detached state.voidinitialiseForEmbedded(Class<Persistable> pcClass) Initialises a state manager to manage an embedded instance of the specified type.voidinitialiseForEmbedded(Persistable pc, boolean copyPc) Initialises a state manager to manage a provided Persistable instance that will be EMBEDDED/SERIALISED into another Persistable object.voidinitialiseForHollow(Object id, FieldValues fv, Class pcClass) Initialises a state manager to manage a hollow instance having the given object ID and the given (optional) field values.voidinitialiseForHollowAppId(FieldValues fv, Class pcClass) Deprecated.Remove use of this and use initialiseForHollowvoidInitialises a state manager to manage the given hollow instance having the given object ID.voidInitialises a state manager to manage the passed persistent instance having the given object ID.voidinitialiseForPersistentNew(Persistable pc, FieldValues preInsertChanges) Initialises a state manager to manage a transient instance that is becoming newly persistent.voidInitialises the StateManager to manage a Persistable object that is not persistent but is about to be deleted.voidInitialises a state manager to manage a Transactional Transient instance.private voidinternalAttachCopy(DNStateManager detachedSM, boolean[] loadedFields, boolean[] dirtyFields, boolean persistent, Object version, boolean cascade) Attach the fields for this object using the provided detached object.protected voidMethod to delete the object from the datastore.private voidMethod to persist the object to the datastore.booleanprotected booleanbooleanbooleanTests whether this object has been deleted.booleanisDeleted(Persistable pc) Tests whether this object has been deleted.booleanTests whether this object is being deleted.booleanTests whether this object is in the process of being detached.booleanisDirty(Persistable pc) Tests whether this object is dirty.booleanConvenience accessor for whether this StateManager manages an embedded/serialised object.booleanisFieldLoaded(int fieldNumber) Accessor for whether a field is currently loaded.booleanWhether this record has been flushed to the datastore in this transaction (i.e called persist() and is in the datastore now).booleanAccessor for whether all changes have been written to the datastore.protected booleanbooleanTests whether this object is being inserted.booleanisLoaded(int fieldNumber) Returns the loaded setting for the field of the managed object.booleanisLoaded(Persistable pc, int fieldNumber) Return true if the field is cached in the calling instance; in this implementation we always return true.booleanisNew(Persistable pc) Tests whether this object has been newly made persistent.booleanTests whether this object is persistent.protected booleanbooleanAccessor for whether we are in the process of restoring the values.protected booleanbooleanTests whether this object is transactional.booleanMethod to return if the version is loaded.booleanAccessor for whether the instance is newly persistent yet hasnt yet been flushed to the datastore.voidloadField(int fieldNumber) Convenience method to load the specified field if not loaded.voidloadFieldFromDatastore(int fieldNumber) Convenience method to load a field from the datastore.protected voidloadFieldsFromDatastore(int[] fieldNumbers) Convenience method to load fields from the datastore.protected int[]loadFieldsFromLevel2Cache(int[] fieldNumbers) Convenience method to retrieve field values from an L2 cached object if they are loaded in that object.voidMethod to load all unloaded fields in the FetchPlan.voidConvenience method to load the passed field values.protected voidloadSpecifiedFields(int[] fieldNumbers) Fetch the specified fields from the database.booleanloadStoredField(int fieldNumber) Convenience method to load the specified field from the stored associated value cache if available.voidFetch from the database all fields that are not currently loaded regardless of whether they are in the current fetch group or not.voidLoads (from the database) all unloaded fields that are in the current FetchPlan.protected voidFetch from the database all fields in current fetch plan that are not currently loaded as well as the version.voidloadUnloadedFieldsOfClassInFetchPlan(FetchPlan fetchPlan) Loads (from the database) all unloaded fields of the managed class that are in the specified FetchPlan.voidLoads (from the database) all unloaded fields that store relations.voidlocate()Locate the object in the datastore.voidlog(NucleusLogger log) Utility to dump the contents of the StateManager to the provided log.voidmakeDirty(int fieldNumber) Marks the given field dirty.voidmakeDirty(Persistable pc, String fieldName) Mark the associated persistable field dirty.voidMethod to change the object state to nontransactional.voidMethod to make the object persistent.voidMakes Transactional Transient instances persistent.voidMethod to change the object state to transactional.voidmakeTransient(FetchPlanState state) Method to change the object state to transient.voidMake the managed object transient as a result of persistence-by-reachability when run at commit time.voidMethod to notify the StateManager that the object has now been flushed to the datastore.voidmarkFieldsAsLoaded(int[] fieldNumbers) Convenience method to mark all fields as "loaded".voidMark the state manager as needing to validate the inheritance of the managed object existence before loading fields.protected voidConvenience method to mark PK fields as loaded (if using app id).protected static ObjectUtility to take a peek at a field in the persistable object.private voidConvenience method to populate all members in the PC object that need their value generating (according to metadata) and that aren't datastore-attributed.voidThis method is invoked just after a commit is performed in a Transaction involving the persistable object managed by this StateManagerprivate voidpostLoad()Called whenever the default fetch group fields have all been loaded.protected voidMethod called after a change in state.protected voidpostWriteField(boolean wasDirty) Method called after the write of a field.voidpreBegin(Transaction tx) Method invoked just before a transaction starts for the ExecutionContext managing us.voidThis method is invoked just before a rollback is performed in a Transaction involving the persistable object managed by this StateManager.voidGuarantee that the serializable transactional and persistent fields are loaded into the instance.protected voidMethod called before a change in state.protected booleanpreWriteField(int fieldNumber) Method called before a write of the specified field.voidprovidedBooleanField(Persistable ignored, int fieldNumber, boolean currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedByteField(Persistable ignored, int fieldNumber, byte currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedCharField(Persistable ignored, int fieldNumber, char currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedDoubleField(Persistable ignored, int fieldNumber, double currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedFloatField(Persistable ignored, int fieldNumber, float currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedIntField(Persistable ignored, int fieldNumber, int currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedLongField(Persistable ignored, int fieldNumber, long currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedObjectField(Persistable ignored, int fieldNumber, Object currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedShortField(Persistable ignored, int fieldNumber, short currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.voidprovidedStringField(Persistable ignored, int fieldNumber, String currentValue) This method is called from the associated persistable when its dnProvideFields() method is invoked.provideField(int fieldNumber) Method to return the current value of a particular field.protected ObjectprovideField(Persistable pc, int fieldNumber) Method to retrieve the value of a field from the PC object.voidprovideFields(int[] fieldNumbers, FieldManager fm) Called from the StoreManager after StoreManager.update() is called to obtain updated values from the Persistable associated with this StateManager.voidrefresh()Method to refresh the object.voidRefreshes from the database all fields in fetch plan.voidRefreshes from the database all fields currently loaded.voidRegisters the pc class in the cachevoidMethod to remove the associated value with the specified key (if it exists).voidMethod to replace all loaded SCO fields that have wrappers with their value.voidMethod to replace all loaded SCO fields with wrappers.voidreplaceField(int fieldNumber, Object value) Method to change the value of a particular field and not mark it dirty.protected voidreplaceField(Persistable pc, int fieldNumber, Object value) Method to change the value of a field in the PC object.protected voidreplaceField(Persistable pc, int fieldNumber, Object value, boolean makeDirty) Method to change the value of a field in the PC object.voidreplaceFieldMakeDirty(int fieldNumber, Object value) Method to change the value of a particular field and mark it dirty.voidreplaceFields(int[] fieldNumbers, FieldManager fm) Called from the StoreManager to refresh data in the Persistable object associated with this StateManager.voidreplaceFields(int[] fieldNumbers, FieldManager fm, boolean replaceWhenDirty) Called from the StoreManager to refresh data in the Persistable object associated with this StateManager.voidreplaceFieldValue(int fieldNumber, Object newValue) Convenience method to change the value of a field that is assumed loaded.voidMethod that replaces the PC managed by this StateManager to be the supplied object.voidreplaceNonLoadedFields(int[] fieldNumbers, FieldManager fm) Called from the StoreManager to refresh data in the Persistable object associated with this StateManager.protected voidUtility to update the passed object with the passed StateManager (can be null).booleanreplacingBooleanField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a boolean field.bytereplacingByteField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a byte field.charreplacingCharField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a char field.Object[]replacingDetachedState(Detachable pc, Object[] currentState) Method to update the "detached state" in the detached object to obtain the "detached state" from the detached object, or to reset it (to null).doublereplacingDoubleField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a double field.byteThe StateManager uses this method to supply the value of dnFlags to the associated persistable instance.floatreplacingFloatField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a float field.intreplacingIntField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a int field.longreplacingLongField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a long field.replacingObjectField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of an Object field.shortreplacingShortField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a short field.Replace the current value of StateManager in the Persistable object.replacingStringField(Persistable ignored, int fieldNumber) This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a String field.voidConvenience method to reset the detached state in the current object.voidMethod to restore all fields of the object.voidretrieve(boolean fgOnly) Method to retrieve the object.voidConvenience method to retrieve the detach state from the passed StateManager's object.voidMethod to save all fields of the object, for use in any rollback.voidsetAssociatedValue(Object key, Object value) Method to set an associated value stored with this object.(package private) voidsetAttaching(boolean flag) voidsetBooleanField(Persistable pc, int fieldNumber, boolean currentValue, boolean newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.voidsetByteField(Persistable pc, int fieldNumber, byte currentValue, byte newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.voidsetCharField(Persistable pc, int fieldNumber, char currentValue, char newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.(package private) voidsetDetaching(boolean flag) voidsetDoubleField(Persistable pc, int fieldNumber, double currentValue, double newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.voidsetFloatField(Persistable pc, int fieldNumber, float currentValue, float newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.voidsetFlushedNew(boolean flag) voidsetFlushing(boolean flushing) private voidsetIdentity(boolean afterPreStore) Utility to set the identity for the Persistable object.voidvoidvoidsetIntField(Persistable pc, int fieldNumber, int currentValue, int newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.voidsetLongField(Persistable pc, int fieldNumber, long currentValue, long newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.voidsetObjectField(Persistable pc, int fieldNumber, Object currentValue, Object newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.(package private) voidsetPostLoadPending(boolean flag) voidIf the id is obtained after inserting the object into the database, set new a new id for persistent classes (for example, increment).voidsetShortField(Persistable pc, int fieldNumber, short currentValue, short newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.voidMethod to set the storing PC flag.voidsetStringField(Persistable pc, int fieldNumber, String currentValue, String newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.voidsetTransactionalVersion(Object version) Sets the value for the version column in a transaction not yet committedvoidsetVersion(Object version) Sets the value for the version column in the datastorevoidstoreFieldValue(int fieldNumber, Object value) Method to store the value for the specified field.toString()protected voidtransitionReadField(boolean isLoaded) Method to change the object state to read-field.protected voidMethod to change the object state to write-field.voidunloadField(int fieldNumber) Mark the specified field as not loaded so that it will be reloaded on next access.voidMethod that will unload all fields that are not in the FetchPlan.voidMethod to unset the storing PC flag.protected voidupdateField(Persistable pc, int fieldNumber, Object value) Convenience method to perform the update of a field value when a setter is invoked.voidupdateFieldAfterInsert(Object pc, int fieldNumber) Marks the given field dirty for issuing an update after the insert.protected voidupdateLevel2CacheForFields(int[] fieldNumbers) Convenience method to update a Level2 cached version of this object if cacheable and has not been modified during this transaction.voidupdateOwnerFieldInEmbeddedField(int fieldNumber, Object value) Method to update the "owner-field" in an embedded object with the owner object.voidvalidate()Validates whether the persistable instance exists in the datastore.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface StateManager
getBooleanField, getByteField, getCharField, getDoubleField, getFloatField, getIntField, getLongField, getObjectField, getShortField, getStringField
-
Field Details
-
HOLLOWFIELDMANAGER
-
FLAG_INSERTING
protected static final int FLAG_INSERTINGWhether we are in the process of INSERTING the object to persistence.- See Also:
-
FLAG_INSERTING_CALLBACKS
protected static final int FLAG_INSERTING_CALLBACKSWhether we are in the process of INSERTING the object from persistence, running callbacks.- See Also:
-
FLAG_DELETING
protected static final int FLAG_DELETINGWhether we are in the process of DELETING the object from persistence.- See Also:
-
FLAG_EMBEDDED
protected static final int FLAG_EMBEDDEDWhether we are managing an embedded object.- See Also:
-
FLAG_VALIDATING
protected static final int FLAG_VALIDATINGWhether we are currently validating the object in the datastore.- See Also:
-
FLAG_RESTORE_VALUES
protected static final int FLAG_RESTORE_VALUESWhether to restore values at StateManager. If true, overwrites the restore values at tx level.- See Also:
-
FLAG_STORING_PC
protected static final int FLAG_STORING_PCFlag to signify that we are currently storing the persistable object, so we don't detach it on serialisation.- See Also:
-
FLAG_NEED_INHERITANCE_VALIDATION
protected static final int FLAG_NEED_INHERITANCE_VALIDATIONWhether the managed object needs the inheritance level validating before loading fields.- See Also:
-
FLAG_POSTINSERT_UPDATE
protected static final int FLAG_POSTINSERT_UPDATE- See Also:
-
FLAG_LOADINGFPFIELDS
protected static final int FLAG_LOADINGFPFIELDS- See Also:
-
FLAG_POSTLOAD_PENDING
protected static final int FLAG_POSTLOAD_PENDING- See Also:
-
FLAG_CHANGING_STATE
protected static final int FLAG_CHANGING_STATE- See Also:
-
FLAG_FLUSHED_NEW
protected static final int FLAG_FLUSHED_NEWif the persistable object is new and was flushed to the datastore.- See Also:
-
FLAG_BECOMING_DELETED
protected static final int FLAG_BECOMING_DELETED- See Also:
-
FLAG_UPDATING_EMBEDDING_FIELDS_WITH_OWNER
protected static final int FLAG_UPDATING_EMBEDDING_FIELDS_WITH_OWNERFlag whether this SM is updating the ownership of its embedded/serialised field(s).- See Also:
-
FLAG_RETRIEVING_DETACHED_STATE
protected static final int FLAG_RETRIEVING_DETACHED_STATEFlag forflagswhether we are retrieving detached state from the detached object.- See Also:
-
FLAG_RESETTING_DETACHED_STATE
protected static final int FLAG_RESETTING_DETACHED_STATEFlag forflagswhether we are resetting the detached state.- See Also:
-
FLAG_ATTACHING
protected static final int FLAG_ATTACHINGFlag forflagswhether we are in the process of attaching the object.- See Also:
-
FLAG_DETACHING
protected static final int FLAG_DETACHINGFlag forflagswhether we are in the process of detaching the object.- See Also:
-
FLAG_MAKING_TRANSIENT
protected static final int FLAG_MAKING_TRANSIENTFlag forflagswhether we are in the process of making transient the object.- See Also:
-
FLAG_FLUSHING
protected static final int FLAG_FLUSHINGFlag forflagswhether we are in the process of flushing changes to the object.- See Also:
-
FLAG_DISCONNECTING
protected static final int FLAG_DISCONNECTINGFlag forflagswhether we are in the process of disconnecting the object.- See Also:
-
myPC
The persistable instance managed by this StateManager. -
flags
protected int flagsBit-packed flags for operational settings (packed into "int" for memory benefit). -
myEC
The ExecutionContext for this StateManager -
cmd
the metadata for the class. -
myInternalID
The object identity in the JVM. Will be "myID" (if set) or otherwise a temporary id based on this StateManager. -
myID
The object identity in the datastore -
myLC
The actual LifeCycleState for the persistable instance -
myVersion
Optimistic version, when starting any transaction. -
transactionalVersion
Optimistic version, after insert/update but not yet committed (i.e incremented). -
persistenceFlags
protected byte persistenceFlagsFlags for state stored with the object. Maps onto org.datanucleus.enhancement.Persistable "dnFlags". -
myFP
Fetch plan for the class of the managed object. -
dirty
protected boolean dirtyIndicator for whether the persistable instance is dirty. Note that "dirty" in this case is not equated to being in the P_DIRTY state. The P_DIRTY state means that at least one field in the object has been written by the user during the current transaction, whereas for this parameter, a field is "dirty" if it's been written by the user but not yet updated in the data store. The difference is, it's possible for an object's state to be P_DIRTY, yet have no "dirty" fields because flush() has been called at least once during the transaction. -
dirtyFields
protected boolean[] dirtyFieldsindicators for which fields are currently dirty in the persistable instance. -
loadedFields
protected boolean[] loadedFieldsindicators for which fields are currently loaded in the persistable instance. -
currFM
Current FieldManager. -
savedState
Saved state, for use during any rollback for reinstating the object. -
HELPER
-
preDeleteLoadedFields
boolean[] preDeleteLoadedFieldsCopy of the "loadedFields" just before delete was started to avoid reload during delete
-
-
Constructor Details
-
StateManagerImpl
Constructor for object of specified type managed by the provided ExecutionContext.- Parameters:
ec- ExecutionContextcmd- the metadata for the class.
-
-
Method Details
-
connect
Description copied from interface:DNStateManagerMethod to (re)connect this StateManager to the specified ExecutionContext and object type.- Specified by:
connectin interfaceDNStateManager<Persistable>- Parameters:
ec- ExecutionContext to connect tocmd- Metadata for the persistable class
-
disconnect
public void disconnect()Disconnect from the ExecutionContext and persistable object.- Specified by:
disconnectin interfaceDNStateManager<Persistable>
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin interfaceDNStateManager<Persistable>
-
initialiseForHollow
Initialises a state manager to manage a hollow instance having the given object ID and the given (optional) field values. This constructor is used for creating new instances of existing persistent objects, and consequently shouldn't be used when the StoreManager controls the creation of such objects (such as in an ODBMS).- Specified by:
initialiseForHollowin interfaceDNStateManager<Persistable>- Parameters:
id- the JDO identity of the object.fv- the initial field values of the object (optional)pcClass- Class of the object that this will manage the state for
-
initialiseForHollowPreConstructed
Initialises a state manager to manage the given hollow instance having the given object ID. Unlike theinitialiseForHollow(Object, FieldValues, Class)method, this method does not create a new instance and instead takes a pre-constructed instance (such as from an ODBMS).- Specified by:
initialiseForHollowPreConstructedin interfaceDNStateManager<Persistable>- Parameters:
id- the identity of the object.pc- the object to be managed.
-
initialiseForPersistentClean
Initialises a state manager to manage the passed persistent instance having the given object ID. Used where we have retrieved a PC object from a datastore directly (not field-by-field), for example on an object datastore. This initialiser will not add StateManagers to all related PCs. This must be done by any calling process. This simply adds the StateManager to the specified object and records the id, setting all fields of the object as loaded.- Specified by:
initialiseForPersistentCleanin interfaceDNStateManager<Persistable>- Parameters:
id- the identity of the object.pc- The object to be managed
-
initialiseForEmbedded
Initialises a state manager to manage a provided Persistable instance that will be EMBEDDED/SERIALISED into another Persistable object. The instance will not be assigned an identity in the process since it is a SCO.- Specified by:
initialiseForEmbeddedin interfaceDNStateManager<Persistable>- Parameters:
pc- The Persistable to manage (see copyPc also)copyPc- Whether the SM should manage a copy of the passed PC or that one
-
initialiseForEmbedded
Initialises a state manager to manage an embedded instance of the specified type. This constructor is used for creating new instances of existing (embedded) persistent objects, and consequently shouldn't be used when the StoreManager controls the creation of such objects (such as in an ODBMS). TODO Consider passing in a FieldValues and set the fields- Specified by:
initialiseForEmbeddedin interfaceDNStateManager<Persistable>- Parameters:
pcClass- Class of the (embedded) object that this will manage the state for
-
initialiseForPersistentNew
Initialises a state manager to manage a transient instance that is becoming newly persistent. A new object ID for the instance is obtained from the store manager and the object is inserted in the data store.This constructor is used for assigning state managers to existing instances that are transitioning to a persistent state.
- Specified by:
initialiseForPersistentNewin interfaceDNStateManager<Persistable>- Parameters:
pc- the instance being make persistent.preInsertChanges- Any changes to make before inserting
-
initialiseForTransactionalTransient
Initialises a state manager to manage a Transactional Transient instance. A new object ID for the instance is obtained from the store manager and the object is inserted in the data store.This constructor is used for assigning state managers to Transient instances that are transitioning to a transient clean state.
- Specified by:
initialiseForTransactionalTransientin interfaceDNStateManager<Persistable>- Parameters:
pc- the instance being make persistent.
-
initialiseForDetached
Initialises the StateManager to manage a Persistable object in detached state.- Specified by:
initialiseForDetachedin interfaceDNStateManager<Persistable>- Parameters:
pc- the detach object.id- the identity of the object.version- the detached version
-
initialiseForPNewToBeDeleted
Initialises the StateManager to manage a Persistable object that is not persistent but is about to be deleted.- Specified by:
initialiseForPNewToBeDeletedin interfaceDNStateManager<Persistable>- Parameters:
pc- the object to delete
-
initialiseForCachedPC
Initialise StateManager, assigning the specified id to the object. This is used when getting objects out of the L2 Cache, where they have no StateManager assigned, and returning them as associated with a particular ExecutionContext.- Specified by:
initialiseForCachedPCin interfaceDNStateManager<Persistable>- Parameters:
cachedPC- The cached PC objectid- Id to assign to the Persistable object
-
populateValueGenerationMembers
private void populateValueGenerationMembers()Convenience method to populate all members in the PC object that need their value generating (according to metadata) and that aren't datastore-attributed. This applies not just to PK members (main use-case) but also to any other member (DN extension). Members can be populated only if they are null, dependent on metadata. This method is called once on a PC object, when makePersistent is called. -
getClassMetaData
Description copied from interface:DNStateManagerAccessor for the ClassMetaData for this persistable object.- Specified by:
getClassMetaDatain interfaceDNStateManager<Persistable>- Returns:
- The ClassMetaData.
-
getExecutionContext
- Specified by:
getExecutionContextin interfaceDNStateManager<Persistable>
-
getExecutionContextReference
Description copied from interface:StateManagerReturn theExecutionContextthat owns this instance.- Specified by:
getExecutionContextReferencein interfaceStateManager- Returns:
- the
ExecutionContextthat owns this instance
-
getStoreManager
- Specified by:
getStoreManagerin interfaceDNStateManager<Persistable>
-
getFetchPlanForClass
Description copied from interface:DNStateManagerAccessor for the FetchPlan for this class.- Specified by:
getFetchPlanForClassin interfaceDNStateManager<Persistable>- Returns:
- The FetchPlanForClass to be used on all fetches
-
getLifecycleState
Description copied from interface:DNStateManagerAccessor for the LifeCycleState of this persistable object.- Specified by:
getLifecycleStatein interfaceDNStateManager<Persistable>- Returns:
- the LifeCycleState
-
getCallbackHandler
-
getObject
Description copied from interface:DNStateManagerAccessor for the persistable object being managed.- Specified by:
getObjectin interfaceDNStateManager<Persistable>- Returns:
- the persistable object
-
getObjectAsPrintable
Description copied from interface:DNStateManagerReturns a printable form of the managed object.- Specified by:
getObjectAsPrintablein interfaceDNStateManager<Persistable>- Returns:
- The object reference for the persistable object.
-
toString
-
isWaitingToBeFlushedToDatastore
public boolean isWaitingToBeFlushedToDatastore()Accessor for whether the instance is newly persistent yet hasnt yet been flushed to the datastore.- Specified by:
isWaitingToBeFlushedToDatastorein interfaceDNStateManager<Persistable>- Returns:
- Whether not yet flushed to the datastore
-
isRestoreValues
public boolean isRestoreValues()Accessor for whether we are in the process of restoring the values.- Specified by:
isRestoreValuesin interfaceDNStateManager<Persistable>- Returns:
- Whether we are restoring values
-
isChangingState
protected boolean isChangingState() -
isInserting
public boolean isInserting()Description copied from interface:DNStateManagerTests whether this object is being inserted.- Specified by:
isInsertingin interfaceDNStateManager<Persistable>- Returns:
- true if this instance is inserting.
-
setInserting
public void setInserting()- Specified by:
setInsertingin interfaceDNStateManager<Persistable>
-
setInsertingCallbacks
public void setInsertingCallbacks()- Specified by:
setInsertingCallbacksin interfaceDNStateManager<Persistable>
-
isDeleting
public boolean isDeleting()Description copied from interface:DNStateManagerTests whether this object is being deleted.- Specified by:
isDeletingin interfaceDNStateManager<Persistable>- Returns:
- true if this instance is being deleted.
-
markForInheritanceValidation
public void markForInheritanceValidation()Description copied from interface:DNStateManagerMark the state manager as needing to validate the inheritance of the managed object existence before loading fields.- Specified by:
markForInheritanceValidationin interfaceDNStateManager<Persistable>
-
setTransactionalVersion
Sets the value for the version column in a transaction not yet committed- Specified by:
setTransactionalVersionin interfaceDNStateManager<Persistable>- Parameters:
version- The version
-
getTransactionalVersion
-
setVersion
Sets the value for the version column in the datastore- Specified by:
setVersionin interfaceDNStateManager<Persistable>- Parameters:
version- The version
-
setFlushedNew
public void setFlushedNew(boolean flag) - Specified by:
setFlushedNewin interfaceDNStateManager<Persistable>
-
isFlushedNew
public boolean isFlushedNew()Description copied from interface:DNStateManagerWhether this record has been flushed to the datastore in this transaction (i.e called persist() and is in the datastore now). If user has called persist() on it yet not yet persisted then returns false.- Specified by:
isFlushedNewin interfaceDNStateManager<Persistable>- Returns:
- Whether this is flushed new.
-
isFlushedToDatastore
public boolean isFlushedToDatastore()Description copied from interface:DNStateManagerAccessor for whether all changes have been written to the datastore.- Specified by:
isFlushedToDatastorein interfaceDNStateManager<Persistable>- Returns:
- Whether the datastore has all changes
-
setFlushing
public void setFlushing(boolean flushing) - Specified by:
setFlushingin interfaceDNStateManager<Persistable>
-
isFlushing
protected boolean isFlushing() -
markAsFlushed
public void markAsFlushed()Description copied from interface:DNStateManagerMethod to notify the StateManager that the object has now been flushed to the datastore. This is performed when handling inserts or deletes in a batch external to StateManager.- Specified by:
markAsFlushedin interfaceDNStateManager<Persistable>
-
refresh
public void refresh()Method to refresh the object.- Specified by:
refreshin interfaceDNStateManager<Persistable>
-
retrieve
public void retrieve(boolean fgOnly) Method to retrieve the object.- Specified by:
retrievein interfaceDNStateManager<Persistable>- Parameters:
fgOnly- Only load the current fetch group fields
-
makePersistentTransactionalTransient
public void makePersistentTransactionalTransient()Makes Transactional Transient instances persistent.- Specified by:
makePersistentTransactionalTransientin interfaceDNStateManager<Persistable>
-
makeNontransactional
public void makeNontransactional()Method to change the object state to nontransactional.- Specified by:
makeNontransactionalin interfaceDNStateManager<Persistable>
-
transitionReadField
protected void transitionReadField(boolean isLoaded) Method to change the object state to read-field.- Parameters:
isLoaded- if the field was previously loaded
-
transitionWriteField
protected void transitionWriteField()Method to change the object state to write-field. -
evict
public void evict()Method to change the object state to evicted.- Specified by:
evictin interfaceDNStateManager<Persistable>
-
preBegin
Method invoked just before a transaction starts for the ExecutionContext managing us.- Specified by:
preBeginin interfaceDNStateManager<Persistable>- Parameters:
tx- The transaction
-
postCommit
This method is invoked just after a commit is performed in a Transaction involving the persistable object managed by this StateManager- Specified by:
postCommitin interfaceDNStateManager<Persistable>- Parameters:
tx- The transaction
-
preRollback
This method is invoked just before a rollback is performed in a Transaction involving the persistable object managed by this StateManager.- Specified by:
preRollbackin interfaceDNStateManager<Persistable>- Parameters:
tx- The transaction
-
internalDeletePersistent
protected void internalDeletePersistent()Method to delete the object from the datastore. -
locate
public void locate()Locate the object in the datastore.- Specified by:
locatein interfaceDNStateManager<Persistable>- Throws:
NucleusObjectNotFoundException- if the object doesnt exist.
-
getReferencedPC
Accessor for the referenced PC object when we are attaching or detaching. When attaching and this is the detached object this returns the newly attached object. When attaching and this is the newly attached object this returns the detached object. When detaching and this is the newly detached object this returns the attached object. When detaching and this is the attached object this returns the newly detached object.- Specified by:
getReferencedPCin interfaceDNStateManager<Persistable>- Returns:
- The referenced object (or null).
-
areFieldsLoaded
protected boolean areFieldsLoaded(int[] fieldNumbers) Accessor for whether all of the specified field numbers are loaded.- Parameters:
fieldNumbers- The field numbers to check- Returns:
- Whether the specified fields are all loaded.
-
unloadField
public void unloadField(int fieldNumber) Description copied from interface:DNStateManagerMark the specified field as not loaded so that it will be reloaded on next access.- Specified by:
unloadFieldin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- Absolute field number
-
unloadNonFetchPlanFields
public void unloadNonFetchPlanFields()Description copied from interface:DNStateManagerMethod that will unload all fields that are not in the FetchPlan.- Specified by:
unloadNonFetchPlanFieldsin interfaceDNStateManager<Persistable>
-
markFieldsAsLoaded
public void markFieldsAsLoaded(int[] fieldNumbers) Description copied from interface:DNStateManagerConvenience method to mark all fields as "loaded". NOTE: This is a convenience mutator only to be used when you know what you are doing. Currently only used by the XML plugin.- Specified by:
markFieldsAsLoadedin interfaceDNStateManager<Persistable>- Parameters:
fieldNumbers- The field numbers to mark as loaded
-
markPKFieldsAsLoaded
protected void markPKFieldsAsLoaded()Convenience method to mark PK fields as loaded (if using app id). -
updateLevel2CacheForFields
protected void updateLevel2CacheForFields(int[] fieldNumbers) Convenience method to update a Level2 cached version of this object if cacheable and has not been modified during this transaction.- Parameters:
fieldNumbers- Numbers of fields to update in L2 cached object
-
loadFieldsFromLevel2Cache
protected int[] loadFieldsFromLevel2Cache(int[] fieldNumbers) Convenience method to retrieve field values from an L2 cached object if they are loaded in that object. If the object is not in the L2 cache then just returns, and similarly if the required fields aren't available.- Parameters:
fieldNumbers- Numbers of fields to load from the L2 cache- Returns:
- The fields that couldn't be loaded
-
loadFieldsInFetchPlan
Method to load all unloaded fields in the FetchPlan. Recurses through the FetchPlan objects and loads fields of sub-objects where needed. Used as a precursor to detaching objects at commit since fields can't be loaded during the postCommit phase when the detach actually happens.- Specified by:
loadFieldsInFetchPlanin interfaceDNStateManager<Persistable>- Parameters:
state- The FetchPlan state
-
loadFieldFromDatastore
public void loadFieldFromDatastore(int fieldNumber) Convenience method to load a field from the datastore. Used in attaching fields and checking their old values (so we don't want any postLoad method being called). TODO Merge this with one of the loadXXXFields methods.- Specified by:
loadFieldFromDatastorein interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- The field number. If fieldNumber is -1 then this means call loadFieldsFromDatastore(null);
-
loadFieldsFromDatastore
protected void loadFieldsFromDatastore(int[] fieldNumbers) Convenience method to load fields from the datastore. Note that if the fieldNumbers is null/empty we still should call the persistence handler since it may mean that the version field needs loading.- Parameters:
fieldNumbers- The field numbers.
-
getFieldNumbersOfLoadedOrDirtyFields
protected int[] getFieldNumbersOfLoadedOrDirtyFields(boolean[] loadedFields, boolean[] dirtyFields) Convenience accessor to return the field numbers for the input loaded and dirty field arrays.- Parameters:
loadedFields- Fields that were detached with the objectdirtyFields- Fields that have been modified while detached- Returns:
- The field numbers of loaded or dirty fields
-
getDirtyFields
public boolean[] getDirtyFields()Creates a copy of thedirtyFieldsbitmap.- Specified by:
getDirtyFieldsin interfaceDNStateManager<Persistable>- Returns:
- a copy of the
dirtyFieldsbitmap.
-
getDirtyFieldNumbers
public int[] getDirtyFieldNumbers()Accessor for the field numbers of all dirty fields.- Specified by:
getDirtyFieldNumbersin interfaceDNStateManager<Persistable>- Returns:
- Absolute field numbers of the dirty fields in this instance.
-
getLoadedFields
public boolean[] getLoadedFields()Accessor for the fields- Specified by:
getLoadedFieldsin interfaceDNStateManager<Persistable>- Returns:
- boolean array of loaded state in order of absolute field numbers
-
getLoadedFieldNumbers
public int[] getLoadedFieldNumbers()Accessor for the field numbers of all loaded fields in this managed instance.- Specified by:
getLoadedFieldNumbersin interfaceDNStateManager<Persistable>- Returns:
- Field numbers of all (currently) loaded fields
-
getAllFieldsLoaded
public boolean getAllFieldsLoaded()Returns whether all fields are loaded.- Specified by:
getAllFieldsLoadedin interfaceDNStateManager<Persistable>- Returns:
- Returns true if all fields are loaded.
-
getDirtyFieldNames
Convenience accessor for the names of the fields that are dirty.- Specified by:
getDirtyFieldNamesin interfaceDNStateManager<Persistable>- Returns:
- Names of the dirty fields
-
getLoadedFieldNames
Convenience accessor for the names of the fields that are loaded.- Specified by:
getLoadedFieldNamesin interfaceDNStateManager<Persistable>- Returns:
- Names of the loaded fields
-
isFieldLoaded
public boolean isFieldLoaded(int fieldNumber) Accessor for whether a field is currently loaded. Just returns the status, unlike "isLoaded" which also loads it if not.- Specified by:
isFieldLoadedin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- The (absolute) field number- Returns:
- Whether it is loaded
-
storeFieldValue
Description copied from interface:DNStateManagerMethod to store the value for the specified field. This is for use with fields that are of type Persistable, and we stored the "id" of the related object in case they need loading later rather than instantiating now.- Specified by:
storeFieldValuein interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- Absolute field numbervalue- The value to store (FK "id")
-
clearFieldsByNumbers
protected void clearFieldsByNumbers(int[] fieldNumbers) -
clearDirtyFlags
protected void clearDirtyFlags()Method to clear all dirty flags on the object. -
clearDirtyFlags
protected void clearDirtyFlags(int[] fieldNumbers) Method to clear all dirty flags on the object.- Parameters:
fieldNumbers- the fields to clear
-
isEmbedded
public boolean isEmbedded()Convenience accessor for whether this StateManager manages an embedded/serialised object.- Specified by:
isEmbeddedin interfaceDNStateManager<Persistable>- Returns:
- Whether the managed object is embedded/serialised.
-
providedBooleanField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedBooleanFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedByteField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedByteFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedCharField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedCharFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedDoubleField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedDoubleFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedFloatField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedFloatFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedIntField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedIntFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedLongField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedLongFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedShortField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedShortFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedStringField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedStringFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
providedObjectField
This method is called from the associated persistable when its dnProvideFields() method is invoked. Its purpose is to provide the value of the specified field to the StateManager.- Specified by:
providedObjectFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field numbercurrentValue- the current value of the field
-
replacingBooleanField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a boolean field.- Specified by:
replacingBooleanFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingByteField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a byte field.- Specified by:
replacingByteFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingCharField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a char field.- Specified by:
replacingCharFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingDoubleField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a double field.- Specified by:
replacingDoubleFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingFloatField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a float field.- Specified by:
replacingFloatFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingIntField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a int field.- Specified by:
replacingIntFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingLongField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a long field.- Specified by:
replacingLongFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingShortField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a short field.- Specified by:
replacingShortFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingStringField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of a String field.- Specified by:
replacingStringFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
replacingObjectField
This method is invoked by the persistable object's dnReplaceField() method to refresh the value of an Object field.- Specified by:
replacingObjectFieldin interfaceStateManager- Parameters:
ignored- the calling persistable instancefieldNumber- the field number- Returns:
- the new value for the field
-
registerTransactional
public void registerTransactional()Registers the pc class in the cache- Specified by:
registerTransactionalin interfaceDNStateManager<Persistable>
-
setAssociatedValue
Description copied from interface:DNStateManagerMethod to set an associated value stored with this object. This is for a situation such as in ORM where this object can have an "external" foreign-key provided by an owning object (e.g 1-N uni relation and this is the element with no knowledge of the owner, so the associated value is the FK value).- Specified by:
setAssociatedValuein interfaceDNStateManager<Persistable>- Parameters:
key- Key for the valuevalue- The associated value
-
getAssociatedValue
Description copied from interface:DNStateManagerAccessor for the value of an external field. This is for a situation such as in ORM where this object can have an "external" foreign-key provided by an owning object (e.g 1-N uni relation and this is the element with no knowledge of the owner, so the associated value is the FK value).- Specified by:
getAssociatedValuein interfaceDNStateManager<Persistable>- Parameters:
key- The key for this associated information- Returns:
- The value stored (if any) against this key
-
removeAssociatedValue
Description copied from interface:DNStateManagerMethod to remove the associated value with the specified key (if it exists).- Specified by:
removeAssociatedValuein interfaceDNStateManager<Persistable>- Parameters:
key- The key
-
containsAssociatedValue
Description copied from interface:DNStateManagerAccessor for whether the specified associated value key is present.- Specified by:
containsAssociatedValuein interfaceDNStateManager<Persistable>- Parameters:
key- The key- Returns:
- Whether it is present
-
enlistInTransaction
public void enlistInTransaction()Method to enlist the managed object in the current transaction.- Specified by:
enlistInTransactionin interfaceDNStateManager<Persistable>
-
evictFromTransaction
public void evictFromTransaction()Method to evict the managed object from the current transaction.- Specified by:
evictFromTransactionin interfaceDNStateManager<Persistable>
-
replaceStateManager
Utility to update the passed object with the passed StateManager (can be null).- Parameters:
pc- The object to updatesm- The new state manager
-
replacingStateManager
Replace the current value of StateManager in the Persistable object.This method is called by the Persistable whenever dnReplaceStateManager is called and there is already an owning StateManager. This is a security precaution to ensure that the owning StateManager is the only source of any change to its reference in the Persistable.
- Specified by:
replacingStateManagerin interfaceStateManager- Parameters:
pc- the calling Persistable instancesm- the proposed new value for the StateManager- Returns:
- the new value for the StateManager
-
replaceManagedPC
Method that replaces the PC managed by this StateManager to be the supplied object. This is used when we want to get an object for an id and create a Hollow object, and then validate against the datastore. This validation can pull in a new object graph from the datastore (e.g for an ODBMS).- Specified by:
replaceManagedPCin interfaceDNStateManager<Persistable>- Parameters:
pc- The persistable to use
-
isDirty
Tests whether this object is dirty. Instances that have been modified, deleted, or newly made persistent in the current transaction return true. Transient nontransactional instances return false (JDO spec).- Specified by:
isDirtyin interfaceStateManager- Parameters:
pc- the calling persistable instance- Returns:
- true if this instance has been modified in current transaction.
- See Also:
-
isTransactional
Tests whether this object is transactional. Instances that respect transaction boundaries return true. These instances include transient instances made transactional as a result of being the target of a makeTransactional method call; newly made persistent or deleted persistent instances; persistent instances read in data store transactions; and persistent instances modified in optimistic transactions.Transient nontransactional instances return false.
- Specified by:
isTransactionalin interfaceStateManager- Parameters:
pc- the calling persistable instance- Returns:
- true if this instance is transactional.
-
isPersistent
Tests whether this object is persistent. Instances whose state is stored in the data store return true. Transient instances return false.- Specified by:
isPersistentin interfaceStateManager- Parameters:
pc- the calling persistable instance- Returns:
- true if this instance is persistent.
-
isNew
Tests whether this object has been newly made persistent. Instances that have been made persistent in the current transaction return true.Transient instances return false.
- Specified by:
isNewin interfaceStateManager- Parameters:
pc- the calling persistable instance- Returns:
- true if this instance was made persistent in the current transaction.
-
isDeleted
public boolean isDeleted()Description copied from interface:DNStateManagerTests whether this object has been deleted. Instances that have been deleted in the current transaction return true. Transient instances return false.- Specified by:
isDeletedin interfaceDNStateManager<Persistable>- Returns:
- true if this instance was deleted in the current transaction.
-
isDeleted
Tests whether this object has been deleted. Instances that have been deleted in the current transaction return true.Transient instances return false.
- Specified by:
isDeletedin interfaceStateManager- Parameters:
pc- the calling persistable instance- Returns:
- true if this instance was deleted in the current transaction.
-
getVersion
Return the object representing the version of the calling instance.- Specified by:
getVersionin interfaceStateManager- Parameters:
pc- the calling persistable instance- Returns:
- the object representing the version of the calling instance
-
isVersionLoaded
public boolean isVersionLoaded()Method to return if the version is loaded. If the class represented is not versioned then returns true- Specified by:
isVersionLoadedin interfaceDNStateManager<Persistable>- Returns:
- Whether it is loaded.
-
getVersion
Method to return the current version of the managed object.- Specified by:
getVersionin interfaceDNStateManager<Persistable>- Returns:
- The version
-
getTransactionalVersion
Return the transactional version of the managed object.- Specified by:
getTransactionalVersionin interfaceDNStateManager<Persistable>- Returns:
- Version of the managed instance at this point in the transaction
-
clearFields
public void clearFields()Method to clear all fields of the object.- Specified by:
clearFieldsin interfaceDNStateManager<Persistable>
-
clearNonPrimaryKeyFields
public void clearNonPrimaryKeyFields()Method to clear all fields that are not part of the primary key of the object.- Specified by:
clearNonPrimaryKeyFieldsin interfaceDNStateManager<Persistable>
-
clearLoadedFlags
public void clearLoadedFlags()Method to clear all loaded flags on the object. Note that the contract of this method implies, especially for object database backends, that the memory form of the object is outdated. Thus, for features like implicit saving of dirty object subgraphs should be switched off for this PC, even if the object actually looks like being dirty (because it is being changed to null values).- Specified by:
clearLoadedFlagsin interfaceDNStateManager<Persistable>
-
replacingFlags
The StateManager uses this method to supply the value of dnFlags to the associated persistable instance.- Specified by:
replacingFlagsin interfaceStateManager- Parameters:
pc- the calling Persistable instance- Returns:
- the value of dnFlags to be stored in the Persistable instance
-
provideField
Method to return the current value of a particular field.- Specified by:
provideFieldin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- Number of field- Returns:
- The value of the field
-
provideField
Method to retrieve the value of a field from the PC object. Assumes that it is loaded.- Parameters:
pc- The PC objectfieldNumber- Number of field- Returns:
- The value of the field
-
provideFields
Called from the StoreManager after StoreManager.update() is called to obtain updated values from the Persistable associated with this StateManager.- Specified by:
provideFieldsin interfaceDNStateManager<Persistable>- Parameters:
fieldNumbers- An array of field numbers to be updated by the Storefm- The updated values are stored in this object. This object is only valid for the duration of this call.
-
setBooleanField
public void setBooleanField(Persistable pc, int fieldNumber, boolean currentValue, boolean newValue) This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setBooleanFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setByteField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setByteFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setCharField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setCharFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setDoubleField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setDoubleFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setFloatField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setFloatFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setIntField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setIntFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setLongField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setLongFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setShortField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setShortFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setStringField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setStringFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
setObjectField
This method is called by the associated Persistable when the corresponding mutator method (setXXX()) is called on the Persistable.- Specified by:
setObjectFieldin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the field numbercurrentValue- the current value of the fieldnewValue- the new value for the field
-
updateField
Convenience method to perform the update of a field value when a setter is invoked. Called by setXXXField methods.- Parameters:
pc- The PC objectfieldNumber- The field numbervalue- The new value
-
replaceField
Method to change the value of a field in the PC object.- Parameters:
pc- The PC objectfieldNumber- Number of fieldvalue- The new value of the field
-
disconnectClone
Method to disconnect any cloned persistence capable objects from their StateManager.- Parameters:
pc- The Persistable object- Returns:
- Whether the object was disconnected.
-
retrieveDetachState
Convenience method to retrieve the detach state from the passed StateManager's object.- Specified by:
retrieveDetachStatein interfaceDNStateManager<Persistable>- Parameters:
sm- StateManager
-
resetDetachState
public void resetDetachState()Convenience method to reset the detached state in the current object.- Specified by:
resetDetachStatein interfaceDNStateManager<Persistable>
-
replacingDetachedState
Method to update the "detached state" in the detached object to obtain the "detached state" from the detached object, or to reset it (to null).- Specified by:
replacingDetachedStatein interfaceStateManager- Parameters:
pc- The Persistable being updatedcurrentState- The current state values- Returns:
- The detached state to assign to the object
-
makeDirty
public void makeDirty(int fieldNumber) Marks the given field dirty.- Specified by:
makeDirtyin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- The no of field to mark as dirty.
-
makeDirty
Mark the associated persistable field dirty.- Specified by:
makeDirtyin interfaceStateManager- Parameters:
pc- the calling persistable instancefieldName- the name of the field
-
getInternalObjectId
Accessor for the internal object id of the object we are managing. This will return the "id" if it has been set, otherwise a temporary id (IdentityReference).- Specified by:
getInternalObjectIdin interfaceDNStateManager<Persistable>- Returns:
- The internal object id
-
getObjectId
Return the object representing the persistent identity of the calling instance. According to the JDO specification, if the persistent identity is being changed in the current transaction, this method returns the persistent identify as of the beginning of the transaction. In DataNucleus we don't allow change of identity so this is always the same as the result of getExternalObjectId(Persistable).- Specified by:
getObjectIdin interfaceStateManager- Parameters:
pc- the calling Persistable instance- Returns:
- the object representing the persistent identity of the calling instance
-
getTransactionalObjectId
Return the object representing the persistent identity of the calling instance. If the persistent identity is being changed in the current transaction, this method returns the current identity as changed in the transaction. In DataNucleus we don't allow change of identity so this is always the same as the result of getObjectId(Persistable).- Specified by:
getTransactionalObjectIdin interfaceStateManager- Parameters:
pc- the calling Persistable instance- Returns:
- the object representing the persistent identity of the calling instance
-
getExternalObjectId
Description copied from interface:DNStateManagerReturn an object id that the user can use.- Specified by:
getExternalObjectIdin interfaceDNStateManager<Persistable>- Returns:
- the object id
-
setIdentity
private void setIdentity(boolean afterPreStore) Utility to set the identity for the Persistable object. Creates the identity instance if the required PK field(s) are all already set (by the user, or by a value-strategy). If the identity is set in the datastore (sequence, autoassign, etc) then this will not set the identity.- Parameters:
afterPreStore- Whether preStore has (just) been invoked
-
setPostStoreNewObjectId
If the id is obtained after inserting the object into the database, set new a new id for persistent classes (for example, increment).- Specified by:
setPostStoreNewObjectIdin interfaceDNStateManager<Persistable>- Parameters:
id- the id received from the datastore
-
loadFieldValues
Convenience method to load the passed field values. Loads the fields using any required fetch plan and calls dnPostLoad() as appropriate.- Specified by:
loadFieldValuesin interfaceDNStateManager<Persistable>- Parameters:
fv- Field Values to load (including any fetch plan to use when loading)
-
loadSpecifiedFields
protected void loadSpecifiedFields(int[] fieldNumbers) Fetch the specified fields from the database.- Parameters:
fieldNumbers- the numbers of the field(s) to fetch.
-
loadField
public void loadField(int fieldNumber) Convenience method to load the specified field if not loaded.- Specified by:
loadFieldin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- Absolute field number
-
loadStoredField
public boolean loadStoredField(int fieldNumber) Description copied from interface:DNStateManagerConvenience method to load the specified field from the stored associated value cache if available.- Specified by:
loadStoredFieldin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- Absolute field number- Returns:
- whether it was loaded from stored cache values
-
loadUnloadedRelationFields
public void loadUnloadedRelationFields()Description copied from interface:DNStateManagerLoads (from the database) all unloaded fields that store relations.- Specified by:
loadUnloadedRelationFieldsin interfaceDNStateManager<Persistable>
-
loadUnloadedFields
public void loadUnloadedFields()Description copied from interface:DNStateManagerFetch from the database all fields that are not currently loaded regardless of whether they are in the current fetch group or not. Called by lifecycle transitions.- Specified by:
loadUnloadedFieldsin interfaceDNStateManager<Persistable>
-
loadUnloadedFieldsInFetchPlan
public void loadUnloadedFieldsInFetchPlan()Description copied from interface:DNStateManagerLoads (from the database) all unloaded fields that are in the current FetchPlan.- Specified by:
loadUnloadedFieldsInFetchPlanin interfaceDNStateManager<Persistable>
-
loadUnloadedFieldsInFetchPlanAndVersion
protected void loadUnloadedFieldsInFetchPlanAndVersion()Fetch from the database all fields in current fetch plan that are not currently loaded as well as the version. Called by lifecycle transitions. -
loadUnloadedFieldsOfClassInFetchPlan
Description copied from interface:DNStateManagerLoads (from the database) all unloaded fields of the managed class that are in the specified FetchPlan.- Specified by:
loadUnloadedFieldsOfClassInFetchPlanin interfaceDNStateManager<Persistable>- Parameters:
fetchPlan- The FetchPlan
-
refreshFieldsInFetchPlan
public void refreshFieldsInFetchPlan()Description copied from interface:DNStateManagerRefreshes from the database all fields in fetch plan. Called by life-cycle transitions when the object undergoes a "transitionRefresh".- Specified by:
refreshFieldsInFetchPlanin interfaceDNStateManager<Persistable>
-
refreshLoadedFields
public void refreshLoadedFields()Description copied from interface:DNStateManagerRefreshes from the database all fields currently loaded. Called by life-cycle transitions when making transactional or reading fields.- Specified by:
refreshLoadedFieldsin interfaceDNStateManager<Persistable>
-
isLoaded
public boolean isLoaded(int fieldNumber) Description copied from interface:DNStateManagerReturns the loaded setting for the field of the managed object. Refer to the javadoc of isLoaded(Persistable, int);- Specified by:
isLoadedin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- the absolute field number- Returns:
- always returns true (this implementation)
-
isLoaded
Return true if the field is cached in the calling instance; in this implementation we always return true. If the field is not loaded, it will be loaded as a side effect of the call to this method. If it is in the default fetch group, the default fetch group, including this field, will be loaded.- Specified by:
isLoadedin interfaceStateManager- Parameters:
pc- the calling Persistable instancefieldNumber- the absolute field number- Returns:
- always returns true (this implementation)
-
replaceFieldValue
Convenience method to change the value of a field that is assumed loaded. Will mark the object/field as dirty if it isn't previously. If the object is deleted then does nothing. Doesn't cater for embedded fields. *** Only for use in management of relations. ***- Specified by:
replaceFieldValuein interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- Number of fieldnewValue- The new value
-
replaceField
Method to change the value of a particular field and not mark it dirty.- Specified by:
replaceFieldin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- Number of fieldvalue- New value
-
replaceFieldMakeDirty
Method to change the value of a particular field and mark it dirty.- Specified by:
replaceFieldMakeDirtyin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- Number of fieldvalue- New value
-
replaceField
Method to change the value of a field in the PC object. Adds on handling for embedded fields to the superclass handler.- Parameters:
pc- The PC objectfieldNumber- Number of fieldvalue- The new value of the fieldmakeDirty- Whether to make the field dirty while replacing its value (in embedded owners)
-
replaceFields
Called from the StoreManager to refresh data in the Persistable object associated with this StateManager. Typically called as a result of a query, so as to populate the query results into the associated persistable object(s).- Specified by:
replaceFieldsin interfaceDNStateManager<Persistable>- Parameters:
fieldNumbers- Field numbers to be refreshed from the store datafm- The updated values are stored in this object. This object is only valid for the duration of this call.replaceWhenDirty- Whether to replace the fields when they are dirty here
-
replaceFields
Called from the StoreManager to refresh data in the Persistable object associated with this StateManager.- Specified by:
replaceFieldsin interfaceDNStateManager<Persistable>- Parameters:
fieldNumbers- An array of field numbers to be refreshed by the Storefm- The updated values are stored in this object. This object is only valid for the duration of this call.
-
replaceNonLoadedFields
Called from the StoreManager to refresh data in the Persistable object associated with this StateManager. Only fields that are not currently loaded are refreshed- Specified by:
replaceNonLoadedFieldsin interfaceDNStateManager<Persistable>- Parameters:
fieldNumbers- An array of field numbers to be refreshed by the Storefm- The updated values are stored in this object. This object is only valid for the duration of this call.
-
replaceAllLoadedSCOFieldsWithWrappers
public void replaceAllLoadedSCOFieldsWithWrappers()Method to replace all loaded SCO fields with wrappers. If the loaded field already uses a SCO wrapper nothing happens to that field.- Specified by:
replaceAllLoadedSCOFieldsWithWrappersin interfaceDNStateManager<Persistable>
-
replaceAllLoadedSCOFieldsWithValues
public void replaceAllLoadedSCOFieldsWithValues()Method to replace all loaded SCO fields that have wrappers with their value. If the loaded field doesn't have a SCO wrapper nothing happens to that field.- Specified by:
replaceAllLoadedSCOFieldsWithValuesin interfaceDNStateManager<Persistable>
-
updateOwnerFieldInEmbeddedField
Method to update the "owner-field" in an embedded object with the owner object. TODO Likely this should be moved into a replaceField method, or maybe Managed Relationships.- Specified by:
updateOwnerFieldInEmbeddedFieldin interfaceDNStateManager<Persistable>- Parameters:
fieldNumber- The field numbervalue- The value to initialise the wrapper with (if any)
-
makePersistent
public void makePersistent()Method to make the object persistent.- Specified by:
makePersistentin interfaceDNStateManager<Persistable>
-
internalMakePersistent
private void internalMakePersistent()Method to persist the object to the datastore. -
makeTransactional
public void makeTransactional()Method to change the object state to transactional.- Specified by:
makeTransactionalin interfaceDNStateManager<Persistable>
-
makeTransient
Method to change the object state to transient.- Specified by:
makeTransientin interfaceDNStateManager<Persistable>- Parameters:
state- Object containing the state of any fetchplan processing
-
makeTransientForReachability
public void makeTransientForReachability()Make the managed object transient as a result of persistence-by-reachability when run at commit time. The object was brought into persistence by reachability but found to not be needed at commit time. Here we delete it from persistence (since it will have been persisted/flushed to the datastore), and then we migrate the lifecycle to transient (which disconnects this StateManager).- Specified by:
makeTransientForReachabilityin interfaceDNStateManager<Persistable>
-
detach
Method to detach this object. If the object is detachable then it will be migrated to DETACHED state, otherwise will migrate to TRANSIENT. Used by "DetachAllOnCommit"/"DetachAllOnRollback"- Specified by:
detachin interfaceDNStateManager<Persistable>- Parameters:
state- State for the detachment process
-
detachCopy
Method to make detached copy of this instance If the object is detachable then the copy will be migrated to DETACHED state, otherwise will migrate the copy to TRANSIENT. Used by "ExecutionContext.detachObjectCopy()".- Specified by:
detachCopyin interfaceDNStateManager<Persistable>- Parameters:
state- State for the detachment process- Returns:
- the detached Persistable instance
-
setDetaching
void setDetaching(boolean flag) -
isDetaching
public boolean isDetaching()Description copied from interface:DNStateManagerTests whether this object is in the process of being detached.- Specified by:
isDetachingin interfaceDNStateManager<Persistable>- Returns:
- true if this instance is being detached.
-
getFieldsNumbersToDetach
private int[] getFieldsNumbersToDetach()Return an array of field numbers that must be included in the detached object- Returns:
- the field numbers array for detaching
-
attach
Description copied from interface:DNStateManagerMethod to attach the provided detached object into the managed instance.- Specified by:
attachin interfaceDNStateManager<Persistable>- Parameters:
detachedPC- Detached object
-
attach
public void attach(boolean embedded) Method to attach the object managed by this StateManager.- Specified by:
attachin interfaceDNStateManager<Persistable>- Parameters:
embedded- Whether it is embedded
-
attachCopy
Method to attach a copy of the detached persistable instance and return the (attached) copy.- Specified by:
attachCopyin interfaceDNStateManager<Persistable>- Parameters:
detachedPC- the detached persistable instance to be attachedembedded- Whether the object is stored embedded/serialised in another object- Returns:
- The attached copy
-
setAttaching
void setAttaching(boolean flag) -
isAttaching
public boolean isAttaching() -
internalAttachCopy
private void internalAttachCopy(DNStateManager detachedSM, boolean[] loadedFields, boolean[] dirtyFields, boolean persistent, Object version, boolean cascade) Attach the fields for this object using the provided detached object. This will attach all loaded plus all dirty fields.- Parameters:
detachedSM- StateManager for the detached object.loadedFields- Fields that were detached with the objectdirtyFields- Fields that have been modified while detachedpersistent- whether the object is already persistentversion- the versioncascade- Whether to cascade the attach to related fields
-
deletePersistent
public void deletePersistent()Method to delete the object from persistence.- Specified by:
deletePersistentin interfaceDNStateManager<Persistable>
-
becomingDeleted
public boolean becomingDeleted()Description copied from interface:DNStateManagerWhether this object is moving to a deleted state.- Specified by:
becomingDeletedin interfaceDNStateManager<Persistable>- Returns:
- Whether the object will be moved into a deleted state during this operation
-
validate
public void validate()Validates whether the persistable instance exists in the datastore. If the instance doesn't exist in the datastore, this method will fail raising a NucleusObjectNotFoundException. If the object is transactional then does nothing. If the object has unloaded (non-SCO, non-PK) fetch plan fields then fetches them. Else it checks the existence of the object in the datastore.- Specified by:
validatein interfaceDNStateManager<Persistable>
-
preWriteField
protected boolean preWriteField(int fieldNumber) Method called before a write of the specified field.- Parameters:
fieldNumber- The field to write- Returns:
- true if the field was already dirty before
-
postWriteField
protected void postWriteField(boolean wasDirty) Method called after the write of a field.- Parameters:
wasDirty- whether before writing this field the pc was dirty
-
preStateChange
protected void preStateChange()Method called before a change in state. -
postStateChange
protected void postStateChange()Method called after a change in state. -
setPostLoadPending
void setPostLoadPending(boolean flag) -
isPostLoadPending
protected boolean isPostLoadPending() -
postLoad
private void postLoad()Called whenever the default fetch group fields have all been loaded. Updates dnFlags and calls dnPostLoad() as appropriate.If it's called in the midst of a life-cycle transition both actions will be deferred until the transition is complete. This deferral is important. Without it, we could enter user code (dnPostLoad()) while still making a state transition, and that way lies madness.
As an example, consider a dnPostLoad() that calls other enhanced methods that read fields (dnPostLoad() itself is not enhanced). A P_NONTRANS object accessed within a transaction would produce the following infinite loop:
isLoaded() transitionReadField() refreshLoadedFields() dnPostLoad() isLoaded() ...
because the transition from P_NONTRANS to P_CLEAN can never be completed.
-
preSerialize
Guarantee that the serializable transactional and persistent fields are loaded into the instance. This method is called by the generated dnPreSerialize method prior to serialization of the instance.- Specified by:
preSerializein interfaceStateManager- Parameters:
pc- the calling Persistable instance
-
setStoringPC
public void setStoringPC()Description copied from interface:DNStateManagerMethod to set the storing PC flag.- Specified by:
setStoringPCin interfaceDNStateManager<Persistable>
-
unsetStoringPC
public void unsetStoringPC()Description copied from interface:DNStateManagerMethod to unset the storing PC flag.- Specified by:
unsetStoringPCin interfaceDNStateManager<Persistable>
-
isStoringPC
protected boolean isStoringPC() -
flush
public void flush()Flushes any outstanding changes to the object to the datastore. This will process :-- Any objects that have been marked as provisionally persistent yet haven't been flushed to the datastore.
- Any objects that have been marked as provisionally deleted yet haven't been flushed to the datastore.
- Any fields that have been updated.
- Specified by:
flushin interfaceDNStateManager<Persistable>
-
saveFields
public void saveFields()Method to save all fields of the object, for use in any rollback.- Specified by:
saveFieldsin interfaceDNStateManager<Persistable>
-
restoreFields
public void restoreFields()Method to restore all fields of the object.- Specified by:
restoreFieldsin interfaceDNStateManager<Persistable>
-
clearSavedFields
public void clearSavedFields()Method to clear all saved fields on the object.- Specified by:
clearSavedFieldsin interfaceDNStateManager<Persistable>
-
convertPCToString
Method to convert the persistable object into String form.- Parameters:
pc- The persistable objectcmd- Metadata for the class- Returns:
- The string containing the description of the Persistable
-
log
Utility to dump the contents of the StateManager to the provided log.- Parameters:
log- Logger to use
-
peekField
-
updateFieldAfterInsert
Description copied from interface:DNStateManagerMarks the given field dirty for issuing an update after the insert.- Specified by:
updateFieldAfterInsertin interfaceDNStateManager<Persistable>- Parameters:
pc- The Persistable objectfieldNumber- The no of field to mark as dirty.
-
initialiseForHollowAppId
Deprecated.Remove use of this and use initialiseForHollowInitialises a state manager to manage a HOLLOW / P_CLEAN instance having the given FieldValues. This constructor is used for creating new instances of existing persistent objects using application identity, and consequently shouldn't be used when the StoreManager controls the creation of such objects (such as in an ODBMS).- Specified by:
initialiseForHollowAppIdin interfaceDNStateManager<Persistable>- Parameters:
fv- the initial field values of the object.pcClass- Class of the object that this will manage the state for
-
checkInheritance
Deprecated.Dont use this, to be removedLook to the database to determine which class this object is. This parameter is a hint. Set false, if it's already determined the correct pcClass for this pc "object" in a certain level in the hierarchy. Set to true and it will look to the database. TODO This is only called by some outdated code in LDAPUtils; remove it when that is fixed- Specified by:
checkInheritancein interfaceDNStateManager<Persistable>- Parameters:
fv- the initial field values of the object.
-