1 22 package org.jboss.ejb3.entity; 23 24 import org.jboss.aop.advice.Interceptor; 25 import org.jboss.aop.joinpoint.Invocation; 26 import org.jboss.logging.Logger; 27 28 import javax.persistence.EntityManager; 29 import java.util.IdentityHashMap ; 30 import java.util.Map ; 31 32 40 public class TransactionScopedEntityManagerInterceptor implements Interceptor 41 { 42 private static final Logger log = Logger.getLogger(TransactionScopedEntityManagerInterceptor.class); 43 44 public String getName() 45 { 46 return this.getClass().getName(); 47 } 48 49 public Object invoke(Invocation invocation) throws Throwable 50 { 51 try 52 { 53 ManagedEntityManagerFactory.nonTxStack.push(new IdentityHashMap ()); 54 return invocation.invokeNext(); 55 } 56 finally 57 { 58 Map map = ManagedEntityManagerFactory.nonTxStack.pop(); 59 for (Object obj : map.values()) 60 { 61 try 62 { 63 ((EntityManager)obj).close(); 64 log.debug("********************* CLOSING tx scoped nontx entity manager"); 65 } 66 catch (Exception ignored) 67 { 68 } 69 } 70 } 71 } 72 } 73 | Popular Tags |