1 22 package org.jboss.ejb3.test.interceptors; 23 24 import javax.ejb.EJB ; 25 import javax.annotation.Resource; 26 import javax.transaction.TransactionManager ; 27 import javax.sql.DataSource ; 28 import javax.persistence.PersistenceContext; 29 import javax.persistence.EntityManager; 30 import javax.persistence.PersistenceUnit; 31 import javax.persistence.EntityManagerFactory; 32 import javax.interceptor.AroundInvoke; 33 import javax.interceptor.InvocationContext; 34 35 import org.jboss.annotation.JndiInject; 36 import org.hibernate.Session; 37 import org.hibernate.SessionFactory; 38 39 45 public class MyInterceptor extends MyBaseInterceptor 46 { 47 @EJB MySession2 session2; 48 @JndiInject(jndiName="java:/TransactionManager") TransactionManager tm; 49 @Resource(name="DefaultDS", mappedName="java:DefaultDS") DataSource ds; 50 @PersistenceContext(unitName="interceptors-test") EntityManager em; 51 @PersistenceContext(unitName="interceptors-test") Session session; 52 @PersistenceUnit(unitName="interceptors-test") EntityManagerFactory factory; 53 @PersistenceUnit(unitName="interceptors-test") SessionFactory sessionFactory; 54 55 MySession2 session2Method; 56 TransactionManager tmMethod; 57 DataSource dsMethod; 58 EntityManager emMethod; 59 Session sessionMethod; 60 EntityManagerFactory factoryMethod; 61 SessionFactory sessionFactoryMethod; 62 63 @EJB 64 public void setSession2Method(MySession2 session2Method) 65 { 66 this.session2Method = session2Method; 67 } 68 @JndiInject(jndiName="java:/TransactionManager") 69 public void setTmMethod(TransactionManager tmMethod) 70 { 71 this.tmMethod = tmMethod; 72 } 73 @Resource(name="DefaultDS", mappedName="java:DefaultDS") 74 public void setDsMethod(DataSource dsMethod) 75 { 76 this.dsMethod = dsMethod; 77 } 78 @PersistenceContext(unitName="interceptors-test") 79 public void setEmMethod(EntityManager emMethod) 80 { 81 this.emMethod = emMethod; 82 } 83 @PersistenceContext(unitName="interceptors-test") 84 public void setSessionMethod(Session sessionMethod) 85 { 86 this.sessionMethod = sessionMethod; 87 } 88 @PersistenceUnit(unitName="interceptors-test") 89 public void setFactoryMethod(EntityManagerFactory factoryMethod) 90 { 91 this.factoryMethod = factoryMethod; 92 } 93 @PersistenceUnit(unitName="interceptors-test") 94 public void setSessionFactoryMethod(SessionFactory sessionFactoryMethod) 95 { 96 this.sessionFactoryMethod = sessionFactoryMethod; 97 } 98 99 @AroundInvoke 100 public Object invoke(InvocationContext ctx) throws Exception 101 { 102 session2.doit(); 103 if (tm == null) throw new RuntimeException ("tm was null"); 104 if (ds == null) throw new RuntimeException ("ds was null"); 105 if (em == null) throw new RuntimeException ("em was null"); 106 if (session == null) throw new RuntimeException ("session was null"); 107 if (factory == null) throw new RuntimeException ("factory was null"); 108 if (sessionFactory == null) throw new RuntimeException ("sessionFactory was null"); 109 110 session2Method.doit(); 111 if (tmMethod == null) throw new RuntimeException ("tm was null"); 112 if (dsMethod == null) throw new RuntimeException ("ds was null"); 113 if (emMethod == null) throw new RuntimeException ("em was null"); 114 if (sessionMethod == null) throw new RuntimeException ("session was null"); 115 if (factoryMethod == null) throw new RuntimeException ("factory was null"); 116 if (sessionFactoryMethod == null) throw new RuntimeException ("sessionFactory was null"); 117 return ctx.proceed(); 118 } 119 } 120 | Popular Tags |