Search in sources :

Example 1 with AuditProcess

use of org.hibernate.envers.internal.synchronization.AuditProcess in project hibernate-orm by hibernate.

the class EnversPostInsertEventListenerImpl method onPostInsert.

@Override
public void onPostInsert(PostInsertEvent event) {
    final String entityName = event.getPersister().getEntityName();
    if (getEnversService().getEntitiesConfigurations().isVersioned(entityName)) {
        checkIfTransactionInProgress(event.getSession());
        final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get(event.getSession());
        final AuditWorkUnit workUnit = new AddWorkUnit(event.getSession(), event.getPersister().getEntityName(), getEnversService(), event.getId(), event.getPersister(), event.getState());
        auditProcess.addWorkUnit(workUnit);
        if (workUnit.containsWork()) {
            generateBidirectionalCollectionChangeWorkUnits(auditProcess, event.getPersister(), entityName, event.getState(), null, event.getSession());
        }
    }
}
Also used : AuditProcess(org.hibernate.envers.internal.synchronization.AuditProcess) AuditWorkUnit(org.hibernate.envers.internal.synchronization.work.AuditWorkUnit) AddWorkUnit(org.hibernate.envers.internal.synchronization.work.AddWorkUnit)

Example 2 with AuditProcess

use of org.hibernate.envers.internal.synchronization.AuditProcess in project hibernate-orm by hibernate.

the class EnversPostUpdateEventListenerImpl method onPostUpdate.

@Override
public void onPostUpdate(PostUpdateEvent event) {
    final String entityName = event.getPersister().getEntityName();
    if (getEnversService().getEntitiesConfigurations().isVersioned(entityName)) {
        checkIfTransactionInProgress(event.getSession());
        final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get(event.getSession());
        Object[] oldState = getOldDBState(auditProcess, entityName, event);
        final Object[] newDbState = postUpdateDBState(event);
        final AuditWorkUnit workUnit = new ModWorkUnit(event.getSession(), event.getPersister().getEntityName(), getEnversService(), event.getId(), event.getPersister(), newDbState, oldState);
        auditProcess.addWorkUnit(workUnit);
        if (workUnit.containsWork()) {
            generateBidirectionalCollectionChangeWorkUnits(auditProcess, event.getPersister(), entityName, newDbState, oldState, event.getSession());
        }
    }
}
Also used : AuditProcess(org.hibernate.envers.internal.synchronization.AuditProcess) AuditWorkUnit(org.hibernate.envers.internal.synchronization.work.AuditWorkUnit) ModWorkUnit(org.hibernate.envers.internal.synchronization.work.ModWorkUnit)

Example 3 with AuditProcess

use of org.hibernate.envers.internal.synchronization.AuditProcess in project hibernate-orm by hibernate.

the class AuditReaderImpl method getCurrentRevision.

@Override
@SuppressWarnings({ "unchecked" })
public <T> T getCurrentRevision(Class<T> revisionEntityClass, boolean persist) {
    revisionEntityClass = getTargetClassIfProxied(revisionEntityClass);
    if (!(session instanceof EventSource)) {
        throw new IllegalArgumentException("The provided session is not an EventSource!");
    }
    // Obtaining the current audit sync
    final AuditProcess auditProcess = enversService.getAuditProcessManager().get((EventSource) session);
    // And getting the current revision data
    return (T) auditProcess.getCurrentRevisionData(session, persist);
}
Also used : EventSource(org.hibernate.event.spi.EventSource) AuditProcess(org.hibernate.envers.internal.synchronization.AuditProcess)

Example 4 with AuditProcess

use of org.hibernate.envers.internal.synchronization.AuditProcess in project hibernate-orm by hibernate.

the class EnversPostDeleteEventListenerImpl method onPostDelete.

@Override
public void onPostDelete(PostDeleteEvent event) {
    final String entityName = event.getPersister().getEntityName();
    if (getEnversService().getEntitiesConfigurations().isVersioned(entityName)) {
        checkIfTransactionInProgress(event.getSession());
        final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get(event.getSession());
        final AuditWorkUnit workUnit = new DelWorkUnit(event.getSession(), event.getPersister().getEntityName(), getEnversService(), event.getId(), event.getPersister(), event.getDeletedState());
        auditProcess.addWorkUnit(workUnit);
        if (workUnit.containsWork()) {
            generateBidirectionalCollectionChangeWorkUnits(auditProcess, event.getPersister(), entityName, null, event.getDeletedState(), event.getSession());
        }
    }
}
Also used : AuditProcess(org.hibernate.envers.internal.synchronization.AuditProcess) DelWorkUnit(org.hibernate.envers.internal.synchronization.work.DelWorkUnit) AuditWorkUnit(org.hibernate.envers.internal.synchronization.work.AuditWorkUnit)

Example 5 with AuditProcess

use of org.hibernate.envers.internal.synchronization.AuditProcess in project hibernate-orm by hibernate.

the class EnversPreUpdateEventListenerImpl method onPreUpdate.

@Override
public boolean onPreUpdate(PreUpdateEvent event) {
    final String entityName = event.getPersister().getEntityName();
    if (getEnversService().getEntitiesConfigurations().isVersioned(entityName)) {
        checkIfTransactionInProgress(event.getSession());
        if (isDetachedEntityUpdate(entityName, event.getOldState())) {
            final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get(event.getSession());
            auditProcess.cacheEntityState(event.getId(), entityName, event.getPersister().getDatabaseSnapshot(event.getId(), event.getSession()));
        }
    }
    return false;
}
Also used : AuditProcess(org.hibernate.envers.internal.synchronization.AuditProcess)

Aggregations

AuditProcess (org.hibernate.envers.internal.synchronization.AuditProcess)6 AuditWorkUnit (org.hibernate.envers.internal.synchronization.work.AuditWorkUnit)3 RelationDescription (org.hibernate.envers.internal.entities.RelationDescription)1 AddWorkUnit (org.hibernate.envers.internal.synchronization.work.AddWorkUnit)1 CollectionChangeWorkUnit (org.hibernate.envers.internal.synchronization.work.CollectionChangeWorkUnit)1 DelWorkUnit (org.hibernate.envers.internal.synchronization.work.DelWorkUnit)1 ModWorkUnit (org.hibernate.envers.internal.synchronization.work.ModWorkUnit)1 PersistentCollectionChangeWorkUnit (org.hibernate.envers.internal.synchronization.work.PersistentCollectionChangeWorkUnit)1 EventSource (org.hibernate.event.spi.EventSource)1 AbstractCollectionPersister (org.hibernate.persister.collection.AbstractCollectionPersister)1