类org.hibernate.boot.registry.BootstrapServiceRegistryBuilder源码实例Demo

下面列出了怎么用org.hibernate.boot.registry.BootstrapServiceRegistryBuilder的API类实例代码及写法,或者点击链接到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 项目: lams   文件: SchemaExport.java
private static StandardServiceRegistry buildStandardServiceRegistry(CommandLineArgs commandLineArgs)
		throws Exception {
	final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
	final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder( bsr );

	if ( commandLineArgs.cfgXmlFile != null ) {
		ssrBuilder.configure( commandLineArgs.cfgXmlFile );
	}

	Properties properties = new Properties();
	if ( commandLineArgs.propertiesFile != null ) {
		properties.load( new FileInputStream( commandLineArgs.propertiesFile ) );
	}
	ssrBuilder.applySettings( properties );

	return ssrBuilder.build();
}
 
源代码4 项目: lams   文件: SchemaUpdate.java
private static StandardServiceRegistry buildStandardServiceRegistry(CommandLineArgs parsedArgs) throws Exception {
	final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
	final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder( bsr );

	if ( parsedArgs.cfgXmlFile != null ) {
		ssrBuilder.configure( parsedArgs.cfgXmlFile );
	}

	if ( parsedArgs.propertiesFile != null ) {
		Properties props = new Properties();
		props.load( new FileInputStream( parsedArgs.propertiesFile ) );
		ssrBuilder.applySettings( props );
	}

	return ssrBuilder.build();
}
 
源代码5 项目: lams   文件: SchemaValidator.java
private static StandardServiceRegistry buildStandardServiceRegistry(CommandLineArgs parsedArgs) throws Exception {
	final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
	final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder( bsr );

	if ( parsedArgs.cfgXmlFile != null ) {
		ssrBuilder.configure( parsedArgs.cfgXmlFile );
	}

	if ( parsedArgs.propertiesFile != null ) {
		Properties properties = new Properties();
		properties.load( new FileInputStream( parsedArgs.propertiesFile ) );
		ssrBuilder.applySettings( properties );
	}

	return ssrBuilder.build();
}
 
源代码6 项目: tutorials   文件: BootstrapAPIIntegrationTest.java
@Test
public void whenServiceRegistryAndMetadata_thenSessionFactory() throws IOException {

    BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder()
            .build();

    ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder(bootstrapRegistry)
            // No need for hibernate.cfg.xml file, an hibernate.properties is sufficient.
            //.configure()
            .build();

    MetadataSources metadataSources = new MetadataSources(standardRegistry);
    metadataSources.addAnnotatedClass(Movie.class);

    Metadata metadata = metadataSources.getMetadataBuilder().build();

    sessionFactory = metadata.buildSessionFactory();
    assertNotNull(sessionFactory);
    sessionFactory.close();
}
 
源代码7 项目: 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;
}
 
源代码8 项目: micronaut-sql   文件: JpaConfiguration.java
/**
 * Creates the default {@link BootstrapServiceRegistryBuilder}.
 *
 * @param integrator  The integrator to use. Can be null
 * @param classLoader The class loade rto use
 * @return The BootstrapServiceRegistryBuilder
 */
@SuppressWarnings("WeakerAccess")
protected BootstrapServiceRegistryBuilder createBootstrapServiceRegistryBuilder(
        @Nullable Integrator integrator,
        ClassLoader classLoader) {
    BootstrapServiceRegistryBuilder bootstrapServiceRegistryBuilder = new BootstrapServiceRegistryBuilder();
    bootstrapServiceRegistryBuilder.applyClassLoader(classLoader);
    if (integrator != null) {
        bootstrapServiceRegistryBuilder.applyIntegrator(integrator);
    }
    return bootstrapServiceRegistryBuilder;
}
 
源代码9 项目: 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;
}
 
源代码10 项目: wallride   文件: Hbm2ddl.java
public static void main(String[] args) throws Exception {
	String locationPattern = "classpath:/org/wallride/domain/*";

	final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build();
	final MetadataSources metadataSources = new MetadataSources(registry);
	final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(registry);

	registryBuilder.applySetting(AvailableSettings.DIALECT, ExtendedMySQL5InnoDBDialect.class.getCanonicalName());
	registryBuilder.applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, true);
	registryBuilder.applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY, PhysicalNamingStrategySnakeCaseImpl.class);

	final PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
	final Resource[] resources = resourcePatternResolver.getResources(locationPattern);
	final SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
	for (Resource resource : resources) {
		MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
		AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
		if (metadata.hasAnnotation(Entity.class.getName())) {
			metadataSources.addAnnotatedClass(Class.forName(metadata.getClassName()));
		}
	}

	final StandardServiceRegistryImpl registryImpl = (StandardServiceRegistryImpl) registryBuilder.build();
	final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(registryImpl);

	new SchemaExport()
			.setHaltOnError(true)
			.setDelimiter(";")
			.create(EnumSet.of(TargetType.STDOUT), metadataBuilder.build());
}
 
源代码11 项目: 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();
}
 
/**
 * Create a default builder.
 */
public ReactiveServiceRegistryBuilder() {
    this( new BootstrapServiceRegistryBuilder().enableAutoClose().build() );
}
 
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
  final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
  builder.applyClassLoader( getClass().getClassLoader() );
  prepareBootstrapRegistryBuilder( builder );
  return builder.build();
}
 
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
}
 
源代码15 项目: lams   文件: Configuration.java
public Configuration() {
	this( new BootstrapServiceRegistryBuilder().build() );
}
 
源代码16 项目: lams   文件: MetadataSources.java
public MetadataSources() {
	this( new BootstrapServiceRegistryBuilder().build() );
}
 
源代码17 项目: 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();
}
 
源代码18 项目: 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();
}
 
/**
 * Create a new LocalSessionFactoryBuilder for the given DataSource.
 * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using
 * (may be {@code null})
 * @param resourceLoader the ResourceLoader to load application classes from
 */
public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ResourceLoader resourceLoader) {
	this(dataSource, resourceLoader, new MetadataSources(
			new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build()));
}
 
/**
 * Create a new LocalSessionFactoryBuilder for the given DataSource.
 * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using
 * (may be {@code null})
 * @param resourceLoader the ResourceLoader to load application classes from
 */
public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ResourceLoader resourceLoader) {
	this(dataSource, resourceLoader, new MetadataSources(
			new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build()));
}
 
源代码22 项目: lams   文件: LocalSessionFactoryBuilder.java
/**
 * Create a new LocalSessionFactoryBuilder for the given DataSource.
 * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using
 * (may be {@code null})
 * @param resourceLoader the ResourceLoader to load application classes from
 */
public LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader) {
	this(dataSource, resourceLoader, new MetadataSources(
			new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build()));
}
 
/**
 * Creates the {@link BootstrapServiceRegistryBuilder} to use
 *
 * @return The {@link BootstrapServiceRegistryBuilder}
 */
protected BootstrapServiceRegistryBuilder createBootstrapServiceRegistryBuilder() {
    return new BootstrapServiceRegistryBuilder();
}
 
 类所在包
 同包方法