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
Modifier and TypeFieldDescriptionstatic final BitSet
Marker bitset to indicate that all field loads should be excluded in thefind
methods of this interface.static final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Begin a data store transaction.embed
(Object obj, Object id, OpenJPAStateManager owner, ValueMetaData ownerMeta) Make the given instance embedded.extentIterator
(Class<?> cls, boolean subs, FetchConfiguration fetch, boolean ignoreChanges) Return an iterator over all instances of the given type.find
(Object oid, boolean validate, FindCallbacks call) Find the persistence object with the given oid.find
(Object oid, FetchConfiguration fetch, BitSet exclude, Object edata, int flags) Return the object with the given oid.Object[]
findAll
(Collection<Object> oids, boolean validate, FindCallbacks call) Return the objects with the given oids.Object[]
findAll
(Collection<Object> oids, FetchConfiguration fetch, BitSet exclude, Object edata, int flags) Return the objects with the given oids.findCached
(Object oid, FindCallbacks call) Return the instance for the given oid/object , or null if not found in the L1 cache.boolean
Affirms if this context will allow its managed instances to refer instances that are managed by other contexts.Return the broker for this context, if possible.Return the current thread's class loader at the time this context was obtained.Return the configuration associated with this context.Return the connection in use by the context, or a new connection if none.Return the 'JTA' ConnectionFactory, looking it up from JNDI if needed.Return the 'NonJTA' ConnectionFactory, looking it up from JNDI if needed.Return the 'NonJTA' ConnectionFactoryName.Return the 'JTA' connectionFactoryNameReturn the connection password.Return the connection user name.Collection<Class<?>>
Return the set of classes that have been deleted in the current transaction.int
Detach mode constant to determine which fields are part of the detached graph.Return a list of current dirty instances.Return the (mutable) fetch configuration for loading objects from this context.int
getLockLevel
(Object obj) Return the lock level of the specified object.Return the lock manager in use.Return a list of all managed instances.getObjectId
(Object obj) Return the oid of the given instance.Class<?>
getObjectIdType
(Class<?> cls) Return the application or datastore identity class the given persistent class uses for object ids.boolean
Whether to maintain the order in which objects are dirtied forgetDirtyObjects()
.Return a list of instances which will become transactional upon the next transaction.Collection<Class<?>>
Return the set of classes that have been made persistent in the current transaction.boolean
Whether objects accessed during this transaction will be added to the store cache.boolean
Force sending a @PostLoad lifecycle event while merging.getStateManager
(Object obj) Return the state manager for the given instance.Return the store manager in use.Return a list of current transaction instances.Collection<Class<?>>
Return the set of classes for objects that have been modified in the current transaction.getVersion
(Object obj) Returns the current version indicator foro
.boolean
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
Indicate whether the oid can be found in the StoreContext's L1 cache or in the StoreManager cache.boolean
Return whether the given object is deleted.boolean
Return whether the given object is dirty.boolean
Whether this context is using managed transactions.boolean
Return whether the given object is a newly-created instance registered withbroker
.boolean
isPersistent
(Object obj) Return whether the given object is persistent.boolean
Whether a data store transaction is active.boolean
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
(Object obj) Return whether the given object is transactional.void
lock()
Synchronizes on an internal lock if theMultithreaded
flag is set to true.newObjectId
(Class<?> cls, Object val) Create a new object id instance from the given value.void
nontransactional
(Object pc, OpCallbacks call) Make the given object non-transactional.void
nontransactionalAll
(Collection<Object> objs, OpCallbacks call) Make the given objects nontransactional.void
Pops the fetch configuration from the top of the stack, making the next one down the active one.Pushes a new fetch configuration that inherits from the current fetch configuration onto a stack, and makes the new configuration the active one.Pushes the fetch configuration argument onto a stack, and makes the new configuration the active one.void
retrieve
(Object pc, boolean fgOnly, OpCallbacks call) Immediately load the given object's persistent fields.void
retrieveAll
(Collection<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
(String connectionFactory2Name) Set the 'NonJTA' ConnectionFactoryName.void
setConnectionFactoryName
(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
(Object pc, boolean updateVersion, OpCallbacks call) Make the given object transactional.void
transactionalAll
(Collection<Object> objs, boolean updateVersion, OpCallbacks call) Make the given objects transactional.void
unlock()
Releases the internal lock.
-
Field Details
-
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:
-
OID_NODELETED
static final int OID_NODELETED- See Also:
-
OID_COPY
static final int OID_COPY- See Also:
-
OID_ALLOW_NEW
static final int OID_ALLOW_NEW- See Also:
-
-
Method Details
-
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
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
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
String getConnectionUserName()Return the connection user name. -
getConnectionPassword
String getConnectionPassword()Return the connection password. -
findCached
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
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
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
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
Object[] findAll(Collection<Object> oids, FetchConfiguration fetch, BitSet exclude, Object edata, int flags) Return the objects with the given oids. -
extentIterator
Iterator<Object> extentIterator(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
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:
-
retrieveAll
Retrieve the given objects' persistent state. Unmanaged targets are ignored.- Parameters:
fgOnly
- indicator as to whether to retrieve only fields- See Also:
-
embed
OpenJPAStateManager embed(Object obj, 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
Return the application or datastore identity class the given persistent class uses for object ids. -
newObjectId
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
Collection<Class<?>> getPersistedTypes()Return the set of classes that have been made persistent in the current transaction.- Since:
- 0.3.4
-
getDeletedTypes
Collection<Class<?>> getDeletedTypes()Return the set of classes that have been deleted in the current transaction.- Since:
- 0.3.4
-
getUpdatedTypes
Collection<Class<?>> getUpdatedTypes()Return the set of classes for objects that have been modified in the current transaction.- Since:
- 0.3.4
-
getManagedObjects
Collection<Object> getManagedObjects()Return a list of all managed instances. -
getTransactionalObjects
Collection<Object> getTransactionalObjects()Return a list of current transaction instances. -
getPendingTransactionalObjects
Collection<Object> getPendingTransactionalObjects()Return a list of instances which will become transactional upon the next transaction. -
getDirtyObjects
Collection<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
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
Return the lock level of the specified object. -
getVersion
Returns the current version indicator foro
. -
isDirty
Return whether the given object is dirty. -
isTransactional
Return whether the given object is transactional. -
transactional
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
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
Make the given object non-transactional. -
nontransactionalAll
Make the given objects nontransactional. -
isPersistent
Return whether the given object is persistent. -
isNew
Return whether the given object is a newly-created instance registered withbroker
. -
isDeleted
Return whether the given object is deleted. -
getObjectId
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
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
String getConnectionFactoryName()Return the 'JTA' connectionFactoryName -
setConnectionFactoryName
Set the 'JTA' ConnectionFactoryName. -
getConnectionFactory2Name
String getConnectionFactory2Name()Return the 'NonJTA' ConnectionFactoryName. -
setConnectionFactory2Name
Set the 'NonJTA' ConnectionFactoryName. -
getConnectionFactory
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
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
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
-