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 ) ); } } }
private <T> EventListenerGroup<T> eventListenerGroup(EventType<T> type) { return getFactory().getServiceRegistry().getService( EventListenerRegistry.class ).getEventListenerGroup( type ); }
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) { return getSession() .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( eventType ); }
private Iterable<PostLoadEventListener> postLoadEventListeners(EventSource session) { return session .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.POST_LOAD ) .listeners(); }
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) { return getSession() .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( eventType ); }
private void integrate(SessionFactoryServiceRegistry serviceRegistry) { serviceRegistry.getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.PRE_UPDATE ) .appendListener( InitializingPreUpdateEventListener.INSTANCE ); }
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 ); } } } } }
final Iterable<FlushEntityEventListener> flushListeners = source.getFactory().getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.FLUSH_ENTITY ) .listeners();
.getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.PRE_LOAD ); for ( PreLoadEventListener listener : listenerGroup.listeners() ) { listener.onPreLoad( preLoadEvent );
@Test @TestForIssue(jiraKey = "HHH-7478") public void testTransactionProcessSynchronization() { final EventListenerRegistry registry = sessionFactory().getServiceRegistry() .getService( EventListenerRegistry.class ); final CountingPostInsertTransactionBoundaryListener listener = new CountingPostInsertTransactionBoundaryListener(); registry.getEventListenerGroup( EventType.POST_INSERT ).appendListener( listener ); Session session = openSession(); session.getTransaction().begin(); StrTestEntity entity = new StrTestEntity( "str1" ); session.save( entity ); session.getTransaction().commit(); session.close(); // Post insert listener invoked three times - before/after insertion of original data, // revision entity and audit row. Assert.assertEquals( 3, listener.getBeforeCount() ); Assert.assertEquals( 3, listener.getAfterCount() ); }
/** * PostLoad cannot occur during initializeEntity, as that call occurs *before* * the Set collections are added to the persistence context by Loader. * Without the split, LazyInitializationExceptions can occur in the Entity's * postLoad if it acts upon the collection. * * HHH-6043 * * @param entity The entity * @param session The Session * @param postLoadEvent The (re-used) post-load event */ public static void postLoad( final Object entity, final SharedSessionContractImplementor session, final PostLoadEvent postLoadEvent) { if ( session.isEventSource() ) { final PersistenceContext persistenceContext = session.getPersistenceContext(); final EntityEntry entityEntry = persistenceContext.getEntry( entity ); postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() ); final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.POST_LOAD ); for ( PostLoadEventListener listener : listenerGroup.listeners() ) { listener.onPostLoad( postLoadEvent ); } } }
@PostConstruct public void registerListener() { EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService( EventListenerRegistry.class); registry.getEventListenerGroup(EventType.POST_LOAD).appendListener(this); }
.getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.PRE_LOAD ); for ( PreLoadEventListener listener : listenerGroup.listeners() ) { listener.onPreLoad( preLoadEvent );
private <T> void register(EventType<T> eventType, T t) { EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(EventListenerRegistry.class); log.info("Registering {} listener on {} events", t.getClass(), eventType); registry.getEventListenerGroup(eventType).appendListener(t); }
private static <T> org.hibernate.event.service.spi.EventListenerGroup<T> eventListenerGroup( final Session session, final org.hibernate.event.spi.EventType<T> type) { final org.hibernate.engine.spi.SessionFactoryImplementor sessionFactoryImpl = (org.hibernate.engine.spi.SessionFactoryImplementor) session.getSessionFactory(); return sessionFactoryImpl.getServiceRegistry().getService(org.hibernate.event.service.spi.EventListenerRegistry.class) .getEventListenerGroup(type); }
private Iterable<PostLoadEventListener> postLoadEventListeners(EventSource session) { return session .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.POST_LOAD ) .listeners(); } }
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) { return getSession() .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( eventType ); }
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) { return getSession() .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( eventType ); }
@Override public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class); final EventListenerGroup<MergeEventListener> mergeListeners = eventListenerRegistry.getEventListenerGroup(EventType.MERGE); mergeListeners.addDuplicationStrategy(USE_DERIVED); mergeListeners.appendListener(new IdTransferringMergeEventListener()); }
public void autoFlush(Set<String> querySpaces, SessionImplementor sessionImplementor) { AutoFlushEvent event = new AutoFlushEvent(querySpaces, (EventSource) sessionImplementor); for (AutoFlushEventListener listener : sessionImplementor.getFactory().getServiceRegistry().getService(EventListenerRegistry.class).getEventListenerGroup(EventType.AUTO_FLUSH).listeners()) { listener.onAutoFlush(event); } }