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 ArrayList
hiddenValues
Array of Object.static String
USE_BATCH_PROPERTY
Name 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 void
addDependency(StateManager sm)
This method adds the dependency between this StateManager and the other.void
applyUpdates(String fieldName, SCOCollection c)
This method is central to record changes to SCOCollections.Object
clone()
void
commit(boolean retainValues)
...void
copyFields(StateManager source)
Copies field values fromsource
to this StateManager's fields.void
deletePersistent()
Prepares the associated object for delete.void
flushed()
...SQLStateManager
getBeforeImage()
protected LifeCycleState
getCurrentState()
For test purposesObject
getHiddenValue(int index)
Returns value for a hidden field.void
getLock()
Lock this instance.Object
getObjectId()
...PersistenceConfig
getPersistenceConfig()
...PersistenceManager
getPersistenceManager()
...PersistenceManager
getPersistenceManagerInternal()
...Object
getPersistent()
get actualImage associated with thisStateManager
boolean
getPresenceMaskBit(int index)
Returns true if field with this index is present in the instance.boolean
getSetMaskBit(int index)
PersistenceStore
getStore()
boolean
hasVersionConsistency()
Returns true, if the managed instance has Version Consistency.void
incrementVersion()
Increments the version fields for this state manager.void
initialize(boolean persistentInDB)
State initializationboolean
isBeforeImageRequired()
boolean
isDeleted()
...boolean
isDirty()
...boolean
isNew()
...boolean
isPersistent()
...boolean
isProcessed()
...boolean
isTransactional()
...boolean
isValid()
Return value for valid flag.boolean
isVerificationFailed()
Returns, if this state manager has failed version consistency validation.void
loadForRead()
Triggers the state transition for READ and registers the instance in the transaction cache.void
loadForUpdate()
Triggers the state transition for WRITE and registers the instance in the transaction cache.void
makeDirty(String fieldName)
...void
makePersistent(PersistenceManager pm, Object pc)
Prepares the associated object to be stored in the datastore.void
makePresent(String fieldName, Object value)
...void
markNotRegistered()
Marks this instance needs to require registering with the global (weak) cache at rollback if it transitions to persistent state.void
markReplacement()
Marks this instance as a replacement for a deleted instance with the same ObjectId.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.boolean
needsRegisterWithVersionConsistencyCache()
boolean
needsUpdateInVersionConsistencyCache()
void
prepareGetField(int fieldID)
void
prepareToUpdatePhaseI()
PersistenceManager calls this method to prepare a persistent object for update.void
prepareToUpdatePhaseII(HashSet phase3sms)
This is the second phase of the commit processing.void
prepareToUpdatePhaseIII()
This is the third phase of commit processing.void
refreshPersistent()
...void
release()
Release references in the StateManager to the persistent instance, ObjectId, and PersistenceManager.void
releaseLock()
Release lock.void
reload()
Reloads the instance by delegating actual work, state transition, and instance registration toreload(FieldDesc)
Withnull
as an argument.void
replaceCollection(ForeignFieldDesc ff, Collection c)
This method serves two purposes: 1.void
replaceObjectField(String fieldName, Object o)
...void
resolveDependencies()
Resolves the dependencies for the instances waiting for this state manager.void
rollback(boolean retainValues)
...boolean[]
setBooleanArrayField(int fieldNumber, boolean[] value)
boolean
setBooleanField(int fieldNumber, boolean value)
byte[]
setByteArrayField(int fieldNumber, byte[] value)
byte
setByteField(int fieldNumber, byte value)
char
setCharArrayField(int fieldNumber, char value)
char
setCharField(int fieldNumber, char value)
double[]
setDoubleArrayField(int fieldNumber, double[] value)
double
setDoubleField(int fieldNumber, double value)
byte
setFlags(byte flags)
...float[]
setFloatArrayField(int fieldNumber, float[] value)
float
setFloatField(int fieldNumber, float value)
void
setHiddenValue(int index, Object value)
Sets value for a hidden field.int[]
setIntArrayField(int fieldNumber, int[] value)
int
setIntField(int fieldNumber, int value)
long[]
setLongArrayField(int fieldNumber, long[] value)
long
setLongField(int fieldNumber, long value)
Object[]
setObjectArrayField(int fieldNumber, Object[] value)
Object
setObjectField(int fieldNumber, Object value)
This method sets object fields, e.g.void
setObjectId(Object objectId)
...void
setPersistenceManager(PersistenceManager pm)
...void
setPersistent(Object pc)
set actualImage associated with thisStateManager
void
setPresenceMaskBit(int index)
Marks field with this index as present.short[]
setShortArrayField(int fieldNumber, short[] value)
short
setShortField(int fieldNumber, short value)
String[]
setStringArrayField(int fieldNumber, String[] value)
String
setStringField(int fieldNumber, String value)
void
setValid()
Mark this StateManager as valid.void
setVerificationFailed()
Marks that this state manager has failed version consistency validation.boolean
testIsAutoPersistent()
This method is used to determine if an instance is in the autopersistent state.boolean
testIsLoaded(int fieldNumber)
This method is used to test if a field identified by fieldNumber is loaded in memory.boolean
testIsLoaded(String fieldName)
This method is used to test if a field identified by fieldName is loaded in memory.void
updatePersistent(StateManager next)
Stores the associated object in the datastore.boolean
verifyPersistent()
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:StateManager
State initialization- Specified by:
initialize
in interfaceStateManager
- Parameters:
persistentInDB
- true if object is persistent in DB
-
setPersistenceManager
public void setPersistenceManager(PersistenceManager pm)
Description copied from interface:StateManager
...- Specified by:
setPersistenceManager
in interfaceStateManager
-
setPersistent
public void setPersistent(Object pc)
Description copied from interface:StateManager
set actualImage associated with thisStateManager
- Specified by:
setPersistent
in interfaceStateManager
-
getStore
public PersistenceStore getStore()
-
getPersistent
public Object getPersistent()
Description copied from interface:StateManager
get actualImage associated with thisStateManager
- Specified by:
getPersistent
in interfaceStateManager
-
getPersistenceConfig
public PersistenceConfig getPersistenceConfig()
Description copied from interface:StateManager
...- Specified by:
getPersistenceConfig
in interfaceStateManager
-
setPresenceMaskBit
public void setPresenceMaskBit(int index)
Description copied from interface:StateManager
Marks field with this index as present.- Specified by:
setPresenceMaskBit
in interfaceStateManager
- Parameters:
index
- - the field number.
-
getPresenceMaskBit
public boolean getPresenceMaskBit(int index)
Description copied from interface:StateManager
Returns true if field with this index is present in the instance.- Specified by:
getPresenceMaskBit
in interfaceStateManager
-
getSetMaskBit
public boolean getSetMaskBit(int index)
-
getHiddenValue
public Object getHiddenValue(int index)
Description copied from interface:StateManager
Returns value for a hidden field. This method expects index to be negative for hidden fields.- Specified by:
getHiddenValue
in interfaceStateManager
- Parameters:
index
- - the hidden field index.
-
setHiddenValue
public void setHiddenValue(int index, Object value)
Description copied from interface:StateManager
Sets value for a hidden field. This method expects index to be negative for hidden fields.- Specified by:
setHiddenValue
in 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:
replaceObjectField
in interfaceStateManager
-
makeDirty
public void makeDirty(String fieldName)
Description copied from interface:StateManager
...- Specified by:
makeDirty
in interfaceStateManager
-
applyUpdates
public void applyUpdates(String fieldName, SCOCollection c)
This method is central to record changes to SCOCollections.- Specified by:
applyUpdates
in interfaceStateManager
-
makePresent
public void makePresent(String fieldName, Object value)
Description copied from interface:StateManager
...- Specified by:
makePresent
in interfaceStateManager
-
setObjectId
public void setObjectId(Object objectId)
Description copied from interface:StateManager
...- Specified by:
setObjectId
in interfaceStateManager
-
getObjectId
public Object getObjectId()
Description copied from interface:StateManager
...- Specified by:
getObjectId
in 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:
makePersistent
in 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:
deletePersistent
in 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:
updatePersistent
in 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:StateManager
Returns true, if the managed instance has Version Consistency.- Specified by:
hasVersionConsistency
in interfaceStateManager
- Returns:
- True, if the managed object has Version Consistency.
-
verifyPersistent
public boolean verifyPersistent()
Description copied from interface:StateManager
Verify that an instance set up with Version consistency is not modified in a parallel transaction.- Specified by:
verifyPersistent
in 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:StateManager
Marks that this state manager has failed version consistency validation.- Specified by:
setVerificationFailed
in interfaceStateManager
-
isVerificationFailed
public boolean isVerificationFailed()
Description copied from interface:StateManager
Returns, if this state manager has failed version consistency validation.- Specified by:
isVerificationFailed
in interfaceStateManager
- Returns:
- True, if this state manager is marked as failed.
-
refreshPersistent
public void refreshPersistent()
Description copied from interface:StateManager
... ThePersistenceManager
calls this method to refresh the state of theStateManager
from the database.- Specified by:
refreshPersistent
in interfaceStateManager
-
reload
public void reload()
Reloads the instance by delegating actual work, state transition, and instance registration toreload(FieldDesc)
Withnull
as an argument. Called byPersistenceManager.getObjectById(Object, boolean)
with validate flag set totrue
- Specified by:
reload
in 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:
prepareToUpdatePhaseI
in 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:
prepareToUpdatePhaseII
in 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:
prepareToUpdatePhaseIII
in interfaceStateManager
-
release
public void release()
Description copied from interface:StateManager
Release references in the StateManager to the persistent instance, ObjectId, and PersistenceManager.- Specified by:
release
in interfaceStateManager
-
isProcessed
public boolean isProcessed()
Description copied from interface:StateManager
... ThePersistenceManager
calls this method to verify that corresponding object has been flushed to the database- Specified by:
isProcessed
in interfaceStateManager
- Returns:
- true if persistentObject has been flushed to db
-
flushed
public void flushed()
Description copied from interface:StateManager
... ThePersistenceManager
calls this method to inform theStateManager
that the flush processing is completed.- Specified by:
flushed
in interfaceStateManager
-
commit
public void commit(boolean retainValues)
Description copied from interface:StateManager
... ThePersistenceManager
calls this method to inform theStateManager
that the transaction has been committed.- Specified by:
commit
in interfaceStateManager
-
rollback
public void rollback(boolean retainValues)
Description copied from interface:StateManager
... ThePersistenceManager
calls this method to inform theStateManager
that the transaction has been rolled back.- Specified by:
rollback
in interfaceStateManager
-
prepareGetField
public void prepareGetField(int fieldID)
- Specified by:
prepareGetField
in interfaceStateManager
-
getBeforeImage
public SQLStateManager getBeforeImage()
-
isBeforeImageRequired
public boolean isBeforeImageRequired()
-
copyFields
public void copyFields(StateManager source)
Description copied from interface:StateManager
Copies field values fromsource
to this StateManager's fields.- Specified by:
copyFields
in 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:
addDependency
in 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:
resolveDependencies
in interfaceStateManager
-
getPersistenceManagerInternal
public PersistenceManager getPersistenceManagerInternal()
...- Specified by:
getPersistenceManagerInternal
in interfaceStateManager
-
getPersistenceManager
public PersistenceManager getPersistenceManager()
...- Specified by:
getPersistenceManager
in interfaceStateManager
-
setFlags
public byte setFlags(byte flags)
...- Specified by:
setFlags
in interfaceStateManager
-
loadForRead
public void loadForRead()
Triggers the state transition for READ and registers the instance in the transaction cache.- Specified by:
loadForRead
in 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:
loadForUpdate
in 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:
isDirty
in interfaceStateManager
-
isTransactional
public boolean isTransactional()
...- Specified by:
isTransactional
in interfaceStateManager
-
isNew
public boolean isNew()
...- Specified by:
isNew
in interfaceStateManager
-
isDeleted
public boolean isDeleted()
...- Specified by:
isDeleted
in interfaceStateManager
-
isPersistent
public boolean isPersistent()
...- Specified by:
isPersistent
in interfaceStateManager
-
needsRegisterWithVersionConsistencyCache
public boolean needsRegisterWithVersionConsistencyCache()
- Specified by:
needsRegisterWithVersionConsistencyCache
in interfaceStateManager
- Returns:
- True, if this instance is persistent, transactional, not new, not dirty, and not deleted; false otherwise.
-
needsUpdateInVersionConsistencyCache
public boolean needsUpdateInVersionConsistencyCache()
- Specified by:
needsUpdateInVersionConsistencyCache
in 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:
setBooleanField
in interfaceStateManager
-
setBooleanArrayField
public boolean[] setBooleanArrayField(int fieldNumber, boolean[] value)
- Specified by:
setBooleanArrayField
in interfaceStateManager
-
setByteField
public byte setByteField(int fieldNumber, byte value)
- Specified by:
setByteField
in interfaceStateManager
-
setByteArrayField
public byte[] setByteArrayField(int fieldNumber, byte[] value)
- Specified by:
setByteArrayField
in interfaceStateManager
-
setShortField
public short setShortField(int fieldNumber, short value)
- Specified by:
setShortField
in interfaceStateManager
-
setShortArrayField
public short[] setShortArrayField(int fieldNumber, short[] value)
- Specified by:
setShortArrayField
in interfaceStateManager
-
setIntField
public int setIntField(int fieldNumber, int value)
- Specified by:
setIntField
in interfaceStateManager
-
setIntArrayField
public int[] setIntArrayField(int fieldNumber, int[] value)
- Specified by:
setIntArrayField
in interfaceStateManager
-
setLongField
public long setLongField(int fieldNumber, long value)
- Specified by:
setLongField
in interfaceStateManager
-
setLongArrayField
public long[] setLongArrayField(int fieldNumber, long[] value)
- Specified by:
setLongArrayField
in interfaceStateManager
-
setCharField
public char setCharField(int fieldNumber, char value)
- Specified by:
setCharField
in interfaceStateManager
-
setCharArrayField
public char setCharArrayField(int fieldNumber, char value)
- Specified by:
setCharArrayField
in interfaceStateManager
-
setFloatField
public float setFloatField(int fieldNumber, float value)
- Specified by:
setFloatField
in interfaceStateManager
-
setFloatArrayField
public float[] setFloatArrayField(int fieldNumber, float[] value)
- Specified by:
setFloatArrayField
in interfaceStateManager
-
setDoubleField
public double setDoubleField(int fieldNumber, double value)
- Specified by:
setDoubleField
in interfaceStateManager
-
setDoubleArrayField
public double[] setDoubleArrayField(int fieldNumber, double[] value)
- Specified by:
setDoubleArrayField
in interfaceStateManager
-
setStringField
public String setStringField(int fieldNumber, String value)
- Specified by:
setStringField
in interfaceStateManager
-
setStringArrayField
public String[] setStringArrayField(int fieldNumber, String[] value)
- Specified by:
setStringArrayField
in interfaceStateManager
-
setObjectField
public Object setObjectField(int fieldNumber, Object value)
This method sets object fields, e.g. relationship fields.- Specified by:
setObjectField
in interfaceStateManager
-
setObjectArrayField
public Object[] setObjectArrayField(int fieldNumber, Object[] value)
- Specified by:
setObjectArrayField
in interfaceStateManager
-
testIsLoaded
public boolean testIsLoaded(int fieldNumber)
Description copied from interface:TestStateManager
This 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:
testIsLoaded
in interfaceTestStateManager
-
testIsLoaded
public boolean testIsLoaded(String fieldName)
Description copied from interface:TestStateManager
This 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:
testIsLoaded
in interfaceTestStateManager
-
testIsAutoPersistent
public boolean testIsAutoPersistent()
Description copied from interface:TestStateManager
This 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:
testIsAutoPersistent
in 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:
markNotRegistered
in 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:
markVerifyAtDeregister
in interfaceStateManager
-
markReplacement
public void markReplacement()
Marks this instance as a replacement for a deleted instance with the same ObjectId.- Specified by:
markReplacement
in interfaceStateManager
-
getLock
public void getLock()
Lock this instance.- Specified by:
getLock
in interfaceStateManager
-
releaseLock
public void releaseLock()
Release lock.- Specified by:
releaseLock
in interfaceStateManager
-
isValid
public boolean isValid()
Return value for valid flag.- Specified by:
isValid
in interfaceStateManager
-
setValid
public void setValid()
Mark this StateManager as valid. Called before returning from getObjectById.- Specified by:
setValid
in interfaceStateManager
-
-