use of org.eclipse.persistence.jpa.JpaEntityManagerFactory in project eclipselink by eclipse-ee4j.
the class JPAPerformanceServerTestSuite method testPerformance.
public void testPerformance() throws Throwable {
TestExecutor executor = new TestExecutor();
EntityManagerFactory factory = Persistence.createEntityManagerFactory("performance");
executor.setSession(((JpaEntityManagerFactory) factory).getServerSession());
executor.setEntityManagerFactory(factory);
JPAPerformanceRegressionModel test = new JPAPerformanceRegressionModel();
executor.runTest(test);
executor.logResultForTestEntity(test);
factory.close();
}
use of org.eclipse.persistence.jpa.JpaEntityManagerFactory in project eclipselink by eclipse-ee4j.
the class EmfRunnerInjector method inject.
/**
* This method will create / inject EntityManagerFactory and SQLListeners into test instances
*/
public void inject(Object testInstance) throws Exception {
if (testInstance == null) {
return;
}
Class<?> cls = testInstance.getClass();
// Check for duplicate injected EMFs
Set<EntityManagerFactory> injectedEmfs = new HashSet<EntityManagerFactory>();
Set<Field> injectedSqlListeneFields = new HashSet<Field>();
// PU name -> Field
Map<String, Field> annotatedSqlListenerFields = getSqlListenerFieldMap(cls);
Map<String, Field> annotatedSqlCallListenerFields = getSqlCallListenerFieldMap(cls);
for (Field emfField : cls.getDeclaredFields()) {
Emf emfAnno = emfField.getAnnotation(Emf.class);
if (emfAnno == null) {
continue;
}
String emfName = emfAnno.name();
SqlCollector sqlCollector = null;
Field sqlListenerField = annotatedSqlListenerFields.get(emfName);
if (sqlListenerField != null) {
sqlCollector = new SqlCollector();
}
SqlCallCollector sqlCallCollector = null;
Field sqlCallListenerField = annotatedSqlCallListenerFields.get(emfName);
if (sqlCallListenerField != null) {
sqlCallCollector = new SqlCallCollector();
}
Map<String, Object> props = null;
if (testInstance instanceof PUPropertiesProvider) {
props = ((PUPropertiesProvider) testInstance).getAdditionalPersistenceProperties(emfName);
}
EntityManagerFactory factory = getEntityManagerFactory(emfAnno, props);
if (!injectedEmfs.add(factory)) {
throw new RuntimeException("Attempted to inject the same EntityManagerFactory multiple times into " + testInstance + ". Please remove the duplicate @Emf annotation, or change the name so that each " + "annotation is for a distinct EntityManagerFactory.");
}
emfField.setAccessible(true);
emfField.set(testInstance, factory);
d("Injected " + factory + " into " + testInstance);
if (sqlCollector != null) {
((JpaEntityManagerFactory) factory).getServerSession().getEventManager().addListener(sqlCollector);
sqlCollector.inject(testInstance, sqlListenerField);
injectedSqlListeneFields.add(sqlListenerField);
d("Injected " + sqlCollector + " into " + sqlListenerField);
}
if (sqlCallCollector != null) {
((JpaEntityManagerFactory) factory).getServerSession().getEventManager().addListener(sqlCallCollector);
sqlCallCollector.inject(testInstance, sqlCallListenerField);
injectedSqlListeneFields.add(sqlCallListenerField);
d("Injected " + sqlCallCollector + " into " + sqlCallListenerField);
}
}
// Check for @SQLListeners that weren't injected
validateSQLListenerAnnotations(annotatedSqlListenerFields, injectedSqlListeneFields);
}
use of org.eclipse.persistence.jpa.JpaEntityManagerFactory in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testEMFTargetServerEnforcing.
public void testEMFTargetServerEnforcing() {
// the test requires passing properties to createEMF or createContainerEMF method.
if (isOnServer()) {
return;
}
EntityManagerFactory emf = null;
try {
System.setProperty(SystemProperties.ENFORCE_TARGET_SERVER, "true");
Map<String, String> properties = new HashMap<>(JUnitTestCaseHelper.getDatabaseProperties());
properties.put(PersistenceUnitProperties.TARGET_SERVER, Platform.class.getName());
properties.put(PersistenceUnitProperties.SESSION_NAME, "dummy-default-session");
PersistenceProvider provider = new PersistenceProvider();
JPAInitializer initializer = provider.getInitializer(getPersistenceUnitName(), properties);
SEPersistenceUnitInfo sePUImpl = initializer.findPersistenceUnitInfo(getPersistenceUnitName(), properties);
emf = provider.createContainerEntityManagerFactory(sePUImpl, properties);
ServerPlatform server = ((JpaEntityManagerFactory) emf).getServerSession().getServerPlatform();
assertNotNull(server);
assertFalse("server should be overridden", server instanceof Platform);
} finally {
System.clearProperty(SystemProperties.ENFORCE_TARGET_SERVER);
if (emf != null) {
emf.close();
}
}
}
use of org.eclipse.persistence.jpa.JpaEntityManagerFactory in project eclipselink by eclipse-ee4j.
the class TestSessionCustomizer method customizerInvoked.
@Test
public void customizerInvoked() {
Customizer customizerInstance = new Customizer();
props.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, customizerInstance);
try (JpaEntityManagerFactory emf = (JpaEntityManagerFactory) Persistence.createEntityManagerFactory(PU_NAME, props)) {
emf.createEntityManager();
Assert.assertTrue(customizerInstance.customized);
}
}
use of org.eclipse.persistence.jpa.JpaEntityManagerFactory in project eclipselink by eclipse-ee4j.
the class TestSessionCustomizer method stringCustomizerInvoked.
@Test
public void stringCustomizerInvoked() {
props.put(PersistenceUnitProperties.SESSION_CUSTOMIZER, Customizer.class.getName());
try (JpaEntityManagerFactory emf = (JpaEntityManagerFactory) Persistence.createEntityManagerFactory(PU_NAME, props)) {
emf.createEntityManager();
Assert.assertTrue(Customizer.staticCustomized);
}
}
Aggregations