Search in sources :

Example 6 with PersistenceUnitInfoAdapter

use of org.hibernate.jpa.test.PersistenceUnitInfoAdapter 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)

Aggregations

PersistenceUnitInfoAdapter (org.hibernate.jpa.test.PersistenceUnitInfoAdapter)6 Test (org.junit.Test)5 EntityManagerFactoryBuilderImpl (org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 EntityManager (javax.persistence.EntityManager)1 HibernateException (org.hibernate.HibernateException)1 EntityManagerFactoryBuilder (org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)1