FileDocCategorySizeDatePackage
TransactionScopedSessionInvocationHandler.javaAPI DocJBoss 4.2.13856Fri Jul 13 20:53:58 BST 2007org.jboss.ejb3.entity.hibernate

TransactionScopedSessionInvocationHandler

public class TransactionScopedSessionInvocationHandler extends Object implements Externalizable, InvocationHandler
Handle method execution delegation to an Hibernate session following the transaction scoped persistence context rules
author
Emmanuel Bernard

Fields Summary
private static final long
serialVersionUID
private transient org.jboss.ejb3.entity.ManagedEntityManagerFactory
factory
Constructors Summary
public TransactionScopedSessionInvocationHandler(org.jboss.ejb3.entity.ManagedEntityManagerFactory factory)


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

   
Methods Summary
protected org.hibernate.SessiongetHibernateSession()

      if ( getSession() instanceof HibernateEntityManager )
      {
         return ( (HibernateEntityManager) getSession() ).getSession();
      }
      throw new RuntimeException( "ILLEGAL ACTION: Not a Hibernate persistence provider" );
   
protected javax.persistence.EntityManagergetSession()

      return factory.getTransactionScopedEntityManager();
   
public java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)

      if ( "close".equals( method.getName() ) ) {
         throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
      }
      else {
         //catch all
         try {
            return method.invoke( getHibernateSession(), args );
         }
         catch ( InvocationTargetException e ) {
				if ( e.getTargetException() instanceof RuntimeException ) {
					throw ( RuntimeException ) e.getTargetException();
				}
				else {
					throw e;
				}
			}
      }
   
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 voidwriteExternal(java.io.ObjectOutput out)

      out.writeUTF( factory.getKernelName() );