|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.easybeans.persistence.TxEntityManager
public class TxEntityManager
This class represents an EntityManager that will be used as a container managed transaction scoped persistence context. The lifetime of this context is a single transaction. When the transaction is committed or rollbacked, the persistence context ends.
Field Summary | |
---|---|
private TxEntityManagerHandler |
handler
Handler of the manager. |
Constructor Summary | |
---|---|
TxEntityManager(TxEntityManagerHandler handler)
Build a new entity manager which have TransactionScoped type. |
Method Summary | ||
---|---|---|
void |
clear()
Clear the persistence context, causing all managed entities to become detached. |
|
void |
close()
Close an application-managed EntityManager. |
|
boolean |
contains(java.lang.Object entity)
Check if the instance belongs to the current persistence context. |
|
javax.persistence.Query |
createNamedQuery(java.lang.String name)
Create an instance of Query for executing a named query (in EJB QL or native SQL). |
|
javax.persistence.Query |
createNativeQuery(java.lang.String sqlString)
Create an instance of Query for executing a native SQL statement, e.g., for update or delete. |
|
javax.persistence.Query |
createNativeQuery(java.lang.String sqlString,
java.lang.Class resultClass)
Create an instance of Query for executing a native SQL query. |
|
javax.persistence.Query |
createNativeQuery(java.lang.String sqlString,
java.lang.String resultSetMapping)
Create an instance of Query for executing a native SQL query. |
|
javax.persistence.Query |
createQuery(java.lang.String ejbqlString)
Create an instance of Query for executing an EJB QL statement. |
|
|
find(java.lang.Class<T> entityClass,
java.lang.Object primaryKey)
Find by primary key. |
|
void |
flush()
Synchronize the persistence context to the underlying database. |
|
javax.persistence.EntityManager |
getCurrentEntityManager()
Gets (or create) a new EntityManager for the current tx (if any). |
|
java.lang.Object |
getDelegate()
|
|
javax.persistence.FlushModeType |
getFlushMode()
Get the flush mode that applies to all objects contained in the persistence context. |
|
|
getReference(java.lang.Class<T> entityClass,
java.lang.Object primaryKey)
Get an instance, whose state may be lazily fetched. |
|
javax.persistence.EntityTransaction |
getTransaction()
Return the resource-level transaction object. |
|
boolean |
isOpen()
Determine whether the EntityManager is open. |
|
void |
joinTransaction()
TODO: document this. |
|
void |
lock(java.lang.Object entity,
javax.persistence.LockModeType lockMode)
Set the lock mode for an entity object contained in the persistence context. |
|
|
merge(T entity)
Merge the state of the given entity into the current persistence context. |
|
void |
persist(java.lang.Object entity)
Make an instance managed and persistent. |
|
void |
refresh(java.lang.Object entity)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any. |
|
void |
remove(java.lang.Object entity)
Remove the entity instance. |
|
void |
setFlushMode(javax.persistence.FlushModeType flushMode)
Set the flush mode that applies to all objects contained in the persistence context. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private TxEntityManagerHandler handler
Constructor Detail |
---|
public TxEntityManager(TxEntityManagerHandler handler)
handler
- object managing the transaction's EntityManager.Method Detail |
---|
public javax.persistence.EntityManager getCurrentEntityManager()
public void persist(java.lang.Object entity) throws java.lang.IllegalArgumentException, javax.persistence.TransactionRequiredException
persist
in interface javax.persistence.EntityManager
entity
- entity bean.
java.lang.IllegalArgumentException
- if not an entity or entity is detached
javax.persistence.TransactionRequiredException
- if there is no transaction and the
persistence context is of type PersistenceContextType.TRANSACTIONpublic <T> T merge(T entity) throws java.lang.IllegalArgumentException, javax.persistence.TransactionRequiredException
merge
in interface javax.persistence.EntityManager
T
- entity object's class.entity
- entity bean
java.lang.IllegalArgumentException
- if instance is not an entity or is a
removed entity
javax.persistence.TransactionRequiredException
- if there is no transaction and the
persistence context is of type PersistenceContextType.TRANSACTIONpublic void remove(java.lang.Object entity) throws java.lang.IllegalArgumentException, javax.persistence.TransactionRequiredException
remove
in interface javax.persistence.EntityManager
entity
- entity bean
java.lang.IllegalArgumentException
- if not an entity or if a detached entity
javax.persistence.TransactionRequiredException
- if there is no transaction and the
persistence context is of type PersistenceContextType.TRANSACTIONpublic <T> T find(java.lang.Class<T> entityClass, java.lang.Object primaryKey) throws java.lang.IllegalArgumentException
find
in interface javax.persistence.EntityManager
T
- entity object's class.entityClass
- the class of the entityprimaryKey
- the primary key
java.lang.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 keypublic <T> T getReference(java.lang.Class<T> entityClass, java.lang.Object primaryKey) throws java.lang.IllegalArgumentException, javax.persistence.EntityNotFoundException
getReference
in interface javax.persistence.EntityManager
T
- entity object's class.entityClass
- the class of the entityprimaryKey
- the primary key
java.lang.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 key
javax.persistence.EntityNotFoundException
- if the entity state cannot be accessedpublic void flush() throws javax.persistence.TransactionRequiredException, javax.persistence.PersistenceException
flush
in interface javax.persistence.EntityManager
javax.persistence.TransactionRequiredException
- if there is no transaction
javax.persistence.PersistenceException
- if the flush failspublic void setFlushMode(javax.persistence.FlushModeType flushMode)
setFlushMode
in interface javax.persistence.EntityManager
flushMode
- the mode of flushingpublic javax.persistence.FlushModeType getFlushMode()
getFlushMode
in interface javax.persistence.EntityManager
public void lock(java.lang.Object entity, javax.persistence.LockModeType lockMode) throws javax.persistence.PersistenceException, java.lang.IllegalArgumentException, javax.persistence.TransactionRequiredException
lock
in interface javax.persistence.EntityManager
entity
- entity beanlockMode
- mode for locking
javax.persistence.PersistenceException
- if an unsupported lock call is made
java.lang.IllegalArgumentException
- if the instance is not an entity or is a
detached entity
javax.persistence.TransactionRequiredException
- if there is no transactionpublic void refresh(java.lang.Object entity) throws java.lang.IllegalArgumentException, javax.persistence.TransactionRequiredException, javax.persistence.EntityNotFoundException
refresh
in interface javax.persistence.EntityManager
entity
- entity bean
java.lang.IllegalArgumentException
- if not an entity or entity is not
managed
javax.persistence.TransactionRequiredException
- if there is no transaction and the
persistence context is of type PersistenceContextType.TRANSACTION
javax.persistence.EntityNotFoundException
- if the entity no longer exists in the
databasepublic void clear()
clear
in interface javax.persistence.EntityManager
public boolean contains(java.lang.Object entity) throws java.lang.IllegalArgumentException
contains
in interface javax.persistence.EntityManager
entity
- the entity bean
java.lang.IllegalArgumentException
- if not an entitypublic javax.persistence.Query createQuery(java.lang.String ejbqlString) throws java.lang.IllegalArgumentException
createQuery
in interface javax.persistence.EntityManager
ejbqlString
- an EJB QL query string
java.lang.IllegalArgumentException
- if query string is not validpublic javax.persistence.Query createNamedQuery(java.lang.String name) throws java.lang.IllegalArgumentException
createNamedQuery
in interface javax.persistence.EntityManager
name
- the name of a query defined in metadata
java.lang.IllegalArgumentException
- if a query has not been defined with the
given namepublic javax.persistence.Query createNativeQuery(java.lang.String sqlString)
createNativeQuery
in interface javax.persistence.EntityManager
sqlString
- a native SQL query string
public javax.persistence.Query createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
createNativeQuery
in interface javax.persistence.EntityManager
sqlString
- a native SQL query stringresultClass
- the class of the resulting instance(s)
public javax.persistence.Query createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
createNativeQuery
in interface javax.persistence.EntityManager
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mapping
public void joinTransaction()
joinTransaction
in interface javax.persistence.EntityManager
public java.lang.Object getDelegate()
getDelegate
in interface javax.persistence.EntityManager
public void close() throws java.lang.IllegalStateException
close
in interface javax.persistence.EntityManager
java.lang.IllegalStateException
- if the EntityManager is associated with an
active transaction or if the EntityManager is container-managed.public boolean isOpen()
isOpen
in interface javax.persistence.EntityManager
public javax.persistence.EntityTransaction getTransaction() throws java.lang.IllegalStateException
getTransaction
in interface javax.persistence.EntityManager
java.lang.IllegalStateException
- if invoked on a JTA EntityManager or an
EntityManager that has been closed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |