Lines 33-38
Link Here
|
33 |
/** The entity manager factory for the test is injected and passed to the test server platform. */ |
33 |
/** The entity manager factory for the test is injected and passed to the test server platform. */ |
34 |
public static EntityManagerFactory entityManagerFactory; |
34 |
public static EntityManagerFactory entityManagerFactory; |
35 |
|
35 |
|
|
|
36 |
/** The variable for getting entity manager by jndi lookup, set it to true in test.properties if you want jndi lookup */ |
37 |
public static final String EJB_LOOKUP = "ejb.lookup"; |
38 |
|
36 |
/** |
39 |
/** |
37 |
* Nothing required in JEE. |
40 |
* Nothing required in JEE. |
38 |
*/ |
41 |
*/ |
Lines 152-181
Link Here
|
152 |
* Return the managed EntityManager for the persistence unit. |
155 |
* Return the managed EntityManager for the persistence unit. |
153 |
*/ |
156 |
*/ |
154 |
public EntityManager getEntityManager(String persistenceUnit) { |
157 |
public EntityManager getEntityManager(String persistenceUnit) { |
155 |
if (entityManager != null) { |
158 |
String property = System.getProperty(EJB_LOOKUP); |
|
|
159 |
if (property == null || !property.toUpperCase().equals("TRUE")){ |
156 |
return entityManager; |
160 |
return entityManager; |
|
|
161 |
} else { |
162 |
String contextName = "java:comp/env/persistence/" + persistenceUnit + "/entity-manager"; |
163 |
try { |
164 |
return (EntityManager)new InitialContext().lookup(contextName); |
165 |
} catch (NamingException exception) { |
166 |
throw new RuntimeException(exception); |
167 |
} |
157 |
} |
168 |
} |
158 |
String contextName = "java:comp/env/persistence/" + persistenceUnit + "/entity-manager"; |
|
|
159 |
try { |
160 |
return (EntityManager)new InitialContext().lookup(contextName); |
161 |
} catch (NamingException exception) { |
162 |
throw new RuntimeException(exception); |
163 |
} |
164 |
} |
169 |
} |
165 |
|
170 |
|
166 |
/** |
171 |
/** |
167 |
* Return the managed EntityManagerFactory for the persistence unit. |
172 |
* Return the managed EntityManagerFactory for the persistence unit. |
168 |
*/ |
173 |
*/ |
169 |
public EntityManagerFactory getEntityManagerFactory(String persistenceUnit) { |
174 |
public EntityManagerFactory getEntityManagerFactory(String persistenceUnit) { |
170 |
if (entityManagerFactory != null) { |
175 |
String property = System.getProperty(EJB_LOOKUP); |
|
|
176 |
if (property == null || !property.toUpperCase().equals("TRUE")){ |
171 |
return entityManagerFactory; |
177 |
return entityManagerFactory; |
|
|
178 |
} else{ |
179 |
String contextName = "java:comp/env/persistence/" + persistenceUnit + "/factory"; |
180 |
try { |
181 |
return (EntityManagerFactory)new InitialContext().lookup(contextName); |
182 |
} catch (NamingException exception) { |
183 |
throw new RuntimeException(exception); |
184 |
} |
172 |
} |
185 |
} |
173 |
String contextName = "java:comp/env/persistence/" + persistenceUnit + "/factory"; |
|
|
174 |
try { |
175 |
return (EntityManagerFactory)new InitialContext().lookup(contextName); |
176 |
} catch (NamingException exception) { |
177 |
throw new RuntimeException(exception); |
178 |
} |
179 |
} |
186 |
} |
180 |
|
187 |
|
181 |
} |
188 |
} |