1 22 package org.jboss.injection; 23 24 import javax.persistence.EntityManager; 25 import org.jboss.ejb3.BeanContext; 26 import org.jboss.ejb3.entity.ManagedEntityManagerFactory; 27 import org.jboss.ejb3.stateful.StatefulBeanContext; 28 import org.jboss.logging.Logger; 29 30 36 public class ExtendedPersistenceContextInjector implements Injector, PojoInjector 37 { 38 protected static final Logger log = Logger.getLogger(ExtendedPersistenceContextInjector.class); 39 protected ManagedEntityManagerFactory factory; 40 41 protected ExtendedPersistenceContextInjector(ManagedEntityManagerFactory factory) 42 { 43 this.factory = factory; 44 } 45 46 public void inject(BeanContext ctx) 47 { 48 inject(ctx, ctx.getInstance()); 49 } 50 51 public void inject(BeanContext beanContext, Object instance) 52 { 53 StatefulBeanContext ctx = (StatefulBeanContext)beanContext; 54 EntityManager pc = ctx.getExtendedPersistenceContext(factory.getKernelName()); 55 if (pc == null) 56 { 57 pc = factory.createEntityManager(); 58 ctx.addExtendedPersistenceContext(factory.getKernelName(), pc); 59 } 60 } 61 62 public void inject(Object instance) 63 { 64 throw new RuntimeException ("Illegal operation"); 65 } 66 67 public Class getInjectionClass() 68 { 69 return null; 70 } 71 72 } 73 | Popular Tags |