use of javax.persistence.EntityManagerFactory in project OpenAttestation by OpenAttestation.
the class PersistenceManager method getEntityManagerFactory.
public EntityManagerFactory getEntityManagerFactory(String persistenceUnitName) {
log.info("PersistenceManager is configured with {} factories in getEntityManagerFactory", factories.keySet().size());
if (factories.keySet().isEmpty()) {
log.info("PersistenceManager factories is empty, calling configure()");
configure();
for (String factoryName : factories.keySet()) {
EntityManagerFactory factory = factories.get(factoryName);
if (factory != null && factory.isOpen()) {
log.info("PersistenceManager is configured with factory {} in getEntityManagerFactory", factoryName);
}
}
}
if (factories.containsKey(persistenceUnitName)) {
return factories.get(persistenceUnitName);
}
throw new IllegalArgumentException("Cannot return EntityManagerFactory for unknown persistence unit: " + persistenceUnitName);
}
use of javax.persistence.EntityManagerFactory in project OpenAttestation by OpenAttestation.
the class PersistenceManager method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent sce) {
for (String factoryName : factories.keySet()) {
EntityManagerFactory factory = factories.get(factoryName);
if (factory != null && factory.isOpen()) {
log.info("PersistenceManager closing factory {} in contextDestroyed", factoryName);
factory.close();
}
factories.remove(factoryName);
}
}
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 spring-framework by spring-projects.
the class HibernateJpaSessionFactoryBean method getObject.
@Override
public SessionFactory getObject() {
EntityManagerFactory emf = getEntityManagerFactory();
Assert.state(emf != null, "EntityManagerFactory must not be null");
try {
Method getSessionFactory = emf.getClass().getMethod("getSessionFactory");
return (SessionFactory) ReflectionUtils.invokeMethod(getSessionFactory, emf);
} catch (NoSuchMethodException ex) {
throw new IllegalStateException("No compatible Hibernate EntityManagerFactory found: " + ex);
}
}
use of javax.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class PersistenceContextTransactionTests method setUp.
@Before
public void setUp() throws Exception {
factory = mock(EntityManagerFactory.class);
manager = mock(EntityManager.class);
tx = mock(EntityTransaction.class);
JpaTransactionManager tm = new JpaTransactionManager(factory);
tt = new TransactionTemplate(tm);
given(factory.createEntityManager()).willReturn(manager);
given(manager.getTransaction()).willReturn(tx);
given(manager.isOpen()).willReturn(true);
bean = new EntityManagerHoldingBean();
@SuppressWarnings("serial") PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() {
@Override
protected EntityManagerFactory findEntityManagerFactory(String unitName, String requestingBeanName) {
return factory;
}
};
pabpp.postProcessPropertyValues(null, null, bean, "bean");
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
Aggregations