public abstract class AbstractEntityManagerImpl extends Object implements HibernateEntityManagerImplementor, Serializable
Modifier and Type | Class and Description |
---|---|
static class |
AbstractEntityManagerImpl.TupleBuilderTransformer |
HibernateEntityManagerImplementor.Options
Modifier and Type | Field and Description |
---|---|
protected PersistenceContextType |
persistenceContextType |
protected TransactionImpl |
tx |
Modifier | Constructor and Description |
---|---|
protected |
AbstractEntityManagerImpl(EntityManagerFactoryImpl entityManagerFactory,
PersistenceContextType type,
PersistenceUnitTransactionType transactionType,
Map properties) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the persistence context, causing all managed
entities to become detached.
|
boolean |
contains(Object entity)
Check if the instance is a managed entity instance belonging
to the current persistence context.
|
RuntimeException |
convert(HibernateException e)
Converts a Hibernate-specific exception into a JPA-specified exception; note that the JPA sepcification makes use
of exceptions outside its exception hierarchy, though they are all runtime exceptions.
|
RuntimeException |
convert(HibernateException e,
LockOptions lockOptions)
Converts a Hibernate-specific exception into a JPA-specified exception; note that the JPA sepcification makes use
of exceptions outside its exception hierarchy, though they are all runtime exceptions.
|
RuntimeException |
convert(RuntimeException e) |
Query |
createNamedQuery(String name)
Create an instance of
Query for executing a named query
(in the Java Persistence query language or in native SQL). |
<T> TypedQuery<T> |
createNamedQuery(String name,
Class<T> resultClass)
Create an instance of
TypedQuery for executing a
Java Persistence query language named query. |
Query |
createNativeQuery(String sqlString)
Create an instance of
Query for executing
a native SQL statement, e.g., for update or delete. |
Query |
createNativeQuery(String sqlString,
Class resultClass)
Create an instance of
Query for executing
a native SQL query. |
Query |
createNativeQuery(String sqlString,
String resultSetMapping)
Create an instance of
Query for executing
a native SQL query. |
<T> TypedQuery<T> |
createQuery(CriteriaQuery<T> criteriaQuery)
Create an instance of
TypedQuery for executing a
criteria query. |
Query |
createQuery(String jpaqlString)
Create an instance of
Query for executing a
Java Persistence query language statement. |
<T> TypedQuery<T> |
createQuery(String jpaqlString,
Class<T> resultClass)
Create an instance of
TypedQuery for executing a
Java Persistence query language statement. |
<T> TypedQuery<T> |
createQuery(String jpaqlString,
Class<T> resultClass,
Selection selection,
HibernateEntityManagerImplementor.Options options)
Used during "compiling" a JPA criteria query.
|
void |
detach(Object entity)
Remove the given entity from the persistence context, causing
a managed entity to become detached.
|
CacheMode |
determineAppropriateLocalCacheMode(Map<String,Object> localProperties) |
<A> A |
find(Class<A> entityClass,
Object primaryKey)
Find by primary key.
|
<A> A |
find(Class<A> entityClass,
Object primaryKey,
LockModeType lockModeType)
Find by primary key and lock.
|
<A> A |
find(Class<A> entityClass,
Object primaryKey,
LockModeType lockModeType,
Map<String,Object> properties)
Find by primary key and lock, using the specified properties.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
Map<String,Object> properties)
Find by primary key, using the specified properties.
|
void |
flush()
Synchronize the persistence context to the
underlying database.
|
CriteriaBuilder |
getCriteriaBuilder()
Return an instance of
CriteriaBuilder for the creation of
CriteriaQuery objects. |
Object |
getDelegate()
returns the underlying session
|
EntityManagerFactoryImpl |
getEntityManagerFactory()
Return the entity manager factory for the entity manager.
|
HibernateEntityManagerFactory |
getFactory()
Get access to the Hibernate extended EMF contract.
|
FlushModeType |
getFlushMode()
Hibernate can be set in various flush modes that are unknown to
JPA 2.0.
|
LockModeType |
getLockMode(Object entity)
Get the current lock mode for the entity instance.
|
LockOptions |
getLockRequest(LockModeType lockModeType,
Map<String,Object> properties)
Convert from JPA 2
LockModeType & properties into LockOptions |
Metamodel |
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.
|
protected abstract Session |
getRawSession()
Return a Session (even if the entity manager is closed).
|
<T> T |
getReference(Class<T> entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched.
|
abstract Session |
getSession()
return a Session
|
EntityTransaction |
getTransaction()
Return the resource-level
EntityTransaction object. |
PersistenceUnitTransactionType |
getTransactionType() |
void |
handlePersistenceException(PersistenceException e)
Handles marking for rollback and other such operations that need to occur depending on the type of
exception being handled.
|
boolean |
isTransactionInProgress()
Provides access to whether a transaction is currently in progress.
|
void |
joinTransaction()
Indicate to the entity manager that a JTA transaction is
active.
|
void |
lock(Object entity,
LockModeType lockMode)
Lock an entity instance that is contained in the persistence
context with the specified lock mode type.
|
void |
lock(Object entity,
LockModeType lockModeType,
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.
|
protected void |
markAsRollback() |
<A> A |
merge(A entity)
Merge the state of the given entity into the
current persistence context.
|
void |
persist(Object entity)
Make an instance managed and persistent.
|
protected void |
postInit() |
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,
LockModeType lockModeType)
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,
LockModeType lockModeType,
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 |
setFlushMode(FlushModeType flushModeType)
Set the flush mode that applies to all objects contained
in the persistence context.
|
void |
setProperty(String s,
Object o)
Set an entity manager property or hint.
|
void |
throwPersistenceException(HibernateException e)
Delegates to
HibernateEntityManagerImplementor.convert(org.hibernate.HibernateException, org.hibernate.LockOptions) and then throws the given exception. |
void |
throwPersistenceException(PersistenceException e)
Delegates to
HibernateEntityManagerImplementor.handlePersistenceException(javax.persistence.PersistenceException) and then throws the given exception. |
<T> T |
unwrap(Class<T> clazz)
Return an object of the specified type to allow access to the
provider-specific API.
|
PersistenceException |
wrapLockException(HibernateException e,
LockOptions lockOptions) |
PersistenceException |
wrapStaleStateException(StaleStateException e) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, isOpen
protected transient TransactionImpl tx
protected PersistenceContextType persistenceContextType
protected AbstractEntityManagerImpl(EntityManagerFactoryImpl entityManagerFactory, PersistenceContextType type, PersistenceUnitTransactionType transactionType, Map properties)
public PersistenceUnitTransactionType getTransactionType()
protected void postInit()
public Query createQuery(String jpaqlString)
EntityManager
Query
for executing a
Java Persistence query language statement.createQuery
in interface EntityManager
jpaqlString
- a Java Persistence query stringpublic <T> TypedQuery<T> createQuery(String jpaqlString, Class<T> resultClass)
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 EntityManager
jpaqlString
- a Java Persistence query stringresultClass
- the type of the query resultpublic <T> TypedQuery<T> createQuery(String jpaqlString, Class<T> resultClass, Selection selection, HibernateEntityManagerImplementor.Options options)
HibernateEntityManagerImplementor
createQuery
in interface HibernateEntityManagerImplementor
T
- The query typejpaqlString
- The criteria query rendered as a JPA QL stringresultClass
- The result type (the type expected in the result list)selection
- The selection(s)options
- The options to use to build the query.public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
EntityManager
TypedQuery
for executing a
criteria query.createQuery
in interface EntityManager
criteriaQuery
- a criteria query objectpublic Query createNamedQuery(String name)
EntityManager
Query
for executing a named query
(in the Java Persistence query language or in native SQL).createNamedQuery
in interface EntityManager
name
- the name of a query defined in metadatapublic <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
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 EntityManager
name
- the name of a query defined in metadataresultClass
- the type of the query resultpublic Query createNativeQuery(String sqlString)
EntityManager
Query
for executing
a native SQL statement, e.g., for update or delete.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringpublic Query createNativeQuery(String sqlString, Class resultClass)
EntityManager
Query
for executing
a native SQL query.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringresultClass
- the class of the resulting instance(s)public Query createNativeQuery(String sqlString, String resultSetMapping)
EntityManager
Query
for executing
a native SQL query.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mappingpublic <T> T getReference(Class<T> entityClass, Object primaryKey)
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 EntityManager
entityClass
- entity classprimaryKey
- primary keypublic <A> A find(Class<A> entityClass, Object primaryKey)
EntityManager
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keypublic <T> T find(Class<T> entityClass, Object primaryKey, Map<String,Object> properties)
EntityManager
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keyproperties
- standard and vendor-specific properties
and hintspublic <A> A find(Class<A> entityClass, Object primaryKey, LockModeType lockModeType)
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 EntityManager
entityClass
- entity classprimaryKey
- primary keylockModeType
- lock modepublic <A> A find(Class<A> entityClass, Object primaryKey, LockModeType lockModeType, Map<String,Object> properties)
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 EntityManager
entityClass
- entity classprimaryKey
- primary keylockModeType
- lock modeproperties
- standard and vendor-specific properties
and hintspublic CacheMode determineAppropriateLocalCacheMode(Map<String,Object> localProperties)
public void persist(Object entity)
EntityManager
persist
in interface EntityManager
entity
- entity instancepublic <A> A merge(A entity)
EntityManager
merge
in interface EntityManager
entity
- entity instancepublic void remove(Object entity)
EntityManager
remove
in interface EntityManager
entity
- entity instancepublic void refresh(Object entity)
EntityManager
refresh
in interface EntityManager
entity
- entity instancepublic void refresh(Object entity, Map<String,Object> properties)
EntityManager
If a vendor-specific property or hint is not recognized, it is silently ignored.
refresh
in interface EntityManager
entity
- entity instanceproperties
- standard and vendor-specific properties
and hintspublic void refresh(Object entity, LockModeType lockModeType)
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 EntityManager
entity
- entity instancelockModeType
- lock modepublic void refresh(Object entity, LockModeType lockModeType, Map<String,Object> properties)
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 EntityManager
entity
- entity instancelockModeType
- lock modeproperties
- standard and vendor-specific properties
and hintspublic boolean contains(Object entity)
EntityManager
contains
in interface EntityManager
entity
- entity instancepublic LockModeType getLockMode(Object entity)
EntityManager
getLockMode
in interface EntityManager
entity
- entity instancepublic void setProperty(String s, Object o)
EntityManager
setProperty
in interface EntityManager
s
- name of property or hinto
- value for property or hintpublic Map<String,Object> getProperties()
EntityManager
getProperties
in interface EntityManager
public void flush()
EntityManager
flush
in interface EntityManager
public abstract Session getSession()
getSession
in interface HibernateEntityManager
IllegalStateException
- if the entity manager is closedprotected abstract Session getRawSession()
public EntityTransaction getTransaction()
EntityManager
EntityTransaction
object.
The EntityTransaction
instance may be used serially to
begin and commit multiple transactions.getTransaction
in interface EntityManager
public EntityManagerFactoryImpl getEntityManagerFactory()
getEntityManagerFactory
in interface EntityManager
public HibernateEntityManagerFactory getFactory()
getFactory
in interface HibernateEntityManagerImplementor
public CriteriaBuilder getCriteriaBuilder()
CriteriaBuilder
for the creation of
CriteriaQuery
objects.getCriteriaBuilder
in interface EntityManager
public Metamodel getMetamodel()
Metamodel
interface for access to the
metamodel of the persistence unit.getMetamodel
in interface EntityManager
public void setFlushMode(FlushModeType flushModeType)
EntityManager
setFlushMode
in interface EntityManager
flushModeType
- flush modepublic void clear()
EntityManager
clear
in interface EntityManager
public void detach(Object entity)
EntityManager
detach
in interface EntityManager
entity
- entity instancepublic FlushModeType getFlushMode()
getFlushMode
in interface EntityManager
public void lock(Object entity, LockModeType lockMode)
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 EntityManager
entity
- entity instancelockMode
- lock modepublic void lock(Object entity, LockModeType lockModeType, Map<String,Object> properties)
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 EntityManager
entity
- entity instancelockModeType
- lock modeproperties
- standard and vendor-specific properties
and hintspublic LockOptions getLockRequest(LockModeType lockModeType, Map<String,Object> properties)
HibernateEntityManagerImplementor
LockModeType
& properties into LockOptions
getLockRequest
in interface HibernateEntityManagerImplementor
lockModeType
- is the requested lock typeproperties
- are the lock propertiespublic boolean isTransactionInProgress()
HibernateEntityManagerImplementor
isTransactionInProgress
in interface HibernateEntityManagerImplementor
protected void markAsRollback()
public void joinTransaction()
EntityManager
joinTransaction
in interface EntityManager
public <T> T unwrap(Class<T> clazz)
EntityManager
EntityManager
implementation does not support the specified class, the
PersistenceException
is thrown.unwrap
in interface EntityManager
clazz
- 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()
getDelegate
in interface EntityManager
public void handlePersistenceException(PersistenceException e)
handlePersistenceException
in interface HibernateEntityManagerImplementor
e
- The exception being handled.public void throwPersistenceException(PersistenceException e)
HibernateEntityManagerImplementor.handlePersistenceException(javax.persistence.PersistenceException)
and then throws the given exception.throwPersistenceException
in interface HibernateEntityManagerImplementor
e
- The exception being handled and finally thrown.public RuntimeException convert(HibernateException e)
HibernateEntityManagerImplementor.handlePersistenceException(javax.persistence.PersistenceException)
are also made.convert
in interface HibernateEntityManagerImplementor
e
- The Hibernate excepton.public RuntimeException convert(RuntimeException e)
public RuntimeException convert(HibernateException e, LockOptions lockOptions)
HibernateEntityManagerImplementor.handlePersistenceException(javax.persistence.PersistenceException)
are also made.convert
in interface HibernateEntityManagerImplementor
e
- The Hibernate excepton.lockOptions
- The lock options in effect at the time of exception (can be null)public void throwPersistenceException(HibernateException e)
HibernateEntityManagerImplementor.convert(org.hibernate.HibernateException, org.hibernate.LockOptions)
and then throws the given exception.throwPersistenceException
in interface HibernateEntityManagerImplementor
e
- The exception being handled and finally thrown.public PersistenceException wrapStaleStateException(StaleStateException e)
wrapStaleStateException
in interface HibernateEntityManagerImplementor
public PersistenceException wrapLockException(HibernateException e, LockOptions lockOptions)
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.