Class SQLStateManager
- java.lang.Object
-
- com.sun.jdo.spi.persistence.support.sqlstore.SQLStateManager
-
- All Implemented Interfaces:
StateManager,TestStateManager,Cloneable
public class SQLStateManager extends Object implements Cloneable, StateManager, TestStateManager
-
-
Field Summary
Fields Modifier and Type Field Description ArrayListhiddenValuesArray of Object.static StringUSE_BATCH_PROPERTYName of the USE_BATCH property.-
Fields inherited from interface com.sun.jdo.spi.persistence.support.sqlstore.StateManager
LOAD_REQUIRED, READ_OK, READ_WRITE_OK
-
-
Constructor Summary
Constructors Constructor Description SQLStateManager(PersistenceStore store, ClassDesc persistenceConfig)Construct a new SQLStateManager so that it locks or does not lock as per whether or not it is used in a managed environment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDependency(StateManager sm)This method adds the dependency between this StateManager and the other.voidapplyUpdates(String fieldName, SCOCollection c)This method is central to record changes to SCOCollections.Objectclone()voidcommit(boolean retainValues)...voidcopyFields(StateManager source)Copies field values fromsourceto this StateManager's fields.voiddeletePersistent()Prepares the associated object for delete.voidflushed()...SQLStateManagergetBeforeImage()protected LifeCycleStategetCurrentState()For test purposesObjectgetHiddenValue(int index)Returns value for a hidden field.voidgetLock()Lock this instance.ObjectgetObjectId()...PersistenceConfiggetPersistenceConfig()...PersistenceManagergetPersistenceManager()...PersistenceManagergetPersistenceManagerInternal()...ObjectgetPersistent()get actualImage associated with thisStateManagerbooleangetPresenceMaskBit(int index)Returns true if field with this index is present in the instance.booleangetSetMaskBit(int index)PersistenceStoregetStore()booleanhasVersionConsistency()Returns true, if the managed instance has Version Consistency.voidincrementVersion()Increments the version fields for this state manager.voidinitialize(boolean persistentInDB)State initializationbooleanisBeforeImageRequired()booleanisDeleted()...booleanisDirty()...booleanisNew()...booleanisPersistent()...booleanisProcessed()...booleanisTransactional()...booleanisValid()Return value for valid flag.booleanisVerificationFailed()Returns, if this state manager has failed version consistency validation.voidloadForRead()Triggers the state transition for READ and registers the instance in the transaction cache.voidloadForUpdate()Triggers the state transition for WRITE and registers the instance in the transaction cache.voidmakeDirty(String fieldName)...voidmakePersistent(PersistenceManager pm, Object pc)Prepares the associated object to be stored in the datastore.voidmakePresent(String fieldName, Object value)...voidmarkNotRegistered()Marks this instance needs to require registering with the global (weak) cache at rollback if it transitions to persistent state.voidmarkReplacement()Marks this instance as a replacement for a deleted instance with the same ObjectId.voidmarkVerifyAtDeregister()Marks this instance as needs to be verified at the time it is removed from the global (weak) cache at rollback if it transitions to transient state.booleanneedsRegisterWithVersionConsistencyCache()booleanneedsUpdateInVersionConsistencyCache()voidprepareGetField(int fieldID)voidprepareToUpdatePhaseI()PersistenceManager calls this method to prepare a persistent object for update.voidprepareToUpdatePhaseII(HashSet phase3sms)This is the second phase of the commit processing.voidprepareToUpdatePhaseIII()This is the third phase of commit processing.voidrefreshPersistent()...voidrelease()Release references in the StateManager to the persistent instance, ObjectId, and PersistenceManager.voidreleaseLock()Release lock.voidreload()Reloads the instance by delegating actual work, state transition, and instance registration toreload(FieldDesc)Withnullas an argument.voidreplaceCollection(ForeignFieldDesc ff, Collection c)This method serves two purposes: 1.voidreplaceObjectField(String fieldName, Object o)...voidresolveDependencies()Resolves the dependencies for the instances waiting for this state manager.voidrollback(boolean retainValues)...boolean[]setBooleanArrayField(int fieldNumber, boolean[] value)booleansetBooleanField(int fieldNumber, boolean value)byte[]setByteArrayField(int fieldNumber, byte[] value)bytesetByteField(int fieldNumber, byte value)charsetCharArrayField(int fieldNumber, char value)charsetCharField(int fieldNumber, char value)double[]setDoubleArrayField(int fieldNumber, double[] value)doublesetDoubleField(int fieldNumber, double value)bytesetFlags(byte flags)...float[]setFloatArrayField(int fieldNumber, float[] value)floatsetFloatField(int fieldNumber, float value)voidsetHiddenValue(int index, Object value)Sets value for a hidden field.int[]setIntArrayField(int fieldNumber, int[] value)intsetIntField(int fieldNumber, int value)long[]setLongArrayField(int fieldNumber, long[] value)longsetLongField(int fieldNumber, long value)Object[]setObjectArrayField(int fieldNumber, Object[] value)ObjectsetObjectField(int fieldNumber, Object value)This method sets object fields, e.g.voidsetObjectId(Object objectId)...voidsetPersistenceManager(PersistenceManager pm)...voidsetPersistent(Object pc)set actualImage associated with thisStateManagervoidsetPresenceMaskBit(int index)Marks field with this index as present.short[]setShortArrayField(int fieldNumber, short[] value)shortsetShortField(int fieldNumber, short value)String[]setStringArrayField(int fieldNumber, String[] value)StringsetStringField(int fieldNumber, String value)voidsetValid()Mark this StateManager as valid.voidsetVerificationFailed()Marks that this state manager has failed version consistency validation.booleantestIsAutoPersistent()This method is used to determine if an instance is in the autopersistent state.booleantestIsLoaded(int fieldNumber)This method is used to test if a field identified by fieldNumber is loaded in memory.booleantestIsLoaded(String fieldName)This method is used to test if a field identified by fieldName is loaded in memory.voidupdatePersistent(StateManager next)Stores the associated object in the datastore.booleanverifyPersistent()Verify that an instance set up with Version consistency is not modified in a parallel transaction.
-
-
-
Field Detail
-
hiddenValues
public ArrayList hiddenValues
Array of Object.
-
USE_BATCH_PROPERTY
public static final String USE_BATCH_PROPERTY
Name of the USE_BATCH property.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SQLStateManager
public SQLStateManager(PersistenceStore store, ClassDesc persistenceConfig)
Construct a new SQLStateManager so that it locks or does not lock as per whether or not it is used in a managed environment.
-
-
Method Detail
-
initialize
public void initialize(boolean persistentInDB)
Description copied from interface:StateManagerState initialization- Specified by:
initializein interfaceStateManager- Parameters:
persistentInDB- true if object is persistent in DB
-
setPersistenceManager
public void setPersistenceManager(PersistenceManager pm)
Description copied from interface:StateManager...- Specified by:
setPersistenceManagerin interfaceStateManager
-
setPersistent
public void setPersistent(Object pc)
Description copied from interface:StateManagerset actualImage associated with thisStateManager- Specified by:
setPersistentin interfaceStateManager
-
getStore
public PersistenceStore getStore()
-
getPersistent
public Object getPersistent()
Description copied from interface:StateManagerget actualImage associated with thisStateManager- Specified by:
getPersistentin interfaceStateManager
-
getPersistenceConfig
public PersistenceConfig getPersistenceConfig()
Description copied from interface:StateManager...- Specified by:
getPersistenceConfigin interfaceStateManager
-
setPresenceMaskBit
public void setPresenceMaskBit(int index)
Description copied from interface:StateManagerMarks field with this index as present.- Specified by:
setPresenceMaskBitin interfaceStateManager- Parameters:
index- - the field number.
-
getPresenceMaskBit
public boolean getPresenceMaskBit(int index)
Description copied from interface:StateManagerReturns true if field with this index is present in the instance.- Specified by:
getPresenceMaskBitin interfaceStateManager
-
getSetMaskBit
public boolean getSetMaskBit(int index)
-
getHiddenValue
public Object getHiddenValue(int index)
Description copied from interface:StateManagerReturns value for a hidden field. This method expects index to be negative for hidden fields.- Specified by:
getHiddenValuein interfaceStateManager- Parameters:
index- - the hidden field index.
-
setHiddenValue
public void setHiddenValue(int index, Object value)Description copied from interface:StateManagerSets value for a hidden field. This method expects index to be negative for hidden fields.- Specified by:
setHiddenValuein interfaceStateManager- Parameters:
index- - the hidden field index.value- - new value.
-
replaceObjectField
public void replaceObjectField(String fieldName, Object o)
Description copied from interface:StateManager...- Specified by:
replaceObjectFieldin interfaceStateManager
-
makeDirty
public void makeDirty(String fieldName)
Description copied from interface:StateManager...- Specified by:
makeDirtyin interfaceStateManager
-
applyUpdates
public void applyUpdates(String fieldName, SCOCollection c)
This method is central to record changes to SCOCollections.- Specified by:
applyUpdatesin interfaceStateManager
-
makePresent
public void makePresent(String fieldName, Object value)
Description copied from interface:StateManager...- Specified by:
makePresentin interfaceStateManager
-
setObjectId
public void setObjectId(Object objectId)
Description copied from interface:StateManager...- Specified by:
setObjectIdin interfaceStateManager
-
getObjectId
public Object getObjectId()
Description copied from interface:StateManager...- Specified by:
getObjectIdin interfaceStateManager
-
makePersistent
public void makePersistent(PersistenceManager pm, Object pc)
Prepares the associated object to be stored in the datastore. This method is called by PersistenceManager.makePersistent(). Thread synchronization is done in the persistence manager.- Specified by:
makePersistentin interfaceStateManager
-
deletePersistent
public void deletePersistent()
Prepares the associated object for delete. This method is called by PersistenceManager.deletePersistent(). After nullifying the relationship fields, the instance transitions to deleted state.- Specified by:
deletePersistentin interfaceStateManager
-
updatePersistent
public void updatePersistent(StateManager next)
Stores the associated object in the datastore. This method is called byPersistenceManager.beforeCompletion()on flush/commit. The specified state manager argument is used to determine whether the actual instance should be flushed immediately or whether batch update is possible.- Specified by:
updatePersistentin interfaceStateManager- Parameters:
next- Next state manager in the transaction cache.
-
incrementVersion
public void incrementVersion()
Increments the version fields for this state manager. Instances mapped to multiple tables have got a version field for each table.
-
hasVersionConsistency
public boolean hasVersionConsistency()
Description copied from interface:StateManagerReturns true, if the managed instance has Version Consistency.- Specified by:
hasVersionConsistencyin interfaceStateManager- Returns:
- True, if the managed object has Version Consistency.
-
verifyPersistent
public boolean verifyPersistent()
Description copied from interface:StateManagerVerify that an instance set up with Version consistency is not modified in a parallel transaction.- Specified by:
verifyPersistentin interfaceStateManager- Returns:
- false if the instance is persistent clean and modified by a parallel transaction, true otherwise.
-
setVerificationFailed
public void setVerificationFailed()
Description copied from interface:StateManagerMarks that this state manager has failed version consistency validation.- Specified by:
setVerificationFailedin interfaceStateManager
-
isVerificationFailed
public boolean isVerificationFailed()
Description copied from interface:StateManagerReturns, if this state manager has failed version consistency validation.- Specified by:
isVerificationFailedin interfaceStateManager- Returns:
- True, if this state manager is marked as failed.
-
refreshPersistent
public void refreshPersistent()
Description copied from interface:StateManager... ThePersistenceManagercalls this method to refresh the state of theStateManagerfrom the database.- Specified by:
refreshPersistentin interfaceStateManager
-
reload
public void reload()
Reloads the instance by delegating actual work, state transition, and instance registration toreload(FieldDesc)Withnullas an argument. Called byPersistenceManager.getObjectById(Object, boolean)with validate flag set totrue- Specified by:
reloadin interfaceStateManager
-
prepareToUpdatePhaseI
public void prepareToUpdatePhaseI()
PersistenceManager calls this method to prepare a persistent object for update. This is required for foreign fields only as they could reference "regular" JDK Collections vs. SCO Collections. Such process has the side-effect of causing more objects to be registered with the transaction cache.- Specified by:
prepareToUpdatePhaseIin interfaceStateManager
-
prepareToUpdatePhaseII
public void prepareToUpdatePhaseII(HashSet phase3sms)
This is the second phase of the commit processing. It populates phase3sms with all the autopersistent instances that are no longer reachable from a persistent instance.- Specified by:
prepareToUpdatePhaseIIin interfaceStateManager- Parameters:
phase3sms- List containing autopersistent instances that are no longer reachable from a persistent instance.
-
prepareToUpdatePhaseIII
public void prepareToUpdatePhaseIII()
This is the third phase of commit processing. It sets up the delete dependencies among all the autopersistent instances that have been flushed to the database.- Specified by:
prepareToUpdatePhaseIIIin interfaceStateManager
-
release
public void release()
Description copied from interface:StateManagerRelease references in the StateManager to the persistent instance, ObjectId, and PersistenceManager.- Specified by:
releasein interfaceStateManager
-
isProcessed
public boolean isProcessed()
Description copied from interface:StateManager... ThePersistenceManagercalls this method to verify that corresponding object has been flushed to the database- Specified by:
isProcessedin interfaceStateManager- Returns:
- true if persistentObject has been flushed to db
-
flushed
public void flushed()
Description copied from interface:StateManager... ThePersistenceManagercalls this method to inform theStateManagerthat the flush processing is completed.- Specified by:
flushedin interfaceStateManager
-
commit
public void commit(boolean retainValues)
Description copied from interface:StateManager... ThePersistenceManagercalls this method to inform theStateManagerthat the transaction has been committed.- Specified by:
commitin interfaceStateManager
-
rollback
public void rollback(boolean retainValues)
Description copied from interface:StateManager... ThePersistenceManagercalls this method to inform theStateManagerthat the transaction has been rolled back.- Specified by:
rollbackin interfaceStateManager
-
prepareGetField
public void prepareGetField(int fieldID)
- Specified by:
prepareGetFieldin interfaceStateManager
-
getBeforeImage
public SQLStateManager getBeforeImage()
-
isBeforeImageRequired
public boolean isBeforeImageRequired()
-
copyFields
public void copyFields(StateManager source)
Description copied from interface:StateManagerCopies field values fromsourceto this StateManager's fields.- Specified by:
copyFieldsin interfaceStateManager- Parameters:
source- StateManager from which field values are copied into this instance.
-
addDependency
public void addDependency(StateManager sm)
This method adds the dependency between this StateManager and the other.- Specified by:
addDependencyin interfaceStateManager- Parameters:
sm- Second state manager.- See Also:
StateManager.addDependency(StateManager sm)
-
resolveDependencies
public void resolveDependencies()
Resolves the dependencies for the instances waiting for this state manager. Dependencies are registered instantly during the course of the transaction. For this reason, the introduced dependencies must be checked, if they are still valid at commit/flush. E.g. remove dependencies introduced on relationship removal are only valid, if the removed instance is deleted.This method checks the dependencies for all instances waiting for the current state manager to be flushed to the store.
- Specified by:
resolveDependenciesin interfaceStateManager
-
getPersistenceManagerInternal
public PersistenceManager getPersistenceManagerInternal()
...- Specified by:
getPersistenceManagerInternalin interfaceStateManager
-
getPersistenceManager
public PersistenceManager getPersistenceManager()
...- Specified by:
getPersistenceManagerin interfaceStateManager
-
setFlags
public byte setFlags(byte flags)
...- Specified by:
setFlagsin interfaceStateManager
-
loadForRead
public void loadForRead()
Triggers the state transition for READ and registers the instance in the transaction cache.- Specified by:
loadForReadin interfaceStateManager
-
loadForUpdate
public void loadForUpdate()
Triggers the state transition for WRITE and registers the instance in the transaction cache. Prepares all DFG fields for update.- Specified by:
loadForUpdatein interfaceStateManager
-
replaceCollection
public void replaceCollection(ForeignFieldDesc ff, Collection c)
This method serves two purposes: 1. If the field value is null or contains a non-SCOCollection instance, it creates a new SCOCollection and populates with elements in c. 2. If the field value is a SCOCollection instance, then if it is deferred, it calls applyDeferredUpdates on the collection passing in c. Otherwise, it clears the collection and repopulates with elements in c.
-
getCurrentState
protected LifeCycleState getCurrentState()
For test purposes
-
isDirty
public boolean isDirty()
...- Specified by:
isDirtyin interfaceStateManager
-
isTransactional
public boolean isTransactional()
...- Specified by:
isTransactionalin interfaceStateManager
-
isNew
public boolean isNew()
...- Specified by:
isNewin interfaceStateManager
-
isDeleted
public boolean isDeleted()
...- Specified by:
isDeletedin interfaceStateManager
-
isPersistent
public boolean isPersistent()
...- Specified by:
isPersistentin interfaceStateManager
-
needsRegisterWithVersionConsistencyCache
public boolean needsRegisterWithVersionConsistencyCache()
- Specified by:
needsRegisterWithVersionConsistencyCachein interfaceStateManager- Returns:
- True, if this instance is persistent, transactional, not new, not dirty, and not deleted; false otherwise.
-
needsUpdateInVersionConsistencyCache
public boolean needsUpdateInVersionConsistencyCache()
- Specified by:
needsUpdateInVersionConsistencyCachein interfaceStateManager- Returns:
- True, if this instance should be synchronized with the version consistency cache; false otherwise.
-
setBooleanField
public boolean setBooleanField(int fieldNumber, boolean value)- Specified by:
setBooleanFieldin interfaceStateManager
-
setBooleanArrayField
public boolean[] setBooleanArrayField(int fieldNumber, boolean[] value)- Specified by:
setBooleanArrayFieldin interfaceStateManager
-
setByteField
public byte setByteField(int fieldNumber, byte value)- Specified by:
setByteFieldin interfaceStateManager
-
setByteArrayField
public byte[] setByteArrayField(int fieldNumber, byte[] value)- Specified by:
setByteArrayFieldin interfaceStateManager
-
setShortField
public short setShortField(int fieldNumber, short value)- Specified by:
setShortFieldin interfaceStateManager
-
setShortArrayField
public short[] setShortArrayField(int fieldNumber, short[] value)- Specified by:
setShortArrayFieldin interfaceStateManager
-
setIntField
public int setIntField(int fieldNumber, int value)- Specified by:
setIntFieldin interfaceStateManager
-
setIntArrayField
public int[] setIntArrayField(int fieldNumber, int[] value)- Specified by:
setIntArrayFieldin interfaceStateManager
-
setLongField
public long setLongField(int fieldNumber, long value)- Specified by:
setLongFieldin interfaceStateManager
-
setLongArrayField
public long[] setLongArrayField(int fieldNumber, long[] value)- Specified by:
setLongArrayFieldin interfaceStateManager
-
setCharField
public char setCharField(int fieldNumber, char value)- Specified by:
setCharFieldin interfaceStateManager
-
setCharArrayField
public char setCharArrayField(int fieldNumber, char value)- Specified by:
setCharArrayFieldin interfaceStateManager
-
setFloatField
public float setFloatField(int fieldNumber, float value)- Specified by:
setFloatFieldin interfaceStateManager
-
setFloatArrayField
public float[] setFloatArrayField(int fieldNumber, float[] value)- Specified by:
setFloatArrayFieldin interfaceStateManager
-
setDoubleField
public double setDoubleField(int fieldNumber, double value)- Specified by:
setDoubleFieldin interfaceStateManager
-
setDoubleArrayField
public double[] setDoubleArrayField(int fieldNumber, double[] value)- Specified by:
setDoubleArrayFieldin interfaceStateManager
-
setStringField
public String setStringField(int fieldNumber, String value)
- Specified by:
setStringFieldin interfaceStateManager
-
setStringArrayField
public String[] setStringArrayField(int fieldNumber, String[] value)
- Specified by:
setStringArrayFieldin interfaceStateManager
-
setObjectField
public Object setObjectField(int fieldNumber, Object value)
This method sets object fields, e.g. relationship fields.- Specified by:
setObjectFieldin interfaceStateManager
-
setObjectArrayField
public Object[] setObjectArrayField(int fieldNumber, Object[] value)
- Specified by:
setObjectArrayFieldin interfaceStateManager
-
testIsLoaded
public boolean testIsLoaded(int fieldNumber)
Description copied from interface:TestStateManagerThis method is used to test if a field identified by fieldNumber is loaded in memory. It returns true is the field is loaded and false otehrwise.- Specified by:
testIsLoadedin interfaceTestStateManager
-
testIsLoaded
public boolean testIsLoaded(String fieldName)
Description copied from interface:TestStateManagerThis method is used to test if a field identified by fieldName is loaded in memory. It returns true is the field is loaded and false, otehrwise.- Specified by:
testIsLoadedin interfaceTestStateManager
-
testIsAutoPersistent
public boolean testIsAutoPersistent()
Description copied from interface:TestStateManagerThis method is used to determine if an instance is in the autopersistent state. It returns true if the instance is autopersistence and false otherwise.- Specified by:
testIsAutoPersistentin interfaceTestStateManager
-
markNotRegistered
public void markNotRegistered()
Marks this instance needs to require registering with the global (weak) cache at rollback if it transitions to persistent state. Used for replacing a deleted instance with the newly persistent with the same object id.- Specified by:
markNotRegisteredin interfaceStateManager
-
markVerifyAtDeregister
public void markVerifyAtDeregister()
Marks this instance as needs to be verified at the time it is removed from the global (weak) cache at rollback if it transitions to transient state.- Specified by:
markVerifyAtDeregisterin interfaceStateManager
-
markReplacement
public void markReplacement()
Marks this instance as a replacement for a deleted instance with the same ObjectId.- Specified by:
markReplacementin interfaceStateManager
-
getLock
public void getLock()
Lock this instance.- Specified by:
getLockin interfaceStateManager
-
releaseLock
public void releaseLock()
Release lock.- Specified by:
releaseLockin interfaceStateManager
-
isValid
public boolean isValid()
Return value for valid flag.- Specified by:
isValidin interfaceStateManager
-
setValid
public void setValid()
Mark this StateManager as valid. Called before returning from getObjectById.- Specified by:
setValidin interfaceStateManager
-
-