/** * Create a new LocalSessionFactoryBuilder for the given DataSource. * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using * (may be {@code null}) * @param resourceLoader the ResourceLoader to load application classes from */ public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ResourceLoader resourceLoader) { this(dataSource, resourceLoader, new MetadataSources( new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build())); }
public Configuration() { this( new BootstrapServiceRegistryBuilder().build() ); }
private BootstrapServiceRegistryBuilder createBootstrapRegistryBuilder() { return new BootstrapServiceRegistryBuilder(); }
public MetadataSources() { this( new BootstrapServiceRegistryBuilder().build() ); }
public static ServiceRegistryTestingImpl forUnitTesting(Map settings) { return new ServiceRegistryTestingImpl( true, new BootstrapServiceRegistryBuilder().build(), StandardServiceInitiators.LIST, Arrays.asList( dialectFactoryService(), connectionProviderService() ), settings ); }
/** * Create a default builder. */ public StandardServiceRegistryBuilder() { this( new BootstrapServiceRegistryBuilder().enableAutoClose().build() ); }
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() { final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder(); builder.applyClassLoader( getClass().getClassLoader() ); prepareBootstrapRegistryBuilder( builder ); return builder.build(); }
/** * Create a new LocalSessionFactoryBuilder for the given DataSource. * @param dataSource the JDBC DataSource that the resulting Hibernate SessionFactory should be using * (may be {@code null}) * @param resourceLoader the ResourceLoader to load application classes from */ public LocalSessionFactoryBuilder(@Nullable DataSource dataSource, ResourceLoader resourceLoader) { this(dataSource, resourceLoader, new MetadataSources( new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build())); }
public static ServiceRegistryTestingImpl forUnitTesting() { return new ServiceRegistryTestingImpl( true, new BootstrapServiceRegistryBuilder().build(), StandardServiceInitiators.LIST, Arrays.asList( dialectFactoryService(), connectionProviderService() ), Environment.getProperties() ); }
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(); }
/** * Determine the Hibernate {@link MetadataSources} to use. * <p>Can also be externally called to initialize and pre-populate a {@link MetadataSources} * instance which is then going to be used for {@link SessionFactory} building. * @return the MetadataSources to use (never {@code null}) * @since 4.3 * @see LocalSessionFactoryBuilder#LocalSessionFactoryBuilder(DataSource, ResourceLoader, MetadataSources) */ public MetadataSources getMetadataSources() { this.metadataSourcesAccessed = true; if (this.metadataSources == null) { BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder(); if (this.resourcePatternResolver != null) { builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader()); } if (this.hibernateIntegrators != null) { for (Integrator integrator : this.hibernateIntegrators) { builder = builder.applyIntegrator(integrator); } } this.metadataSources = new MetadataSources(builder.build()); } return this.metadataSources; }
@Before public void before() { bsr = (BootstrapServiceRegistryImpl) new BootstrapServiceRegistryBuilder().build(); }
@Test public void test_bootstrap_bootstrap_native_registry_StandardServiceRegistryBuilder_example_2() { //tag::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[] // An example using an explicitly built BootstrapServiceRegistry BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder().build(); StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder( bootstrapRegistry ); //end::bootstrap-bootstrap-native-registry-StandardServiceRegistryBuilder-example[] }
@Test public void test_bootstrap_bootstrap_native_registry_BootstrapServiceRegistry_example() { ClassLoader customClassLoader = Thread.currentThread().getContextClassLoader(); Integrator customIntegrator = new BeanValidationIntegrator(); //tag::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[] BootstrapServiceRegistryBuilder bootstrapRegistryBuilder = new BootstrapServiceRegistryBuilder(); // add a custom ClassLoader bootstrapRegistryBuilder.applyClassLoader( customClassLoader ); // manually add an Integrator bootstrapRegistryBuilder.applyIntegrator( customIntegrator ); BootstrapServiceRegistry bootstrapRegistry = bootstrapRegistryBuilder.build(); //end::bootstrap-bootstrap-native-registry-BootstrapServiceRegistry-example[] }
@Test public void testCachingImplicitlyEnabledRegistered() { final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder() .build(); final Collection<Class<? extends RegionFactory>> implementors = bsr .getService( StrategySelector.class ) .getRegisteredStrategyImplementors( RegionFactory.class ); assertThat( implementors.size(), equalTo( 1 ) ); final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ) .applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "" ) .build(); assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) ); }
@Test public void testStrategySelectorRegistrations() { final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build(); final Collection<Class<? extends RegionFactory>> implementors = registry .getService( StrategySelector.class ) .getRegisteredStrategyImplementors( RegionFactory.class ); assertTrue( implementors.contains( EhcacheRegionFactory.class ) ); assertTrue( implementors.contains( SingletonEhcacheRegionFactory.class ) ); }
@Test public void testCachingImplicitlyEnabledNoRegistered() { final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder() .build(); final Collection<Class<? extends RegionFactory>> implementors = bsr .getService( StrategySelector.class ) .getRegisteredStrategyImplementors( RegionFactory.class ); assertThat( implementors.size(), equalTo( 1 ) ); bsr.getService( StrategySelector.class ).unRegisterStrategyImplementor( RegionFactory.class, implementors.iterator().next() ); final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ) .applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "" ) .build(); assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) ); }
@Test public void testConnectionsRegistered() { final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder() .build(); final Collection<Class<? extends ConnectionProvider>> implementors = bsr .getService( StrategySelector.class ) .getRegisteredStrategyImplementors( ConnectionProvider.class ); assertThat( implementors.size(), equalTo( 0 ) ); bsr.getService( StrategySelector.class ).registerStrategyImplementor( ConnectionProvider.class, "testing", DriverManagerConnectionProviderImpl.class ); final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ).build(); final ConnectionProvider configuredProvider = ssr.getService( ConnectionProvider.class ); assertThat( configuredProvider, instanceOf( DriverManagerConnectionProviderImpl.class ) ); } }