本文整理汇总了Java中org.hibernate.boot.registry.BootstrapServiceRegistryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java BootstrapServiceRegistryBuilder类的具体用法?Java BootstrapServiceRegistryBuilder怎么用?Java BootstrapServiceRegistryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BootstrapServiceRegistryBuilder类属于org.hibernate.boot.registry包,在下文中一共展示了BootstrapServiceRegistryBuilder类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createSession
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
/**
* Create a {@link Session} based on the provided configuration file.
*
* @param prefix - the prefix for using when loading properties for the session
* @param hibernateCfg - The location of the hibernate configuration file.
* @param classLoader - class loader to use with the session factory
* @return {@link Session}
* @throws Exception
*/
private Session createSession(final String prefix, final String hibernateCfg, final ClassLoader classLoader)
throws Exception {
SessionFactory sessionFactory = null;
DbBootstrapLogger.ROOT_LOGGER.tracef("Using hibernate configuration file %s", hibernateCfg);
BootstrapServiceRegistryBuilder serviceRegistryBuilder = new BootstrapServiceRegistryBuilder();
serviceRegistryBuilder.with(classLoader)
.with(this.getClass().getClassLoader());
StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder(serviceRegistryBuilder.build())
.configure(hibernateCfg);
configureSettingsFromSystemProperties(prefix, standardRegistryBuilder);
Metadata metadata = new MetadataSources(standardRegistryBuilder.build() ).buildMetadata();
sessionFactory = metadata.getSessionFactoryBuilder()
.build();
return sessionFactory.openSession();
}
开发者ID:wildfly-extras,项目名称:db-bootstrap,代码行数:30,代码来源:HibernateBootstrapProvider.java
示例2: getSessionFactory
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
public static SessionFactory getSessionFactory() {
try {
if (sessionFactory == null) {
BootstrapServiceRegistryBuilder serviceRegistryBuilder = new BootstrapServiceRegistryBuilder();
serviceRegistryBuilder.with(HibernateTestUtil.class.getClassLoader());
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder(serviceRegistryBuilder.build())
.configure( "META-INF/hibernate.cfg.xml" )
.build();
Metadata metadata = new MetadataSources( standardRegistry ).buildMetadata();
sessionFactory = metadata.getSessionFactoryBuilder()
.build();
}
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
return sessionFactory;
}
开发者ID:wildfly-extras,项目名称:db-bootstrap,代码行数:20,代码来源:HibernateTestUtil.java
示例3: newSessionFactory
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
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();
}
开发者ID:vladmihalcea,项目名称:hibernate-types,代码行数:50,代码来源:AbstractTest.java
示例4: newSessionFactory
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
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();
}
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:65,代码来源:AbstractTest.java
示例5: configure
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
DataSource ds = env.get(dskey)
.orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder();
bsrb.applyIntegrator(new JpaIntegrator());
this.bsrb.accept(bsrb, conf);
String ddl_auto = env.name().equals("dev") ? "update" : "none";
BootstrapServiceRegistry bsr = bsrb.build();
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(bsr);
ssrb.applySetting(AvailableSettings.HBM2DDL_AUTO, ddl_auto);
ssrb.applySettings(settings(env, conf));
this.ssrb.accept(ssrb, conf);
ssrb.applySetting(AvailableSettings.DATASOURCE, ds);
ssrb.applySetting(org.hibernate.jpa.AvailableSettings.DELAY_CDI_ACCESS, true);
StandardServiceRegistry serviceRegistry = ssrb.build();
MetadataSources sources = new MetadataSources(serviceRegistry);
this.sources.forEach(src -> src.accept(sources, conf));
this.metaSources.accept(sources, conf);
/** scan package? */
List<URL> packages = sources.getAnnotatedPackages()
.stream()
.map(pkg -> getClass().getResource("/" + pkg.replace('.', '/')))
.collect(Collectors.toList());
Metadata metadata = sources.getMetadataBuilder()
.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)
.applyScanEnvironment(new ScanEnvImpl(packages))
.build();
SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
this.sfb.accept(sfb, conf);
sfb.applyName(name);
CompletableFuture<Registry> registry = new CompletableFuture<>();
sfb.applyBeanManager(GuiceBeanManager.beanManager(registry));
SessionFactory sessionFactory = sfb.build();
this.sf.accept(sessionFactory, conf);
Provider<Session> session = new SessionProvider(sessionFactory);
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(SessionFactory.class, name,
k -> binder.bind(k).toInstance(sessionFactory));
serviceKey.generate(EntityManagerFactory.class, name,
k -> binder.bind(k).toInstance(sessionFactory));
/** Session/Entity Manager . */
serviceKey.generate(Session.class, name,
k -> binder.bind(k).toProvider(session));
serviceKey.generate(EntityManager.class, name,
k -> binder.bind(k).toProvider(session));
/** Unit of work . */
Provider<UnitOfWork> uow = new UnitOfWorkProvider(sessionFactory);
serviceKey.generate(UnitOfWork.class, name,
k -> binder.bind(k).toProvider(uow));
bindings.forEach(it -> it.accept(binder));
env.onStart(r -> {
registry.complete(r);
listeners.forEach(it -> it.accept((SessionFactoryImplementor) sessionFactory, r));
});
env.onStop(sessionFactory::close);
}
开发者ID:jooby-project,项目名称:jooby,代码行数:80,代码来源:Hbm.java
示例6: getMetadataSources
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
/**
* 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})
* @see HibernateSpringSessionFactoryBuilder#HibernateSpringSessionFactoryBuilder(DataSource,
* ResourceLoader, MetadataSources)
* @since 4.3
*/
public MetadataSources getMetadataSources() {
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;
}
开发者ID:baomidou,项目名称:hibernate-plus,代码行数:23,代码来源:HibernateSpringSessionFactoryBean.java
示例7: createBootstrapServiceRegistryBuilder
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
/**
* Creates the {@link BootstrapServiceRegistryBuilder} to use
*
* @return The {@link BootstrapServiceRegistryBuilder}
*/
protected BootstrapServiceRegistryBuilder createBootstrapServiceRegistryBuilder() {
return new BootstrapServiceRegistryBuilder();
}
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:9,代码来源:HibernateMappingContextConfiguration.java
示例8: HibernateSpringSessionFactoryBuilder
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
/**
* 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 HibernateSpringSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader) {
this(dataSource, resourceLoader, new MetadataSources(
new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build()));
}
开发者ID:baomidou,项目名称:hibernate-plus,代码行数:12,代码来源:HibernateSpringSessionFactoryBuilder.java
示例9: doWithBootstrap
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; //导入依赖的package包/类
/**
* Configurer callback to apply advanced configuration while bootstrapping hibernate:
*
* @param configurer Configurer callback.
* @return This module
*/
public <T> Hbm doWithBootstrap(final BiConsumer<BootstrapServiceRegistryBuilder, Config> configurer) {
this.bsrb = configurer;
return this;
}
开发者ID:jooby-project,项目名称:jooby,代码行数:11,代码来源:Hbm.java
注:本文中的org.hibernate.boot.registry.BootstrapServiceRegistryBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论