public StatisticsImplementor getStatistics() { if ( statistics == null ) { statistics = serviceRegistry.getService( StatisticsImplementor.class ); } return statistics; }
private boolean canAccessTransactionManager() { try { return serviceRegistry.getService( JtaPlatform.class ).retrieveTransactionManager() != null; } catch (Exception e) { return false; } }
@Override public Connection obtainConnection() throws SQLException { return !settings.getMultiTenancyStrategy().requiresMultiTenantConnectionProvider() ? serviceRegistry.getService( ConnectionProvider.class ).getConnection() : serviceRegistry.getService( MultiTenantConnectionProvider.class ).getAnyConnection(); }
@Override public void releaseConnection(Connection connection) throws SQLException { if ( !settings.getMultiTenancyStrategy().requiresMultiTenantConnectionProvider() ) { serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection ); } else { serviceRegistry.getService( MultiTenantConnectionProvider.class ).releaseAnyConnection( connection ); } }
private void prepareEventListeners(MetadataImplementor metadata) { final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class ); final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); eventListenerRegistry.prepare( metadata ); for ( Map.Entry entry : ( (Map<?, ?>) cfgService.getSettings() ).entrySet() ) { if ( !String.class.isInstance( entry.getKey() ) ) { continue; } final String propertyName = (String) entry.getKey(); if ( !propertyName.startsWith( org.hibernate.jpa.AvailableSettings.EVENT_LISTENER_PREFIX ) ) { continue; } final String eventTypeName = propertyName.substring( org.hibernate.jpa.AvailableSettings.EVENT_LISTENER_PREFIX.length() + 1 ); final EventType eventType = EventType.resolveEventTypeByName( eventTypeName ); final EventListenerGroup eventListenerGroup = eventListenerRegistry.getEventListenerGroup( eventType ); for ( String listenerImpl : ( (String) entry.getValue() ).split( " ," ) ) { eventListenerGroup.appendListener( instantiate( listenerImpl, classLoaderService ) ); } } }
@Override public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { doIntegration( serviceRegistry.getService( ConfigurationService.class ).getSettings(), // pass no permissions here, because atm actually injecting the // permissions into the JaccService is handled on SessionFactoryImpl via // the org.hibernate.boot.cfgxml.spi.CfgXmlAccessService null, serviceRegistry ); }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { serviceRegistry.getService( EventListenerRegistry.class ).setListeners( EventType.CLEAR, listener ); }
Class implClass = serviceRegistry.getService( ClassLoaderService.class ).classForName( impl ); return (CurrentSessionContext) implClass.getConstructor( new Class[] { SessionFactoryImplementor.class } )
private void applyCfgXmlValues(LoadedConfig aggregatedConfig, SessionFactoryServiceRegistry serviceRegistry) { final JaccService jaccService = serviceRegistry.getService( JaccService.class ); if ( jaccService.getContextId() != null ) { final JaccPermissionDeclarations permissions = aggregatedConfig.getJaccPermissions( jaccService.getContextId() ); if ( permissions != null ) { for ( GrantedPermission grantedPermission : permissions.getPermissionDeclarations() ) { jaccService.addPermission( grantedPermission ); } } } if ( aggregatedConfig.getEventListenerMap() != null ) { final ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class ); final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); for ( Map.Entry<EventType, Set<String>> entry : aggregatedConfig.getEventListenerMap().entrySet() ) { final EventListenerGroup group = eventListenerRegistry.getEventListenerGroup( entry.getKey() ); for ( String listenerClassName : entry.getValue() ) { try { group.appendListener( cls.classForName( listenerClassName ).newInstance() ); } catch (Exception e) { throw new ConfigurationException( "Unable to instantiate event listener class : " + listenerClassName, e ); } } } } }
@SuppressWarnings({"unchecked", "UnusedParameters"}) private static void applyRelationalConstraints(ValidatorFactory factory, ActivationContext activationContext) { final ConfigurationService cfgService = activationContext.getServiceRegistry().getService( ConfigurationService.class ); if ( !cfgService.getSetting( BeanValidationIntegrator.APPLY_CONSTRAINTS, StandardConverters.BOOLEAN, true ) ) { LOG.debug( "Skipping application of relational constraints from legacy Hibernate Validator" ); return; } final Set<ValidationMode> modes = activationContext.getValidationModes(); if ( ! ( modes.contains( ValidationMode.DDL ) || modes.contains( ValidationMode.AUTO ) ) ) { return; } applyRelationalConstraints( factory, activationContext.getMetadata().getEntityBindings(), cfgService.getSettings(), activationContext.getServiceRegistry().getService( JdbcServices.class ).getDialect(), new ClassLoaderAccessImpl( null, activationContext.getServiceRegistry().getService( ClassLoaderService.class ) ) ); }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { serviceRegistry.getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.PRE_UPDATE ) .appendListener( InitializingPreUpdateEventListener.INSTANCE ); }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { serviceRegistry.getService( EventListenerRegistry.class ).prependListeners( EventType.LOAD, new CustomLoadListener() ); }
@Override public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { doIntegration( serviceRegistry .getService( ConfigurationService.class ).getSettings(), // pass no permissions here, because atm actually injecting the // permissions into the JaccService is handled on SessionFactoryImpl via // the org.hibernate.boot.cfgxml.spi.CfgXmlAccessService null, serviceRegistry ); }
@SuppressWarnings( {"UnusedDeclaration"}) public static void applyCallbackListeners(ValidatorFactory validatorFactory, ActivationContext activationContext) { final Set<ValidationMode> modes = activationContext.getValidationModes(); if ( ! ( modes.contains( ValidationMode.CALLBACK ) || modes.contains( ValidationMode.AUTO ) ) ) { return; } final ConfigurationService cfgService = activationContext.getServiceRegistry().getService( ConfigurationService.class ); final ClassLoaderService classLoaderService = activationContext.getServiceRegistry().getService( ClassLoaderService.class ); // de-activate not-null tracking at the core level when Bean Validation is present unless the user explicitly // asks for it if ( cfgService.getSettings().get( Environment.CHECK_NULLABILITY ) == null ) { activationContext.getSessionFactory().getSessionFactoryOptions().setCheckNullability( false ); } final BeanValidationEventListener listener = new BeanValidationEventListener( validatorFactory, cfgService.getSettings(), classLoaderService ); final EventListenerRegistry listenerRegistry = activationContext.getServiceRegistry() .getService( EventListenerRegistry.class ); listenerRegistry.addDuplicationStrategy( DuplicationStrategyImpl.INSTANCE ); listenerRegistry.appendListeners( EventType.PRE_INSERT, listener ); listenerRegistry.appendListeners( EventType.PRE_UPDATE, listener ); listenerRegistry.appendListeners( EventType.PRE_DELETE, listener ); listener.initialize( cfgService.getSettings(), classLoaderService ); }
private static ValidatorFactory getValidatorFactory(ActivationContext activationContext) { // IMPL NOTE : We can either be provided a ValidatorFactory or make one. We can be provided // a ValidatorFactory in 2 different ways. So here we "get" a ValidatorFactory in the following order: // 1) Look into SessionFactoryOptions.getValidatorFactoryReference() // 2) Look into ConfigurationService // 3) build a new ValidatorFactory // 1 - look in SessionFactoryOptions.getValidatorFactoryReference() ValidatorFactory factory = resolveProvidedFactory( activationContext.getSessionFactory().getSessionFactoryOptions() ); if ( factory != null ) { return factory; } // 2 - look in ConfigurationService factory = resolveProvidedFactory( activationContext.getServiceRegistry().getService( ConfigurationService.class ) ); if ( factory != null ) { return factory; } // 3 - build our own try { return Validation.buildDefaultValidatorFactory(); } catch ( Exception e ) { throw new IntegrationException( "Unable to build the default ValidatorFactory", e ); } }
private void doIntegration( Map properties, JaccPermissionDeclarations permissionDeclarations, SessionFactoryServiceRegistry serviceRegistry) { boolean isSecurityEnabled = properties.containsKey( AvailableSettings.JACC_ENABLED ); if ( ! isSecurityEnabled ) { log.debug( "Skipping JACC integration as it was not enabled" ); return; } final String contextId = (String) properties.get( AvailableSettings.JACC_CONTEXT_ID ); if ( contextId == null ) { throw new IntegrationException( "JACC context id must be specified" ); } final JaccService jaccService = serviceRegistry.getService( JaccService.class ); if ( jaccService == null ) { throw new IntegrationException( "JaccService was not set up" ); } if ( permissionDeclarations != null ) { for ( GrantedPermission declaration : permissionDeclarations.getPermissionDeclarations() ) { jaccService.addPermission( declaration ); } } final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); eventListenerRegistry.addDuplicationStrategy( DUPLICATION_STRATEGY ); eventListenerRegistry.prependListeners( EventType.PRE_DELETE, new JaccPreDeleteEventListener() ); eventListenerRegistry.prependListeners( EventType.PRE_INSERT, new JaccPreInsertEventListener() ); eventListenerRegistry.prependListeners( EventType.PRE_UPDATE, new JaccPreUpdateEventListener() ); eventListenerRegistry.prependListeners( EventType.PRE_LOAD, new JaccPreLoadEventListener() ); }
private void integrate(SessionFactoryServiceRegistry serviceRegistry, SessionFactoryImplementor sessionFactory) { if ( !sessionFactory.getSessionFactoryOptions().isAutoEvictCollectionCache() ) { // feature is disabled return; } if ( !sessionFactory.getSessionFactoryOptions().isSecondLevelCacheEnabled() ) { // Nothing to do, if caching is disabled return; } EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); eventListenerRegistry.appendListeners( EventType.POST_INSERT, this ); eventListenerRegistry.appendListeners( EventType.POST_DELETE, this ); eventListenerRegistry.appendListeners( EventType.POST_UPDATE, this ); }
.getService( JaccService.class ); if ( jaccService == null ) { throw new IntegrationException( "JaccService was not set up" ); serviceRegistry.getService( EventListenerRegistry.class ); eventListenerRegistry.addDuplicationStrategy( DUPLICATION_STRATEGY );
@Override public void integrate( Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { // As you might expect, an EventListenerRegistry is the thing with which event // listeners are registered // It is a service so we look it up using the service registry final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); // If you wish to have custom determination and handling of "duplicate" listeners, // you would have to add an implementation of the // org.hibernate.event.service.spi.DuplicationStrategy contract like this eventListenerRegistry.addDuplicationStrategy( new CustomDuplicationStrategy() ); // EventListenerRegistry defines 3 ways to register listeners: // 1) This form overrides any existing registrations with eventListenerRegistry.setListeners( EventType.AUTO_FLUSH, DefaultAutoFlushEventListener.class ); // 2) This form adds the specified listener(s) to the beginning of the listener chain eventListenerRegistry.prependListeners( EventType.PERSIST, DefaultPersistEventListener.class ); // 3) This form adds the specified listener(s) to the end of the listener chain eventListenerRegistry.appendListeners( EventType.MERGE, DefaultMergeEventListener.class ); }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); eventListenerRegistry.setListeners( EventType.PERSIST, buildPersistEventListeners() ); eventListenerRegistry.setListeners( EventType.PERSIST_ONFLUSH, buildPersisOnFlushEventListeners() ); eventListenerRegistry.setListeners( EventType.AUTO_FLUSH, buildAutoFlushEventListeners() ); eventListenerRegistry.setListeners( EventType.FLUSH, buildFlushEventListeners() ); eventListenerRegistry.setListeners( EventType.FLUSH_ENTITY, buildFlushEntityEventListeners() ); }