Java Code Examples for org.hibernate.boot.registry.BootstrapServiceRegistry

The following examples show how to use org.hibernate.boot.registry.BootstrapServiceRegistry. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public StandardServiceRegistryImpl buildNewServiceRegistry() {
    final BootstrapServiceRegistry bootstrapServiceRegistry = buildEmptyBootstrapServiceRegistry();

    // Can skip, it's only deprecated stuff:
    // applyServiceContributingIntegrators( bootstrapServiceRegistry );

    // This is NOT deprecated stuff.. yet they will at best contribute stuff we
    // already recorded as part of #applyIntegrator, #addInitiator, #addService
    // applyServiceContributors( bootstrapServiceRegistry );

    final Map settingsCopy = new HashMap();
    settingsCopy.putAll(configurationValues);

    destroyedRegistry.resetAndReactivate(bootstrapServiceRegistry, initiators, providedServices, settingsCopy);
    return destroyedRegistry;

    //		return new StandardServiceRegistryImpl(
    //				true,
    //				bootstrapServiceRegistry,
    //				initiators,
    //				providedServices,
    //				settingsCopy
    //		);
}
 
Example 2
public StandardServiceRegistryImpl buildNewServiceRegistry() {
    final BootstrapServiceRegistry bootstrapServiceRegistry = buildEmptyBootstrapServiceRegistry();

    // Can skip, it's only deprecated stuff:
    // applyServiceContributingIntegrators( bootstrapServiceRegistry );

    // This is NOT deprecated stuff.. yet they will at best contribute stuff we
    // already recorded as part of #applyIntegrator, #addInitiator, #addService
    // applyServiceContributors( bootstrapServiceRegistry );

    final Map settingsCopy = new HashMap();
    settingsCopy.putAll(configurationValues);

    destroyedRegistry.resetAndReactivate(bootstrapServiceRegistry, initiators, providedServices, settingsCopy);
    return destroyedRegistry;
}
 
Example 3
Source Project: teiid-spring-boot   Source File: TeiidServer.java    License: Apache License 2.0 6 votes vote down vote up
private Metadata getMetadata(Set<BeanDefinition> components, PhysicalNamingStrategy namingStrategy,
        MetadataFactory mf) {
    ServiceRegistry registry = metadataSources.getServiceRegistry();
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(
            (BootstrapServiceRegistry) registry).applySetting(AvailableSettings.DIALECT, TeiidDialect.class)
            .build();
    // Generate Hibernate model based on @Entity definitions
    for (BeanDefinition c : components) {
        try {
            Class<?> clazz = Class.forName(c.getBeanClassName());
            metadataSources.addAnnotatedClass(clazz);
        } catch (ClassNotFoundException e) {
        }
    }
    return metadataSources.getMetadataBuilder(serviceRegistry).applyPhysicalNamingStrategy(namingStrategy).build();
}
 
Example 4
Source Project: lams   Source File: SchemaExport.java    License: GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 5
Source Project: lams   Source File: SchemaUpdate.java    License: GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 6
Source Project: lams   Source File: SchemaValidator.java    License: GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 7
Source Project: lams   Source File: MetadataBuilderImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
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()
				)
		);
	}
}
 
Example 8
Source Project: tutorials   Source File: BootstrapAPIIntegrationTest.java    License: MIT License 6 votes vote down vote up
@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();
}
 
Example 9
/**
 * Intended for use exclusively from JPA boot-strapping, or extensions of
 * this class. Consider this an SPI.
 *
 * @see #forJpa
 */
protected ReactiveServiceRegistryBuilder(
        BootstrapServiceRegistry bootstrapServiceRegistry,
        Map settings,
        LoadedConfig loadedConfig) {
    this.bootstrapServiceRegistry = bootstrapServiceRegistry;
    this.configLoader = new ConfigLoader( bootstrapServiceRegistry );
    this.settings = settings;
    this.aggregatedCfgXml = loadedConfig;
    this.initiators = defaultReactiveInitiatorList();
}
 
Example 10
/**
 * Intended for use exclusively from Quarkus boot-strapping, or extensions of
 * this class which need to override the standard ServiceInitiator list.
 * Consider this an SPI.
 */
protected ReactiveServiceRegistryBuilder(
        BootstrapServiceRegistry bootstrapServiceRegistry,
        Map settings,
        LoadedConfig loadedConfig,
        @SuppressWarnings("rawtypes")
        List<StandardServiceInitiator> initiators) {
    this.bootstrapServiceRegistry = bootstrapServiceRegistry;
    this.configLoader = new ConfigLoader( bootstrapServiceRegistry );
    this.settings = settings;
    this.aggregatedCfgXml = loadedConfig;
    this.initiators = initiators;
}
 
