Search in sources :

Example 6 with PersistenceUnitTransactionType

use of javax.persistence.spi.PersistenceUnitTransactionType in project keycloak by keycloak.

the class JpaUtils method createEntityManagerFactory.

public static EntityManagerFactory createEntityManagerFactory(KeycloakSession session, String unitName, Map<String, Object> properties, boolean jta) {
    PersistenceUnitTransactionType txType = jta ? PersistenceUnitTransactionType.JTA : PersistenceUnitTransactionType.RESOURCE_LOCAL;
    List<ParsedPersistenceXmlDescriptor> persistenceUnits = PersistenceXmlParser.locatePersistenceUnits(properties);
    for (ParsedPersistenceXmlDescriptor persistenceUnit : persistenceUnits) {
        if (persistenceUnit.getName().equals(unitName)) {
            List<Class<?>> providedEntities = getProvidedEntities(session);
            for (Class<?> entityClass : providedEntities) {
                // Add all extra entity classes to the persistence unit.
                persistenceUnit.addClasses(entityClass.getName());
            }
            // Now build the entity manager factory, supplying a proxy classloader, so Hibernate will be able
            // to find and load the extra provided entities.
            persistenceUnit.setTransactionType(txType);
            return Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, properties, new ProxyClassLoader(providedEntities)).build();
        }
    }
    throw new RuntimeException("Persistence unit '" + unitName + "' not found");
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) ProxyClassLoader(org.keycloak.connections.jpa.entityprovider.ProxyClassLoader) PersistenceUnitTransactionType(javax.persistence.spi.PersistenceUnitTransactionType)

Aggregations

PersistenceUnitTransactionType (javax.persistence.spi.PersistenceUnitTransactionType)6 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 SharedCacheMode (javax.persistence.SharedCacheMode)1 ValidationMode (javax.persistence.ValidationMode)1 CommonDataSource (javax.sql.CommonDataSource)1 DataSource (javax.sql.DataSource)1 OpenEJBException (org.apache.openejb.OpenEJBException)1 PersistenceUnitInfoImpl (org.apache.openejb.persistence.PersistenceUnitInfoImpl)1 ContainerSystem (org.apache.openejb.spi.ContainerSystem)1 ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)1 JdbcResourceLocalTransactionCoordinatorBuilderImpl (org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl)1 ProxyClassLoader (org.keycloak.connections.jpa.entityprovider.ProxyClassLoader)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1