/** * Read setting information from an XML file using the standard resource location. * * @return this, for method chaining * * @see #DEFAULT_CFG_RESOURCE_NAME * @see #configure(String) * @see #loadProperties(String) */ public StandardServiceRegistryBuilder configure() { return configure( DEFAULT_CFG_RESOURCE_NAME ); }
public StandardServiceRegistryBuilder configure(File configurationFile) { return configure( configLoader.loadConfigXmlFile( configurationFile ) ); }
/** * Read setting information from an XML file using the named resource location. * * @param resourceName The named resource * * @return this, for method chaining */ public StandardServiceRegistryBuilder configure(String resourceName) { return configure( configLoader.loadConfigXmlResource( resourceName ) ); }
public StandardServiceRegistryBuilder configure(URL url) { return configure( configLoader.loadConfigXmlUrl( url ) ); }
/** * Use the mappings and properties specified in the given application file. The format of the file is defined in * <tt>hibernate-configuration-3.0.dtd</tt>. * * @param configFile File from which you wish to load the configuration * * @return this for method chaining * * @throws HibernateException Generally indicates a problem access the file */ public Configuration configure(File configFile) throws HibernateException { standardServiceRegistryBuilder.configure( configFile ); properties.putAll( standardServiceRegistryBuilder.getSettings() ); return this; }
/** * Use the mappings and properties specified in the given document. The format of the document is defined in * <tt>hibernate-configuration-3.0.dtd</tt>. * * @param url URL from which you wish to load the configuration * * @return this for method chaining * * @throws HibernateException Generally indicates a problem access the url */ public Configuration configure(URL url) throws HibernateException { standardServiceRegistryBuilder.configure( url ); properties.putAll( standardServiceRegistryBuilder.getSettings() ); return this; }
/** * Use the mappings and properties specified in the given application resource. The format of the resource is * defined in <tt>hibernate-configuration-3.0.dtd</tt>. * * @param resource The resource to use * * @return this for method chaining * * @throws HibernateException Generally indicates we cannot find the named resource */ public Configuration configure(String resource) throws HibernateException { standardServiceRegistryBuilder.configure( resource ); // todo : still need to have StandardServiceRegistryBuilder handle the "other cfg.xml" elements. // currently it just reads the config properties properties.putAll( standardServiceRegistryBuilder.getSettings() ); return this; }
@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 ); }
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 ); }
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 ); }
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(); }
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(); }
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(); }
public static StandardServiceRegistryBuilder getStandardServiceRegistryBuilder() { final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .configure( "hibernate-config/hibernate.cfg.xml" ) .applySetting( AvailableSettings.GENERATE_STATISTICS, "true" ) .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE ) .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ); if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) { ssrb.applySetting( AvailableSettings.URL, "jdbc:h2:mem:db-mvcc;MVCC=true" ); } return ssrb; }
public static StandardServiceRegistryBuilder getStandardServiceRegistryBuilder() { final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .configure( "hibernate-config/hibernate.cfg.xml" ) .applySetting( AvailableSettings.GENERATE_STATISTICS, "true" ) .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE ) .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ); if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) { ssrb.applySetting( AvailableSettings.URL, "jdbc:h2:mem:db-mvcc;MVCC=true" ); } return ssrb; }
@Test(expected = ConfigurationException.class ) public void testCfgXmlWithBadNamespaceAndSchemaLocation() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .configure( "org/hibernate/test/boot/cfgXml/badnamespace.cfg.xml" ) .build(); StandardServiceRegistryBuilder.destroy( ssr ); fail( "Expecting the bad namespace to fail" ); } }
@Test public void testCfgXmlWithSchemaLocation() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .configure( "org/hibernate/test/boot/cfgXml/hibernate.cfg.xml" ) .build(); try { final ConfigurationService cs = ssr.getService( ConfigurationService.class ); // augmented form assertNotNull( cs.getSettings().get( "hibernate.cache.provider_class" ) ); // original form assertNotNull( cs.getSettings().get( "cache.provider_class" ) ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } }
@Before @SuppressWarnings("unused") public void acquireResources() { final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .configure( "hibernate-config/hibernate.cfg.xml" ); if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) { ssrb.applySetting( AvailableSettings.URL, "jdbc:h2:mem:db-mvcc;MVCC=true" ); } ssrb.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" ); serviceRegistry = ssrb .configure( "hibernate-config/hibernate.cfg.xml" ) .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE ) .build(); final MetadataSources metadataSources = new MetadataSources( serviceRegistry ); metadataSources.addAnnotatedClass( ReadWriteCacheableItem.class ); metadataSources.addAnnotatedClass( ReadWriteVersionedCacheableItem.class ); metadataSources.addAnnotatedClass( NonStrictReadWriteCacheableItem.class ); metadataSources.addAnnotatedClass( NonStrictReadWriteVersionedCacheableItem.class ); final Metadata metadata = metadataSources.buildMetadata(); TestHelper.createRegions( metadata, true ); sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory(); }
@Test public void testStreamClosing() { BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder() .applyClassLoaderService( classLoaderService ) .build(); StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ) .configure( "org/hibernate/test/boot/cfgXml/hibernate.cfg.xml" ) .build(); try { for ( InputStreamWrapper openedStream : classLoaderService.openedStreams ) { assertTrue( openedStream.wasClosed ); } } finally { StandardServiceRegistryBuilder.destroy( ssr ); } assertTrue( classLoaderService.stopped ); } }