Search in sources :

Example 1 with SessionFactoryBuilder

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);
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) MetadataSources(org.hibernate.boot.MetadataSources)

Example 2 with SessionFactoryBuilder

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);
    }
}
Also used : SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) PersistenceException(javax.persistence.PersistenceException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 3 with SessionFactoryBuilder

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();
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool) DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) MultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 4 with SessionFactoryBuilder

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();
}
Also used : SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) PersistenceException(javax.persistence.PersistenceException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 5 with SessionFactoryBuilder

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;
}
Also used : SessionFactoryBuilderFactory(org.hibernate.boot.spi.SessionFactoryBuilderFactory) HibernateException(org.hibernate.HibernateException) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)7 Metadata (org.hibernate.boot.Metadata)3 MetadataSources (org.hibernate.boot.MetadataSources)3 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EntityNotFoundException (javax.persistence.EntityNotFoundException)2 PersistenceException (javax.persistence.PersistenceException)2 MetadataBuilder (org.hibernate.boot.MetadataBuilder)2 DdlTransactionIsolatorTestingImpl (org.hibernate.test.util.DdlTransactionIsolatorTestingImpl)2 HibernateSchemaManagementTool (org.hibernate.tool.schema.internal.HibernateSchemaManagementTool)2 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)2 SchemaDropperImpl (org.hibernate.tool.schema.internal.SchemaDropperImpl)2 GenerationTargetToDatabase (org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase)2 HibernateException (org.hibernate.HibernateException)1 TypeContributor (org.hibernate.boot.model.TypeContributor)1 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 SessionFactoryBuilderFactory (org.hibernate.boot.spi.SessionFactoryBuilderFactory)1 SQLFunction (org.hibernate.dialect.function.SQLFunction)1