Java 类org.hibernate.boot.registry.BootstrapServiceRegistry 实例源码

项目:lams    文件:MetadataBuilderImpl.java   
private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
    if ( serviceRegistry == null ) {
        throw new HibernateException( "ServiceRegistry passed to MetadataBuilder cannot be null" );
    }

    if ( StandardServiceRegistry.class.isInstance( serviceRegistry ) ) {
        return ( StandardServiceRegistry ) serviceRegistry;
    }
    else if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
        log.debugf(
                "ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely wont end well" +
                        "if attempt is made to build SessionFactory"
        );
        return new StandardServiceRegistryBuilder( (BootstrapServiceRegistry) serviceRegistry ).build();
    }
    else {
        throw new HibernateException(
                String.format(
                        "Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder",
                        serviceRegistry.getClass().getName()
                )
        );
    }
}
项目:lams    文件:StandardServiceRegistryImpl.java   
/**
 * Constructs a StandardServiceRegistryImpl.  Should not be instantiated directly; use
 * {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
 *
 * @param autoCloseRegistry See discussion on
 * {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder#disableAutoClose}
 * @param bootstrapServiceRegistry The bootstrap service registry.
 * @param serviceInitiators Any StandardServiceInitiators provided by the user to the builder
 * @param providedServices Any standard services provided directly to the builder
 * @param configurationValues Configuration values
 *
 * @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
 */
@SuppressWarnings( {"unchecked"})
public StandardServiceRegistryImpl(
        boolean autoCloseRegistry,
        BootstrapServiceRegistry bootstrapServiceRegistry,
        List<StandardServiceInitiator> serviceInitiators,
        List<ProvidedService> providedServices,
        Map<?, ?> configurationValues) {
    super( bootstrapServiceRegistry, autoCloseRegistry );

    this.configurationValues = configurationValues;

    // process initiators
    for ( ServiceInitiator initiator : serviceInitiators ) {
        createServiceBinding( initiator );
    }

    // then, explicitly provided service instances
    for ( ProvidedService providedService : providedServices ) {
        createServiceBinding( providedService );
    }
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
public AbstractServiceRegistryImpl(
        BootstrapServiceRegistry bootstrapServiceRegistry,
        boolean autoCloseRegistry) {
    if ( ! ServiceRegistryImplementor.class.isInstance( bootstrapServiceRegistry ) ) {
        throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" );
    }
    this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry;
    this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );

    this.autoCloseRegistry = autoCloseRegistry;
    this.parent.registerChild( this );
}
项目:lams    文件:MetadataSources.java   
protected static boolean isExpectedServiceRegistryType(ServiceRegistry serviceRegistry) {
    return BootstrapServiceRegistry.class.isInstance( serviceRegistry )
            || StandardServiceRegistry.class.isInstance( serviceRegistry );
}
项目:lams    文件:ConfigLoader.java   
public ConfigLoader(BootstrapServiceRegistry bootstrapServiceRegistry) {
    this.bootstrapServiceRegistry = bootstrapServiceRegistry;
}
项目:lams    文件:AbstractServiceRegistryImpl.java   
public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegistry) {
    this( bootstrapServiceRegistry, true );
}
项目: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();
}
项目: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();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringPhysicalNamingStrategyTests.java   
private StandardServiceRegistry getServiceRegistry(MetadataSources metadataSources) {
    ServiceRegistry registry = metadataSources.getServiceRegistry();
    return new StandardServiceRegistryBuilder((BootstrapServiceRegistry) registry)
            .applySetting(AvailableSettings.DIALECT, H2Dialect.class).build();
}
项目:spring-boot-concourse    文件:SpringPhysicalNamingStrategyTests.java   
private StandardServiceRegistry getServiceRegistry(MetadataSources metadataSources) {
    ServiceRegistry registry = metadataSources.getServiceRegistry();
    return new StandardServiceRegistryBuilder((BootstrapServiceRegistry) registry)
            .applySetting(AvailableSettings.DIALECT, H2Dialect.class).build();
}
项目:high-performance-java-persistence    文件: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();
}
项目:jooby    文件:Hbm.java   
@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);
}
项目:lams    文件:StandardServiceRegistryImpl.java   
/**
 * Constructs a StandardServiceRegistryImpl.  Should not be instantiated directly; use
 * {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
 *
 * @param bootstrapServiceRegistry The bootstrap service registry.
 * @param serviceInitiators Any StandardServiceInitiators provided by the user to the builder
 * @param providedServices Any standard services provided directly to the builder
 * @param configurationValues Configuration values
 *
 * @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
 */
@SuppressWarnings( {"unchecked"})
public StandardServiceRegistryImpl(
        BootstrapServiceRegistry bootstrapServiceRegistry,
        List<StandardServiceInitiator> serviceInitiators,
        List<ProvidedService> providedServices,
        Map<?, ?> configurationValues) {
    this( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
}
项目:gorm-hibernate5    文件:HibernateMappingContextConfiguration.java   
/**
 * Creates the standard service registry builder. Subclasses can override to customize the creation of the StandardServiceRegistry
 *
 * @param bootstrapServiceRegistry The {@link BootstrapServiceRegistry}
 * @return The {@link StandardServiceRegistryBuilder}
 */
protected StandardServiceRegistryBuilder createStandardServiceRegistryBuilder(BootstrapServiceRegistry bootstrapServiceRegistry) {
    return new StandardServiceRegistryBuilder(bootstrapServiceRegistry);
}