public void AddToManyNotOwningRelation(string fromPropertyName, string mappedByPropertyName, string toEntityName,
                                        IIdMapper idMapper, IPropertyMapper fakeBidirectionalRelationMapper,
                                        IPropertyMapper fakeBidirectionalRelationIndexMapper)
 {
     relations.Add(fromPropertyName, RelationDescription.ToMany(fromPropertyName, RelationType.ToManyNotOwning,
                                                                toEntityName, mappedByPropertyName, idMapper, fakeBidirectionalRelationMapper,
                                                                fakeBidirectionalRelationIndexMapper, true));
 }
        public FakeBidirectionalRelationWorkUnit(ISessionImplementor sessionImplementor, String entityName,
            AuditConfiguration verCfg, Object id,
            String referencingPropertyName, Object owningEntity,
            RelationDescription rd, RevisionType revisionType,
            Object index,
            IAuditWorkUnit nestedWorkUnit)
            : base(sessionImplementor, entityName, verCfg, id)
        {
            this.nestedWorkUnit = nestedWorkUnit;

            // Adding the change for the relation.
            fakeRelationChanges = new Dictionary<String, FakeRelationChange>();
            fakeRelationChanges.Add(referencingPropertyName, new FakeRelationChange(owningEntity, rd, revisionType, index));
        }
Beispiel #3
0
        public RelationDescription GetRelationDescription(String entityName, String propertyName)
        {
            EntityConfiguration entCfg  = entitiesConfigurations[entityName];
            RelationDescription relDesc = entCfg.GetRelationDescription(propertyName);

            if (relDesc != null)
            {
                return(relDesc);
            }
            else if (entCfg.ParentEntityName != null)
            {
                // The field may be declared in a superclass ...
                return(GetRelationDescription(entCfg.ParentEntityName, propertyName));
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        private void GenerateFakeBidirecationalRelationWorkUnits(AuditProcess auditProcess,
																IPersistentCollection newColl,
																object oldColl,
																string collectionEntityName,
																string referencingPropertyName,
																AbstractCollectionEvent evt,
																RelationDescription rd)
        {
            // First computing the relation changes
            var collectionChanges = VerCfg.EntCfg[collectionEntityName].PropertyMapper
                    .MapCollectionChanges(referencingPropertyName, newColl, oldColl, evt.AffectedOwnerIdOrNull);

            // Getting the id mapper for the related entity, as the work units generated will corrspond to the related
            // entities.
            var relatedEntityName = rd.ToEntityName;
            var relatedIdMapper = VerCfg.EntCfg[relatedEntityName].IdMapper;

            // For each collection change, generating the bidirectional work unit.
            foreach (var changeData in collectionChanges)
            {
                var relatedObj = changeData.GetChangedElement();
                var relatedId = relatedIdMapper.MapToIdFromEntity(relatedObj);
                var revType = (RevisionType)changeData.Data[VerCfg.AuditEntCfg.RevisionTypePropName];

                // This can be different from relatedEntityName, in case of inheritance (the real entity may be a subclass
                // of relatedEntityName).
                var realRelatedEntityName = evt.Session.BestGuessEntityName(relatedObj);

                // By default, the nested work unit is a collection change work unit.
                var nestedWorkUnit = new CollectionChangeWorkUnit(evt.Session, realRelatedEntityName, VerCfg,
                        relatedId, relatedObj);

                auditProcess.AddWorkUnit(new FakeBidirectionalRelationWorkUnit(evt.Session, realRelatedEntityName, VerCfg,
                        relatedId, referencingPropertyName, evt.AffectedOwnerOrNull, rd, revType,
                        changeData.GetChangedElementIndex(), nestedWorkUnit));
            }

            // We also have to generate a collection change work unit for the owning entity.
            auditProcess.AddWorkUnit(new CollectionChangeWorkUnit(evt.Session, collectionEntityName, VerCfg,
                    evt.AffectedOwnerIdOrNull, evt.AffectedOwnerOrNull));
        }
Beispiel #5
0
        private void GenerateBidirectionalCollectionChangeWorkUnits(AuditProcess auditProcess,
																	IDatabaseEventArgs 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);

                    auditProcess.AddWorkUnit(new CollectionChangeWorkUnit(evt.Session,
                                                                                            evt.Session.BestGuessEntityName(relatedObj),
                                                                                            VerCfg,
                                                                                            relatedId,
                                                                                            relatedObj));
                }
            }
        }
            public FakeRelationChange(object owningEntity, RelationDescription rd, RevisionType revisionType,
									  object index)
            {
                this.owningEntity = owningEntity;
                this.rd = rd;
                this.revisionType = revisionType;
                this.index = index;
            }
 public void AddToManyMiddleNotOwningRelation(string fromPropertyName, string mappedByPropertyName, string toEntityName)
 {
     relations.Add(fromPropertyName, RelationDescription.ToMany(fromPropertyName, RelationType.ToManyMiddleNotOwning,
                                                                toEntityName, mappedByPropertyName, null, null, null, true));
 }
 public void AddToOneNotOwningRelation(string fromPropertyName, string mappedByPropertyName, string toEntityName,
                                       IIdMapper idMapper, bool ignoreNotFound)
 {
     relations.Add(fromPropertyName, RelationDescription.ToOne(fromPropertyName, RelationType.ToOneNotOwning,
                                                               toEntityName, mappedByPropertyName, idMapper, null, null, true, ignoreNotFound));
 }
 public void AddToOneRelation(string fromPropertyName, string toEntityName, IIdMapper idMapper, bool insertable, bool ignoreNotFound)
 {
     relations.Add(fromPropertyName, RelationDescription.ToOne(fromPropertyName, RelationType.ToOne,
                                                               toEntityName, null, idMapper, null, null, insertable, ignoreNotFound));
 }
        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));
                }
            }
        }