| java.lang.Object org.ow2.easybeans.persistence.TxEntityManager
TxEntityManager | public class TxEntityManager implements EntityManager(Code) | | 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.
author: Florent Benoit |
Method Summary | |
public void | clear() Clear the persistence context, causing all managed entities to become
detached. | public void | close() Close an application-managed EntityManager. | public boolean | contains(Object entity) Check if the instance belongs to the current persistence context. | public Query | createNamedQuery(String name) Create an instance of Query for executing a named query (in EJB QL or
native SQL). | public Query | createNativeQuery(String sqlString) Create an instance of Query for executing a native SQL statement, e.g.,
for update or delete. | public Query | createNativeQuery(String sqlString, Class resultClass) Create an instance of Query for executing a native SQL query. | public Query | createNativeQuery(String sqlString, String resultSetMapping) Create an instance of Query for executing a native SQL query. | public Query | createQuery(String ejbqlString) Create an instance of Query for executing an EJB QL statement. | public T | find(Class<T> entityClass, Object primaryKey) Find by primary key. | public void | flush() Synchronize the persistence context to the underlying database. | public EntityManager | getCurrentEntityManager() Gets (or create) a new EntityManager for the current tx (if any). | public Object | getDelegate() | public FlushModeType | getFlushMode() Get the flush mode that applies to all objects contained in the
persistence context. | public T | getReference(Class<T> entityClass, Object primaryKey) Get an instance, whose state may be lazily fetched. | public EntityTransaction | getTransaction() Return the resource-level transaction object. | public boolean | isOpen() Determine whether the EntityManager is open. | public void | joinTransaction() TODO: document this. | public void | lock(Object entity, LockModeType lockMode) Set the lock mode for an entity object contained in the persistence
context. | public T | merge(T entity) Merge the state of the given entity into the current persistence context.
Parameters: entity - entity bean< Parameters: T - > entity object's class. | public void | persist(Object entity) Make an instance managed and persistent. | public void | refresh(Object entity) Refresh the state of the instance from the database, overwriting changes
made to the entity, if any. | public void | remove(Object entity) Remove the entity instance. | public void | setFlushMode(FlushModeType flushMode) Set the flush mode that applies to all objects contained in the
persistence context. |
TxEntityManager | public TxEntityManager(TxEntityManagerHandler handler)(Code) | | Build a new entity manager which have TransactionScoped type.
Parameters: handler - object managing the transaction's EntityManager. |
clear | public void clear()(Code) | | Clear the persistence context, causing all managed entities to become
detached. Changes made to entities that have not been flushed to the
database will not be persisted.
|
close | public void close() throws IllegalStateException(Code) | | Close an application-managed EntityManager. After an EntityManager has
been closed, all methods on the EntityManager instance will throw the
IllegalStateException except for isOpen, which will return false. This
method can only be called when the EntityManager is not associated with
an active transaction.
throws: IllegalStateException - if the EntityManager is associated with anactive transaction or if the EntityManager is container-managed. |
createNamedQuery | public Query createNamedQuery(String name) throws IllegalArgumentException(Code) | | Create an instance of Query for executing a named query (in EJB QL or
native SQL).
Parameters: name - the name of a query defined in metadata the new query instance throws: IllegalArgumentException - if a query has not been defined with thegiven name |
createNativeQuery | public Query createNativeQuery(String sqlString)(Code) | | Create an instance of Query for executing a native SQL statement, e.g.,
for update or delete.
Parameters: sqlString - a native SQL query string the new query instance |
createNativeQuery | public Query createNativeQuery(String sqlString, Class resultClass)(Code) | | Create an instance of Query for executing a native SQL query.
Parameters: sqlString - a native SQL query string Parameters: resultClass - the class of the resulting instance(s) the new query instance |
createNativeQuery | public Query createNativeQuery(String sqlString, String resultSetMapping)(Code) | | Create an instance of Query for executing a native SQL query.
Parameters: sqlString - a native SQL query string Parameters: resultSetMapping - the name of the result set mapping the new query instance |
find | public T find(Class<T> entityClass, Object primaryKey) throws IllegalArgumentException(Code) | | Find by primary key.
< Parameters: T - > entity object's class. Parameters: entityClass - the class of the entity Parameters: primaryKey - the primary key the found entity instance or null if the entity does not exist throws: IllegalArgumentException - if the first argument does not denote anentity type or the second argument is not a valid type for thatentity?s primary key |
flush | public void flush() throws TransactionRequiredException, PersistenceException(Code) | | Synchronize the persistence context to the underlying database.
throws: TransactionRequiredException - if there is no transaction throws: PersistenceException - if the flush fails |
getCurrentEntityManager | public EntityManager getCurrentEntityManager()(Code) | | Gets (or create) a new EntityManager for the current tx (if any).
an entity manager. |
getDelegate | public Object getDelegate()(Code) | | TODO: document this. |
getFlushMode | public FlushModeType getFlushMode()(Code) | | Get the flush mode that applies to all objects contained in the
persistence context.
flushMode |
getReference | public T getReference(Class<T> entityClass, Object primaryKey) throws IllegalArgumentException, EntityNotFoundException(Code) | | Get an instance, whose state may be lazily fetched. If the requested
instance does not exist in the database, throws EntityNotFoundException
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.
< Parameters: T - > entity object's class. Parameters: entityClass - the class of the entity Parameters: primaryKey - the primary key the found entity instance throws: IllegalArgumentException - if the first argument does not denote anentity type or the second argument is not a valid type for thatentity?s primary key throws: EntityNotFoundException - if the entity state cannot be accessed |
getTransaction | public EntityTransaction getTransaction() throws IllegalStateException(Code) | | Return the resource-level transaction object. The EntityTransaction
instance may be used serially to begin and commit multiple transactions.
EntityTransaction instance throws: IllegalStateException - if invoked on a JTA EntityManager or anEntityManager that has been closed. |
isOpen | public boolean isOpen()(Code) | | Determine whether the EntityManager is open.
true until the EntityManager has been closed. |
joinTransaction | public void joinTransaction()(Code) | | TODO: document this.
|
lock | public void lock(Object entity, LockModeType lockMode) throws PersistenceException, IllegalArgumentException, TransactionRequiredException(Code) | | Set the lock mode for an entity object contained in the persistence
context.
Parameters: entity - entity bean Parameters: lockMode - mode for locking throws: PersistenceException - if an unsupported lock call is made throws: IllegalArgumentException - if the instance is not an entity or is adetached entity throws: TransactionRequiredException - if there is no transaction |
merge | public T merge(T entity) throws IllegalArgumentException, TransactionRequiredException(Code) | | Merge the state of the given entity into the current persistence context.
Parameters: entity - entity bean< Parameters: T - > entity object's class. the instance that the state was merged to throws: IllegalArgumentException - if instance is not an entity or is aremoved entity throws: TransactionRequiredException - if there is no transaction and thepersistence context is of type PersistenceContextType.TRANSACTION |
persist | public void persist(Object entity) throws IllegalArgumentException, TransactionRequiredException(Code) | | Make an instance managed and persistent.
Parameters: entity - entity bean. throws: IllegalArgumentException - if not an entity or entity is detached throws: TransactionRequiredException - if there is no transaction and thepersistence context is of type PersistenceContextType.TRANSACTION |
refresh | public void refresh(Object entity) throws IllegalArgumentException, TransactionRequiredException, EntityNotFoundException(Code) | | Refresh the state of the instance from the database, overwriting changes
made to the entity, if any.
Parameters: entity - entity bean throws: IllegalArgumentException - if not an entity or entity is notmanaged throws: TransactionRequiredException - if there is no transaction and thepersistence context is of type PersistenceContextType.TRANSACTION throws: EntityNotFoundException - if the entity no longer exists in thedatabase |
remove | public void remove(Object entity) throws IllegalArgumentException, TransactionRequiredException(Code) | | Remove the entity instance.
Parameters: entity - entity bean throws: IllegalArgumentException - if not an entity or if a detached entity throws: TransactionRequiredException - if there is no transaction and thepersistence context is of type PersistenceContextType.TRANSACTION |
setFlushMode | public void setFlushMode(FlushModeType flushMode)(Code) | | Set the flush mode that applies to all objects contained in the
persistence context.
Parameters: flushMode - the mode of flushing |
|
|