Java 类org.hibernate.event.service.spi.EventListenerGroup 实例源码

项目:lams    文件:EntityUpdateAction.java   
private boolean preUpdate() {
    boolean veto = false;
    final EventListenerGroup<PreUpdateEventListener> listenerGroup = listenerGroup( EventType.PRE_UPDATE );
    if ( listenerGroup.isEmpty() ) {
        return veto;
    }
    final PreUpdateEvent event = new PreUpdateEvent(
            getInstance(),
            getId(),
            state,
            previousState,
            getPersister(),
            eventSource()
    );
    for ( PreUpdateEventListener listener : listenerGroup.listeners() ) {
        veto |= listener.onPreUpdate( event );
    }
    return veto;
}
项目:lams    文件:TwoPhaseLoad.java   
/**
 * 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 SessionImplementor 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 );
        }
    }
}
项目:lams    文件:EntityDeleteAction.java   
private void postDelete() {
    final EventListenerGroup<PostDeleteEventListener> listenerGroup = listenerGroup( EventType.POST_DELETE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostDeleteEvent event = new PostDeleteEvent(
            getInstance(),
            getId(),
            state,
            getPersister(),
            eventSource()
    );
    for ( PostDeleteEventListener listener : listenerGroup.listeners() ) {
        listener.onPostDelete( event );
    }
}
项目:lams    文件:EntityInsertAction.java   
private void postInsert() {
    final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_INSERT );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostInsertEvent event = new PostInsertEvent(
            getInstance(),
            getId(),
            getState(),
            getPersister(),
            eventSource()
    );
    for ( PostInsertEventListener listener : listenerGroup.listeners() ) {
        listener.onPostInsert( event );
    }
}
项目:lams    文件:EntityIdentityInsertAction.java   
private void postInsert() {
    if ( isDelayed ) {
        getSession().getPersistenceContext().replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId );
    }

    final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_INSERT );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostInsertEvent event = new PostInsertEvent(
            getInstance(),
            generatedId,
            getState(),
            getPersister(),
            eventSource()
    );
    for ( PostInsertEventListener listener : listenerGroup.listeners() ) {
        listener.onPostInsert( event );
    }
}
项目:lams    文件:EntityUpdateAction.java   
private void postUpdate() {
    final EventListenerGroup<PostUpdateEventListener> listenerGroup = listenerGroup( EventType.POST_UPDATE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostUpdateEvent event = new PostUpdateEvent(
            getInstance(),
            getId(),
            state,
            previousState,
            dirtyFields,
            getPersister(),
            eventSource()
    );
    for ( PostUpdateEventListener listener : listenerGroup.listeners() ) {
        listener.onPostUpdate( event );
    }
}
项目:gorm-hibernate5    文件:EventListenerIntegrator.java   
protected <T> void appendListeners(EventListenerRegistry listenerRegistry,
                                   EventType<T> eventType, Collection<T> listeners) {

    EventListenerGroup<T> group = listenerRegistry.getEventListenerGroup(eventType);
    for (T listener : listeners) {
        if (listener != null) {
            if(shouldOverrideListeners(eventType, listener)) {
                // since ClosureEventTriggeringInterceptor extends DefaultSaveOrUpdateEventListener we want to override instead of append the listener here
                // to avoid there being 2 implementations which would impact performance too
                group.clear();
                group.appendListener(listener);
            }
            else {
                group.appendListener(listener);
            }
        }
    }
}
项目:lams    文件:StandardCacheEntryImpl.java   
/**
 * Assemble the previously disassembled state represented by this entry into the given entity instance.
 *
 * Additionally manages the PreLoadEvent callbacks.
 *
 * @param instance The entity instance
 * @param id The entity identifier
 * @param persister The entity persister
 * @param interceptor (currently unused)
 * @param session The session
 *
 * @return The assembled state
 *
 * @throws HibernateException Indicates a problem performing assembly or calling the PreLoadEventListeners.
 *
 * @see org.hibernate.type.Type#assemble
 * @see org.hibernate.type.Type#disassemble
 */
