|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.easybeans.persistence.TxEntityManagerHandler
public class TxEntityManagerHandler
This class is used to handle different entity manager for Transaction Scoped Persistence Context. It associates one EntityManager to a given transaction
Field Summary | |
---|---|
private EntityManagerFactory |
entityManagerFactory
EntityManager factory that will create entity manager. |
private java.util.Map<javax.transaction.Transaction,EntityManager> |
entityManagers
Map between transactions and the entity manager. |
private java.lang.ThreadLocal<EntityManager> |
previousEntityManager
Previous entity manager (must be kept). |
private java.lang.ThreadLocal<EntityManager> |
threadEntityManager
Entity Manager used for a single method call when there is no TX. |
Constructor Summary | |
---|---|
TxEntityManagerHandler(EntityManagerFactory entityManagerFactory)
Build a new handler of these entity managers. |
Method Summary | |
---|---|
void |
addCurrent()
Sets the current entity manager (used when to transaction is active). |
private EntityManager |
buildNewTxEntityManager(javax.transaction.Transaction tx)
Builds a new Entity manager for the given transaction. |
private EntityManager |
buildNoTxEntityManager()
Builds a new Entity manager used when there is no transaction. |
void |
closeCurrentAndReturnToPrevious()
Sets back to the previous entity manager and close the current entity manager. |
EntityManager |
getCurrent()
Gets the current entity manager (or create one) for the given transaction if there is one. |
void |
release(javax.transaction.Transaction tx)
Release the entity manager associated to the given tx. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private EntityManagerFactory entityManagerFactory
private java.util.Map<javax.transaction.Transaction,EntityManager> entityManagers
private java.lang.ThreadLocal<EntityManager> previousEntityManager
private java.lang.ThreadLocal<EntityManager> threadEntityManager
Constructor Detail |
---|
public TxEntityManagerHandler(EntityManagerFactory entityManagerFactory)
entityManagerFactory
- Factory used to create the entity manager (if
no entity manager is already associated to the current
transaction)Method Detail |
---|
public EntityManager getCurrent()
private EntityManager buildNewTxEntityManager(javax.transaction.Transaction tx)
tx
- transaction on which associate the entity manager
private EntityManager buildNoTxEntityManager()
public void release(javax.transaction.Transaction tx)
tx
- tx to removedpublic void addCurrent()
public void closeCurrentAndReturnToPrevious()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |