Package org.apache.openjpa.kernel
Interface StoreContext
-
- All Known Subinterfaces:
Broker
,DistributedBroker
- All Known Implementing Classes:
BrokerImpl
,DelegatingBroker
,DistributedBrokerImpl
,FinalizingBrokerImpl
public interface StoreContext
Represents a set of managed objects and their environment.- Since:
- 0.4.0
- Author:
- Abe White
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.BitSet
EXCLUDE_ALL
Marker bitset to indicate that all field loads should be excluded in thefind
methods of this interface.static int
OID_ALLOW_NEW
static int
OID_COPY
static int
OID_NODELETED
static int
OID_NOVALIDATE
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
beginStore()
Begin a data store transaction.OpenJPAStateManager
embed(java.lang.Object obj, java.lang.Object id, OpenJPAStateManager owner, ValueMetaData ownerMeta)
Make the given instance embedded.java.util.Iterator<java.lang.Object>
extentIterator(java.lang.Class<?> cls, boolean subs, FetchConfiguration fetch, boolean ignoreChanges)
Return an iterator over all instances of the given type.java.lang.Object
find(java.lang.Object oid, boolean validate, FindCallbacks call)
Find the persistence object with the given oid.java.lang.Object
find(java.lang.Object oid, FetchConfiguration fetch, java.util.BitSet exclude, java.lang.Object edata, int flags)
Return the object with the given oid.java.lang.Object[]
findAll(java.util.Collection<java.lang.Object> oids, boolean validate, FindCallbacks call)
Return the objects with the given oids.java.lang.Object[]
findAll(java.util.Collection<java.lang.Object> oids, FetchConfiguration fetch, java.util.BitSet exclude, java.lang.Object edata, int flags)
Return the objects with the given oids.java.lang.Object
findCached(java.lang.Object oid, FindCallbacks call)
Return the instance for the given oid/object , or null if not found in the L1 cache.boolean
getAllowReferenceToSiblingContext()
Affirms if this context will allow its managed instances to refer instances that are managed by other contexts.Broker
getBroker()
Return the broker for this context, if possible.java.lang.ClassLoader
getClassLoader()
Return the current thread's class loader at the time this context was obtained.OpenJPAConfiguration
getConfiguration()
Return the configuration associated with this context.java.lang.Object
getConnection()
Return the connection in use by the context, or a new connection if none.java.lang.Object
getConnectionFactory()
Return the 'JTA' ConnectionFactory, looking it up from JNDI if needed.java.lang.Object
getConnectionFactory2()
Return the 'NonJTA' ConnectionFactory, looking it up from JNDI if needed.java.lang.String
getConnectionFactory2Name()
Return the 'NonJTA' ConnectionFactoryName.java.lang.String
getConnectionFactoryName()
Return the 'JTA' connectionFactoryNamejava.lang.String
getConnectionPassword()
Return the connection password.java.lang.String
getConnectionUserName()
Return the connection user name.java.util.Collection<java.lang.Class<?>>
getDeletedTypes()
Return the set of classes that have been deleted in the current transaction.int
getDetachState()
Detach mode constant to determine which fields are part of the detached graph.java.util.Collection<java.lang.Object>
getDirtyObjects()
Return a list of current dirty instances.FetchConfiguration
getFetchConfiguration()
Return the (mutable) fetch configuration for loading objects from this context.int
getLockLevel(java.lang.Object obj)
Return the lock level of the specified object.LockManager
getLockManager()
Return the lock manager in use.java.util.Collection<java.lang.Object>
getManagedObjects()
Return a list of all managed instances.java.lang.Object
getObjectId(java.lang.Object obj)
Return the oid of the given instance.java.lang.Class<?>
getObjectIdType(java.lang.Class<?> cls)
Return the application or datastore identity class the given persistent class uses for object ids.boolean
getOrderDirtyObjects()
Whether to maintain the order in which objects are dirtied forgetDirtyObjects()
.java.util.Collection<java.lang.Object>
getPendingTransactionalObjects()
Return a list of instances which will become transactional upon the next transaction.java.util.Collection<java.lang.Class<?>>
getPersistedTypes()
Return the set of classes that have been made persistent in the current transaction.boolean
getPopulateDataCache()
Whether objects accessed during this transaction will be added to the store cache.boolean
getPostLoadOnMerge()
Force sending a @PostLoad lifecycle event while merging.OpenJPAStateManager
getStateManager(java.lang.Object obj)
Return the state manager for the given instance.DelegatingStoreManager
getStoreManager()
Return the store manager in use.java.util.Collection<java.lang.Object>
getTransactionalObjects()
Return a list of current transaction instances.java.util.Collection<java.lang.Class<?>>
getUpdatedTypes()
Return the set of classes for objects that have been modified in the current transaction.java.lang.Object
getVersion(java.lang.Object obj)
Returns the current version indicator foro
.boolean
hasConnection()
Whether the broker has a dedicated connection based on the configured connection retain mode and transaction status.boolean
isActive()
Whether a logical transaction is active.boolean
isCached(java.util.List<java.lang.Object> oid)
Indicate whether the oid can be found in the StoreContext's L1 cache or in the StoreManager cache.boolean
isDeleted(java.lang.Object obj)
Return whether the given object is deleted.boolean
isDirty(java.lang.Object obj)
Return whether the given object is dirty.boolean
isManaged()
Whether this context is using managed transactions.boolean
isNew(java.lang.Object obj)
Return whether the given object is a newly-created instance registered withbroker
.boolean
isPersistent(java.lang.Object obj)
Return whether the given object is persistent.boolean
isStoreActive()
Whether a data store transaction is active.boolean
isTrackChangesByType()
Whether memory usage is reduced during this transaction at the expense of tracking changes at the type level instead of the instance level, resulting in more aggressive cache invalidation.boolean
isTransactional(java.lang.Object obj)
Return whether the given object is transactional.void
lock()
Synchronizes on an internal lock if theMultithreaded
flag is set to true.java.lang.Object
newObjectId(java.lang.Class<?> cls, java.lang.Object val)
Create a new object id instance from the given value.void
nontransactional(java.lang.Object pc, OpCallbacks call)
Make the given object non-transactional.void
nontransactionalAll(java.util.Collection<java.lang.Object> objs, OpCallbacks call)
Make the given objects nontransactional.void
popFetchConfiguration()
Pops the fetch configuration from the top of the stack, making the next one down the active one.FetchConfiguration
pushFetchConfiguration()
Pushes a new fetch configuration that inherits from the current fetch configuration onto a stack, and makes the new configuration the active one.FetchConfiguration
pushFetchConfiguration(FetchConfiguration fc)
Pushes the fetch configuration argument onto a stack, and makes the new configuration the active one.void
retrieve(java.lang.Object pc, boolean fgOnly, OpCallbacks call)
Immediately load the given object's persistent fields.void
retrieveAll(java.util.Collection<java.lang.Object> objs, boolean fgOnly, OpCallbacks call)
Retrieve the given objects' persistent state.void
setAllowReferenceToSiblingContext(boolean flag)
Affirms if this context will allow its managed instances to refer instances that are managed by other contexts.void
setConnectionFactory2Name(java.lang.String connectionFactory2Name)
Set the 'NonJTA' ConnectionFactoryName.void
setConnectionFactoryName(java.lang.String connectionFactoryName)
Set the 'JTA' ConnectionFactoryName.void
setDetachState(int mode)
Detach mode constant to determine which fields are part of the detached graph.void
setOrderDirtyObjects(boolean order)
Whether to maintain the order in which objects are dirtied forgetDirtyObjects()
.void
setPopulateDataCache(boolean cache)
Whether to populate the store cache with objects used by this transaction.void
setPostLoadOnMerge(boolean allow)
Set totrue
if the merge operation should trigger a @PostLoad lifecycle event.void
setTrackChangesByType(boolean largeTransaction)
If a large number of objects will be created, modified, or deleted during this transaction setting this option to true will reduce memory usage if you perform periodic flushes by tracking changes at the type level instead of the instance level, resulting in more aggressive cache invalidation.void
transactional(java.lang.Object pc, boolean updateVersion, OpCallbacks call)
Make the given object transactional.void
transactionalAll(java.util.Collection<java.lang.Object> objs, boolean updateVersion, OpCallbacks call)
Make the given objects transactional.void
unlock()
Releases the internal lock.
-
-
-
Field Detail
-
EXCLUDE_ALL
static final java.util.BitSet EXCLUDE_ALL
Marker bitset to indicate that all field loads should be excluded in thefind
methods of this interface.
-
OID_NOVALIDATE
static final int OID_NOVALIDATE
- See Also:
- Constant Field Values
-
OID_NODELETED
static final int OID_NODELETED
- See Also:
- Constant Field Values
-
OID_COPY
static final int OID_COPY
- See Also:
- Constant Field Values
-
OID_ALLOW_NEW
static final int OID_ALLOW_NEW
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBroker
Broker getBroker()
Return the broker for this context, if possible. Note that a broker will be unavailable in remote contexts, and this method may return null.
-
getConfiguration
OpenJPAConfiguration getConfiguration()
Return the configuration associated with this context.
-
getFetchConfiguration
FetchConfiguration getFetchConfiguration()
Return the (mutable) fetch configuration for loading objects from this context.
-
pushFetchConfiguration
FetchConfiguration pushFetchConfiguration()
Pushes a new fetch configuration that inherits from the current fetch configuration onto a stack, and makes the new configuration the active one.- Returns:
- the new fetch configuration
- Since:
- 1.1.0
-
pushFetchConfiguration
FetchConfiguration pushFetchConfiguration(FetchConfiguration fc)
Pushes the fetch configuration argument onto a stack, and makes the new configuration the active one.- Returns:
- the new fetch configuration
- Since:
- 2.1.1
-
popFetchConfiguration
void popFetchConfiguration()
Pops the fetch configuration from the top of the stack, making the next one down the active one. This returns void to avoid confusion, since fetch configurations tend to be used in method-chaining patterns often.- Throws:
UserException
- if the fetch configuration stack is empty- Since:
- 1.1.0
-
getClassLoader
java.lang.ClassLoader getClassLoader()
Return the current thread's class loader at the time this context was obtained.
-
getLockManager
LockManager getLockManager()
Return the lock manager in use.
-
getStoreManager
DelegatingStoreManager getStoreManager()
Return the store manager in use. This will be a wrapper around the native store manager, which you can retrieve viaDelegatingStoreManager.getInnermostDelegate()
.
-
getConnectionUserName
java.lang.String getConnectionUserName()
Return the connection user name.
-
getConnectionPassword
java.lang.String getConnectionPassword()
Return the connection password.
-
findCached
java.lang.Object findCached(java.lang.Object oid, FindCallbacks call)
Return the instance for the given oid/object , or null if not found in the L1 cache.- Parameters:
oid
- the object's id- Returns:
- the cached object, or null if not cached
-
find
java.lang.Object find(java.lang.Object oid, boolean validate, FindCallbacks call)
Find the persistence object with the given oid. Ifvalidate
is true, the broker will check the store for the object, and return null if it does not exist. Ifvalidate
is false, this method never returns null. The broker will either return its cached instance, attempt to create a hollow instance, or throw anObjectNotFoundException
if unable to return a hollow instance.- Parameters:
validate
- if true, validate that the instance exists in the store and load fetch group fields, otherwise return any cached or hollow instance
-
findAll
java.lang.Object[] findAll(java.util.Collection<java.lang.Object> oids, boolean validate, FindCallbacks call)
Return the objects with the given oids.- Parameters:
oids
- the oids of the objects to return- Returns:
- the objects that were looked up, in the same order as the oids parameter
- See Also:
find(Object,boolean,FindCallbacks)
-
find
java.lang.Object find(java.lang.Object oid, FetchConfiguration fetch, java.util.BitSet exclude, java.lang.Object edata, int flags)
Return the object with the given oid. If present, the cached instance will be returned. Otherwise, the instance will be initialized through the store as usual; however, in this case the store will be passed the given execution data, and the system will load the object according to the given fetch configuration (or the context's configuration, if the given one is null). Fields can optionally be excluded from required loading using theexclude
mask. By default this method does not find new unflushed instances, validates, and does not throw an exception if a cached instance has been deleted concurrently. These options are controllable through the givenOID_XXX
flags.
-
findAll
java.lang.Object[] findAll(java.util.Collection<java.lang.Object> oids, FetchConfiguration fetch, java.util.BitSet exclude, java.lang.Object edata, int flags)
Return the objects with the given oids.
-
extentIterator
java.util.Iterator<java.lang.Object> extentIterator(java.lang.Class<?> cls, boolean subs, FetchConfiguration fetch, boolean ignoreChanges)
Return an iterator over all instances of the given type. The iterator should be closed withImplHelper.close(java.lang.Object)
when no longer needed. This method delegates toStoreManager.executeExtent(org.apache.openjpa.meta.ClassMetaData, boolean, org.apache.openjpa.kernel.FetchConfiguration)
.
-
retrieve
void retrieve(java.lang.Object pc, boolean fgOnly, OpCallbacks call)
Immediately load the given object's persistent fields. One might use this action to make sure that an instance's fields are loaded before transitioning it to transient. Note that this action is not recursive. Any related objects that are loaded will not necessarily have their fields loaded. Unmanaged target is ignored.- Parameters:
fgOnly
- indicator as to whether to retrieve only fields in the current fetch groups, or all fields- See Also:
retrieve(java.lang.Object, boolean, org.apache.openjpa.kernel.OpCallbacks)
-
retrieveAll
void retrieveAll(java.util.Collection<java.lang.Object> objs, boolean fgOnly, OpCallbacks call)
Retrieve the given objects' persistent state. Unmanaged targets are ignored.- Parameters:
fgOnly
- indicator as to whether to retrieve only fields- See Also:
retrieve(java.lang.Object, boolean, org.apache.openjpa.kernel.OpCallbacks)
-
embed
OpenJPAStateManager embed(java.lang.Object obj, java.lang.Object id, OpenJPAStateManager owner, ValueMetaData ownerMeta)
Make the given instance embedded.- Parameters:
obj
- the instance to embed; may be null to create a new instanceid
- the id to give the embedded state manager; may be null for defaultowner
- the owning state managerownerMeta
- the value in which the object is embedded- Returns:
- the state manager for the embedded instance
-
getObjectIdType
java.lang.Class<?> getObjectIdType(java.lang.Class<?> cls)
Return the application or datastore identity class the given persistent class uses for object ids.
-
newObjectId
java.lang.Object newObjectId(java.lang.Class<?> cls, java.lang.Object val)
Create a new object id instance from the given value.- Parameters:
cls
- the persistent class that uses this identity valueval
- an object id instance, stringified object id, or primary key value
-
getPersistedTypes
java.util.Collection<java.lang.Class<?>> getPersistedTypes()
Return the set of classes that have been made persistent in the current transaction.- Since:
- 0.3.4
-
getDeletedTypes
java.util.Collection<java.lang.Class<?>> getDeletedTypes()
Return the set of classes that have been deleted in the current transaction.- Since:
- 0.3.4
-
getUpdatedTypes
java.util.Collection<java.lang.Class<?>> getUpdatedTypes()
Return the set of classes for objects that have been modified in the current transaction.- Since:
- 0.3.4
-
getManagedObjects
java.util.Collection<java.lang.Object> getManagedObjects()
Return a list of all managed instances.
-
getTransactionalObjects
java.util.Collection<java.lang.Object> getTransactionalObjects()
Return a list of current transaction instances.
-
getPendingTransactionalObjects
java.util.Collection<java.lang.Object> getPendingTransactionalObjects()
Return a list of instances which will become transactional upon the next transaction.
-
getDirtyObjects
java.util.Collection<java.lang.Object> getDirtyObjects()
Return a list of current dirty instances.
-
getOrderDirtyObjects
boolean getOrderDirtyObjects()
Whether to maintain the order in which objects are dirtied forgetDirtyObjects()
. Default is the store manager's decision.
-
setOrderDirtyObjects
void setOrderDirtyObjects(boolean order)
Whether to maintain the order in which objects are dirtied forgetDirtyObjects()
. Default is the store manager's decision.
-
getStateManager
OpenJPAStateManager getStateManager(java.lang.Object obj)
Return the state manager for the given instance. Includes objects made persistent in the current transaction. Ifobj
is not a managed type or is managed by another context, throw an exception.
-
getLockLevel
int getLockLevel(java.lang.Object obj)
Return the lock level of the specified object.
-
getVersion
java.lang.Object getVersion(java.lang.Object obj)
Returns the current version indicator foro
.
-
isDirty
boolean isDirty(java.lang.Object obj)
Return whether the given object is dirty.
-
isTransactional
boolean isTransactional(java.lang.Object obj)
Return whether the given object is transactional.
-
transactional
void transactional(java.lang.Object pc, boolean updateVersion, OpCallbacks call)
Make the given object transactional.- Parameters:
pc
- instance to make transactionalupdateVersion
- if true, the instance's version will be incremented at the next flush
-
transactionalAll
void transactionalAll(java.util.Collection<java.lang.Object> objs, boolean updateVersion, OpCallbacks call)
Make the given objects transactional.- Parameters:
objs
- instances to make transactionalupdateVersion
- if true, the instance's version will be incremented at the next flush
-
nontransactional
void nontransactional(java.lang.Object pc, OpCallbacks call)
Make the given object non-transactional.
-
nontransactionalAll
void nontransactionalAll(java.util.Collection<java.lang.Object> objs, OpCallbacks call)
Make the given objects nontransactional.
-
isPersistent
boolean isPersistent(java.lang.Object obj)
Return whether the given object is persistent.
-
isNew
boolean isNew(java.lang.Object obj)
Return whether the given object is a newly-created instance registered withbroker
.
-
isDeleted
boolean isDeleted(java.lang.Object obj)
Return whether the given object is deleted.
-
getObjectId
java.lang.Object getObjectId(java.lang.Object obj)
Return the oid of the given instance.
-
getDetachState
int getDetachState()
Detach mode constant to determine which fields are part of the detached graph. Defaults toDetachState.DETACH_LOADED
.
-
setDetachState
void setDetachState(int mode)
Detach mode constant to determine which fields are part of the detached graph. Defaults toDetachState.DETACH_LOADED
.
-
getPopulateDataCache
boolean getPopulateDataCache()
Whether objects accessed during this transaction will be added to the store cache. Defaults to true.- Since:
- 0.3.4
-
setPopulateDataCache
void setPopulateDataCache(boolean cache)
Whether to populate the store cache with objects used by this transaction. Defaults to true.- Since:
- 0.3.4
-
isTrackChangesByType
boolean isTrackChangesByType()
Whether memory usage is reduced during this transaction at the expense of tracking changes at the type level instead of the instance level, resulting in more aggressive cache invalidation.- Since:
- 1.0.0
-
setTrackChangesByType
void setTrackChangesByType(boolean largeTransaction)
If a large number of objects will be created, modified, or deleted during this transaction setting this option to true will reduce memory usage if you perform periodic flushes by tracking changes at the type level instead of the instance level, resulting in more aggressive cache invalidation. Upon transaction commit the data cache will have to more aggressively flush objects. The store cache will have to flush instances of objects for each class of object modified during the transaction. A side benefit of large transaction mode is that smaller update messages can be used forRemoteCommitEvent
s. Defaults to false.- Since:
- 1.0.0
-
isManaged
boolean isManaged()
Whether this context is using managed transactions.
-
isActive
boolean isActive()
Whether a logical transaction is active.
-
isStoreActive
boolean isStoreActive()
Whether a data store transaction is active.
-
beginStore
void beginStore()
Begin a data store transaction.
-
hasConnection
boolean hasConnection()
Whether the broker has a dedicated connection based on the configured connection retain mode and transaction status.
-
getConnection
java.lang.Object getConnection()
Return the connection in use by the context, or a new connection if none.
-
lock
void lock()
Synchronizes on an internal lock if theMultithreaded
flag is set to true. Make sure to callunlock()
in a finally clause of the same method.
-
unlock
void unlock()
Releases the internal lock.
-
getConnectionFactoryName
java.lang.String getConnectionFactoryName()
Return the 'JTA' connectionFactoryName
-
setConnectionFactoryName
void setConnectionFactoryName(java.lang.String connectionFactoryName)
Set the 'JTA' ConnectionFactoryName.
-
getConnectionFactory2Name
java.lang.String getConnectionFactory2Name()
Return the 'NonJTA' ConnectionFactoryName.
-
setConnectionFactory2Name
void setConnectionFactory2Name(java.lang.String connectionFactory2Name)
Set the 'NonJTA' ConnectionFactoryName.
-
getConnectionFactory
java.lang.Object getConnectionFactory()
Return the 'JTA' ConnectionFactory, looking it up from JNDI if needed.- Returns:
- the JTA connection factory or null if connectionFactoryName is blank.
-
getConnectionFactory2
java.lang.Object getConnectionFactory2()
Return the 'NonJTA' ConnectionFactory, looking it up from JNDI if needed.- Returns:
- the NonJTA connection factory or null if connectionFactoryName is blank.
-
isCached
boolean isCached(java.util.List<java.lang.Object> oid)
Indicate whether the oid can be found in the StoreContext's L1 cache or in the StoreManager cache.- Parameters:
oid
- List of ObjectIds for PersistenceCapables which may be found in memory.- Returns:
- true if the oid is available in memory (cached) otherwise false.
- Since:
- 2.0.0.
-
setAllowReferenceToSiblingContext
void setAllowReferenceToSiblingContext(boolean flag)
Affirms if this context will allow its managed instances to refer instances that are managed by other contexts. Note: Some specification (such as JPA) does not warranty predictable behavior when strict group-like property of a persistent context (where managed instances can only refer to instances managed by the same context). Please be aware of consequences when the flag is set to true.- Since:
- 2.1
-
getAllowReferenceToSiblingContext
boolean getAllowReferenceToSiblingContext()
Affirms if this context will allow its managed instances to refer instances that are managed by other contexts.- Returns:
- false by default.
- Since:
- 2.1
-
setPostLoadOnMerge
void setPostLoadOnMerge(boolean allow)
Set totrue
if the merge operation should trigger a @PostLoad lifecycle event.- Parameters:
allow
- PostLoad lifecycle events to be triggered on a merge operation
-
getPostLoadOnMerge
boolean getPostLoadOnMerge()
Force sending a @PostLoad lifecycle event while merging.- Returns:
false
by default- Since:
- 2.2
-
-