org.hibernate.event.spi.PostInsertEvent Java Examples

The following examples show how to use org.hibernate.event.spi.PostInsertEvent. 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: 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 #2
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 #3
Source File: EntityCrudEventListener.java    From mojito with Apache License 2.0 6 votes vote down vote up
@Override
public void onPostInsert(PostInsertEvent event) {
    Repository repository = null;
    Object entity = event.getEntity();

    if (entity instanceof RepositoryLocale) {
        RepositoryLocale repositoryLocale = (RepositoryLocale) entity;
        repository = repositoryLocale.getRepository();
        logger.debug("Repository statistics is outdated because locale is added");
    } else if (entity instanceof TMTextUnitVariant) {
        TMTextUnitVariant tmTextUnitVariant = (TMTextUnitVariant) entity;
        TMTextUnit tmTextUnit = tmTextUnitVariant.getTmTextUnit();
        repository = tmTextUnit.getAsset().getRepository();
        logger.debug("Repository statistics is outdated because string/translation is added");
    }

    setRepositoryStatistisOutOfDate(repository);
}
 
Example #4
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 #5
Source File: EntityIdentityInsertAction.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(),
			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 );
		}
	}
}
 
Example #6
Source File: ClosureEventTriggeringInterceptor.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
public void onPostInsert(PostInsertEvent hibernateEvent) {
    Object entity = hibernateEvent.getEntity();
    org.grails.datastore.mapping.engine.event.PostInsertEvent grailsEvent = new org.grails.datastore.mapping.engine.event.PostInsertEvent(
            this.datastore, entity);
    activateDirtyChecking(entity);
    publishEvent(hibernateEvent, grailsEvent);
}
 
Example #7
Source File: DeletedObjectPostInsertEventListener.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onPostInsert( PostInsertEvent event )
{
    if ( IdentifiableObject.class.isInstance( event.getEntity() )
        && MetadataObject.class.isInstance( event.getEntity() )
        && !EmbeddedObject.class.isInstance( event.getEntity() ) )
    {
        StatelessSession session = event.getPersister().getFactory().openStatelessSession();
        session.beginTransaction();

        try
        {
            List<DeletedObject> deletedObjects = deletedObjectService
                .getDeletedObjects( new DeletedObjectQuery( (IdentifiableObject) event.getEntity() ) );

            deletedObjects.forEach( deletedObject -> session.delete( deletedObject ) );

            session.getTransaction().commit();
        }
        catch ( Exception ex )
        {
            log.error( "Failed to delete DeletedObject for:" + event.getEntity() );
            session.getTransaction().rollback();
        }
        finally
        {
            session.close();
        }
    }
}
 
Example #8
Source File: PostInsertAuditListener.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onPostInsert( PostInsertEvent postInsertEvent )
{
    Object entity = postInsertEvent.getEntity();

    getAuditable( entity, "create" ).ifPresent( auditable ->
        auditManager.send( Audit.builder()
            .auditType( getAuditType() )
            .auditScope( auditable.scope() )
            .createdAt( LocalDateTime.now() )
            .createdBy( getCreatedBy() )
            .object( entity )
            .auditableEntity( new AuditableEntity( entity ) )
            .build() ) );
}
 
Example #9
Source File: CollectionCacheInvalidator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onPostInsert(PostInsertEvent event) {
	evictCache( event.getEntity(), event.getPersister(), event.getSession(), null );
}
 
Example #10
Source File: PostInsertEventListenerStandardImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onPostInsert(PostInsertEvent event) {
	Object entity = event.getEntity();
	callbackRegistry.postCreate( entity );
}
 
Example #11
Source File: EntityCrudEventListener.java    From mojito with Apache License 2.0 4 votes vote down vote up
@Override
public void onPostInsertCommitFailed(PostInsertEvent pie) {
}
 
Example #12
Source File: DeletedObjectPostInsertEventListener.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onPostInsertCommitFailed( PostInsertEvent event )
{
    log.debug( "onPostInsertCommitFailed: " + event );
}
 
Example #13
Source File: PostInsertAuditListener.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onPostInsertCommitFailed( PostInsertEvent event )
{
    log.warn( "onPostInsertCommitFailed: " + event );
}