|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface EntityManager
An EntityManager allows transactional introspection and manipulation of entities.
Each EntityManager is associated with an ObjectGrid Session
. Use
the Session.getEntityManager()
method to retrieve the Session's
EntityManager instance. Simultaneous interaction with the EntityManager and the owning
ObjectGrid Session is allowed.
All interactions with the EntityManager must be from a single thread. Multi-thread access to the EntityManager is not supported.
The EntityManager manages each entity within it's context scope. Entity operations will not be synchronized to the underlying ObjectGrid cache until the transaction is committed or the EntityManager context is flushed to the cache.
Each entity is backed by an ObjectGrid map with the same name as the entity and utilizes the
inherent map configuration for locking, evicting, indexing and synchronizing with a loader.
See BackingMap
for details on how entity a map can
be configured and optimized for each entity.
The EntityManager converts each entity instance to key and value Tuple instances using
the entity's persistent fields or properties and stores the Tuples in the entity's associated
ObjectMap. The metadata that describes the Tuple can
be accessed using the ObjectMap.getEntityMetadata()
or
BackingMap.getEntityMetadata()
methods.
Tuples can be manually extracted from entities using the Projector
which is obtained using the
ProjectorFactory.getProjector(EntityManager)
factory method.
Accessing entities and Tuples simultaneously in a single transaction is not supported and may cause unexpected results.
Tuple
,
EntityMetadata
Method Summary | |
---|---|
void |
clear()
Clear the EntityManager's context. |
Query |
createQuery(String qlString)
Create a Query instance for executing an ObjectGrid query language statement. |
QueryQueue |
createQueryQueue(String qlString,
Class entityClass)
Create a QueryQueue for an entity map. |
Object |
find(Class entityClass,
Object primaryKey)
Find an entity by primary key in the ObjectGrid cache. |
Object |
findForUpdate(Class entityClass,
Object primaryKey)
Find an entity by primary key with the intent to be updated. |
void |
flush()
Synchronize the EntityManager to the ObjectGrid cache. |
FetchPlan |
getFetchPlan()
Get the current mutable FetchPlan. |
FlushModeType |
getFlushMode()
Get the flush mode that applies to all objects contained in the EntityManager's context. |
EntityTransaction |
getTransaction()
Return the resource-level transaction object. |
void |
invalidate(Object entity)
Invalidate the entity instance from the ObjectGrid cache, including the transactional, client and server caches. |
Object |
merge(Object entity)
Merge the entity instance with the ObjectGrid. |
void |
persist(Object entity)
Make an entity instance managed and persistent in the ObjectGrid cache. |
void |
remove(Object entity)
Remove the entity instance from the ObjectGrid. |
void |
setFlushMode(FlushModeType flushMode)
Set the flush mode that applies to all objects contained in the EntityManager's context. |
Method Detail |
---|
void persist(Object entity)
entity
- the entity object instance to make persistent.
EntityExistsException
- if the entity already exists. (The EntityExistsException may be thrown when the persist operation is
invoked, or the EntityExistsException or another PersistenceException may be thrown at flush or
commit time.)
IllegalArgumentException
- if not a valid entity
TransactionRequiredException
- if invoked without an active transaction.ObjectMap.insert(Object, Object)
void remove(Object entity)
entity
- the managed entity instance to remove from the ObjectGrid cache.
IllegalArgumentException
- if instance is not an entity or is a detached entity
TransactionRequiredException
- if invoked without an active transaction.ObjectMap.remove(Object)
void invalidate(Object entity)
This method is similar to remove, but does not flow the changes to the entity's Loader.
entity
- the managed entity instance to evict from the ObjectGrid cache.
IllegalArgumentException
- if instance is not an entity or is a detached entity
TransactionRequiredException
- if invoked without an active transaction.ObjectMap.invalidate(Object, boolean)
Object find(Class entityClass, Object primaryKey)
entityClass
- the class representing the entity to find.primaryKey
- an object instance representing the key of the entity to find. The key may be a single
Object (for single value keys), an IdClass or Entity instance (for composite keys)
or a Tuple instance.
IllegalArgumentException
- if the first argument does not denote an entity type or the second argument is not a valid type for
that entity's primary keyTuple
,
ObjectMap.get(Object)
Object findForUpdate(Class entityClass, Object primaryKey)
If the underlying map is configured with pessimistic locking strategy, an upgradeable
lock mode is obtained for this entity instance's map entry.
Any associated entities that are loaded are not locked for update. If the associates
are need to be locked in the same manner, then findForUpdate
should be
called for each associated entity.
entityClass
- the class representing the entity to find.primaryKey
- an object instance representing the key of the entity to find.
IllegalArgumentException
- if the first argument does not denote an entity type or the second argument is not a valid type for
that entity's primary keyObjectMap.getForUpdate(Object)
void flush()
All managed entities in the current transaction are synchronized with the ObjectGrid cache and the associated ObjectGrid session is flushed.
TransactionRequiredException
- if there is no transaction
PersistenceException
- if the flush failsSession.flush()
void setFlushMode(FlushModeType flushMode)
If not set, the default is FlushModeType.AUTO.
flushMode
- the FlushModeType.FlushModeType getFlushMode()
EntityTransaction getTransaction()
Each EntityManager is associated with one EntityTransaction. Repeated calls to this method for the same EntityManager instance will result in the same EntityTransaction instance.
Query createQuery(String qlString)
When security is enabled, this method requires an com.ibm.websphere.objectgrid.security.ObjectGridPermission with action "query".
Required Permission: ObjectGridPermission.QUERY
qlString
- an ObjectGrid query string
IllegalArgumentException
- if query string is not validvoid clear()
Causes all managed entities to become detached. Any changes made to entities that have not been flushed to the cache will not be persisted.
QueryQueue createQueryQueue(String qlString, Class entityClass)
An entity QueryQueue will select all the entities which match the query filter's WHERE
condition. Users can call QueryQueue.getNextEntity(long)
or
QueryQueue.getNextEntities(int, long)
to get one or more entities at one time.
A QueryQueue is useful for retrieving select entities in an iterative manner.
The query string's SELECT clause must specify one and only one entity identification variable and no other functions or attributes.
For example:
"SELECT t FROM Tasks t WHERE t.type=?1 AND t.status='PENDING' ORDER BY t.createTime"
An entity class can be optionally specified to indicate which class the result(s) will be projected
into. The specified entity class must have the same entity name as specified in the query string.
If a null value is used as the entity class, then the result will not be projected; the key tuple(s)
will be returned by theQueryQueue.getNextEntity(long)
or
QueryQueue.getNextEntities(int, long)
methods.
qlString
- the query SQL stringentityClass
- the entity class the result will be projected to; null if the results
are not projected.
QueryQueue
instanceQueryQueue
Object merge(Object entity)
entity
- the managed, new or detached entity instance to merge with the ObjectGrid cache.
IllegalArgumentException
- if instance is not an entity or a removed entity
TransactionRequiredException
- if invoked without an active transaction.
OptimisticLockException
- if there is a mismatch between the version of the entity and a managed entity. This exception may
not be thrown until commit or flush time.FetchPlan getFetchPlan()
A FetchPlan is used to customize how the eager relations are fetched with the fetch operation.
A fetch operation could be any of the following: find(Class, Object)
, findForUpdate(Class, Object)
,
Query
operations, or QueryQueue
operations.
A FetchPlan object is normally used on the client side to access for a distributed ObjectGrid. However, when used with a local ObjectGrid, the FetchPlan object can be used to customize the relations to be projected when the fetch operation is executed.
The FetchPlan object is mutable, and once changed, the changed value will be applied to the fetch operations executed afterwards.
|
IBM WebSphereTM eXtreme Scale, Release 8.6 API Specification |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |