1 7 package org.jboss.ejb3.injection; 8 9 import java.lang.reflect.Field ; 10 import javax.persistence.EntityManager; 11 import javax.persistence.Transient; 12 import javax.persistence.PersistenceContextType; 13 import org.jboss.ejb3.BeanContext; 14 import org.jboss.ejb3.Container; 15 import org.jboss.ejb3.EJBContainer; 16 import org.jboss.ejb3.entity.ManagedEntityManagerFactory; 17 18 24 public class EntityManagerFieldInjector extends EntityManagerInjector 25 { 26 protected Field field; 27 28 public EntityManagerFieldInjector(Field field, Container container, ManagedEntityManagerFactory factory, PersistenceContextType type) 29 { 30 super(container, factory, type); 31 this.field = field; 32 this.field.setAccessible(true); 33 } 34 35 public void inject(BeanContext ctx) 36 { 37 try 38 { 39 EntityManager entityManager = null; 40 boolean isTransient = ((EJBContainer)container).resolveAnnotation(field, Transient.class) != null; 41 entityManager = getEntityManager(ctx, isTransient); 42 field.set(ctx.getInstance(), entityManager); 43 } 44 catch (IllegalAccessException e) 45 { 46 throw new RuntimeException (e); } 48 catch (IllegalArgumentException e) 49 { 50 throw new RuntimeException ("Failed in setting EntityManager on setter field: " + field.toString()); 51 } 52 } 53 54 } 55 | Popular Tags |