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();
}
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;
}
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();
}
}
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;
}
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
}
}
Aggregations