use of javax.persistence.EntityManagerFactory in project enhydrator by AdamBien.
the class CoffeeTestFixture method perform.
public static Object perform(String unitName, Function<EntityManager, ?> statement) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(unitName);
EntityManager em = emf.createEntityManager();
EntityTransaction et = em.getTransaction();
et.begin();
Object result = statement.apply(em);
et.commit();
return result;
}
use of javax.persistence.EntityManagerFactory in project aries by apache.
the class JPAEntityManagerProviderFactoryImpl method getProviderFor.
@Override
public AbstractJPAEntityManagerProvider getProviderFor(EntityManagerFactoryBuilder emfb, Map<String, Object> jpaProperties, Map<String, Object> resourceProviderProperties) {
checkEnlistment(resourceProviderProperties);
EntityManagerFactory emf = emfb.createEntityManagerFactory(jpaProperties);
validateEMF(emf);
return new JPAEntityManagerProviderImpl(emf, () -> emf.close());
}
use of javax.persistence.EntityManagerFactory in project wildfly by wildfly.
the class TestPersistenceProvider method createContainerEntityManagerFactory.
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) {
persistenceUnitInfo.put(info.getPersistenceUnitName(), info);
TestClassTransformer testClassTransformer = new TestClassTransformer();
info.addTransformer(testClassTransformer);
TestEntityManagerFactory testEntityManagerFactory = new TestEntityManagerFactory();
Class[] targetInterfaces = javax.persistence.EntityManagerFactory.class.getInterfaces();
// include extra element for extensionClass
Class[] proxyInterfaces = new Class[targetInterfaces.length + 1];
boolean alreadyHasInterfaceClass = false;
for (int interfaceIndex = 0; interfaceIndex < targetInterfaces.length; interfaceIndex++) {
Class interfaceClass = targetInterfaces[interfaceIndex];
if (interfaceClass.equals(javax.persistence.EntityManagerFactory.class)) {
// targetInterfaces already has all interfaces
proxyInterfaces = targetInterfaces;
alreadyHasInterfaceClass = true;
break;
}
proxyInterfaces[1 + interfaceIndex] = interfaceClass;
}
if (!alreadyHasInterfaceClass) {
proxyInterfaces[0] = javax.persistence.EntityManagerFactory.class;
}
EntityManagerFactory proxyEntityManagerFactory = (EntityManagerFactory) Proxy.newProxyInstance(//use the target classloader so the proxy has the same scope
testEntityManagerFactory.getClass().getClassLoader(), proxyInterfaces, testEntityManagerFactory);
return proxyEntityManagerFactory;
}
use of javax.persistence.EntityManagerFactory in project wildfly by wildfly.
the class TestPersistenceProvider method createContainerEntityManagerFactory.
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) {
persistenceUnitInfo.put(info.getPersistenceUnitName(), info);
TestEntityManagerFactory testEntityManagerFactory = new TestEntityManagerFactory();
Class[] targetInterfaces = EntityManagerFactory.class.getInterfaces();
// include extra element for extensionClass
Class[] proxyInterfaces = new Class[targetInterfaces.length + 1];
boolean alreadyHasInterfaceClass = false;
for (int interfaceIndex = 0; interfaceIndex < targetInterfaces.length; interfaceIndex++) {
Class interfaceClass = targetInterfaces[interfaceIndex];
if (interfaceClass.equals(EntityManagerFactory.class)) {
// targetInterfaces already has all interfaces
proxyInterfaces = targetInterfaces;
alreadyHasInterfaceClass = true;
break;
}
proxyInterfaces[1 + interfaceIndex] = interfaceClass;
}
if (!alreadyHasInterfaceClass) {
proxyInterfaces[0] = EntityManagerFactory.class;
}
EntityManagerFactory proxyEntityManagerFactory = (EntityManagerFactory) Proxy.newProxyInstance(//use the target classloader so the proxy has the same scope
testEntityManagerFactory.getClass().getClassLoader(), proxyInterfaces, testEntityManagerFactory);
return proxyEntityManagerFactory;
}
use of javax.persistence.EntityManagerFactory in project wildfly by wildfly.
the class SingletonBean method sleepAndDestroy.
@PreDestroy
private void sleepAndDestroy() throws Exception {
logger.trace("Sleeping for 3 seconds while destroying singleton bean " + this);
// sleep for a while just to reproduce a race condition with EntityManagerFactory being closed before
// the singleton bean can finish its pre-destroy
Thread.sleep(3000);
logger.trace("Woke up after 3 seconds while destroying singleton bean " + this);
final EntityManagerFactory entityManagerFactory = this.entityManager.getEntityManagerFactory();
boolean emFactoryOpen = entityManagerFactory.isOpen();
if (!emFactoryOpen) {
throw new RuntimeException("Entitymanager factory: " + entityManagerFactory + " has been closed " + "even before singleton bean " + this + " could complete its @PreDestroy");
}
}
Aggregations