Search in sources :

Example 6 with AuditProcess

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

the class BaseEnversCollectionEventListener method onCollectionAction.

protected final void onCollectionAction(AbstractCollectionEvent event, PersistentCollection newColl, Serializable oldColl, CollectionEntry collectionEntry) {
    if (shouldGenerateRevision(event)) {
        checkIfTransactionInProgress(event.getSession());
        final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get(event.getSession());
        final String entityName = event.getAffectedOwnerEntityName();
        final String ownerEntityName = ((AbstractCollectionPersister) collectionEntry.getLoadedPersister()).getOwnerEntityName();
        final String referencingPropertyName = collectionEntry.getRole().substring(ownerEntityName.length() + 1);
        // Checking if this is not a "fake" many-to-one bidirectional relation. The relation description may be
        // null in case of collections of non-entities.
        final RelationDescription rd = searchForRelationDescription(entityName, referencingPropertyName);
        if (rd != null && rd.getMappedByPropertyName() != null) {
            generateFakeBidirecationalRelationWorkUnits(auditProcess, newColl, oldColl, entityName, referencingPropertyName, event, rd);
        } else {
            final PersistentCollectionChangeWorkUnit workUnit = new PersistentCollectionChangeWorkUnit(event.getSession(), entityName, getEnversService(), newColl, collectionEntry, oldColl, event.getAffectedOwnerIdOrNull(), referencingPropertyName);
            auditProcess.addWorkUnit(workUnit);
            if (workUnit.containsWork()) {
                // There are some changes: a revision needs also be generated for the collection owner
                auditProcess.addWorkUnit(new CollectionChangeWorkUnit(event.getSession(), event.getAffectedOwnerEntityName(), referencingPropertyName, getEnversService(), event.getAffectedOwnerIdOrNull(), event.getAffectedOwnerOrNull()));
                generateBidirectionalCollectionChangeWorkUnits(auditProcess, event, workUnit, rd);
            }
        }
    }
}
Also used : AuditProcess(org.hibernate.envers.internal.synchronization.AuditProcess) RelationDescription(org.hibernate.envers.internal.entities.RelationDescription) PersistentCollectionChangeWorkUnit(org.hibernate.envers.internal.synchronization.work.PersistentCollectionChangeWorkUnit) AbstractCollectionPersister(org.hibernate.persister.collection.AbstractCollectionPersister) CollectionChangeWorkUnit(org.hibernate.envers.internal.synchronization.work.CollectionChangeWorkUnit) PersistentCollectionChangeWorkUnit(org.hibernate.envers.internal.synchronization.work.PersistentCollectionChangeWorkUnit)

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