org.hibernate.event.spi.EventType Java Examples

The following examples show how to use org.hibernate.event.spi.EventType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
public CompletionStage<Void> reactiveInitializeCollection(PersistentCollection collection, boolean writing) {
	checkOpenOrWaitingForAutoClose();
	pulseTransactionCoordinator();
	InitializeCollectionEvent event = new InitializeCollectionEvent( collection, this );
	return fire( event, EventType.INIT_COLLECTION,
			(DefaultReactiveInitializeCollectionEventListener l) -> l::onReactiveInitializeCollection )
			.handle( (v, e) -> {
				delayedAfterCompletion();

				if ( e instanceof MappingException ) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage() ) );
				}
				else if ( e instanceof RuntimeException ) {
					throw getExceptionConverter().convert( (RuntimeException) e );
				}
				return CompletionStages.returnNullorRethrow( e );
			} );
}
 
Example #2
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> CompletionStage<T> fireMerge(MergeEvent event) {
	checkTransactionSynchStatus();
	checkNoUnresolvedActionsBeforeOperation();

	return fire(event, EventType.MERGE,
			(ReactiveMergeEventListener l) -> l::reactiveOnMerge)
			.handle( (v,e) -> {
				checkNoUnresolvedActionsAfterOperation();

				if (e instanceof ObjectDeletedException) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e ) );
				}
				else if (e instanceof MappingException) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
				}
				else if (e instanceof RuntimeException) {
					//including HibernateException
					throw getExceptionConverter().convert( (RuntimeException) e );
				}
				return CompletionStages.returnOrRethrow( e, (T) event.getResult() );
			});
}
 
Example #3
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
private CompletionStage<Void> fireRemove(DeleteEvent event, IdentitySet transientEntities) {
	pulseTransactionCoordinator();

	return fire(event, transientEntities, EventType.DELETE,
			(ReactiveDeleteEventListener l) -> l::reactiveOnDelete)
			.handle( (v, e) -> {
				delayedAfterCompletion();

				if ( e instanceof ObjectDeletedException ) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e ) );
				}
				else if ( e instanceof MappingException ) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
				}
				else if ( e instanceof RuntimeException ) {
					//including HibernateException
					throw getExceptionConverter().convert( (RuntimeException) e );
				}
				return CompletionStages.returnNullorRethrow( e );
			});
}
 
Example #4
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
private CompletionStage<Void> firePersist(IdentitySet copiedAlready, PersistEvent event) {
	pulseTransactionCoordinator();

	return fire(event, copiedAlready, EventType.PERSIST,
			(ReactivePersistEventListener l) -> l::reactiveOnPersist)
			.handle( (v, e) -> {
				delayedAfterCompletion();

				if (e instanceof MappingException) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage() ) );
				}
				else if (e instanceof RuntimeException) {
					throw getExceptionConverter().convert( (RuntimeException) e );
				}
				return CompletionStages.returnNullorRethrow( e );
			});
}
 
Example #5
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
private CompletionStage<Void> fireMerge(MergeContext copiedAlready, MergeEvent event) {
	pulseTransactionCoordinator();

	return fire(event, copiedAlready, EventType.MERGE,
			(ReactiveMergeEventListener l) -> l::reactiveOnMerge)
			.handle( (v,e) -> {
				delayedAfterCompletion();

				if (e instanceof ObjectDeletedException) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e ) );
				}
				else if (e instanceof MappingException) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
				}
				else if (e instanceof RuntimeException) {
					//including HibernateException
					throw getExceptionConverter().convert( (RuntimeException) e );
				}
				return CompletionStages.returnNullorRethrow( e );
			});

}
 
Example #6
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
private CompletionStage<Void> doFlush() {
	checkTransactionNeededForUpdateOperation( "no transaction is in progress" );
	pulseTransactionCoordinator();

	if ( getPersistenceContextInternal().getCascadeLevel() > 0 ) {
		throw new HibernateException( "Flush during cascade is dangerous" );
	}

	return fire(new FlushEvent( this ), EventType.FLUSH,
			(ReactiveFlushEventListener l) -> l::reactiveOnFlush)
			.handle( (v, e) -> {
				delayedAfterCompletion();

				if ( e instanceof RuntimeException ) {
					throw getExceptionConverter().convert( (RuntimeException) e );
				}
				return CompletionStages.returnNullorRethrow( e );
			} );
}
 
Example #7
Source File: EntityInsertAction.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 );
	}
}
 
