Search in sources :

Example 6 with EntityManagerFactoryBuilderImpl

use of org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl in project jbosstools-hibernate by jbosstools.

the class HibernateToolsPersistenceProviderTest method testCreateEntityManagerFactoryBuilder.

@Test
public void testCreateEntityManagerFactoryBuilder() {
    Properties properties = new Properties();
    properties.put("foo", "bar");
    assertNull(HibernateToolsPersistenceProvider.createEntityManagerFactoryBuilder("barfoo", properties));
    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = HibernateToolsPersistenceProvider.createEntityManagerFactoryBuilder("foobar", properties);
    assertNotNull(entityManagerFactoryBuilder);
    assertEquals("bar", entityManagerFactoryBuilder.getConfigurationValues().get("foo"));
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 7 with EntityManagerFactoryBuilderImpl

use of org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl in project cas by apereo.

the class CasHibernatePersistenceProvider method createContainerEntityManagerFactory.

@Override
public EntityManagerFactory createContainerEntityManagerFactory(final PersistenceUnitInfo info, final Map properties) {
    val filtered = CollectionUtils.intersection(info.getManagedClassNames(), providerContext.getIncludeEntityClasses());
    if (info.getManagedClassNames().isEmpty() && !providerContext.getIncludeEntityClasses().isEmpty()) {
        filtered.addAll(providerContext.getIncludeEntityClasses());
    }
    LOGGER.trace("Filtered entity classes for entity manager are [{}]", filtered);
    val mergedClassesAndPackages = new HashSet<String>(filtered);
    if (info instanceof SmartPersistenceUnitInfo) {
        mergedClassesAndPackages.addAll(((SmartPersistenceUnitInfo) info).getManagedPackages());
    }
    val persistenceUnit = new CasPersistenceUnitInfoDescriptor(info, new ArrayList<>(mergedClassesAndPackages));
    return new EntityManagerFactoryBuilderImpl(persistenceUnit, properties).build();
}
Also used : lombok.val(lombok.val) EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) SmartPersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo) HashSet(java.util.HashSet)

Example 8 with EntityManagerFactoryBuilderImpl

use of org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl in project hibernate-orm by hibernate.

the class ConfigurationObjectSettingTest method testContainerBootstrapSharedCacheMode.

@Test
public void testContainerBootstrapSharedCacheMode() {
    // first, via the integration vars
    PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
    {
        // as object
        EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(empty, Collections.singletonMap(AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE));
        assertEquals(SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get(AvailableSettings.SHARED_CACHE_MODE));
    }
    {
        // as string
        EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(empty, Collections.singletonMap(AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE.name()));
        assertEquals(SharedCacheMode.DISABLE_SELECTIVE.name(), builder.getConfigurationValues().get(AvailableSettings.SHARED_CACHE_MODE));
    }
    // next, via the PUI
    PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter() {

        @Override
        public SharedCacheMode getSharedCacheMode() {
            return SharedCacheMode.ENABLE_SELECTIVE;
        }
    };
    {
        EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(adapter, null);
        assertEquals(SharedCacheMode.ENABLE_SELECTIVE, builder.getConfigurationValues().get(AvailableSettings.SHARED_CACHE_MODE));
    }
    // via both, integration vars should take precedence
    {
        EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(adapter, Collections.singletonMap(AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE));
        assertEquals(SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get(AvailableSettings.SHARED_CACHE_MODE));
    }
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) PersistenceUnitInfoAdapter(org.hibernate.jpa.test.PersistenceUnitInfoAdapter) Test(org.junit.Test)

Example 9 with EntityManagerFactoryBuilderImpl

use of org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl in project jOOQ by jOOQ.

the class AttributeConverterExtractor method initEntityManagerFactory.

private final EntityManagerFactory initEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<>();
    configuration.put("hibernate.integrator_provider", integratorProvider());
    configuration.put("hibernate.hbm2ddl.auto", "none");
    configuration.put(AvailableSettings.CONNECTION_PROVIDER, database.connectionProvider());
    PersistenceUnitInfoDescriptor descriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo);
    return new EntityManagerFactoryBuilderImpl(descriptor, configuration).build();
}
Also used : PersistenceUnitInfoDescriptor(org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor) EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo)

Example 10 with EntityManagerFactoryBuilderImpl

use of org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl in project hibernate-orm by hibernate.

the class BootstrapTest method test_bootstrap_bootstrap_native_EntityManagerFactory_example.

@Test
public void test_bootstrap_bootstrap_native_EntityManagerFactory_example() {
    try {
        // tag::bootstrap-native-EntityManagerFactory-example[]
        String persistenceUnitName = "CRM";
        List<String> entityClassNames = new ArrayList<>();
        Properties properties = new Properties();
        PersistenceUnitInfoImpl persistenceUnitInfo = new PersistenceUnitInfoImpl(persistenceUnitName, entityClassNames, properties);
        Map<String, Object> integrationSettings = new HashMap<>();
        integrationSettings.put(AvailableSettings.INTERCEPTOR, new CustomSessionFactoryInterceptor());
        EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(persistenceUnitInfo), integrationSettings);
        EntityManagerFactory emf = entityManagerFactoryBuilder.build();
    // end::bootstrap-native-EntityManagerFactory-example[]
    } catch (Exception ignore) {
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) PersistenceUnitInfoDescriptor(org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor) EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) EntityManagerFactory(javax.persistence.EntityManagerFactory) Test(org.junit.Test)

Aggregations

EntityManagerFactoryBuilderImpl (org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl)21 EntityManagerFactory (javax.persistence.EntityManagerFactory)9 Properties (java.util.Properties)6 Test (org.junit.jupiter.api.Test)5 HashMap (java.util.HashMap)3 PersistenceUnitInfoDescriptor (org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor)3 PersistenceUnitInfoAdapter (org.hibernate.jpa.test.PersistenceUnitInfoAdapter)3 Test (org.junit.Test)3 PersistenceDescriptorFactory (com.robo4j.db.sql.jpa.PersistenceDescriptorFactory)1 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 lombok.val (lombok.val)1 EntityManagerFactoryBuilder (org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)1 PersistenceUnitDescriptor (org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor)1 SmartPersistenceUnitInfo (org.springframework.orm.jpa.persistenceunit.SmartPersistenceUnitInfo)1