private void onCollectionAction(AbstractCollectionEvent evt, IPersistentCollection newColl, object oldColl, CollectionEntry collectionEntry) { if (!VerCfg.GlobalCfg.GenerateRevisionsForCollections) { return; } var entityName = evt.GetAffectedOwnerEntityName(); if (!VerCfg.EntCfg.IsVersioned(entityName)) { return; } checkIfTransactionInProgress(evt.Session); var verSync = VerCfg.AuditProcessManager.Get(evt.Session); var ownerEntityName = ((AbstractCollectionPersister)collectionEntry.LoadedPersister).OwnerEntityName; var referencingPropertyName = collectionEntry.Role.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. var rd = getRelationDescriptionWithInheritedRelations(entityName, referencingPropertyName); if (rd?.MappedByPropertyName != null) { generateFakeBidirecationalRelationWorkUnits(verSync, newColl, oldColl, entityName, referencingPropertyName, evt, rd); } else { var workUnit = new PersistentCollectionChangeWorkUnit(evt.Session, entityName, VerCfg, newColl, collectionEntry, oldColl, evt.AffectedOwnerIdOrNull, referencingPropertyName); verSync.AddWorkUnit(workUnit); if (workUnit.ContainsWork()) { // There are some changes: a revision needs also be generated for the collection owner verSync.AddWorkUnit(new CollectionChangeWorkUnit(evt.Session, evt.GetAffectedOwnerEntityName(), referencingPropertyName, VerCfg, evt.AffectedOwnerIdOrNull, evt.AffectedOwnerOrNull)); generateBidirectionalCollectionChangeWorkUnits(verSync, evt, workUnit, rd); } } }
private void OnCollectionAction(AbstractCollectionEvent evt, IPersistentCollection newColl, object oldColl, CollectionEntry collectionEntry) { String entityName = evt.GetAffectedOwnerEntityName(); if (verCfg.EntCfg.IsVersioned(entityName)) { AuditSync verSync = verCfg.AuditSyncManager.get(evt.Session); String ownerEntityName = ((AbstractCollectionPersister)collectionEntry.LoadedPersister).OwnerEntityName; String referencingPropertyName = collectionEntry.Role.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. RelationDescription rd = verCfg.EntCfg[entityName].GetRelationDescription(referencingPropertyName); if (rd != null && rd.MappedByPropertyName != null) { GenerateFakeBidirecationalRelationWorkUnits(verSync, newColl, oldColl, entityName, referencingPropertyName, evt, rd); } else { PersistentCollectionChangeWorkUnit workUnit = new PersistentCollectionChangeWorkUnit(evt.Session, entityName, verCfg, newColl, collectionEntry, oldColl, evt.AffectedOwnerIdOrNull, referencingPropertyName); verSync.AddWorkUnit(workUnit); if (workUnit.ContainsWork()) { // There are some changes: a revision needs also be generated for the collection owner verSync.AddWorkUnit(new CollectionChangeWorkUnit(evt.Session, evt.GetAffectedOwnerEntityName(), verCfg, evt.AffectedOwnerIdOrNull, evt.AffectedOwnerOrNull)); GenerateBidirectionalCollectionChangeWorkUnits(verSync, evt, workUnit, rd); } } } }