Package org.apache.openjpa.kernel
Interface OpenJPAStateManager
-
- All Superinterfaces:
FieldConsumer
,FieldManager
,FieldSupplier
,StateManager
- All Known Implementing Classes:
DetachedStateManager
,DetachedValueStateManager
,ObjectIdStateManager
,StateManagerImpl
public interface OpenJPAStateManager extends StateManager, FieldManager
Interface implemented by OpenJPA state managers. Each state manager manages the state of a single persistence capable instance. The state manager is also responsible for all communications about the instance to theStoreManager
. ThefetchXXXField
andstoreXXXField
methods can be used to get and set fields of the managed persistent object. Most back-end code, however, should use the similarfetchXXX
andstoreXXX
methods in place of the field methods. These methods function just like the field methods, but also pass the value through the externalizer and factory the field may have.- Author:
- Abe White
-
-
Field Summary
Fields Modifier and Type Field Description static int
SET_ATTACH
The field is being attached by a detached state manager; the value is from the detached instance.static int
SET_REMOTE
The remote broker framework is setting the field on the server.static int
SET_USER
A user is setting the field.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
assignObjectId(boolean flush)
Ask the store manager to assign a permanent oid to this new instance.boolean
beforeRefresh(boolean refreshAll)
Prepare the instance for refreshvoid
dirty(int field)
Mark the given field as dirty.java.lang.Object
fetch(int field)
Return the externalized value of the field with the given index as an object.boolean
fetchBoolean(int field)
Return the external value of the given field.byte
fetchByte(int field)
Return the external value of the given field.char
fetchChar(int field)
Return the external value of the given field.double
fetchDouble(int field)
Return the external value of the given field.java.lang.Object
fetchField(int field, boolean transitions)
Return the value of the field with the given index as an object.float
fetchFloat(int field)
Return the external value of the given field.java.lang.Object
fetchInitialField(int field)
Return the value of the field at the specified index as of the beginning of the transaction.int
fetchInt(int field)
Return the external value of the given field.long
fetchLong(int field)
Return the external value of the given field.java.lang.Object
fetchObject(int field)
Return the external value of the given field.java.lang.Object
fetchObjectField(int field)
Fetch an object field by index.short
fetchShort(int field)
Return the external value of the given field.java.lang.String
fetchString(int field)
Return the external value of the given field.StoreContext
getContext()
Return the managing context.java.util.BitSet
getDirty()
Return a read-only mask of the indexes of all dirty fields.java.util.BitSet
getFlushed()
Return a read-only mask of the indexes of all fields that have been flushed since they were last changed.java.lang.Object
getId()
Return the identifier for this state manager.java.lang.Object
getImplData()
An object that concrete back ends can associate with each instance.java.lang.Object
getImplData(int field)
Field-level impl data.java.lang.Object
getIntermediate(int field)
Use intermediate field data to store intermediate information that might be available before the field is fully loaded.java.util.BitSet
getLoaded()
Return a read-only mask of the indexes of all loaded fields.java.lang.Object
getLock()
The lock object set for this instance.java.lang.Object
getManagedInstance()
Return the managed instance.ClassMetaData
getMetaData()
Get the metadata for this instance.java.lang.Object
getObjectId()
Return the instance's object id.OpenJPAStateManager
getOwner()
Return the owning state if this is an embedded instance.int
getOwnerIndex()
Return the owning value's field indexPCState
getPCState()
Return the state that this object is in.PersistenceCapable
getPersistenceCapable()
Return thePersistenceCapable
instance that provides access to the instance managed by this state manager.java.util.BitSet
getUnloaded(FetchConfiguration fetch)
Return a mutable mask of the unloaded fields that need loading based on the given fetch configuration.java.lang.Object
getVersion()
Return the current version indicator for this instance.void
initialize(java.lang.Class forType, PCState state)
Initialize the state manager with a new instance of the given persistence capable type and the proper lifecycle state.boolean
isDefaultValue(int field)
Return true if the given field has a default value.boolean
isDelayed(int field)
Some field types (collection proxies) support delayed loading.boolean
isEmbedded()
Return true if this instance has an owner, meaning it is an embedded value.boolean
isFlushed()
Return whether this object has been flushed to the datastore in this transaction.boolean
isFlushedDirty()
Return whether this object has been flushed, then dirtied again.boolean
isImplDataCacheable()
Whether the instance-level impl data can be shared among instances in different contexts if L2 caching is enabled.boolean
isImplDataCacheable(int field)
Whether the field's impl data is loaded and can be shared among instances in different contexts if L2 caching is enabled.boolean
isProvisional()
Return whether this object is provisionally persistent.boolean
isVersionCheckRequired()
Returns true if this state needs to issue a version check at flush time.boolean
isVersionUpdateRequired()
Returns true if this state needs to issue a version update, possibly as a result of being locked.void
load(FetchConfiguration fetch)
Load fetch group fields.void
loadDelayedField(int field)
If a field was marked delayed in a previous load operation this method can be used to load the field.java.lang.Object
newFieldProxy(int field)
Create a new hollow proxy instance for the given field.java.lang.Object
newProxy(int field)
Create a new hollow proxy instance for the given field.void
removed(int field, java.lang.Object removed, boolean key)
Notification that an element has been removed from the given field.void
setDelayed(int field, boolean delay)
Some field types (collection proxies) support delayed loading.java.lang.Object
setImplData(int field, java.lang.Object data)
Field-level impl data.java.lang.Object
setImplData(java.lang.Object data, boolean cacheable)
An object that concrete back ends can associate with each instance.void
setIntermediate(int field, java.lang.Object value)
Use intermediate field data to store intermediate information that might be available before the field is fully loaded.void
setLock(java.lang.Object lock)
The lock object set for this instance.void
setNextVersion(java.lang.Object version)
Set the next version indicator in the datastore pending a successful flush.void
setObjectId(java.lang.Object oid)
Set the object id for the managed instance.void
setRemote(int field, java.lang.Object value)
Set the given field to the given value.void
setVersion(java.lang.Object version)
Set the version indicator for this instance, as loaded from the data store.void
store(int field, java.lang.Object value)
Set the value of the field with the given index as from the external object value.void
storeBoolean(int field, boolean externalVal)
Set the given external value back into the given field.void
storeByte(int field, byte externalVal)
Set the given external value back into the given field.void
storeChar(int field, char externalVal)
Set the given external value back into the given field.void
storeDouble(int field, double externalVal)
Set the given external value back into the given field.void
storeField(int field, java.lang.Object value)
Set the value of the field with the given index as an object.void
storeFloat(int field, float externalVal)
Set the given external value back into the given field.void
storeInt(int field, int externalVal)
Set the given external value back into the given field.void
storeLong(int field, long externalVal)
Set the given external value back into the given field.void
storeObject(int field, java.lang.Object externalVal)
Set the given external value back into the given field.void
storeShort(int field, short externalVal)
Set the given external value back into the given field.void
storeString(int field, java.lang.String externalVal)
Set the given external value back into the given field.-
Methods inherited from interface org.apache.openjpa.enhance.FieldConsumer
storeBooleanField, storeByteField, storeCharField, storeDoubleField, storeFloatField, storeIntField, storeLongField, storeObjectField, storeShortField, storeStringField
-
Methods inherited from interface org.apache.openjpa.enhance.FieldSupplier
fetchBooleanField, fetchByteField, fetchCharField, fetchDoubleField, fetchFloatField, fetchIntField, fetchLongField, fetchShortField, fetchStringField
-
Methods inherited from interface org.apache.openjpa.enhance.StateManager
accessingField, dirty, fetchObjectId, getGenericContext, getPCPrimaryKey, isDeleted, isDetached, isDirty, isNew, isPersistent, isTransactional, providedBooleanField, providedByteField, providedCharField, providedDoubleField, providedFloatField, providedIntField, providedLongField, providedObjectField, providedShortField, providedStringField, proxyDetachedDeserialized, replaceBooleanField, replaceByteField, replaceCharField, replaceDoubleField, replaceFloatField, replaceIntField, replaceLongField, replaceObjectField, replaceShortField, replaceStateManager, replaceStringField, serializing, settingBooleanField, settingByteField, settingCharField, settingDoubleField, settingFloatField, settingIntField, settingLongField, settingObjectField, settingShortField, settingStringField, writeDetached
-
-
-
-
Field Detail
-
SET_USER
static final int SET_USER
A user is setting the field.- See Also:
- Constant Field Values
-
SET_REMOTE
static final int SET_REMOTE
The remote broker framework is setting the field on the server.- See Also:
- Constant Field Values
-
SET_ATTACH
static final int SET_ATTACH
The field is being attached by a detached state manager; the value is from the detached instance.- See Also:
- Constant Field Values
-
-
Method Detail
-
initialize
void initialize(java.lang.Class forType, PCState state)
Initialize the state manager with a new instance of the given persistence capable type and the proper lifecycle state. Invoking this method may change the object id and metadata for the state manager, as the concrete type specified in the parameter may be a subclass of the expected type.- Parameters:
forType
- the type for which to create a new instancestate
- the initial state to which to set the instance- Since:
- 0.3.1.2
-
load
void load(FetchConfiguration fetch)
Load fetch group fields.
-
getManagedInstance
java.lang.Object getManagedInstance()
Return the managed instance.
-
getPersistenceCapable
PersistenceCapable getPersistenceCapable()
Return thePersistenceCapable
instance that provides access to the instance managed by this state manager. May be a proxy around the actual managed instance.
-
getMetaData
ClassMetaData getMetaData()
Get the metadata for this instance.
-
getOwner
OpenJPAStateManager getOwner()
Return the owning state if this is an embedded instance.
-
getOwnerIndex
int getOwnerIndex()
Return the owning value's field index- Since:
- 1.1.0
-
isEmbedded
boolean isEmbedded()
Return true if this instance has an owner, meaning it is an embedded value.
-
isFlushed
boolean isFlushed()
Return whether this object has been flushed to the datastore in this transaction.
-
isFlushedDirty
boolean isFlushedDirty()
Return whether this object has been flushed, then dirtied again.
-
isProvisional
boolean isProvisional()
Return whether this object is provisionally persistent.
-
getLoaded
java.util.BitSet getLoaded()
Return a read-only mask of the indexes of all loaded fields.
-
getDirty
java.util.BitSet getDirty()
Return a read-only mask of the indexes of all dirty fields.
-
getFlushed
java.util.BitSet getFlushed()
Return a read-only mask of the indexes of all fields that have been flushed since they were last changed.
-
getUnloaded
java.util.BitSet getUnloaded(FetchConfiguration fetch)
Return a mutable mask of the unloaded fields that need loading based on the given fetch configuration. Pass in null to retrieve all unloaded fields.
-
newProxy
java.lang.Object newProxy(int field)
Create a new hollow proxy instance for the given field. In cases where the field externalizes to an SCO but is declared something else, the returned object may not implementProxy
. In all other cases, this method delegates to the systemProxyManager
with the correct field information. The returned proxy's owner is unset so that modifications to the proxy will not be tracked while its state is initialized. CallingstoreField(int, java.lang.Object)
orstore(int, java.lang.Object)
will set the proxy's owner automatically.
-
newFieldProxy
java.lang.Object newFieldProxy(int field)
Create a new hollow proxy instance for the given field. This method differs fromnewProxy(int)
in that it returns a proxy for the field's declared type, not its externalized type.- See Also:
newProxy(int)
-
isDefaultValue
boolean isDefaultValue(int field)
Return true if the given field has a default value.
-
getContext
StoreContext getContext()
Return the managing context.
-
getPCState
PCState getPCState()
Return the state that this object is in.
-
getId
java.lang.Object getId()
Return the identifier for this state manager. This may return a temporary identifier for new unflushed instances that have not been assigned an object id, or for non-persistent or embedded instances. For all other instances this method is the same asgetObjectId()
.
-
getObjectId
java.lang.Object getObjectId()
Return the instance's object id. This method will return null if no oid has been assigned. Oids are assigned to newly-persisted instances when the user first asks for it, or on flush.
-
setObjectId
void setObjectId(java.lang.Object oid)
Set the object id for the managed instance. Some back ends may not be able to assign a permanent oid until flush. Do not call this method on application identity instances; changing the primary key fields of application identity objects through thestoreXXXField
methods will automatically change the oid.
-
assignObjectId
boolean assignObjectId(boolean flush)
Ask the store manager to assign a permanent oid to this new instance.- Parameters:
flush
- if true, flush if necessary to get a permanent oid; if false, the oid may be left unassigned- Returns:
- true if an oid assigned, false otherwise
-
getLock
java.lang.Object getLock()
The lock object set for this instance. This object is generally managed by the system lock manager.
-
setLock
void setLock(java.lang.Object lock)
The lock object set for this instance. This object is generally managed by the system lock manager.
-
getVersion
java.lang.Object getVersion()
Return the current version indicator for this instance.- Specified by:
getVersion
in interfaceStateManager
-
setVersion
void setVersion(java.lang.Object version)
Set the version indicator for this instance, as loaded from the data store. This method is used by theStoreManager
when loading instance data. On rollback, the version will be rolled back to this value. Version objects should be serializable and should not require vendor-specific classes, because they are transferred to detached objects.
-
setNextVersion
void setNextVersion(java.lang.Object version)
Set the next version indicator in the datastore pending a successful flush. TheStoreManager
uses this method during flush.
-
isVersionUpdateRequired
boolean isVersionUpdateRequired()
Returns true if this state needs to issue a version update, possibly as a result of being locked.
-
isVersionCheckRequired
boolean isVersionCheckRequired()
Returns true if this state needs to issue a version check at flush time.
-
getImplData
java.lang.Object getImplData()
An object that concrete back ends can associate with each instance. This object is not used or modified in any way by the generic persistence layer.
-
setImplData
java.lang.Object setImplData(java.lang.Object data, boolean cacheable)
An object that concrete back ends can associate with each instance. This object is not used or modified in any way by the generic persistence layer.- Parameters:
cacheable
- whether the impl data can be shared among instances in different contexts if L2 caching is enabled- Returns:
- the previous impl data value, if any
-
isImplDataCacheable
boolean isImplDataCacheable()
Whether the instance-level impl data can be shared among instances in different contexts if L2 caching is enabled.
-
getImplData
java.lang.Object getImplData(int field)
Field-level impl data. Field-level data only applies to loaded fields, and is cleared when the field is cleared.
-
setImplData
java.lang.Object setImplData(int field, java.lang.Object data)
Field-level impl data. Field-level data only applies to loaded fields, and is cleared when the field is cleared. Whether the data is cached across instances depends on the corresponding field metadata's response toFieldMetaData.usesImplData()
.- Returns:
- the previous impl data value, if any
-
isImplDataCacheable
boolean isImplDataCacheable(int field)
Whether the field's impl data is loaded and can be shared among instances in different contexts if L2 caching is enabled.
-
getIntermediate
java.lang.Object getIntermediate(int field)
Use intermediate field data to store intermediate information that might be available before the field is fully loaded. The system will automatically clear this data when the field gets loaded. This data should be cacheable; the datastore cache will attempt to cache it if the field value is not available.
-
setIntermediate
void setIntermediate(int field, java.lang.Object value)
Use intermediate field data to store intermediate information that might be available before the field is fully loaded. The system will automatically clear this data when the field gets loaded. This data should be cacheable; the datastore cache will attempt to cache it if the field value is not available.
-
fetchBoolean
boolean fetchBoolean(int field)
Return the external value of the given field.
-
fetchByte
byte fetchByte(int field)
Return the external value of the given field.
-
fetchChar
char fetchChar(int field)
Return the external value of the given field.
-
fetchDouble
double fetchDouble(int field)
Return the external value of the given field.
-
fetchFloat
float fetchFloat(int field)
Return the external value of the given field.
-
fetchInt
int fetchInt(int field)
Return the external value of the given field.
-
fetchLong
long fetchLong(int field)
Return the external value of the given field.
-
fetchObject
java.lang.Object fetchObject(int field)
Return the external value of the given field.
-
fetchShort
short fetchShort(int field)
Return the external value of the given field.
-
fetchString
java.lang.String fetchString(int field)
Return the external value of the given field.
-
fetch
java.lang.Object fetch(int field)
Return the externalized value of the field with the given index as an object. If there is no externalizer, this is equivalent tofetchField(int, boolean)
.
-
fetchField
java.lang.Object fetchField(int field, boolean transitions)
Return the value of the field with the given index as an object.- Parameters:
transitions
- if true, this method will cause state transitions to occur as if the field were accessed normally
-
fetchInitialField
java.lang.Object fetchInitialField(int field)
Return the value of the field at the specified index as of the beginning of the transaction.- Since:
- 0.3.1.1
-
storeBoolean
void storeBoolean(int field, boolean externalVal)
Set the given external value back into the given field.
-
storeByte
void storeByte(int field, byte externalVal)
Set the given external value back into the given field.
-
storeChar
void storeChar(int field, char externalVal)
Set the given external value back into the given field.
-
storeDouble
void storeDouble(int field, double externalVal)
Set the given external value back into the given field.
-
storeFloat
void storeFloat(int field, float externalVal)
Set the given external value back into the given field.
-
storeInt
void storeInt(int field, int externalVal)
Set the given external value back into the given field.
-
storeLong
void storeLong(int field, long externalVal)
Set the given external value back into the given field.
-
storeObject
void storeObject(int field, java.lang.Object externalVal)
Set the given external value back into the given field.
-
storeShort
void storeShort(int field, short externalVal)
Set the given external value back into the given field.
-
storeString
void storeString(int field, java.lang.String externalVal)
Set the given external value back into the given field.
-
store
void store(int field, java.lang.Object value)
Set the value of the field with the given index as from the external object value. If there is no externalizer, this is equivalent tostoreField(int, java.lang.Object)
.
-
storeField
void storeField(int field, java.lang.Object value)
Set the value of the field with the given index as an object.
-
dirty
void dirty(int field)
Mark the given field as dirty.
-
removed
void removed(int field, java.lang.Object removed, boolean key)
Notification that an element has been removed from the given field.
-
beforeRefresh
boolean beforeRefresh(boolean refreshAll)
Prepare the instance for refresh- Parameters:
refreshAll
- true if this instance is one of a collection of objects being refreshed- Returns:
- true if the object needs a refresh, false otherwise
- See Also:
Broker.refresh(java.lang.Object, org.apache.openjpa.kernel.OpCallbacks)
-
setRemote
void setRemote(int field, java.lang.Object value)
Set the given field to the given value. Make the field dirty as if user code set it. Do not delete dependent objects in the field's current value. This method is invoked by the remote package to synch a server-side state manager with remote changes. We do not need to delete dependent instances because they will have been deleted when the field changed on the client side, and those client-side deletes will be transmitted independently.- Since:
- 0.3.1
-
isDelayed
boolean isDelayed(int field)
Some field types (collection proxies) support delayed loading. Delayed loading is a step beyond lazy loading. Delayed load allows an instance of a field to be returned without actually loading it.- Returns:
- true if the field is setup for delayed access
-
setDelayed
void setDelayed(int field, boolean delay)
Some field types (collection proxies) support delayed loading. Delayed loading is a step beyond lazy loading. Delayed load allows an instance of a field to be returned without actually loading it.
-
loadDelayedField
void loadDelayedField(int field)
If a field was marked delayed in a previous load operation this method can be used to load the field.
-
fetchObjectField
java.lang.Object fetchObjectField(int field)
Fetch an object field by index.- Specified by:
fetchObjectField
in interfaceFieldSupplier
-
-