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

TransactionScopedEntityManager

public class TransactionScopedEntityManager extends Object implements HibernateSession, Externalizable, org.hibernate.ejb.HibernateEntityManager
author
Bill Burke
version
$Revision: 62768 $

Fields Summary
private static final long
serialVersionUID
private transient ManagedEntityManagerFactory
factory
Constructors Summary
public TransactionScopedEntityManager(ManagedEntityManagerFactory factory)

      if (factory == null) throw new NullPointerException("factory must not be null");
      this.factory = factory;
   
public TransactionScopedEntityManager()

   
Methods Summary
public voidclear()

      factory.getTransactionScopedEntityManager().clear();
   
public voidclose()

      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
   
public booleancontains(java.lang.Object entity)

      return factory.getTransactionScopedEntityManager().contains(entity);
   
public javax.persistence.QuerycreateNamedQuery(java.lang.String name)

      EntityManager em = factory.getTransactionScopedEntityManager();
      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      return em.createNamedQuery(name);
   
public javax.persistence.QuerycreateNativeQuery(java.lang.String sqlString)

      EntityManager em = factory.getTransactionScopedEntityManager();
      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      return em.createNativeQuery(sqlString);
   
public javax.persistence.QuerycreateNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)

      EntityManager em = factory.getTransactionScopedEntityManager();
      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      return em.createNativeQuery(sqlString, resultClass);
   
public javax.persistence.QuerycreateNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)

      EntityManager em = factory.getTransactionScopedEntityManager();
      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      return em.createNativeQuery(sqlString, resultSetMapping);
   
public javax.persistence.QuerycreateQuery(java.lang.String ejbqlString)

      EntityManager em = factory.getTransactionScopedEntityManager();
      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      return em.createQuery(ejbqlString);
   
public Afind(java.lang.Class entityClass, java.lang.Object primaryKey)

      EntityManager em = factory.getTransactionScopedEntityManager();
      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      try
      {
         return em.find(entityClass, primaryKey);
      }
      finally
      {
         if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      }
   
public voidflush()

      factory.verifyInTx();
      factory.getTransactionScopedEntityManager().flush();
   
public java.lang.ObjectgetDelegate()

      return factory.getTransactionScopedEntityManager().getDelegate();
   
public javax.persistence.FlushModeTypegetFlushMode()

      return factory.getTransactionScopedEntityManager().getFlushMode();
   
public org.hibernate.SessiongetHibernateSession()

      EntityManager em = factory.getTransactionScopedEntityManager();
      if (em instanceof HibernateEntityManager)
      {
         return ((HibernateEntityManager) em).getSession();
      }
      throw new RuntimeException("ILLEGAL ACTION:  Not a Hibernate pe" +
              "rsistence provider");
   
public TgetReference(java.lang.Class entityClass, java.lang.Object primaryKey)

      EntityManager em = factory.getTransactionScopedEntityManager();
      if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      try
      {
         return em.getReference(entityClass, primaryKey);
      }
      finally
      {
         if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
      }
   
public org.hibernate.SessiongetSession()


     
   
      return getHibernateSession();
   
public javax.persistence.EntityTransactiongetTransaction()

      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
   
public booleanisOpen()

      throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
   
public voidjoinTransaction()

      factory.verifyInTx();
      factory.getTransactionScopedEntityManager().joinTransaction();
   
public voidlock(java.lang.Object entity, javax.persistence.LockModeType lockMode)

      factory.verifyInTx();
      factory.getTransactionScopedEntityManager().lock(entity, lockMode);
   
public Amerge(A entity)

      factory.verifyInTx();
      return (A) factory.getTransactionScopedEntityManager().merge(entity);
   
public voidpersist(java.lang.Object entity)

      factory.verifyInTx();
      factory.getTransactionScopedEntityManager().persist(entity);
   
public voidreadExternal(java.io.ObjectInput in)

      String kernelName = in.readUTF();
      PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit(kernelName);
      if (deployment == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
      factory = deployment.getManagedFactory();
   
public voidrefresh(java.lang.Object entity)

      factory.verifyInTx();
      factory.getTransactionScopedEntityManager().refresh(entity);
   
public voidremove(java.lang.Object entity)

      factory.verifyInTx();
      factory.getTransactionScopedEntityManager().remove(entity);
   
public voidsetFlushMode(javax.persistence.FlushModeType flushMode)

      factory.getTransactionScopedEntityManager().setFlushMode(flushMode);
   
public voidwriteExternal(java.io.ObjectOutput out)

      out.writeUTF(factory.getKernelName());