Example 11
/**
 * Create a builder with the specified bootstrap services.
 *
 * @param bootstrapServiceRegistry Provided bootstrap registry to use.
 */
public ReactiveServiceRegistryBuilder(
        BootstrapServiceRegistry bootstrapServiceRegistry,
        LoadedConfig loadedConfigBaseline) {
    this.settings = Environment.getProperties();
    this.bootstrapServiceRegistry = bootstrapServiceRegistry;
    this.configLoader = new ConfigLoader( bootstrapServiceRegistry );
    this.aggregatedCfgXml = loadedConfigBaseline;
    this.initiators = defaultReactiveInitiatorList();
}
 
Example 12
protected void buildSessionFactory(Consumer<Configuration> configurationAdapter) {
  // for now, build the configuration to get all the property settings
  configuration = constructAndConfigureConfiguration();
  if ( configurationAdapter != null ) {
    configurationAdapter.accept(configuration);
  }
  BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
  serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
  // this is done here because Configuration does not currently support 4.0 xsd
  afterConstructAndConfigureConfiguration( configuration );
  sessionFactory = ( SessionFactoryImplementor ) configuration.buildSessionFactory( serviceRegistry );
  afterSessionFactoryBuilt();
}
 
Example 13
protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) {
  Properties properties = new Properties();
  properties.putAll( configuration.getProperties() );
  ConfigurationHelper.resolvePlaceHolders( properties );

  StandardServiceRegistryBuilder cfgRegistryBuilder = configuration.getStandardServiceRegistryBuilder();

  StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry, cfgRegistryBuilder.getAggregatedCfgXml() )
      .applySettings( properties );

  prepareBasicRegistryBuilder( registryBuilder );
  return (StandardServiceRegistryImpl) registryBuilder.build();
}
 
Example 14
Source Project: micronaut-sql   Source File: JpaConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates the standard service registry builder.
 *
 * @param bootstrapServiceRegistry The {@link BootstrapServiceRegistry} instance
 * @return The {@link StandardServiceRegistryBuilder} instance
 */
@SuppressWarnings("WeakerAccess")
protected StandardServiceRegistryBuilder createStandServiceRegistryBuilder(BootstrapServiceRegistry bootstrapServiceRegistry) {
    return new StandardServiceRegistryBuilder(
            bootstrapServiceRegistry
    );
}
 
Example 15
Source Project: quarkus   Source File: RecordableBootstrap.java    License: Apache License 2.0 5 votes vote down vote up
private RecordableBootstrap(BootstrapServiceRegistry bootstrapServiceRegistry, Map properties,
        LoadedConfig loadedConfigBaseline) {
    super(bootstrapServiceRegistry, properties, loadedConfigBaseline, null);
    this.settings = properties;
    this.bootstrapServiceRegistry = bootstrapServiceRegistry;
    this.aggregatedCfgXml = loadedConfigBaseline;
    this.initiators = standardInitiatorList();
}
 
Example 16
Source Project: quarkus   Source File: FastBootMetadataBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private BootstrapServiceRegistry buildBootstrapServiceRegistry(ClassLoaderService providedClassLoaderService) {

        // N.B. support for custom IntegratorProvider injected via Properties (as
        // instance) removed

        final QuarkusIntegratorServiceImpl integratorService = new QuarkusIntegratorServiceImpl(providedClassLoaderService);
        final QuarkusStrategySelectorBuilder strategySelectorBuilder = new QuarkusStrategySelectorBuilder();
        final StrategySelector strategySelector = strategySelectorBuilder.buildSelector(providedClassLoaderService);
        return new BootstrapServiceRegistryImpl(true, providedClassLoaderService, strategySelector, integratorService);
    }
 
Example 17
private BootstrapServiceRegistry buildEmptyBootstrapServiceRegistry() {

        // N.B. support for custom IntegratorProvider injected via Properties (as
        // instance) removed

        // N.B. support for custom StrategySelector is not implemented yet

        final StrategySelectorImpl strategySelector = new StrategySelectorImpl(FlatClassLoaderService.INSTANCE);

        return new BootstrapServiceRegistryImpl(true,
                FlatClassLoaderService.INSTANCE,
                strategySelector, // new MirroringStrategySelector(),
                new MirroringIntegratorService(integrators));
    }
 
Example 18
private BootstrapServiceRegistry buildEmptyBootstrapServiceRegistry() {

        // N.B. support for custom IntegratorProvider injected via Properties (as
        // instance) removed

        // N.B. support for custom StrategySelector is not implemented yet

        final StrategySelectorImpl strategySelector = new StrategySelectorImpl(FlatClassLoaderService.INSTANCE);

        return new BootstrapServiceRegistryImpl(true,
                FlatClassLoaderService.INSTANCE,
                strategySelector, // new MirroringStrategySelector(),
                new MirroringIntegratorService(integrators));
    }
 
