org.hibernate.boot.registry.BootstrapServiceRegistryBuilder#build ( )源码实例Demo

下面列出了org.hibernate.boot.registry.BootstrapServiceRegistryBuilder#build ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Determine the Hibernate {@link MetadataSources} to use.
 * <p>Can also be externally called to initialize and pre-populate a {@link MetadataSources}
 * instance which is then going to be used for {@link SessionFactory} building.
 * @return the MetadataSources to use (never {@code null})
 * @since 4.3
 * @see LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources)
 */
public MetadataSources getMetadataSources() {
	this.metadataSourcesAccessed = true;
	if (this.metadataSources == null) {
		BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
		if (this.resourcePatternResolver != null) {
			builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader());
		}
		if (this.hibernateIntegrators != null) {
			for (Integrator integrator : this.hibernateIntegrators) {
				builder = builder.applyIntegrator(integrator);
			}
		}
		this.metadataSources = new MetadataSources(builder.build());
	}
	return this.metadataSources;
}
 
/**
 * Determine the Hibernate {@link MetadataSources} to use.
 * <p>Can also be externally called to initialize and pre-populate a {@link MetadataSources}
 * instance which is then going to be used for {@link SessionFactory} building.
 * @return the MetadataSources to use (never {@code null})
 * @since 4.3
 * @see LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources)
 */
public MetadataSources getMetadataSources() {
	this.metadataSourcesAccessed = true;
	if (this.metadataSources == null) {
		BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
		if (this.resourcePatternResolver != null) {
			builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader());
		}
		if (this.hibernateIntegrators != null) {
			for (Integrator integrator : this.hibernateIntegrators) {
				builder = builder.applyIntegrator(integrator);
			}
		}
		this.metadataSources = new MetadataSources(builder.build());
	}
	return this.metadataSources;
}
 
源代码3 项目: micronaut-sql   文件: JpaConfiguration.java
/**
 * @param applicationContext      The application context
 * @param integrator              The {@link Integrator}
 * @param entityScanConfiguration The entity scan configuration
 */
@Inject
protected JpaConfiguration(ApplicationContext applicationContext,
                           @Nullable Integrator integrator,
                           @Nullable EntityScanConfiguration entityScanConfiguration) {
    ClassLoader classLoader = applicationContext.getClassLoader();
    BootstrapServiceRegistryBuilder bootstrapServiceRegistryBuilder =
            createBootstrapServiceRegistryBuilder(integrator, classLoader);

    this.bootstrapServiceRegistry = bootstrapServiceRegistryBuilder.build();
    this.entityScanConfiguration = entityScanConfiguration != null ? entityScanConfiguration : new EntityScanConfiguration(applicationContext.getEnvironment());
    this.environment = applicationContext.getEnvironment();
    this.applicationContext = applicationContext;
}
 
源代码4 项目: lams   文件: LocalSessionFactoryBean.java
/**
 * Determine the Hibernate {@link MetadataSources} to use.
 * <p>Can also be externally called to initialize and pre-populate a {@link MetadataSources}
 * instance which is then going to be used for {@link SessionFactory} building.
 * @return the MetadataSources to use (never {@code null})
 * @since 4.3
 * @see LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources)
 */
public MetadataSources getMetadataSources() {
	this.metadataSourcesAccessed = true;
	if (this.metadataSources == null) {
		BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
		if (this.resourcePatternResolver != null) {
			builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader());
		}
		this.metadataSources = new MetadataSources(builder.build());
	}
	return this.metadataSources;
}
 
源代码5 项目: hypersistence-optimizer   文件: AbstractTest.java
private SessionFactory newSessionFactory() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
        .enableAutoClose();

    final BootstrapServiceRegistry bsr = bsrb.build();

    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
        .applySettings(properties())
        .build();

    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    for (Class annotatedClass : entities()) {
        metadataSources.addAnnotatedClass(annotatedClass);
    }

    String[] packages = packages();
    if (packages != null) {
        for (String annotatedPackage : packages) {
            metadataSources.addPackage(annotatedPackage);
        }
    }

    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            metadataSources.addResource(resource);
        }
    }

    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
    metadataBuilder.enableNewIdentifierGeneratorSupport(true);

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}
 
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
  final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
  builder.applyClassLoader( getClass().getClassLoader() );
  prepareBootstrapRegistryBuilder( builder );
  return builder.build();
}
 
源代码7 项目: hibernate-types   文件: AbstractTest.java
private SessionFactory newSessionFactory() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
            .enableAutoClose();

    Integrator integrator = integrator();
    if (integrator != null) {
        bsrb.applyIntegrator(integrator);
    }

    final BootstrapServiceRegistry bsr = bsrb.build();

    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
            .applySettings(properties())
            .build();

    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    for (Class annotatedClass : entities()) {
        metadataSources.addAnnotatedClass(annotatedClass);
    }

    String[] packages = packages();
    if (packages != null) {
        for (String annotatedPackage : packages) {
            metadataSources.addPackage(annotatedPackage);
        }
    }

    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            metadataSources.addResource(resource);
        }
    }

    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
    metadataBuilder.enableNewIdentifierGeneratorSupport(true);
    metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        additionalTypes.stream().forEach(type -> {
            metadataBuilder.applyTypes((typeContributions, serviceRegistry1) -> {
                if(type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType ){
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}
 
源代码8 项目: hibernate-types   文件: AbstractTest.java
private SessionFactory newSessionFactory() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
            .enableAutoClose();

    Integrator integrator = integrator();
    if (integrator != null) {
        bsrb.applyIntegrator(integrator);
    }

    final BootstrapServiceRegistry bsr = bsrb.build();

    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
            .applySettings(properties())
            .build();

    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    for (Class annotatedClass : entities()) {
        metadataSources.addAnnotatedClass(annotatedClass);
    }

    String[] packages = packages();
    if (packages != null) {
        for (String annotatedPackage : packages) {
            metadataSources.addPackage(annotatedPackage);
        }
    }

    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            metadataSources.addResource(resource);
        }
    }

    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
    metadataBuilder.enableNewIdentifierGeneratorSupport(true);
    metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}
 
private SessionFactory newSessionFactory() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
        .enableAutoClose();

    Integrator integrator = integrator();
    if (integrator != null) {
        bsrb.applyIntegrator( integrator );
    }

    final BootstrapServiceRegistry bsr = bsrb.build();

    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
        .applySettings(properties())
        .build();

    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    for (Class annotatedClass : entities()) {
        metadataSources.addAnnotatedClass(annotatedClass);
    }

    String[] packages = packages();
    if (packages != null) {
        for (String annotatedPackage : packages) {
            metadataSources.addPackage(annotatedPackage);
        }
    }

    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            metadataSources.addResource(resource);
        }
    }

    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder()
    .enableNewIdentifierGeneratorSupport(true)
    .applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        additionalTypes.stream().forEach(type -> {
            metadataBuilder.applyTypes((typeContributions, sr) -> {
                if(type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType ){
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }

    additionalMetadata(metadataBuilder);

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if(interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}