protected IList <Object> CreateResult(IList <IObjRef> orisToGet, CacheDirective cacheDirective, bool checkVersion) { List <Object> result = new List <Object>(orisToGet.Count); bool returnMisses = cacheDirective.HasFlag(CacheDirective.ReturnMisses); for (int a = 0, size = orisToGet.Count; a < size; a++) { IObjRef oriToGet = orisToGet[a]; if (oriToGet == null) { if (returnMisses) { result.Add(null); } continue; } if (oriToGet is IDirectObjRef) { IDirectObjRef dori = (IDirectObjRef)oriToGet; Object entity = dori.Direct; if (entity != null) { result.Add(entity); continue; } } IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(oriToGet.RealType); Object cacheValue = GetCacheValue(metaData, oriToGet, checkVersion); if (cacheValue != null || returnMisses) { result.Add(cacheValue); } } return(result); }
protected virtual void RemoveUnpersistedDeletedObjectsFromCudResult(IList <IChangeContainer> allChanges, IList <Object> originalRefs, IList <Object> unpersistedObjectsToDelete) { ISet <IObjRef> removedDirectObjRefs = null; for (int a = allChanges.Count; a-- > 0;) { IChangeContainer changeContainer = allChanges[a]; IObjRef objRef = changeContainer.Reference; if (!(changeContainer is DeleteContainer) || objRef.Id != null) { continue; } if (removedDirectObjRefs == null) { removedDirectObjRefs = new IdentityHashSet <IObjRef>(); } IDirectObjRef dirObjRef = (IDirectObjRef)objRef; // These are objects without an id but are marked as deleted. They will be deleted locally without transfer to the service allChanges.RemoveAt(a); originalRefs.RemoveAt(a); unpersistedObjectsToDelete.Add(dirObjRef.Direct); removedDirectObjRefs.Add(dirObjRef); } if (removedDirectObjRefs == null) { return; } // Scan all other changeContainer if they refer to the removed DeleteContainers of unpersisted entities for (int a = allChanges.Count; a-- > 0;) { IChangeContainer changeContainer = allChanges[a]; IRelationUpdateItem[] relations; if (changeContainer is CreateContainer) { relations = ((CreateContainer)changeContainer).Relations; } else if (changeContainer is UpdateContainer) { relations = ((UpdateContainer)changeContainer).Relations; } else { // DeleteContainers can not refer anything beside themselves continue; } if (relations == null) { continue; } for (int b = relations.Length; b-- > 0;) { IRelationUpdateItem childItem = relations[b]; IObjRef[] addedOris = childItem.AddedORIs; if (addedOris == null) { continue; } for (int c = addedOris.Length; c-- > 0;) { IObjRef addedOri = addedOris[c]; if (!removedDirectObjRefs.Contains(addedOri)) { continue; } if (addedOris.Length == 1) { if (childItem.RemovedORIs != null) { ((RelationUpdateItem)childItem).AddedORIs = null; } else { if (relations.Length == 1) { allChanges.RemoveAt(a); originalRefs.RemoveAt(a); relations = null; break; } IRelationUpdateItem[] newChildItems = new IRelationUpdateItem[relations.Length - 1]; Array.Copy(relations, 0, newChildItems, 0, b); Array.Copy(relations, b + 1, newChildItems, b, relations.Length - b - 1); relations = newChildItems; if (changeContainer is CreateContainer) { ((CreateContainer)changeContainer).Relations = relations; } else { ((UpdateContainer)changeContainer).Relations = relations; } } break; } IObjRef[] newAddedOris = new IObjRef[addedOris.Length - 1]; Array.Copy(addedOris, 0, newAddedOris, 0, c); Array.Copy(addedOris, c + 1, newAddedOris, c, addedOris.Length - c - 1); addedOris = newAddedOris; ((RelationUpdateItem)childItem).AddedORIs = addedOris; } if (relations == null) { break; } } } }