Java Code Examples for org.hibernate.boot.registry.StandardServiceRegistryBuilder#applySettings()

The following examples show how to use org.hibernate.boot.registry.StandardServiceRegistryBuilder#applySettings() . 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
Source Project: lams   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 2
private void configure(StandardServiceRegistryBuilder registryBuilder) throws IOException {
	if ( configurationFile != null ) {
		registryBuilder.configure( configurationFile );
	}

	Properties properties = new Properties();
	if ( propertiesFile == null ) {
		properties.putAll( getProject().getProperties() );
	}
	else {
		try (FileInputStream fip = new FileInputStream( propertiesFile )){
			properties.load( fip );
		} 
	}

	registryBuilder.applySettings( properties );
}
 
Example 3
Source Project: lams   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 4
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 5
Source Project: micronaut-sql   File: JpaConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Builds the standard service registry.
 *
 * @param additionalSettings Additional settings for the service registry
 * @return The standard service registry
 */
@SuppressWarnings("WeakerAccess")
public StandardServiceRegistry buildStandardServiceRegistry(@Nullable Map<String, Object> additionalSettings) {
    StandardServiceRegistryBuilder standardServiceRegistryBuilder = createStandServiceRegistryBuilder(bootstrapServiceRegistry);

    Map<String, Object> jpaProperties = getProperties();
    if (CollectionUtils.isNotEmpty(jpaProperties)) {
        standardServiceRegistryBuilder.applySettings(jpaProperties);
    }
    if (additionalSettings != null) {
        standardServiceRegistryBuilder.applySettings(additionalSettings);
    }
    return standardServiceRegistryBuilder.build();
}
 
Example 6
private void configure(StandardServiceRegistryBuilder registryBuilder) throws IOException {
	if ( configurationFile != null ) {
		registryBuilder.configure( configurationFile );
	}

	Properties properties = new Properties();
	if ( propertiesFile == null ) {
		properties.putAll( getProject().getProperties() );
	}
	else {
		properties.load( new FileInputStream( propertiesFile ) );
	}

	registryBuilder.applySettings( properties );
}
 
Example 7
Source Project: TomboloDigitalConnector   File: HibernateUtil.java    License: MIT License 5 votes vote down vote up
private static SessionFactory buildSessionFactoryForPython() {
    SessionFactory factory;
    StandardServiceRegistry registry;
    try {
        StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
        Map<String, String> settings = new HashMap<>();
        settings.put(Environment.DRIVER, "org.postgresql.Driver");
        settings.put(Environment.URL, "jdbc:postgresql://localhost:5432/tombolo");
        settings.put(Environment.USER, "tombolo");
        settings.put(Environment.PASS, "tombolo");
        settings.put(Environment.DIALECT, "org.hibernate.spatial.dialect.postgis.PostgisDialect");
        
        registryBuilder.applySettings(settings);
        registry = registryBuilder.build();
        MetadataSources sources = new MetadataSources(registry)
        .addAnnotatedClass(uk.org.tombolo.core.Provider.class)
        .addAnnotatedClass(uk.org.tombolo.core.Attribute.class)
        .addAnnotatedClass(uk.org.tombolo.core.Subject.class)
        .addAnnotatedClass(uk.org.tombolo.core.SubjectType.class)
        .addAnnotatedClass(uk.org.tombolo.core.FixedValue.class)
        .addAnnotatedClass(uk.org.tombolo.core.TimedValue.class);

        Metadata metadata = sources.getMetadataBuilder().build();
        factory = metadata.getSessionFactoryBuilder().build();
        
    } catch (Exception ex) {
        throw new ServiceConfigurationError("Failed to create SessionFactory", ex);
    }

    return factory;
}
 
