Search in sources :

Example 1 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder in project hibernate-orm by hibernate.

the class OsgiPersistenceProvider method createEntityManagerFactory.

// TODO: Does "hibernate.classloaders" and osgiClassLoader need added to the
// EMFBuilder somehow?
@Override
@SuppressWarnings("unchecked")
public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
    final Map settings = generateSettings(properties);
    // TODO: This needs tested.
    settings.put(org.hibernate.cfg.AvailableSettings.SCANNER, new OsgiScanner(requestingBundle));
    // TODO: This is temporary -- for PersistenceXmlParser's use of
    // ClassLoaderServiceImpl#fromConfigSettings
    settings.put(AvailableSettings.ENVIRONMENT_CLASSLOADER, osgiClassLoader);
    osgiClassLoader.addBundle(requestingBundle);
    final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull(persistenceUnitName, settings, new OSGiClassLoaderServiceImpl(osgiClassLoader, osgiServiceUtil));
    return builder == null ? null : builder.build();
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)

Example 2 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder 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 3 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder in project hibernate-orm by hibernate.

the class TwoPersistenceUnits2LCDisabledEnabled method testIt.

private void testIt(Map config) {
    EntityManagerFactoryBuilder entityManagerFactoryBuilder = Bootstrap.getEntityManagerFactoryBuilder(new BaseEntityManagerFunctionalTestCase.TestingPersistenceUnitDescriptorImpl(getClass().getSimpleName()), config);
    SessionFactoryImplementor sf = entityManagerFactoryBuilder.build().unwrap(SessionFactoryImplementor.class);
    final EntityPersister persister = sf.getMetamodel().entityPersister(AnEntity.class.getName());
    try {
        if (config.get(AvailableSettings.USE_SECOND_LEVEL_CACHE).equals("true")) {
            assertNotNull(persister.getCacheAccessStrategy());
        } else {
            assertNull(persister.getCacheAccessStrategy());
        }
    } finally {
        sf.close();
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) BaseEntityManagerFunctionalTestCase(org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)

Example 4 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder in project hibernate-orm by hibernate.

the class HibernatePersistenceProvider method generateSchema.

@Override
public boolean generateSchema(String persistenceUnitName, Map map) {
    log.tracef("Starting generateSchema for persistenceUnitName %s", persistenceUnitName);
    final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull(persistenceUnitName, map);
    if (builder == null) {
        log.trace("Could not obtain matching EntityManagerFactoryBuilder, returning false");
        return false;
    }
    builder.generateSchema();
    return true;
}
Also used : EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)

Example 5 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder in project hibernate-orm by hibernate.

the class SessionFactoryObserverTest method testSessionFactoryObserverProperty.

@Test
public void testSessionFactoryObserverProperty() {
    EntityManagerFactoryBuilder builder = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitInfoAdapter(), Collections.singletonMap(AvailableSettings.SESSION_FACTORY_OBSERVER, GoofySessionFactoryObserver.class.getName()));
    try {
        final EntityManagerFactory entityManagerFactory = builder.build();
        entityManagerFactory.close();
        Assert.fail("GoofyException should have been thrown");
    } catch (GoofyException e) {
    // success
    }
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder) PersistenceUnitInfoAdapter(org.hibernate.jpa.test.PersistenceUnitInfoAdapter) Test(org.junit.Test)

Aggregations

EntityManagerFactoryBuilder (org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)9 EntityManagerFactory (javax.persistence.EntityManagerFactory)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BaseEntityManagerFunctionalTestCase (org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase)2 PersistenceDescriptorFactory (com.robo4j.db.sql.jpa.PersistenceDescriptorFactory)1 URL (java.net.URL)1 EntityManager (javax.persistence.EntityManager)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 HibernateEntityManagerFactory (org.hibernate.jpa.HibernateEntityManagerFactory)1 HibernatePersistenceProvider (org.hibernate.jpa.HibernatePersistenceProvider)1 EntityManagerFactoryBuilderImpl (org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl)1 PersistenceUnitInfoDescriptor (org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor)1 PersistenceUnitDescriptor (org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor)1 PersistenceUnitInfoAdapter (org.hibernate.jpa.test.PersistenceUnitInfoAdapter)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 JpaXsdVersionsTest (org.hibernate.test.jpa.xml.versions.JpaXsdVersionsTest)1 TestForIssue (org.hibernate.testing.TestForIssue)1