Example #8
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
private CompletionStage<Void> fireRemove(DeleteEvent event) {
	pulseTransactionCoordinator();

	return fire(event, EventType.DELETE,
			(ReactiveDeleteEventListener l) -> l::reactiveOnDelete)
			.handle( (v, e) -> {
				delayedAfterCompletion();

				if ( e instanceof ObjectDeletedException ) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e ) );
				}
				else if ( e instanceof MappingException ) {
					throw getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );
				}
				else if ( e instanceof RuntimeException ) {
					//including HibernateException
					throw getExceptionConverter().convert( (RuntimeException) e );
				}
				return CompletionStages.returnNullorRethrow( e );
			});
}
 
Example #9
Source File: EntityIdentityInsertAction.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 );
	}
}
 
Example #10
Source File: EventListenerIntegrator.java    From gorm-hibernate5 with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example #11
Source File: LoadedConfig.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void addEventListeners(Map<EventType, Set<String>> eventListenerMap) {
	if ( eventListenerMap == null ) {
		return;
	}

	if ( this.eventListenerMap == null ) {
		this.eventListenerMap = new HashMap<EventType, Set<String>>();
	}

	for ( Map.Entry<EventType, Set<String>> incomingEntry : eventListenerMap.entrySet() ) {
		Set<String> listenerClasses = this.eventListenerMap.get( incomingEntry.getKey() );
		if ( listenerClasses == null ) {
			listenerClasses = new HashSet<String>();
			this.eventListenerMap.put( incomingEntry.getKey(), listenerClasses );
		}
		listenerClasses.addAll( incomingEntry.getValue() );
	}
}
 
Example #12
Source File: ReactiveIntegrator.java    From hibernate-reactive with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void attachEventContextManagingListenersIfRequired(SessionFactoryServiceRegistry serviceRegistry) {
	if ( ReactiveModeCheck.isReactiveRegistry( serviceRegistry ) ) {

		CoreLogging.messageLogger(ReactiveIntegrator.class).info("HRX000001: Hibernate Reactive Preview");

		EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
		eventListenerRegistry.addDuplicationStrategy( ReplacementDuplicationStrategy.INSTANCE );

		eventListenerRegistry.getEventListenerGroup( EventType.AUTO_FLUSH ).appendListener( new DefaultReactiveAutoFlushEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.FLUSH ).appendListener( new DefaultReactiveFlushEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.FLUSH_ENTITY ).appendListener( new DefaultReactiveFlushEntityEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.PERSIST ).appendListener( new DefaultReactivePersistEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.PERSIST_ONFLUSH ).appendListener( new DefaultReactivePersistOnFlushEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.MERGE ).appendListener( new DefaultReactiveMergeEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.DELETE ).appendListener( new DefaultReactiveDeleteEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.REFRESH ).appendListener( new DefaultReactiveRefreshEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.LOCK ).appendListener( new DefaultReactiveLockEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.LOAD ).appendListener( new DefaultReactiveLoadEventListener() );
		eventListenerRegistry.getEventListenerGroup( EventType.INIT_COLLECTION ).appendListener( new DefaultReactiveInitializeCollectionEventListener() );
	}
}
 
Example #13
Source File: TwoPhaseLoad.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 );
		}
	}
}
 
Example #14
Source File: EventListenerRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private <T> void prepareListeners(EventType<T> type, T defaultListener, EventListenerGroupImpl[] listenerArray) {
	final EventListenerGroupImpl<T> listenerGroup;
	if ( type == EventType.POST_COMMIT_DELETE
			|| type == EventType.POST_COMMIT_INSERT
			|| type == EventType.POST_COMMIT_UPDATE ) {
		listenerGroup = new PostCommitEventListenerGroupImpl<T>( type, this );
	}
	else {
		listenerGroup = new EventListenerGroupImpl<T>( type, this );
	}

	if ( defaultListener != null ) {
		listenerGroup.appendListener( defaultListener );
	}
	listenerArray[ type.ordinal() ] = listenerGroup;
}
 
Example #15
Source File: EntityUpdateAction.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 );
	}
}
 
Example #16
Source File: EventListenerGroupImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public EventListenerGroupImpl(EventType<T> eventType, EventListenerRegistryImpl listenerRegistry) {
	this.eventType = eventType;
	this.listenerRegistry = listenerRegistry;

	duplicationStrategies.add(
			// At minimum make sure we do not register the same exact listener class multiple times.
			new DuplicationStrategy() {
				@Override
				public boolean areMatch(Object listener, Object original) {
					return listener.getClass().equals( original.getClass() );
				}

				@Override
				public Action getAction() {
					return Action.ERROR;
				}
			}
	);
}
 
Example #17
Source File: EventListenerIntegrator.java    From gorm-hibernate5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected <T> void appendListeners(final EventListenerRegistry listenerRegistry,
                                   final EventType<T> eventType, final Map<String, Object> listeners) {

    Object listener = listeners.get(eventType.eventName());
    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
            listenerRegistry.setListeners(eventType, (T) listener);
        }
        else {
            listenerRegistry.appendListeners(eventType, (T)listener);
        }
    }
}
 
