FileDocCategorySizeDatePackage
ManagedEntityManagerFactory.javaAPI DocJBoss 4.2.16110Fri Jul 13 20:53:58 BST 2007org.jboss.ejb3.entity

ManagedEntityManagerFactory

public class ManagedEntityManagerFactory extends Object
author
Gavin King
version
$Revision: 57207 $

Fields Summary
private static final Logger
log
protected EntityManagerFactory
entityManagerFactory
protected org.jboss.tm.TransactionLocal
session
protected String
kernelName
public static org.jboss.ejb3.ThreadLocalStack
nonTxStack
public static ThreadLocal
longLivedSession
Constructors Summary
public ManagedEntityManagerFactory(EntityManagerFactory sf, String kernelName)

      this.entityManagerFactory = sf;
      this.kernelName = kernelName;
   
Methods Summary
public javax.persistence.EntityManagercreateEntityManager()

      return entityManagerFactory.createEntityManager();
   
public voiddestroy()

      entityManagerFactory.close();
   
public javax.persistence.EntityManagerFactorygetEntityManagerFactory()

      return entityManagerFactory;
   
public java.lang.StringgetKernelName()

      return kernelName;
   
public javax.persistence.EntityManagergetNonTxEntityManager()


     
   
      Map map = nonTxStack.get();
      EntityManager em = (EntityManager)map.get(this);
      if (em == null)
      {
         em = entityManagerFactory.createEntityManager();
         map.put(this, em);
      }
      return em;
   
public javax.persistence.EntityManagergetTransactionScopedEntityManager()

      Transaction tx = session.getTransaction();
      if (tx == null || !TxUtils.isActive(tx)) return getNonTxEntityManager();

      EntityManager rtnSession = (EntityManager) session.get();
      if (rtnSession == null)
      {
         rtnSession = createEntityManager();
         try
         {
            tx.registerSynchronization(new SessionSynchronization(rtnSession, tx, true));
         }
         catch (RollbackException e)
         {
            throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
         }
         catch (SystemException e)
         {
            throw new RuntimeException(e);  //To change body of catch statement use Options | File Templates.
         }
         session.set(rtnSession);
         rtnSession.joinTransaction(); // force registration with TX
      }
      return rtnSession;
   
public org.jboss.tm.TransactionLocalgetTransactionSession()


     
   
      return session;
   
public booleanisInTx()

      Transaction tx = session.getTransaction();
      if (tx == null || !TxUtils.isActive(tx)) return false;
      return true;
   
public voidregisterExtendedWithTransaction(javax.persistence.EntityManager pc)

      pc.joinTransaction();
      session.set(pc);
   
public voidverifyInTx()

      Transaction tx = session.getTransaction();
      if (tx == null || !TxUtils.isActive(tx)) throw new TransactionRequiredException("EntityManager must be access within a transaction");
      if (!TxUtils.isActive(tx))
         throw new TransactionRequiredException("Transaction must be active to access EntityManager");