1 22 package org.jboss.ejb3.test.interceptors; 23 24 import java.util.ArrayList ; 25 26 import javax.ejb.EJB ; 27 import javax.annotation.Resource; 28 import javax.interceptor.AroundInvoke; 29 import javax.interceptor.InvocationContext; 30 import javax.persistence.EntityManager; 31 import javax.persistence.EntityManagerFactory; 32 import javax.persistence.PersistenceContext; 33 import javax.persistence.PersistenceUnit; 34 import javax.sql.DataSource ; 35 import javax.transaction.TransactionManager ; 36 37 import org.hibernate.Session; 38 import org.hibernate.SessionFactory; 39 import org.jboss.annotation.JndiInject; 40 41 46 public class MyBaseInterceptor 47 { 48 @EJB MySession2 baseSession2; 49 @JndiInject(jndiName="java:/TransactionManager") TransactionManager baseTm; 50 @Resource(name="DefaultDS", mappedName="java:DefaultDS") DataSource baseDs; 51 @PersistenceContext(unitName="interceptors-test") EntityManager baseEm; 52 @PersistenceContext(unitName="interceptors-test") Session baseSession; 53 @PersistenceUnit(unitName="interceptors-test") EntityManagerFactory baseFactory; 54 @PersistenceUnit(unitName="interceptors-test") SessionFactory baseSessionFactory; 55 56 MySession2 baseSession2Method; 57 TransactionManager baseTmMethod; 58 DataSource baseDsMethod; 59 EntityManager baseEmMethod; 60 Session baseSessionMethod; 61 EntityManagerFactory baseFactoryMethod; 62 SessionFactory baseSessionFactoryMethod; 63 64 @EJB 65 public void setBaseSession2Method(MySession2 session2Method) 66 { 67 this.baseSession2Method = session2Method; 68 } 69 @JndiInject(jndiName="java:/TransactionManager") 70 public void setBaseTmMethod(TransactionManager tmMethod) 71 { 72 this.baseTmMethod = tmMethod; 73 } 74 @Resource(name="DefaultDS", mappedName="java:DefaultDS") 75 public void setBaseDsMethod(DataSource dsMethod) 76 { 77 this.baseDsMethod = dsMethod; 78 } 79 @PersistenceContext(unitName="interceptors-test") 80 public void setBaseEmMethod(EntityManager emMethod) 81 { 82 this.baseEmMethod = emMethod; 83 } 84 @PersistenceContext(unitName="interceptors-test") 85 public void setBaseSessionMethod(Session sessionMethod) 86 { 87 this.baseSessionMethod = sessionMethod; 88 } 89 @PersistenceUnit(unitName="interceptors-test") 90 public void setBaseFactoryMethod(EntityManagerFactory factoryMethod) 91 { 92 this.baseFactoryMethod = factoryMethod; 93 } 94 @PersistenceUnit(unitName="interceptors-test") 95 public void setBaseSessionFactoryMethod(SessionFactory sessionFactoryMethod) 96 { 97 this.baseSessionFactoryMethod = sessionFactoryMethod; 98 } 99 100 @AroundInvoke 101 public Object baseInvoke(InvocationContext ctx) throws Exception 102 { 103 baseSession2.doit(); 104 if (baseTm == null) throw new RuntimeException ("tm was null"); 105 if (baseDs == null) throw new RuntimeException ("ds was null"); 106 if (baseEm == null) throw new RuntimeException ("em was null"); 107 if (baseSession == null) throw new RuntimeException ("session was null"); 108 if (baseFactory == null) throw new RuntimeException ("factory was null"); 109 if (baseSessionFactory == null) throw new RuntimeException ("sessionFactory was null"); 110 111 baseSession2Method.doit(); 112 if (baseTmMethod == null) throw new RuntimeException ("tm was null"); 113 if (baseDsMethod == null) throw new RuntimeException ("ds was null"); 114 if (baseEmMethod == null) throw new RuntimeException ("em was null"); 115 if (baseSessionMethod == null) throw new RuntimeException ("session was null"); 116 if (baseFactoryMethod == null) throw new RuntimeException ("factory was null"); 117 if (baseSessionFactoryMethod == null) throw new RuntimeException ("sessionFactory was null"); 118 ArrayList list = (ArrayList )ctx.proceed(); 119 list.add(0, "MyBaseInterceptor"); 120 return list; 121 } 122 123 } 124 | Popular Tags |