1 17 18 package org.apache.geronimo.naming.reference; 19 20 import java.util.Map ; 21 22 import javax.naming.NameNotFoundException ; 23 24 import org.apache.geronimo.kernel.repository.Artifact; 25 import org.apache.geronimo.kernel.Kernel; 26 import org.apache.geronimo.kernel.GBeanNotFoundException; 27 import org.apache.geronimo.gbean.AbstractNameQuery; 28 import org.apache.geronimo.gbean.AbstractName; 29 30 33 public class PersistenceContextReference extends ConfigurationAwareReference { 34 35 private boolean transactionScoped; 36 private Map properties; 37 38 public PersistenceContextReference(Artifact configId, AbstractNameQuery abstractNameQuery, boolean transactionScoped, Map properties) { 39 super(configId, abstractNameQuery); 40 this.transactionScoped = transactionScoped; 41 this.properties = properties; 42 } 43 44 public String getClassName() { 45 return "javax.persistence.EntityManager"; 46 } 47 48 public Object getContent() throws NameNotFoundException { 49 Kernel kernel = getKernel(); 50 51 AbstractName target; 52 try { 53 target = resolveTargetName(); 54 } catch (GBeanNotFoundException e) { 55 throw (NameNotFoundException ) new NameNotFoundException ("Could not resolve name query: " + abstractNameQueries).initCause(e); 56 } 57 58 Object entityManager; 59 try { 60 entityManager = kernel.invoke(target, "getEntityManager", new Object [] {Boolean.valueOf(transactionScoped), properties}, new String [] {boolean.class.getName(), Map .class.getName()}); 61 } catch (Exception e) { 62 throw (IllegalStateException ) new IllegalStateException ("Could not get entityManager").initCause(e); 63 } 64 if (entityManager == null) { 65 throw new IllegalStateException ("entity manager not returned. Target " + target + " not started"); 66 } 67 return entityManager; 68 } 69 } 70 | Popular Tags |