HHH-5580 - Handle PersistentCollectionChangeWorkUnit

This commit is contained in:
Lukasz Antoniak 2011-05-08 00:40:14 +02:00
parent d1e092b471
commit 2ba3cc6dab
2 changed files with 13 additions and 6 deletions

View File

@ -33,6 +33,7 @@ import org.hibernate.envers.synchronization.work.PersistentCollectionChangeWorkU
import org.hibernate.envers.tools.Pair;
import org.hibernate.persister.entity.EntityPersister;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
@ -113,10 +114,12 @@ public class AuditProcess implements BeforeTransactionCompletionProcess {
while ((vwu = workUnits.poll()) != null) {
vwu.perform(session, revisionData);
if (!(vwu instanceof PersistentCollectionChangeWorkUnit)) {
Class entityClass = getEntityClass(this.session, session, vwu.getEntityName());
revisionInfoGenerator.entityChanged(entityClass, vwu.getEntityName(), vwu.getEntityId(), vwu.getRevisionType(), currentRevisionData);
Serializable entityId = vwu.getEntityId();
if (entityId instanceof PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) {
entityId = ((PersistentCollectionChangeWorkUnit.PersistentCollectionChangeWorkUnitId) entityId).getOwnerId();
}
Class entityClass = getEntityClass(this.session, session, vwu.getEntityName());
revisionInfoGenerator.entityChanged(entityClass, vwu.getEntityName(), entityId, vwu.getRevisionType(), currentRevisionData);
}
}

View File

@ -45,7 +45,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
AuditConfiguration auditCfg, PersistentCollection collection,
CollectionEntry collectionEntry, Serializable snapshot, Serializable id,
String referencingPropertyName) {
super(sessionImplementor, entityName, auditCfg, new PersistentCollectionChangeWorkUnitId(id, collectionEntry.getRole()), null);
super(sessionImplementor, entityName, auditCfg, new PersistentCollectionChangeWorkUnitId(id, collectionEntry.getRole()), RevisionType.MOD);
this.referencingPropertyName = referencingPropertyName;
@ -57,7 +57,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
AuditConfiguration verCfg, Serializable id,
List<PersistentCollectionChangeData> collectionChanges,
String referencingPropertyName) {
super(sessionImplementor, entityName, verCfg, id, null);
super(sessionImplementor, entityName, verCfg, id, RevisionType.MOD);
this.collectionChanges = collectionChanges;
this.referencingPropertyName = referencingPropertyName;
@ -169,7 +169,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
* the entity plus the name of the field (the role). This is needed because such collections aren't entities
* in the "normal" mapping, but they are entities for Envers.
*/
private static class PersistentCollectionChangeWorkUnitId implements Serializable {
public static class PersistentCollectionChangeWorkUnitId implements Serializable {
private static final long serialVersionUID = -8007831518629167537L;
private final Serializable ownerId;
@ -200,5 +200,9 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
result = 31 * result + (role != null ? role.hashCode() : 0);
return result;
}
public Serializable getOwnerId() {
return ownerId;
}
}
}