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

The following examples show how to use org.hibernate.boot.registry.StandardServiceRegistryBuilder#configure() . 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
@SuppressWarnings("unchecked")
private void processConfigXml(
		LoadedConfig loadedConfig,
		MergedSettings mergedSettings,
		StandardServiceRegistryBuilder ssrBuilder) {
	if ( ! mergedSettings.configurationValues.containsKey( SESSION_FACTORY_NAME ) ) {
		// there is not already a SF-name in the merged settings
		final String sfName = loadedConfig.getSessionFactoryName();
		if ( sfName != null ) {
			// but the cfg.xml file we are processing named one..
			mergedSettings.configurationValues.put( SESSION_FACTORY_NAME, sfName );
		}
	}

	mergedSettings.configurationValues.putAll( loadedConfig.getConfigurationValues() );
	ssrBuilder.configure( loadedConfig );
}
 
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: ignite   File: HibernateL2CacheExample.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new Hibernate {@link SessionFactory} using a programmatic
 * configuration.
 *
 * @param hibernateCfg Hibernate configuration file.
 * @return New Hibernate {@link SessionFactory}.
 */
private static SessionFactory createHibernateSessionFactory(URL hibernateCfg) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", JDBC_URL);
    builder.applySetting("hibernate.show_sql", true);

    builder.configure(hibernateCfg);

    return new MetadataSources(builder.build()).buildMetadata().buildSessionFactory();
}