1 //$Id: HibernatePersistence.java 11171 2007-02-08 03:40:51Z epbernard $
2 package org.hibernate.ejb;
3
4 import java.util.Map;
5 import javax.persistence.EntityManagerFactory;
6 import javax.persistence.spi.PersistenceUnitInfo;
7
8 /**
9 * Hibernate EJB3 persistence provider implementation
10 *
11 * @author Gavin King
12 */
13 public class HibernatePersistence implements javax.persistence.spi.PersistenceProvider {
14
15 /**
16 * Provider
17 */
18 public static final String PROVIDER = "javax.persistence.provider";
19 /**
20 * ?
21 * transaction type
22 */
23 public static final String TRANSACTION_TYPE = "javax.persistence.transactionType";
24 /**
25 * JTA datasource name
26 */
27 public static final String JTA_DATASOURCE = "javax.persistence.jtaDataSource";
28 /**
29 * Non JTA datasource name
30 */
31 public static final String NON_JTA_DATASOURCE = "javax.persistence.nonJtaDataSource";
32 /**
33 * JAR autodetection artifacts class, hbm
34 */
35 public static final String AUTODETECTION = "hibernate.archive.autodetection";
36 /**
37 * cfg.xml configuration file used
38 */
39 public static final String CFG_FILE = "hibernate.ejb.cfgfile";
40 /**
41 * Caching configuration should follow the following pattern
42 * hibernate.ejb.classcache.<fully.qualified.Classname> usage[, region]
43 * where usage is the cache strategy used and region the cache region name
44 */
45 public static final String CLASS_CACHE_PREFIX = "hibernate.ejb.classcache";
46 /**
47 * Caching configuration should follow the following pattern
48 * hibernate.ejb.collectioncache.<fully.qualified.Classname>.<role> usage[, region]
49 * where usage is the cache strategy used and region the cache region name
50 */
51 public static final String COLLECTION_CACHE_PREFIX = "hibernate.ejb.collectioncache";
52 /**
53 * Interceptor class name, the class has to have a no-arg constructor
54 */
55 public static final String INTERCEPTOR = "hibernate.ejb.interceptor";
56 /**
57 * Naming strategy class name, the class has to have a no-arg constructor
58 */
59 public static final String NAMING_STRATEGY = "hibernate.ejb.naming_strategy";
60 /**
61 * Event configuration should follow the following pattern
62 * hibernate.ejb.event.[eventType] f.q.c.n.EventListener1, f.q.c.n.EventListener12 ...
63 */
64 public static final String EVENT_LISTENER_PREFIX = "hibernate.ejb.event";
65 /**
66 * Enable the class file enhancement
67 */
68 public static final String USE_CLASS_ENHANCER = "hibernate.ejb.use_class_enhancer";
69 /**
70 * Whether or not discard persistent context on entityManager.close()
71 * The EJB3 compliant and default choice is false
72 */
73 public static final String DISCARD_PC_ON_CLOSE = "hibernate.ejb.discard_pc_on_close";
74 /**
75 * Consider this as experimental
76 * It is not recommended to set up this property, the configuration is stored
77 * in the JNDI in a serialized form
78 */
79 public static final String CONFIGURATION_JNDI_NAME = "hibernate.ejb.configuration_jndi_name";
80
81 //The following properties are for Internal use only
82 /**
83 * link to the alternative Hibernate configuration file
84 * Internal use only
85 */
86 /**
87 * List of classes names
88 * Internal use only
89 */
90 public static final String CLASS_NAMES = "hibernate.ejb.classes";
91 /**
92 * List of annotated packages
93 * Internal use only
94 */
95 public static final String PACKAGE_NAMES = "hibernate.ejb.packages";
96 /**
97 * List of classes names
98 * Internal use only
99 */
100 public static final String XML_FILE_NAMES = "hibernate.ejb.xml_files";
101 public static final String HBXML_FILES = "hibernate.hbmxml.files";
102 public static final String LOADED_CLASSES = "hibernate.ejb.loaded.classes";
103 public static final String JACC_CONTEXT_ID = "hibernate.jacc.ctx.id";
104 public static final String JACC_PREFIX = "hibernate.jacc";
105 public static final String JACC_ENABLED = "hibernate.jacc.enabled";
106 public static final String PERSISTENCE_UNIT_NAME = "hibernate.ejb.persistenceUnitName";
107
108
109 /**
110 * Get an entity manager factory by its entity manager name and given the
111 * appropriate extra properties. Those proeprties override the one get through
112 * the peristence.xml file.
113 *
114 * @param persistenceUnitName entity manager name
115 * @param overridenProperties properties passed to the persistence provider
116 * @return initialized EntityManagerFactory
117 */
118 public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map overridenProperties) {
119 Ejb3Configuration cfg = new Ejb3Configuration();
120 Ejb3Configuration configured = cfg.configure( persistenceUnitName, overridenProperties );
121 return configured != null ? configured.buildEntityManagerFactory() : null;
122 }
123
124 public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) {
125 Ejb3Configuration cfg = new Ejb3Configuration();
126 Ejb3Configuration configured = cfg.configure( info, map );
127 return configured != null ? configured.buildEntityManagerFactory() : null;
128 }
129
130 /**
131 * create a factory from a canonical version
132 * @deprecated
133 */
134 // This is used directly by JBoss so don't remove until further notice. bill@jboss.org
135 public EntityManagerFactory createEntityManagerFactory(Map properties) {
136 Ejb3Configuration cfg = new Ejb3Configuration();
137 return cfg.createEntityManagerFactory( properties );
138 }
139
140 }