Search in sources :

Example 1 with EntityManagerFactoryBuilderImpl

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

the class PersistenceContextBuilder method build.

public PersistenceContextBuilder build() {
    PersistenceDescriptorFactory persistenceDescriptorFactory = new PersistenceDescriptorFactory();
    PersistenceUnitInfo persistenceUnitInfo = persistenceDescriptorFactory.get(RoboClassLoader.getInstance().getClassLoader(), sourceType, packages);
    PersistenceUnitDescriptor persistenceUnitDescriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo);
    EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilderImpl(persistenceUnitDescriptor, new HashMap<>());
    registeredClasses = persistenceDescriptorFactory.registeredClasses();
    dataSourceContext = new DataSourceProxy(builder.build());
    return this;
}
Also used : PersistenceUnitInfoDescriptor(org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor) EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder) PersistenceDescriptorFactory(com.robo4j.db.sql.jpa.PersistenceDescriptorFactory) PersistenceUnitDescriptor(org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor)

Example 2 with EntityManagerFactoryBuilderImpl

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

the class ConfigurationTest method buildMetadata.

@SuppressWarnings("unchecked")
private MetadataImplementor buildMetadata(SharedCacheMode mode) {
    Map settings = new HashMap();
    settings.put(AvailableSettings.SHARED_CACHE_MODE, mode);
    settings.put(Environment.CACHE_REGION_FACTORY, CustomRegionFactory.class.getName());
    settings.put(AvailableSettings.LOADED_CLASSES, Arrays.asList(ExplicitlyCacheableEntity.class, ExplicitlyNonCacheableEntity.class, NoCacheableAnnotationEntity.class));
    PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter();
    final EntityManagerFactoryBuilderImpl emfb = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(adapter, settings);
    emf = emfb.build();
    return emfb.getMetadata();
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PersistenceUnitInfoAdapter(org.hibernate.jpa.test.PersistenceUnitInfoAdapter)

Example 3 with EntityManagerFactoryBuilderImpl

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

the class ConfigurationObjectSettingTest method testContainerBootstrapValidationMode.

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

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

Example 4 with EntityManagerFactoryBuilderImpl

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

the class JpaConfiguration method getMetadata.

public Metadata getMetadata() {
    if (metadata == null) {
        EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = HibernateToolsPersistenceProvider.createEntityManagerFactoryBuilder(persistenceUnit, getProperties());
        EntityManagerFactory entityManagerFactory = entityManagerFactoryBuilder.build();
        metadata = entityManagerFactoryBuilder.getMetadata();
        getProperties().putAll(entityManagerFactory.getProperties());
    }
    return metadata;
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 5 with EntityManagerFactoryBuilderImpl

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

the class JpaConfiguration method initialize.

void initialize() {
    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = HibernateToolsPersistenceProvider.createEntityManagerFactoryBuilder(persistenceUnit, getProperties());
    EntityManagerFactory entityManagerFactory = entityManagerFactoryBuilder.build();
    sessionFactory = (SessionFactory) entityManagerFactory;
    metadata = entityManagerFactoryBuilder.getMetadata();
    getProperties().putAll(entityManagerFactory.getProperties());
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) EntityManagerFactory(javax.persistence.EntityManagerFactory)

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