private void releaseServiceRegistry() { if ( serviceRegistry != null ) { try { serviceRegistry.destroy(); } finally { serviceRegistry = null; } } } }
/** * Destroy a service registry. Applications should only destroy registries they have explicitly created. * * @param serviceRegistry The registry to be closed. */ public static void destroy(ServiceRegistry serviceRegistry) { if ( serviceRegistry == null ) { return; } ( (BootstrapServiceRegistryImpl) serviceRegistry ).destroy(); } }
/** * 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; applyServiceRegistrations( serviceInitiators, providedServices ); }
public void prepare(boolean needsAutoCommit) throws SQLException { serviceRegistry = createServiceRegistry( cfgProperties ); connection = serviceRegistry.getService( ConnectionProvider.class ).getConnection(); if ( needsAutoCommit && ! connection.getAutoCommit() ) { connection.commit(); connection.setAutoCommit( true ); } }
@AfterClassOnce @SuppressWarnings( {"UnusedDeclaration"}) protected void releaseSessionFactory() { if ( sessionFactory == null ) { return; } sessionFactory.close(); sessionFactory = null; configuration = null; if ( serviceRegistry != null ) { if ( serviceRegistry.isActive() ) { try { serviceRegistry.destroy(); } catch (Exception ignore) { } fail( "StandardServiceRegistry was not closed down as expected" ); } } serviceRegistry=null; }
private void applyServiceRegistrations(List<StandardServiceInitiator> serviceInitiators, List<ProvidedService> providedServices) { 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; } }
@Override public <R extends Service> R getService(Class<R> serviceRole) { final ServiceBinding<R> binding = locateServiceBinding( serviceRole ); return binding == null ? null : binding.getService(); }
/** * Destroy a service registry. Applications should only destroy registries they have explicitly created. * * @param serviceRegistry The registry to be closed. */ public static void destroy(ServiceRegistry serviceRegistry) { if ( serviceRegistry == null ) { return; } ( (StandardServiceRegistryImpl) serviceRegistry ).destroy(); } }
private void releaseConnection() throws SQLException { if ( connection != null ) { try { serviceRegistry.getService( JdbcEnvironment.class ).getSqlExceptionHelper().logAndClearWarnings( connection ); } finally { try { serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection ); } finally { connection = null; } } } }
@Override public synchronized void destroy() { if ( !active ) { return; } active = false; destroy( classLoaderServiceBinding ); destroy( strategySelectorBinding ); destroy( integratorServiceBinding ); if ( childRegistries != null ) { for(ServiceRegistry serviceRegistry : childRegistries) { if(serviceRegistry instanceof ServiceRegistryImplementor) { ServiceRegistryImplementor serviceRegistryImplementor = (ServiceRegistryImplementor) serviceRegistry; serviceRegistryImplementor.destroy(); } } } }
/** * Very advanced and tricky to handle: not designed for this. Intended for experiments only! */ public synchronized void resetAndReactivate(BootstrapServiceRegistry bootstrapServiceRegistry, List<StandardServiceInitiator> serviceInitiators, List<ProvidedService> providedServices, Map<?, ?> configurationValues) { if ( super.isActive() ) { throw new IllegalStateException( "Can't reactivate an active registry!" ); } super.resetParent( bootstrapServiceRegistry ); this.configurationValues = new HashMap( configurationValues ); super.reactivate(); applyServiceRegistrations( serviceInitiators, providedServices ); }
public static void destroy(ServiceRegistry serviceRegistry) { ( (StandardServiceRegistryImpl) serviceRegistry ).destroy(); } }
@After public void after() { if ( bsr != null ) { bsr.destroy(); } }
protected void rebuildSessionFactory(Consumer<Configuration> configurationAdapter) { if ( sessionFactory == null ) { return; } try { sessionFactory.close(); sessionFactory = null; configuration = null; serviceRegistry.destroy(); serviceRegistry = null; } catch (Exception ignore) { } buildSessionFactory( configurationAdapter ); }
@Override public synchronized void deRegisterChild(ServiceRegistryImplementor child) { if ( childRegistries == null ) { throw new IllegalStateException( "No child ServiceRegistry registrations found" ); } childRegistries.remove( child ); if ( childRegistries.isEmpty() ) { if ( autoCloseRegistry ) { LOG.debug( "Implicitly destroying Boot-strap registry on de-registration " + "of all child ServiceRegistries" ); destroy(); } else { LOG.debug( "Skipping implicitly destroying Boot-strap registry on de-registration " + "of all child ServiceRegistries" ); } } } }
@AfterClassOnce public void shutdown() { serviceRegistry.destroy(); }
@After public void tearDown() { serviceRegistry.destroy(); }
protected void buildSessionFactory() { try { super.buildSessionFactory(); fail( "Should throw AnnotationException!" ); } catch ( AnnotationException expected ) { assertTrue( expected.getMessage().startsWith( "@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection" ) ); } finally { serviceRegistry().destroy(); } }
protected void buildSessionFactory() { try { super.buildSessionFactory(); fail( "Should throw AnnotationException!" ); } catch ( AnnotationException expected ) { assertTrue( expected.getMessage().startsWith( "@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection" ) ); } finally { serviceRegistry().destroy(); } }
@Test public void testInitialization() throws Exception { Configuration configuration = new Configuration(); configuration.addAnnotatedClass( A.class ); configuration.addAnnotatedClass( B.class ); configuration.addAnnotatedClass( C.class ); StandardServiceRegistryImpl serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( configuration.getProperties() ); try { SessionFactory sessionFactory = configuration.buildSessionFactory( serviceRegistry ); sessionFactory.close(); } finally { serviceRegistry.destroy(); } } }