Example 19
Source Project: teiid-spring-boot   Source File: SchemaBuilderUtility.java    License: Apache License 2.0 5 votes vote down vote up
public void generateVBLSchema(ApplicationContext context, MetadataFactory source, MetadataFactory target,
        Dialect dialect, MetadataSources metadataSources) {
    generateVBLSchema(source, target);
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(
            (BootstrapServiceRegistry) metadataSources.getServiceRegistry())
            .applySetting(AvailableSettings.DIALECT, dialect).build();
    ArtifactCollector files = generateHibernateModel(source, serviceRegistry);
    for (File f : files.getFiles("hbm.xml")) {
        metadataSources.addFile(f);
    }
}
 
Example 20
Source Project: teiid-spring-boot   Source File: SchemaBuilderUtility.java    License: Apache License 2.0 5 votes vote down vote up
public static Metadata generateHbmModel(ConnectionProvider provider, Dialect dialect) throws SQLException {
    MetadataSources metadataSources = new MetadataSources();
    ServiceRegistry registry = metadataSources.getServiceRegistry();

    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(
            (BootstrapServiceRegistry) registry).applySetting(AvailableSettings.DIALECT, TeiidDialect.class)
            .addService(ConnectionProvider.class, provider).addService(JdbcEnvironment.class,
                    new JdbcEnvironmentImpl(provider.getConnection().getMetaData(), dialect))
            .build();

    MetadataBuildingOptions options = new MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContext bootstrapContext = new BootstrapContextImpl( serviceRegistry, options );

    ReverseEngineeringStrategy strategy = new DefaultReverseEngineeringStrategy();

    InFlightMetadataCollectorImpl metadataCollector =  new InFlightMetadataCollectorImpl(bootstrapContext, options);
    MetadataBuildingContext buildingContext = new MetadataBuildingContextRootImpl(bootstrapContext, options,
            metadataCollector);

    JDBCBinder binder = new JDBCBinder(serviceRegistry, new Properties(), buildingContext, strategy, false);
    Metadata metadata = metadataCollector.buildMetadataInstance(buildingContext);
    binder.readFromDatabase(null, null, buildMapping(metadata));
    HibernateMappingExporter exporter = new HibernateMappingExporter() {
        @Override
        public Metadata getMetadata() {
            return metadata;
        }
    };
    exporter.start();
    return metadata;
}
 
Example 21
Source Project: lams   Source File: Configuration.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static BootstrapServiceRegistry getBootstrapRegistry(ServiceRegistry serviceRegistry) {
	if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
		return (BootstrapServiceRegistry) serviceRegistry;
	}
	else if ( StandardServiceRegistry.class.isInstance( serviceRegistry ) ) {
		final StandardServiceRegistry ssr = (StandardServiceRegistry) serviceRegistry;
		return (BootstrapServiceRegistry) ssr.getParentServiceRegistry();
	}

	throw new HibernateException(
			"No ServiceRegistry was passed to Configuration#buildSessionFactory " +
					"and could not determine how to locate BootstrapServiceRegistry " +
					"from Configuration instantiation"
	);
}
 
Example 22
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 );
}
 
Example 23
/**
 * 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;

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

		// then, explicitly provided service instances
		for ( ProvidedService providedService : providedServices ) {
			createServiceBinding( providedService );
		}
	}
	catch (RuntimeException e) {
		visitServiceBindings( binding -> binding.getLifecycleOwner().stopService( binding ) );
		throw e;
	}
}
 
Example 24
Source Project: wallride   Source File: Hbm2ddl.java    License: Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 25
Source Project: hypersistence-optimizer   Source File: AbstractTest.java    License: Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 26
@SuppressWarnings("unused")
public BootstrapServiceRegistry getBootstrapServiceRegistry() {
    return bootstrapServiceRegistry;
}
 
Example 27
@Override
protected StandardServiceRegistryBuilder getStandardServiceRegistryBuilder(BootstrapServiceRegistry bsr) {
    return ReactiveServiceRegistryBuilder.forJpa( bsr );
}
 
Example 28
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
  final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
  builder.applyClassLoader( getClass().getClassLoader() );
  prepareBootstrapRegistryBuilder( builder );
  return builder.build();
}
 
Example 29
Source Project: quarkus   Source File: RecordableBootstrap.java    License: Apache License 2.0 4 votes vote down vote up
public RecordableBootstrap(BootstrapServiceRegistry bootstrapServiceRegistry) {
    this(bootstrapServiceRegistry, initialProperties(), LoadedConfig.baseline());
}
 
Example 30
Source Project: quarkus   Source File: RecordableBootstrap.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public BootstrapServiceRegistry getBootstrapServiceRegistry() {
    return bootstrapServiceRegistry;
}