Example 8
/**
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(String igniteInstanceName) {
    Configuration cfg = hibernateConfiguration(igniteInstanceName);

    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);
    builder.applySetting("hibernate.show_sql", false);
    builder.applySettings(cfg.getProperties());

    return cfg.buildSessionFactory(builder.build());
}
 
Example 9
/**
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(String igniteInstanceName) {
    Configuration cfg = hibernateConfiguration(igniteInstanceName);

    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);
    builder.applySetting("hibernate.show_sql", false);
    builder.applySettings(cfg.getProperties());

    return cfg.buildSessionFactory(builder.build());
}
 
Example 10
Source Project: primefaces-blueprints   File: HibernateUtil.java    License: The Unlicense 5 votes vote down vote up
private static SessionFactory buildSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration().configure();
    // configures settings from hibernate.cfg.xml

    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();

    // If you miss the below line then it will complain about a missing dialect setting
    serviceRegistryBuilder.applySettings(configuration.getProperties());

    ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
Example 11
Source Project: primefaces-blueprints   File: HibernateUtil.java    License: The Unlicense 5 votes vote down vote up
private static SessionFactory buildSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration().configure();
    // configures settings from hibernate.cfg.xml

    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();

    // If you miss the below line then it will complain about a missing dialect setting
    serviceRegistryBuilder.applySettings(configuration.getProperties());

    ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
Example 12
Source Project: primefaces-blueprints   File: HibernateUtil.java    License: The Unlicense 5 votes vote down vote up
private static SessionFactory buildSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration().configure();
    // configures settings from hibernate.cfg.xml

    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();

    // If you miss the below line then it will complain about a missing dialect setting
    serviceRegistryBuilder.applySettings(configuration.getProperties());

    ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
Example 13
Source Project: primefaces-blueprints   File: HibernateUtil.java    License: The Unlicense 5 votes vote down vote up
private static SessionFactory buildSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration().configure();
    // configures settings from hibernate.cfg.xml

    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();

    // If you miss the below line then it will complain about a missing dialect setting
    serviceRegistryBuilder.applySettings(configuration.getProperties());

    ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
Example 14
Source Project: primefaces-blueprints   File: HibernateUtil.java    License: The Unlicense 5 votes vote down vote up
private static SessionFactory buildSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration().configure();
    // configures settings from hibernate.cfg.xml

    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();

    // If you miss the below line then it will complain about a missing dialect setting
    serviceRegistryBuilder.applySettings(configuration.getProperties());

    ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
Example 15
private EntityManagerFactoryBuilderImpl(
		PersistenceUnitDescriptor persistenceUnit,
		Map integrationSettings,
		ClassLoader providedClassLoader,
		ClassLoaderService providedClassLoaderService) {

	LogHelper.logPersistenceUnitInformation( persistenceUnit );

	this.persistenceUnit = persistenceUnit;

	if ( integrationSettings == null ) {
		integrationSettings = Collections.emptyMap();
	}

	// Build the boot-strap service registry, which mainly handles class loader interactions
	final BootstrapServiceRegistry bsr = buildBootstrapServiceRegistry( integrationSettings, providedClassLoader, providedClassLoaderService);

	// merge configuration sources and build the "standard" service registry
	final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder( bsr );
	final MergedSettings mergedSettings = mergeSettings( persistenceUnit, integrationSettings, ssrBuilder );
	this.configurationValues = mergedSettings.getConfigurationValues();

	// Build the "standard" service registry
	ssrBuilder.applySettings( configurationValues );
	configure( ssrBuilder );
	this.standardServiceRegistry = ssrBuilder.build();
	configure( standardServiceRegistry, mergedSettings );

	final MetadataSources metadataSources = new MetadataSources( bsr );
	List<AttributeConverterDefinition> attributeConverterDefinitions = populate(
			metadataSources,
			mergedSettings,
			standardServiceRegistry
	);
	this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder( standardServiceRegistry );
	populate( metamodelBuilder, mergedSettings, standardServiceRegistry, attributeConverterDefinitions );

	// todo : would be nice to have MetadataBuilder still do the handling of CfgXmlAccessService here
	//		another option is to immediately handle them here (probably in mergeSettings?) as we encounter them...
	final CfgXmlAccessService cfgXmlAccessService = standardServiceRegistry.getService( CfgXmlAccessService.class );
	if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
		if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) {
			for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig().getMappingReferences() ) {
				mappingReference.apply( metadataSources );
			}
		}
	}

	this.managedResources = MetadataBuildingProcess.prepare(
			metadataSources,
			metamodelBuilder.getBootstrapContext()
	);

	applyMetadataBuilderContributor();


	withValidatorFactory( configurationValues.get( org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY ) );

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// push back class transformation to the environment; for the time being this only has any effect in EE
	// container situations, calling back into PersistenceUnitInfo#addClassTransformer

	final boolean dirtyTrackingEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING );
	final boolean lazyInitializationEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION );
	final boolean associationManagementEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT );

	if ( dirtyTrackingEnabled || lazyInitializationEnabled || associationManagementEnabled ) {
		EnhancementContext enhancementContext = getEnhancementContext(
				dirtyTrackingEnabled,
				lazyInitializationEnabled,
				associationManagementEnabled
		);

		persistenceUnit.pushClassTransformer( enhancementContext );
	}

	// for the time being we want to revoke access to the temp ClassLoader if one was passed
	metamodelBuilder.applyTempClassLoader( null );
}
 
Example 16
Source Project: stepic_java_webserver   File: DBService.java    License: MIT License 4 votes vote down vote up
private static SessionFactory createSessionFactory(Configuration configuration) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
Example 17
Source Project: tp_java_2015_02   File: DBServiceImpl.java    License: MIT License 4 votes vote down vote up
private static SessionFactory createSessionFactory(Configuration configuration) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.build();
    return configuration.buildSessionFactory(serviceRegistry);
}