Search in sources :

Example 1 with EntityManagerFactory

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);
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 2 with EntityManagerFactory

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);
    }
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 3 with EntityManagerFactory

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());
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 4 with EntityManagerFactory

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);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) EntityManagerFactory(javax.persistence.EntityManagerFactory) Method(java.lang.reflect.Method)

Example 5 with EntityManagerFactory

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());
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Before(org.junit.Before)

Aggregations

EntityManagerFactory (javax.persistence.EntityManagerFactory)304 EntityManager (javax.persistence.EntityManager)104 Test (org.junit.Test)89 HashMap (java.util.HashMap)48 EntityTransaction (javax.persistence.EntityTransaction)30 EJBException (javax.ejb.EJBException)22 Map (java.util.Map)17 AssertionFailedError (junit.framework.AssertionFailedError)17 TestFailureException (org.apache.openejb.test.TestFailureException)17 ArrayList (java.util.ArrayList)16 JMSException (javax.jms.JMSException)15 Properties (java.util.Properties)14 KieSession (org.kie.api.runtime.KieSession)14 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)14 List (java.util.List)13 InitialContext (javax.naming.InitialContext)13 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)12 RemoteException (java.rmi.RemoteException)11 Query (javax.persistence.Query)11 PrintWriter (java.io.PrintWriter)10