public Object[] assemble(
        final Object instance,
        final Serializable id,
        final EntityPersister persister,
        final Interceptor interceptor,
        final EventSource session) throws HibernateException {
    if ( !persister.getEntityName().equals( subclass ) ) {
        throw new AssertionFailure( "Tried to assemble a different subclass instance" );
    }

    //assembled state gets put in a new array (we read from cache by value!)
    final Object[] assembledProps = TypeHelper.assemble(
            disassembledState,
            persister.getPropertyTypes(),
            session, instance
    );

    //persister.setIdentifier(instance, id); //before calling interceptor, for consistency with normal load

    //TODO: reuse the PreLoadEvent
    final PreLoadEvent preLoadEvent = new PreLoadEvent( session )
            .setEntity( instance )
            .setState( assembledProps )
            .setId( id )
            .setPersister( persister );

    final EventListenerGroup<PreLoadEventListener> listenerGroup = session
            .getFactory()
            .getServiceRegistry()
            .getService( EventListenerRegistry.class )
            .getEventListenerGroup( EventType.PRE_LOAD );
    for ( PreLoadEventListener listener : listenerGroup.listeners() ) {
        listener.onPreLoad( preLoadEvent );
    }

    persister.setPropertyValues( instance, assembledProps );

    return assembledProps;
}
项目:lams    文件:EntityAction.java   
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) {
    return getSession()
            .getFactory()
            .getServiceRegistry()
            .getService( EventListenerRegistry.class )
            .getEventListenerGroup( eventType );
}
项目:lams    文件:EntityDeleteAction.java   
private boolean preDelete() {
    boolean veto = false;
    final EventListenerGroup<PreDeleteEventListener> listenerGroup = listenerGroup( EventType.PRE_DELETE );
    if ( listenerGroup.isEmpty() ) {
        return veto;
    }
    final PreDeleteEvent event = new PreDeleteEvent( getInstance(), getId(), state, getPersister(), eventSource() );
    for ( PreDeleteEventListener listener : listenerGroup.listeners() ) {
        veto |= listener.onPreDelete( event );
    }
    return veto;
}
项目:lams    文件:EntityDeleteAction.java   
private void postCommitDelete(boolean success) {
    final EventListenerGroup<PostDeleteEventListener> listenerGroup = listenerGroup( EventType.POST_COMMIT_DELETE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostDeleteEvent event = new PostDeleteEvent(
            getInstance(),
            getId(),
            state,
            getPersister(),
            eventSource()
    );
    for ( PostDeleteEventListener listener : listenerGroup.listeners() ) {
        if ( PostCommitDeleteEventListener.class.isInstance( listener ) ) {
            if ( success ) {
                listener.onPostDelete( event );
            }
            else {
                ((PostCommitDeleteEventListener) listener).onPostDeleteCommitFailed( event );
            }
        }
        else {
            //default to the legacy implementation that always fires the event
            listener.onPostDelete( event );
        }
    }
}
项目:lams    文件:EntityDeleteAction.java   
@Override
protected boolean hasPostCommitEventListeners() {
    final EventListenerGroup<PostDeleteEventListener> group = listenerGroup( EventType.POST_COMMIT_DELETE );
    for ( PostDeleteEventListener listener : group.listeners() ) {
        if ( listener.requiresPostCommitHanding( getPersister() ) ) {
            return true;
        }
    }

    return false;
}
项目:lams    文件:EntityInsertAction.java   
private void postCommitInsert(boolean success) {
    final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_COMMIT_INSERT );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostInsertEvent event = new PostInsertEvent(
            getInstance(),
            getId(),
            getState(),
            getPersister(),
            eventSource()
    );
    for ( PostInsertEventListener listener : listenerGroup.listeners() ) {
        if ( PostCommitInsertEventListener.class.isInstance( listener ) ) {
            if ( success ) {
                listener.onPostInsert( event );
            }
            else {
                ((PostCommitInsertEventListener) listener).onPostInsertCommitFailed( event );
            }
        }
        else {
            //default to the legacy implementation that always fires the event
            listener.onPostInsert( event );
        }
    }
}
项目:lams    文件:EntityInsertAction.java   
private boolean preInsert() {
    boolean veto = false;

    final EventListenerGroup<PreInsertEventListener> listenerGroup = listenerGroup( EventType.PRE_INSERT );
    if ( listenerGroup.isEmpty() ) {
        return veto;
    }
    final PreInsertEvent event = new PreInsertEvent( getInstance(), getId(), getState(), getPersister(), eventSource() );
    for ( PreInsertEventListener listener : listenerGroup.listeners() ) {
        veto |= listener.onPreInsert( event );
    }
    return veto;
}
项目:lams    文件:EntityInsertAction.java   
@Override
protected boolean hasPostCommitEventListeners() {
    final EventListenerGroup<PostInsertEventListener> group = listenerGroup( EventType.POST_COMMIT_INSERT );
    for ( PostInsertEventListener listener : group.listeners() ) {
        if ( listener.requiresPostCommitHanding( getPersister() ) ) {
            return true;
        }
    }

    return false;
}
项目:lams    文件:CollectionRecreateAction.java   
private void preRecreate() {
    final EventListenerGroup<PreCollectionRecreateEventListener> listenerGroup = listenerGroup( EventType.PRE_COLLECTION_RECREATE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PreCollectionRecreateEvent event = new PreCollectionRecreateEvent( getPersister(), getCollection(), eventSource() );
    for ( PreCollectionRecreateEventListener listener : listenerGroup.listeners() ) {
        listener.onPreRecreateCollection( event );
    }
}
项目:lams    文件:CollectionRecreateAction.java   
private void postRecreate() {
    final EventListenerGroup<PostCollectionRecreateEventListener> listenerGroup = listenerGroup( EventType.POST_COLLECTION_RECREATE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostCollectionRecreateEvent event = new PostCollectionRecreateEvent( getPersister(), getCollection(), eventSource() );
    for ( PostCollectionRecreateEventListener listener : listenerGroup.listeners() ) {
        listener.onPostRecreateCollection( event );
    }
}
项目:lams    文件:CollectionAction.java   
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) {
    return getSession()
            .getFactory()
            .getServiceRegistry()
            .getService( EventListenerRegistry.class )
            .getEventListenerGroup( eventType );
}
项目:lams    文件:CollectionUpdateAction.java   
private void preUpdate() {
    final EventListenerGroup<PreCollectionUpdateEventListener> listenerGroup = listenerGroup( EventType.PRE_COLLECTION_UPDATE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PreCollectionUpdateEvent event = new PreCollectionUpdateEvent(
            getPersister(),
            getCollection(),
            eventSource()
    );
    for ( PreCollectionUpdateEventListener listener : listenerGroup.listeners() ) {
        listener.onPreUpdateCollection( event );
    }
}
项目:lams    文件:CollectionUpdateAction.java   
private void postUpdate() {
    final EventListenerGroup<PostCollectionUpdateEventListener> listenerGroup = listenerGroup( EventType.POST_COLLECTION_UPDATE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostCollectionUpdateEvent event = new PostCollectionUpdateEvent(
            getPersister(),
            getCollection(),
            eventSource()
    );
    for ( PostCollectionUpdateEventListener listener : listenerGroup.listeners() ) {
        listener.onPostUpdateCollection( event );
    }
}
项目:lams    文件:CollectionRemoveAction.java   
private void preRemove() {
    final EventListenerGroup<PreCollectionRemoveEventListener> listenerGroup = listenerGroup( EventType.PRE_COLLECTION_REMOVE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PreCollectionRemoveEvent event = new PreCollectionRemoveEvent(
            getPersister(),
            getCollection(),
            eventSource(),
            affectedOwner
    );
    for ( PreCollectionRemoveEventListener listener : listenerGroup.listeners() ) {
        listener.onPreRemoveCollection( event );
    }
}
项目:lams    文件:CollectionRemoveAction.java   
private void postRemove() {
    final EventListenerGroup<PostCollectionRemoveEventListener> listenerGroup = listenerGroup( EventType.POST_COLLECTION_REMOVE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostCollectionRemoveEvent event = new PostCollectionRemoveEvent(
            getPersister(),
            getCollection(),
            eventSource(),
            affectedOwner
    );
    for ( PostCollectionRemoveEventListener listener : listenerGroup.listeners() ) {
        listener.onPostRemoveCollection( event );
    }
}
项目:lams    文件:EntityIdentityInsertAction.java   
@Override
protected boolean hasPostCommitEventListeners() {
    final EventListenerGroup<PostInsertEventListener> group = listenerGroup( EventType.POST_COMMIT_INSERT );
    for ( PostInsertEventListener listener : group.listeners() ) {
        if ( listener.requiresPostCommitHanding( getPersister() ) ) {
            return true;
        }
    }

    return false;
}
项目:lams    文件:EntityIdentityInsertAction.java   
private void postCommitInsert(boolean success) {
    final EventListenerGroup<PostInsertEventListener> listenerGroup = listenerGroup( EventType.POST_COMMIT_INSERT );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostInsertEvent event = new PostInsertEvent(
            getInstance(),
            generatedId,
            getState(),
            getPersister(),
            eventSource()
    );
    for ( PostInsertEventListener listener : listenerGroup.listeners() ) {
        if ( PostCommitInsertEventListener.class.isInstance( listener ) ) {
            if ( success ) {
                listener.onPostInsert( event );
            }
            else {
                ((PostCommitInsertEventListener) listener).onPostInsertCommitFailed( event );
            }
        }
        else {
            //default to the legacy implementation that always fires the event
            listener.onPostInsert( event );
        }
    }
}
项目:lams    文件:EntityIdentityInsertAction.java   
private boolean preInsert() {
    final EventListenerGroup<PreInsertEventListener> listenerGroup = listenerGroup( EventType.PRE_INSERT );
    if ( listenerGroup.isEmpty() ) {
        // NO_VETO
        return false;
    }
    boolean veto = false;
    final PreInsertEvent event = new PreInsertEvent( getInstance(), null, getState(), getPersister(), eventSource() );
    for ( PreInsertEventListener listener : listenerGroup.listeners() ) {
        veto |= listener.onPreInsert( event );
    }
    return veto;
}
项目:lams    文件:EntityUpdateAction.java   
private void postCommitUpdate(boolean success) {
    final EventListenerGroup<PostUpdateEventListener> listenerGroup = listenerGroup( EventType.POST_COMMIT_UPDATE );
    if ( listenerGroup.isEmpty() ) {
        return;
    }
    final PostUpdateEvent event = new PostUpdateEvent(
            getInstance(),
            getId(),
            state,
            previousState,
            dirtyFields,
            getPersister(),
            eventSource()
    );
    for ( PostUpdateEventListener listener : listenerGroup.listeners() ) {
        if ( PostCommitUpdateEventListener.class.isInstance( listener ) ) {
            if ( success ) {
                listener.onPostUpdate( event );
            }
            else {
                ((PostCommitUpdateEventListener) listener).onPostUpdateCommitFailed( event );
            }
        }
        else {
            //default to the legacy implementation that always fires the event
            listener.onPostUpdate( event );
        }
    }
}
项目:lams    文件:EntityUpdateAction.java   
@Override
protected boolean hasPostCommitEventListeners() {
    final EventListenerGroup<PostUpdateEventListener> group = listenerGroup( EventType.POST_COMMIT_UPDATE );
    for ( PostUpdateEventListener listener : group.listeners() ) {
        if ( listener.requiresPostCommitHanding( getPersister() ) ) {
            return true;
        }
    }

    return false;
}
项目:jersey2-toolkit    文件:HibernateSessionFactoryFactoryTest.java   
/**
 * Helper method that asserts that our event listener is in the passed
 * group.
 *
 * @param group The event listener group in question.
 */
private void assertContainsListener(final EventListenerGroup group) {

    for (Object listener : group.listeners()) {
        if (listener instanceof TestEventListener) {
            return;
        }
    }

    Assert.assertFalse(true);
}
项目:lams    文件:SessionImpl.java   
private <T> EventListenerGroup<T> eventListenerGroup(EventType<T> type) {
    return factory.getServiceRegistry().getService( EventListenerRegistry.class ).getEventListenerGroup( type );
}
项目:jersey2-toolkit    文件:HibernateSessionFactoryFactoryTest.java   
/**
 * Test the application event injectors.
 */
@Test
public void testEventInjection() {

    // Create a fake application.
    SessionFactory factoryFactory = locator
            .getService(SessionFactory.class);
    Assert.assertNotNull(factoryFactory);


    ServiceRegistry serviceRegistry = ((SessionFactoryImpl) factoryFactory)
            .getServiceRegistry();
    EventListenerRegistry eventRegistry = serviceRegistry
            .getService(EventListenerRegistry.class);

    EventListenerGroup<PreInsertEventListener> priGroup = eventRegistry
            .getEventListenerGroup(EventType.PRE_INSERT);
    assertContainsListener(priGroup);

    EventListenerGroup<PostInsertEventListener> poiGroup = eventRegistry
            .getEventListenerGroup(EventType.POST_INSERT);
    assertContainsListener(poiGroup);

    EventListenerGroup<PreUpdateEventListener> pruGroup = eventRegistry
            .getEventListenerGroup(EventType.PRE_UPDATE);
    assertContainsListener(pruGroup);

    EventListenerGroup<PostUpdateEventListener> pouGroup = eventRegistry
            .getEventListenerGroup(EventType.POST_UPDATE);
    assertContainsListener(pouGroup);

    EventListenerGroup<PreDeleteEventListener> prdGroup = eventRegistry
            .getEventListenerGroup(EventType.PRE_DELETE);
    assertContainsListener(prdGroup);

    EventListenerGroup<PostDeleteEventListener> podGroup = eventRegistry
            .getEventListenerGroup(EventType.POST_DELETE);
    assertContainsListener(podGroup);

    EventListenerGroup<PostInsertEventListener> pciGroup = eventRegistry
            .getEventListenerGroup(EventType.POST_COMMIT_INSERT);
    assertContainsListener(pciGroup);

    EventListenerGroup<PostUpdateEventListener> pcuGroup = eventRegistry
            .getEventListenerGroup(EventType.POST_COMMIT_UPDATE);
    assertContainsListener(pcuGroup);

    EventListenerGroup<PostDeleteEventListener> pcdGroup = eventRegistry
            .getEventListenerGroup(EventType.POST_COMMIT_DELETE);
    assertContainsListener(pcdGroup);
}