use of org.hibernate.boot.SessionFactoryBuilder in project hibernate-orm by hibernate.
the class BaseNonConfigCoreFunctionalTestCase method buildResources.
protected void buildResources() {
final StandardServiceRegistryBuilder ssrb = constructStandardServiceRegistryBuilder();
serviceRegistry = ssrb.build();
afterStandardServiceRegistryBuilt(serviceRegistry);
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
applyMetadataSources(metadataSources);
afterMetadataSourcesApplied(metadataSources);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
initialize(metadataBuilder);
configureMetadataBuilder(metadataBuilder);
metadata = (MetadataImplementor) metadataBuilder.build();
applyCacheSettings(metadata);
afterMetadataBuilt(metadata);
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
initialize(sfb, metadata);
configureSessionFactoryBuilder(sfb);
sessionFactory = (SessionFactoryImplementor) sfb.build();
afterSessionFactoryBuilt(sessionFactory);
}
use of org.hibernate.boot.SessionFactoryBuilder in project hibernate-orm by hibernate.
the class EntityManagerFactoryBuilderImpl method build.
@SuppressWarnings("unchecked")
public EntityManagerFactory build() {
SessionFactoryBuilder sfBuilder = metadata().getSessionFactoryBuilder();
populate(sfBuilder, standardServiceRegistry);
try {
return sfBuilder.build();
} catch (Exception e) {
throw persistenceException("Unable to build Hibernate SessionFactory", e);
}
}
use of org.hibernate.boot.SessionFactoryBuilder in project hibernate-orm by hibernate.
the class SchemaBasedMultiTenancyTest method setUp.
@Before
public void setUp() {
AbstractMultiTenantConnectionProvider multiTenantConnectionProvider = buildMultiTenantConnectionProvider();
Map settings = new HashMap();
settings.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(Environment.GENERATE_STATISTICS, "true");
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).addService(MultiTenantConnectionProvider.class, multiTenantConnectionProvider).build();
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Customer.class);
ms.addAnnotatedClass(Invoice.class);
Metadata metadata = ms.buildMetadata();
((RootClass) metadata.getEntityBinding(Customer.class.getName())).setCacheConcurrencyStrategy("read-write");
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
tool.injectServices(serviceRegistry);
final GenerationTargetToDatabase acmeTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, acmeProvider));
final GenerationTargetToDatabase jbossTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, jbossProvider));
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
configure(sfb);
sessionFactory = (SessionFactoryImplementor) sfb.build();
}
use of org.hibernate.boot.SessionFactoryBuilder in project hibernate-orm by hibernate.
the class EntityManagerFactoryBuilderImpl method generateSchema.
@Override
public void generateSchema() {
// Metamodel will clean this up...
try {
SessionFactoryBuilder sfBuilder = metadata().getSessionFactoryBuilder();
populate(sfBuilder, standardServiceRegistry);
SchemaManagementToolCoordinator.process(metadata, standardServiceRegistry, configurationValues, DelayedDropRegistryNotAvailableImpl.INSTANCE);
} catch (Exception e) {
throw persistenceException("Error performing schema management", e);
}
// release this builder
cancel();
}
use of org.hibernate.boot.SessionFactoryBuilder in project hibernate-orm by hibernate.
the class MetadataImpl method getSessionFactoryBuilder.
@Override
public SessionFactoryBuilder getSessionFactoryBuilder() {
final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl(this);
final ClassLoaderService cls = metadataBuildingOptions.getServiceRegistry().getService(ClassLoaderService.class);
final java.util.Collection<SessionFactoryBuilderFactory> discoveredBuilderFactories = cls.loadJavaServices(SessionFactoryBuilderFactory.class);
SessionFactoryBuilder builder = null;
List<String> activeFactoryNames = null;
for (SessionFactoryBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories) {
final SessionFactoryBuilder returnedBuilder = discoveredBuilderFactory.getSessionFactoryBuilder(this, defaultBuilder);
if (returnedBuilder != null) {
if (activeFactoryNames == null) {
activeFactoryNames = new ArrayList<>();
}
activeFactoryNames.add(discoveredBuilderFactory.getClass().getName());
builder = returnedBuilder;
}
}
if (activeFactoryNames != null && activeFactoryNames.size() > 1) {
throw new HibernateException("Multiple active SessionFactoryBuilderFactory definitions were discovered : " + StringHelper.join(", ", activeFactoryNames));
}
if (builder != null) {
return builder;
}
return defaultBuilder;
}
Aggregations