1 25 26 package org.objectweb.easybeans.injection; 27 28 import javax.persistence.EntityManager; 29 import javax.persistence.EntityManagerFactory; 30 import javax.persistence.PersistenceContextType; 31 32 import org.objectweb.easybeans.api.Factory; 33 import org.objectweb.easybeans.api.container.EZBEJBContext; 34 import org.objectweb.easybeans.log.JLog; 35 import org.objectweb.easybeans.log.JLogFactory; 36 import org.objectweb.easybeans.persistence.api.EZBPersistenceUnitManager; 37 38 42 public final class EntityManagerHelper { 43 44 47 private static JLog logger = JLogFactory.getLog(EntityManagerHelper.class); 48 49 52 private EntityManagerHelper() { 53 54 } 55 56 64 public static EntityManager getEntityManager(final EZBEJBContext ejbContext, final String unitName, 65 final PersistenceContextType type) { 66 Factory factory = ejbContext.getBean().getEasyBeansFactory(); 68 EZBPersistenceUnitManager persistenceUnitManager = factory.getContainer().getPersistenceUnitManager(); 69 if (persistenceUnitManager != null) { 70 return persistenceUnitManager.getEntityManager(unitName, type); 71 } 72 logger.warn("Requested an EntityManager object but there is no persistenceUnitManager associated" 73 + " to this bean/interceptor : {0}", factory); 74 return null; 75 } 76 77 85 public static EntityManagerFactory getEntityManagerFactory(final EZBEJBContext ejbContext, 86 final String unitName) { 87 Factory factory = ejbContext.getBean().getEasyBeansFactory(); 89 EZBPersistenceUnitManager persistenceUnitManager = factory.getContainer().getPersistenceUnitManager(); 90 if (persistenceUnitManager != null) { 91 return persistenceUnitManager.getEntityManagerFactory(unitName); 92 } 93 logger.warn("Requested an EntityManagerFactory but there is no persistenceUnitManager associated" 94 + " to this bean/interceptor : {0}", factory); 95 return null; 96 } 97 98 } 99 | Popular Tags |