Example #18
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 ) );
		}
	}
}
 
Example #19
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean isDirty() throws HibernateException {
	checkOpen();
	checkTransactionSynchStatus();
	log.debug( "Checking session dirtiness" );
	if ( actionQueue.areInsertionsOrDeletionsQueued() ) {
		log.debug( "Session dirty (scheduled updates and insertions)" );
		return true;
	}
	DirtyCheckEvent event = new DirtyCheckEvent( this );
	for ( DirtyCheckEventListener listener : listeners( EventType.DIRTY_CHECK ) ) {
		listener.onDirtyCheck( event );
	}
	delayedAfterCompletion();
	return event.isDirty();
}
 
Example #20
Source File: AbstractFlushingEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 1. detect any dirty entities
 * 2. schedule any entity updates
 * 3. search out any reachable collections
 */
private int flushEntities(final FlushEvent event, final PersistenceContext persistenceContext) throws HibernateException {

	LOG.trace( "Flushing entities and processing referenced collections" );

	final EventSource source = event.getSession();
	final Iterable<FlushEntityEventListener> flushListeners = source.getFactory().getServiceRegistry()
			.getService( EventListenerRegistry.class )
			.getEventListenerGroup( EventType.FLUSH_ENTITY )
			.listeners();

	// Among other things, updateReachables() will recursively load all
	// collections that are moving roles. This might cause entities to
	// be loaded.

	// So this needs to be safe from concurrent modification problems.

	final Map.Entry<Object,EntityEntry>[] entityEntries = persistenceContext.reentrantSafeEntityEntries();
	final int count = entityEntries.length;

	for ( Map.Entry<Object,EntityEntry> me : entityEntries ) {

		// Update the status of the object and if necessary, schedule an update

		EntityEntry entry = me.getValue();
		Status status = entry.getStatus();

		if ( status != Status.LOADING && status != Status.GONE ) {
			final FlushEntityEvent entityEvent = new FlushEntityEvent( source, me.getKey(), entry );
			for ( FlushEntityEventListener listener : flushListeners ) {
				listener.onFlushEntity( entityEvent );
			}
		}
	}

	source.getActionQueue().sortActions();

	return count;
}
 
Example #21
Source File: EntityAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected <T> EventListenerGroup<T> listenerGroup(EventType<T> eventType) {
	return getSession()
			.getFactory()
			.getServiceRegistry()
			.getService( EventListenerRegistry.class )
			.getEventListenerGroup( eventType );
}
 
Example #22
Source File: EntityUpdateAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected boolean hasPostCommitEventListeners() {
	final EventListenerGroup<PostUpdateEventListener> group = listenerGroup( EventType.POST_COMMIT_UPDATE );
	for ( PostUpdateEventListener listener : group.listeners() ) {
		if ( listener.requiresPostCommitHandling( getPersister() ) ) {
			return true;
		}
	}

	return false;
}
 
Example #23
Source File: EntityInsertAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: StandardCacheEntryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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[] state = 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( state )
			.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, state );

	return state;
}
 
Example #25
Source File: JaccIntegrator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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() );
}
 
Example #26
Source File: EventListenerIntegrator.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Override
public void integrate(
    Metadata metadata,
    SessionFactoryImplementor sessionFactory,
    SessionFactoryServiceRegistry serviceRegistry) {

    final EventListenerRegistry eventListenerRegistry =
        serviceRegistry.getService(EventListenerRegistry.class);

    eventListenerRegistry.appendListeners(
        EventType.POST_LOAD,
        AuditLogPostLoadEventListener.INSTANCE
    );
}
 
Example #27
Source File: EntityInsertAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 );
		}
	}
}
 
Example #28
Source File: CollectionRemoveAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 );
	}
}
 
Example #29
Source File: EntityDeleteAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected boolean hasPostCommitEventListeners() {
	final EventListenerGroup<PostDeleteEventListener> group = listenerGroup( EventType.POST_COMMIT_DELETE );
	for ( PostDeleteEventListener listener : group.listeners() ) {
		if ( listener.requiresPostCommitHandling( getPersister() ) ) {
			return true;
		}
	}

	return false;
}
 
Example #30
Source File: ReactiveSessionImpl.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected CompletionStage<Void> reactiveAutoFlushIfRequired(Set<?> querySpaces) throws HibernateException {
		checkOpen();
//		if ( !isTransactionInProgress() ) {
			// do not auto-flush while outside a transaction
//			return CompletionStages.nullFuture();
//		}
		AutoFlushEvent event = new AutoFlushEvent( querySpaces, this );
		return fire( event, EventType.AUTO_FLUSH, (DefaultReactiveAutoFlushEventListener l) -> l::reactiveOnAutoFlush );
	}