1 7 package org.jboss.ejb3.entity; 8 9 import java.io.InputStream ; 10 import java.util.List ; 11 import java.util.Properties ; 12 import javax.persistence.EntityManagerFactory; 13 import org.hibernate.ejb.HibernatePersistence; 14 import org.hibernate.ejb.xml.PersistenceXml; 15 import org.hibernate.cfg.Environment; 16 17 23 public class EntityManagerFactoryLoader 24 { 25 public static EntityManagerFactory loadFactory(PersistenceXml xml, List <InputStream > hbmXmlFiles, List <String > packages, List <Class > classes, Properties props) 26 { 27 if (xml != null && xml.jtaDatasource != null) 28 { 29 props.put(Environment.DATASOURCE, xml.jtaDatasource); 30 } 31 return loadFactory(hbmXmlFiles, packages, classes, props); 32 } 33 34 public static EntityManagerFactory loadFactory(List <InputStream > hbmXmlFiles, List <String > packages, List <Class > classes, Properties props) 35 { 36 Properties copy = new Properties (); 37 copy.putAll(props); 38 39 if (classes != null) copy.put(HibernatePersistence.LOADED_CLASSES, classes); 41 if (packages != null) copy.put(HibernatePersistence.PACKAGE_NAMES, packages); 42 if (hbmXmlFiles != null) copy.put(HibernatePersistence.HBXML_FILES, hbmXmlFiles); 43 HibernatePersistence provider = new HibernatePersistence(); 44 return provider.createEntityManagerFactory(copy); 45 } 46 } 47 | Popular Tags |