|
Errai 3.0.1-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.errai.jpa.client.local.ErraiEntityManager
public class ErraiEntityManager
The Errai implementation and specialization of the JPA 2.0 EntityManager interface.
Constructor Summary | |
---|---|
ErraiEntityManager(ErraiEntityManager delegateEntityManager,
StorageBackendFactory namespacedStorageBackend)
Creates an EntityManager that knows about all the same managed types and named queries as the given entity manager, but works from a different storage backend. |
|
ErraiEntityManager(ErraiMetamodel metamodel,
Map<String,TypedQueryFactory> namedQueries,
StorageBackendFactory storageBackendFactory)
Constructor for building custom-purpose EntityManager instances. |
Method Summary | ||
---|---|---|
void |
clear()
Clear the persistence context, causing all managed entities to become detached. |
|
void |
close()
Close an application-managed entity manager. |
|
boolean |
contains(Object entity)
Check if the instance is a managed entity instance belonging to the current persistence context. |
|
javax.persistence.Query |
createNamedQuery(String name)
Create an instance of Query for executing a named query
(in the Java Persistence query language or in native SQL). |
|
|
createNamedQuery(String name,
Class<T> resultClass)
Create an instance of TypedQuery for executing a
Java Persistence query language named query. |
|
javax.persistence.Query |
createNativeQuery(String sqlString)
Create an instance of Query for executing
a native SQL statement, e.g., for update or delete. |
|
javax.persistence.Query |
createNativeQuery(String sqlString,
Class resultClass)
Create an instance of Query for executing
a native SQL query. |
|
javax.persistence.Query |
createNativeQuery(String sqlString,
String resultSetMapping)
Create an instance of Query for executing
a native SQL query. |
|
|
createQuery(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
Create an instance of TypedQuery for executing a
criteria query. |
|
javax.persistence.Query |
createQuery(String qlString)
Create an instance of Query for executing a
Java Persistence query language statement. |
|
|
createQuery(String qlString,
Class<T> resultClass)
Create an instance of TypedQuery for executing a
Java Persistence query language statement. |
|
void |
detach(Object entity)
Remove the given entity from the persistence context, causing a managed entity to become detached. |
|
|
find(Class<T> entityClass,
Object primaryKey,
javax.persistence.LockModeType lockMode)
Find by primary key and lock. |
|
|
find(Class<T> entityClass,
Object primaryKey,
javax.persistence.LockModeType lockMode,
Map<String,Object> properties)
Find by primary key and lock, using the specified properties. |
|
|
find(Class<X> entityClass,
Object primaryKey)
Find by primary key. |
|
|
find(Class<X> entityClass,
Object primaryKey,
Map<String,Object> properties)
Find by primary key, using the specified properties. |
|
|
find(Key<X,?> key,
Map<String,Object> properties)
Retrieves the entity instance identified by the given Key. |
|
|
findAll(ErraiIdentifiableType<X> type,
EntityJsonMatcher matcher)
EXPERIMENTAL. |
|
void |
flush()
Synchronize the persistence context to the underlying database. |
|
javax.persistence.criteria.CriteriaBuilder |
getCriteriaBuilder()
Return an instance of CriteriaBuilder for the creation of
CriteriaQuery objects. |
|
Object |
getDelegate()
Return the underlying provider object for the EntityManager ,
if available. |
|
javax.persistence.EntityManagerFactory |
getEntityManagerFactory()
Return the entity manager factory for the entity manager. |
|
javax.persistence.FlushModeType |
getFlushMode()
Get the flush mode that applies to all objects contained in the persistence context. |
|
javax.persistence.LockModeType |
getLockMode(Object entity)
Get the current lock mode for the entity instance. |
|
ErraiMetamodel |
getMetamodel()
Return an instance of Metamodel interface for access to the
metamodel of the persistence unit. |
|
Map<String,Object> |
getProperties()
Get the properties and hints and associated values that are in effect for the entity manager. |
|
|
getReference(Class<T> entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched. |
|
javax.persistence.EntityTransaction |
getTransaction()
Return the resource-level EntityTransaction object. |
|
boolean |
isKeyInUse(Key<?,?> key)
Tests if this entity manager's storage backend contains an entity that could conflict with the given key. |
|
boolean |
isOpen()
Determine whether the entity manager is open. |
|
void |
joinTransaction()
Indicate to the entity manager that a JTA transaction is active. |
|
|
keyFor(ErraiIdentifiableType<X> entityType,
X entity)
Creates the key that describes the given entity, generating and setting it if it is presently unset and the given entity type's ID is configured to be generated on demand. |
|
|
keyFor(X entity)
Creates the key that describes the given entity, generating and setting it if it is presently unset and the given entity type's ID is configured to be generated on demand. |
|
void |
lock(Object entity,
javax.persistence.LockModeType lockMode)
Lock an entity instance that is contained in the persistence context with the specified lock mode type. |
|
void |
lock(Object entity,
javax.persistence.LockModeType lockMode,
Map<String,Object> properties)
Lock an entity instance that is contained in the persistence context with the specified lock mode type and with specified properties. |
|
|
merge(T entity)
Merge the state of the given entity into the current persistence context. |
|
void |
persist(Object entity)
Make an instance managed and persistent. |
|
void |
refresh(Object entity)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any. |
|
void |
refresh(Object entity,
javax.persistence.LockModeType lockMode)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type. |
|
void |
refresh(Object entity,
javax.persistence.LockModeType lockMode,
Map<String,Object> properties)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type and with specified properties. |
|
void |
refresh(Object entity,
Map<String,Object> properties)
Refresh the state of the instance from the database, using the specified properties, and overwriting changes made to the entity, if any. |
|
void |
remove(Object entity)
Remove the entity instance. |
|
void |
removeAll()
Removes everything from the backend data store and clears the persistence context. |
|
void |
setFlushMode(javax.persistence.FlushModeType flushMode)
Set the flush mode that applies to all objects contained in the persistence context. |
|
void |
setProperty(String propertyName,
Object value)
Set an entity manager property or hint. |
|
|
unwrap(Class<T> cls)
Return an object of the specified type to allow access to the provider-specific API. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ErraiEntityManager(ErraiMetamodel metamodel, Map<String,TypedQueryFactory> namedQueries, StorageBackendFactory storageBackendFactory)
@Inject EntityManager em
and let the
ErraiEntityManagerProvider
handle the prerequisites for you.
public ErraiEntityManager(ErraiEntityManager delegateEntityManager, StorageBackendFactory namespacedStorageBackend)
delegateEntityManager
- namespacedStorageBackend
- Method Detail |
---|
public <X> Key<X,?> keyFor(X entity)
keyFor()
method
assumes the given object's entity type can be obtained by calling entity.getClass()
. If you already have a specific entity type in mind, use
the keyFor(ErraiIdentifiableType, Object)
version of the method.
entityType
- The entity type of the entityentity
- The entity instance. Side effect: this instance may have its ID
value initialized as a result of this call.
public <X> Key<X,?> keyFor(ErraiIdentifiableType<X> entityType, X entity)
entityType
- The entity type of the entityentity
- The entity instance. Side effect: this instance may have its ID
value initialized as a result of this call.
public <X> List<X> findAll(ErraiIdentifiableType<X> type, EntityJsonMatcher matcher)
public boolean isKeyInUse(Key<?,?> key)
key
- The key to test for in backend storage. Not null.
public ErraiMetamodel getMetamodel()
javax.persistence.EntityManager
Metamodel
interface for access to the
metamodel of the persistence unit.
getMetamodel
in interface javax.persistence.EntityManager
public void persist(Object entity)
javax.persistence.EntityManager
persist
in interface javax.persistence.EntityManager
entity
- entity instancepublic void flush()
javax.persistence.EntityManager
flush
in interface javax.persistence.EntityManager
public void detach(Object entity)
javax.persistence.EntityManager
detach
in interface javax.persistence.EntityManager
entity
- entity instancepublic void clear()
javax.persistence.EntityManager
clear
in interface javax.persistence.EntityManager
public <X> X find(Class<X> entityClass, Object primaryKey)
javax.persistence.EntityManager
find
in interface javax.persistence.EntityManager
entityClass
- entity classprimaryKey
- primary key
public <X> X find(Class<X> entityClass, Object primaryKey, Map<String,Object> properties)
javax.persistence.EntityManager
find
in interface javax.persistence.EntityManager
entityClass
- entity classprimaryKey
- primary keyproperties
- standard and vendor-specific properties
and hints
public <X> X find(Key<X,?> key, Map<String,Object> properties)
key
- The key to look up. Must not be null.properties
- JPA hints (standard and Errai-specific) for the lookup.
public void remove(Object entity)
javax.persistence.EntityManager
remove
in interface javax.persistence.EntityManager
entity
- entity instancepublic void removeAll()
public javax.persistence.Query createNamedQuery(String name)
javax.persistence.EntityManager
Query
for executing a named query
(in the Java Persistence query language or in native SQL).
createNamedQuery
in interface javax.persistence.EntityManager
name
- the name of a query defined in metadata
public <T> javax.persistence.TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
javax.persistence.EntityManager
TypedQuery
for executing a
Java Persistence query language named query.
The select list of the query must contain only a single
item, which must be assignable to the type specified by
the resultClass
argument.
createNamedQuery
in interface javax.persistence.EntityManager
name
- the name of a query defined in metadataresultClass
- the type of the query result
public <T> T merge(T entity)
javax.persistence.EntityManager
merge
in interface javax.persistence.EntityManager
entity
- entity instance
public <T> T find(Class<T> entityClass, Object primaryKey, javax.persistence.LockModeType lockMode)
javax.persistence.EntityManager
If the entity is found within the persistence context and the
lock mode type is pessimistic and the entity has a version
attribute, the persistence provider must perform optimistic
version checks when obtaining the database lock. If these
checks fail, the OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
find
in interface javax.persistence.EntityManager
entityClass
- entity classprimaryKey
- primary keylockMode
- lock mode
public <T> T find(Class<T> entityClass, Object primaryKey, javax.persistence.LockModeType lockMode, Map<String,Object> properties)
javax.persistence.EntityManager
If the entity is found
within the persistence context and the lock mode type
is pessimistic and the entity has a version attribute, the
persistence provider must perform optimistic version checks
when obtaining the database lock. If these checks fail,
the OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
find
in interface javax.persistence.EntityManager
entityClass
- entity classprimaryKey
- primary keylockMode
- lock modeproperties
- standard and vendor-specific properties
and hints
public <T> T getReference(Class<T> entityClass, Object primaryKey)
javax.persistence.EntityManager
EntityNotFoundException
is thrown when the instance
state is first accessed. (The persistence provider runtime is
permitted to throw the EntityNotFoundException
when
getReference
is called.)
The application should not expect that the instance state will
be available upon detachment, unless it was accessed by the
application while the entity manager was open.
getReference
in interface javax.persistence.EntityManager
entityClass
- entity classprimaryKey
- primary key
public void setFlushMode(javax.persistence.FlushModeType flushMode)
javax.persistence.EntityManager
setFlushMode
in interface javax.persistence.EntityManager
flushMode
- flush modepublic javax.persistence.FlushModeType getFlushMode()
javax.persistence.EntityManager
getFlushMode
in interface javax.persistence.EntityManager
public void lock(Object entity, javax.persistence.LockModeType lockMode)
javax.persistence.EntityManager
If a pessimistic lock mode type is specified and the entity
contains a version attribute, the persistence provider must
also perform optimistic version checks when obtaining the
database lock. If these checks fail, the
OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
lock
in interface javax.persistence.EntityManager
entity
- entity instancelockMode
- lock modepublic void lock(Object entity, javax.persistence.LockModeType lockMode, Map<String,Object> properties)
javax.persistence.EntityManager
If a pessimistic lock mode type is specified and the entity
contains a version attribute, the persistence provider must
also perform optimistic version checks when obtaining the
database lock. If these checks fail, the
OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
lock
in interface javax.persistence.EntityManager
entity
- entity instancelockMode
- lock modeproperties
- standard and vendor-specific properties
and hintspublic void refresh(Object entity)
javax.persistence.EntityManager
refresh
in interface javax.persistence.EntityManager
entity
- entity instancepublic void refresh(Object entity, Map<String,Object> properties)
javax.persistence.EntityManager
If a vendor-specific property or hint is not recognized, it is silently ignored.
refresh
in interface javax.persistence.EntityManager
entity
- entity instanceproperties
- standard and vendor-specific properties
and hintspublic void refresh(Object entity, javax.persistence.LockModeType lockMode)
javax.persistence.EntityManager
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the
database locking failure causes only statement-level
rollback.
refresh
in interface javax.persistence.EntityManager
entity
- entity instancelockMode
- lock modepublic void refresh(Object entity, javax.persistence.LockModeType lockMode, Map<String,Object> properties)
javax.persistence.EntityManager
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
refresh
in interface javax.persistence.EntityManager
entity
- entity instancelockMode
- lock modeproperties
- standard and vendor-specific properties
and hintspublic boolean contains(Object entity)
javax.persistence.EntityManager
contains
in interface javax.persistence.EntityManager
entity
- entity instance
public javax.persistence.LockModeType getLockMode(Object entity)
javax.persistence.EntityManager
getLockMode
in interface javax.persistence.EntityManager
entity
- entity instance
public void setProperty(String propertyName, Object value)
javax.persistence.EntityManager
setProperty
in interface javax.persistence.EntityManager
propertyName
- name of property or hintvalue
- value for property or hintpublic Map<String,Object> getProperties()
javax.persistence.EntityManager
getProperties
in interface javax.persistence.EntityManager
public javax.persistence.Query createQuery(String qlString)
javax.persistence.EntityManager
Query
for executing a
Java Persistence query language statement.
createQuery
in interface javax.persistence.EntityManager
qlString
- a Java Persistence query string
public <T> javax.persistence.TypedQuery<T> createQuery(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
javax.persistence.EntityManager
TypedQuery
for executing a
criteria query.
createQuery
in interface javax.persistence.EntityManager
criteriaQuery
- a criteria query object
public <T> javax.persistence.TypedQuery<T> createQuery(String qlString, Class<T> resultClass)
javax.persistence.EntityManager
TypedQuery
for executing a
Java Persistence query language statement.
The select list of the query must contain only a single
item, which must be assignable to the type specified by
the resultClass
argument.
createQuery
in interface javax.persistence.EntityManager
qlString
- a Java Persistence query stringresultClass
- the type of the query result
public javax.persistence.Query createNativeQuery(String sqlString)
javax.persistence.EntityManager
Query
for executing
a native SQL statement, e.g., for update or delete.
createNativeQuery
in interface javax.persistence.EntityManager
sqlString
- a native SQL query string
public javax.persistence.Query createNativeQuery(String sqlString, Class resultClass)
javax.persistence.EntityManager
Query
for executing
a native SQL query.
createNativeQuery
in interface javax.persistence.EntityManager
sqlString
- a native SQL query stringresultClass
- the class of the resulting instance(s)
public javax.persistence.Query createNativeQuery(String sqlString, String resultSetMapping)
javax.persistence.EntityManager
Query
for executing
a native SQL query.
createNativeQuery
in interface javax.persistence.EntityManager
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mapping
public void joinTransaction()
javax.persistence.EntityManager
joinTransaction
in interface javax.persistence.EntityManager
public <T> T unwrap(Class<T> cls)
javax.persistence.EntityManager
EntityManager
implementation does not support the specified class, the
PersistenceException
is thrown.
unwrap
in interface javax.persistence.EntityManager
cls
- the class of the object to be returned. This is
normally either the underlying EntityManager
implementation
class or an interface that it implements.
public Object getDelegate()
javax.persistence.EntityManager
EntityManager
,
if available. The result of this method is implementation
specific. The unwrap
method is to be preferred for new
applications.
getDelegate
in interface javax.persistence.EntityManager
public void close()
javax.persistence.EntityManager
EntityManager
instance and any
Query
and TypedQuery
objects obtained from it will throw the IllegalStateException
except for getProperties
,
getTransaction
, and isOpen
(which will return false).
If this method is called when the entity manager is
associated with an active transaction, the persistence
context remains managed until the transaction completes.
close
in interface javax.persistence.EntityManager
public boolean isOpen()
javax.persistence.EntityManager
isOpen
in interface javax.persistence.EntityManager
public javax.persistence.EntityTransaction getTransaction()
javax.persistence.EntityManager
EntityTransaction
object.
The EntityTransaction
instance may be used serially to
begin and commit multiple transactions.
getTransaction
in interface javax.persistence.EntityManager
public javax.persistence.EntityManagerFactory getEntityManagerFactory()
javax.persistence.EntityManager
getEntityManagerFactory
in interface javax.persistence.EntityManager
public javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
javax.persistence.EntityManager
CriteriaBuilder
for the creation of
CriteriaQuery
objects.
getCriteriaBuilder
in interface javax.persistence.EntityManager
|
Errai 3.0.1-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |