private void GenerateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, AbstractCollectionEvent evt, PersistentCollectionChangeWorkUnit workUnit, RelationDescription rd) { // Checking if this is enabled in configuration ... if (!verCfg.GlobalCfg.isGenerateRevisionsForCollections()) { return; } // Checking if this is not a bidirectional relation - then, a revision needs also be generated for // the other side of the relation. // relDesc can be null if this is a collection of simple values (not a relation). if (rd != null && rd.Bidirectional) { String relatedEntityName = rd.ToEntityName; IIdMapper relatedIdMapper = verCfg.EntCfg[relatedEntityName].GetIdMapper(); foreach (PersistentCollectionChangeData changeData in workUnit.getCollectionChanges()) { Object relatedObj = changeData.GetChangedElement(); object relatedId = relatedIdMapper.MapToIdFromEntity(relatedObj); verSync.AddWorkUnit(new CollectionChangeWorkUnit(evt.Session, relatedEntityName, verCfg, relatedId, relatedObj)); } } }
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); } } } }
private void generateBidirectionalCollectionChangeWorkUnits(AuditProcess auditProcess, AbstractCollectionEvent evt, PersistentCollectionChangeWorkUnit workUnit, RelationDescription rd) { // Checking if this is enabled in configuration ... if (!VerCfg.GlobalCfg.GenerateRevisionsForCollections) { return; } // Checking if this is not a bidirectional relation - then, a revision needs also be generated for // the other side of the relation. // relDesc can be null if this is a collection of simple values (not a relation). if (rd != null && rd.Bidirectional) { var relatedEntityName = rd.ToEntityName; var relatedIdMapper = VerCfg.EntCfg[relatedEntityName].IdMapper; foreach (var changeData in workUnit.CollectionChanges) { var relatedObj = changeData.GetChangedElement(); var relatedId = relatedIdMapper.MapToIdFromEntity(relatedObj); var toPropertyNames = VerCfg.EntCfg.ToPropertyNames(evt.GetAffectedOwnerEntityName(), rd.FromPropertyName, relatedEntityName); var toPropertyName = toPropertyNames.First(); auditProcess.AddWorkUnit(new CollectionChangeWorkUnit(evt.Session, evt.Session.BestGuessEntityName(relatedObj), toPropertyName, VerCfg, relatedId, relatedObj)); } } }