public void UnionCachePath(AppendableCachePath cachePath, AppendableCachePath other) { CHashSet <AppendableCachePath> otherChildren = other.children; if (otherChildren == null) { // fast case 1 return; } CHashSet <AppendableCachePath> children = cachePath.children; if (children == null) { // fast case 2 cachePath.children = otherChildren; return; } foreach (AppendableCachePath otherCachePath in otherChildren) { if (children.Add(otherCachePath)) { continue; } UnionCachePath(children.Get(otherCachePath), otherCachePath); } }
public void BuildCachePath(Type entityType, String memberToInitialize, CHashSet <AppendableCachePath> cachePaths) { Type currentType = entityType; String requestedMemberName = memberToInitialize; AppendableCachePath currentCachePath = null; CHashSet <AppendableCachePath> currentCachePaths = cachePaths; while (true) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(currentType); Member widenedMember = metaData.GetWidenedMatchingMember(requestedMemberName); if (widenedMember == null) { throw new ArgumentException("No member found to resolve path " + entityType.FullName + "." + memberToInitialize); } String widenedMemberName = widenedMember.Name; if (widenedMember is PrimitiveMember) { if (widenedMemberName.Equals(memberToInitialize)) { // this member does not need to be prefetched return; } // widened member has been found but not the full path of the requested member name throw new ArgumentException("No member found to resolve path " + entityType.FullName + "." + memberToInitialize); } AppendableCachePath childCachePath = null; if (currentCachePaths == null) { currentCachePaths = new CHashSet <AppendableCachePath>(); currentCachePath.children = currentCachePaths; } foreach (AppendableCachePath cachePath in currentCachePaths) { if (widenedMemberName.Equals(cachePath.memberName)) { childCachePath = cachePath; break; } } if (childCachePath == null) { int relationIndex = metaData.GetIndexByRelation(widenedMember); childCachePath = new AppendableCachePath(widenedMember.ElementType, relationIndex, widenedMemberName); currentCachePaths.Add(childCachePath); } if (widenedMemberName.Equals(requestedMemberName)) { // we have travered the full path of the requested member name return; } requestedMemberName = requestedMemberName.Substring(widenedMemberName.Length + 1); currentCachePath = childCachePath; currentType = currentCachePath.memberType; currentCachePaths = currentCachePath.children; } }
public IPrefetchHandle Union(IPrefetchHandle otherPrefetchHandle) { if (otherPrefetchHandle == null) { return(this); } LinkedHashMap <Type, CHashSet <AppendableCachePath> > newMap = LinkedHashMap <Type, CHashSet <AppendableCachePath> > .Create(entityTypeToPrefetchSteps.Count); foreach (Entry <Type, PrefetchPath[]> entry in entityTypeToPrefetchSteps) { CHashSet <AppendableCachePath> prefetchPaths = newMap.Get(entry.Key); if (prefetchPaths == null) { prefetchPaths = new CHashSet <AppendableCachePath>(); newMap.Put(entry.Key, prefetchPaths); } foreach (PrefetchPath cachePath in entry.Value) { prefetchPaths.Add(cachePathHelper.CopyCachePathToAppendable(cachePath)); } } foreach (Entry <Type, PrefetchPath[]> entry in ((PrefetchHandle)otherPrefetchHandle).entityTypeToPrefetchSteps) { CHashSet <AppendableCachePath> prefetchPaths = newMap.Get(entry.Key); if (prefetchPaths == null) { prefetchPaths = new CHashSet <AppendableCachePath>(); newMap.Put(entry.Key, prefetchPaths); } foreach (PrefetchPath cachePath in entry.Value) { AppendableCachePath clonedCachePath = cachePathHelper.CopyCachePathToAppendable(cachePath); if (prefetchPaths.Add(clonedCachePath)) { continue; } AppendableCachePath existingCachePath = prefetchPaths.Get(clonedCachePath); cachePathHelper.UnionCachePath(existingCachePath, clonedCachePath); } } LinkedHashMap <Type, PrefetchPath[]> targetMap = LinkedHashMap <Type, PrefetchPath[]> .Create(newMap.Count); foreach (Entry <Type, CHashSet <AppendableCachePath> > entry in newMap) { PrefetchPath[] cachePaths = cachePathHelper.CopyAppendableToCachePath(entry.Value); targetMap.Put(entry.Key, cachePaths); } return(new PrefetchHandle(targetMap, cachePathHelper)); }
public PrefetchPath CopyAppendableToCachePath(AppendableCachePath cachePath) { PrefetchPath[] clonedChildren = CopyAppendableToCachePath(cachePath.children); if (clonedChildren == null) { return(new PrefetchPath(cachePath.memberType, cachePath.memberIndex, cachePath.memberName, clonedChildren, new Type[0])); } CHashSet <Type> memberTypesOnDescendants = new CHashSet <Type>(); foreach (PrefetchPath clonedChild in clonedChildren) { memberTypesOnDescendants.Add(clonedChild.memberType); memberTypesOnDescendants.AddAll(clonedChild.memberTypesOnDescendants); } return(new PrefetchPath(cachePath.memberType, cachePath.memberIndex, cachePath.memberName, clonedChildren, memberTypesOnDescendants.ToArray())); }
public AppendableCachePath CopyCachePathToAppendable(PrefetchPath cachePath) { PrefetchPath[] children = cachePath.children; CHashSet <AppendableCachePath> clonedChildren = null; if (children != null) { clonedChildren = CHashSet <AppendableCachePath> .Create(children.Length); for (int a = children.Length; a-- > 0;) { clonedChildren.Add(CopyCachePathToAppendable(children[a])); } } AppendableCachePath clonedCachePath = new AppendableCachePath(cachePath.memberType, cachePath.memberIndex, cachePath.memberName); clonedCachePath.children = clonedChildren; return(clonedCachePath); }