protected void ReallocateObjRefsAndCacheValues(CacheWalkerResult entry, IObjRef[] objRefs, HashMap <IObjRef, int?> allObjRefs) { IObjRef[] oldObjRefs = entry.objRefs; Object[] oldCacheValues = entry.cacheValues; Object[] newCacheValues = new Object[objRefs.Length]; for (int oldIndex = oldObjRefs.Length; oldIndex-- > 0;) { IObjRef oldObjRef = oldObjRefs[oldIndex]; int? newIndex = allObjRefs.Get(oldObjRef); newCacheValues[newIndex.Value] = oldCacheValues[oldIndex]; } entry.cacheValues = newCacheValues; entry.objRefs = objRefs; entry.UpdatePendingChanges(); Object childEntries = entry.childEntries; if (childEntries == null) { return; } if (childEntries.GetType().IsArray) { foreach (CacheWalkerResult childEntry in (CacheWalkerResult[])childEntries) { ReallocateObjRefsAndCacheValues(childEntry, objRefs, allObjRefs); } } else { ReallocateObjRefsAndCacheValues((CacheWalkerResult)childEntries, objRefs, allObjRefs); } }
protected void CollectAllObjRefs(CacheWalkerResult entry, HashMap <IObjRef, int?> allObjRefs) { foreach (IObjRef objRef in entry.objRefs) { allObjRefs.PutIfNotExists(objRef, null); } Object childEntries = entry.childEntries; if (childEntries == null) { return; } if (childEntries.GetType().IsArray) { foreach (CacheWalkerResult childEntry in (CacheWalkerResult[])childEntries) { CollectAllObjRefs(childEntry, allObjRefs); } } else { CollectAllObjRefs((CacheWalkerResult)childEntries, allObjRefs); } }
protected ICacheWalkerResult WalkIntern(IObjRef[] objRefs, IdentityHashSet <ICache> allCachesSet) { IdentityHashMap <ICache, List <ICache> > cacheToChildCaches = new IdentityHashMap <ICache, List <ICache> >(); IdentityHashMap <ICache, ICache> cacheToProxyCache = new IdentityHashMap <ICache, ICache>(); ICache currentCommittedRootCache = CommittedRootCache.CurrentCache; if (!CacheProvider.IsNewInstanceOnCall) { allCachesSet.Add(FirstLevelCache.CurrentCache); } ICache[] allChildCaches = allCachesSet.ToArray(); allCachesSet.Add(currentCommittedRootCache); foreach (ICache childCache in allChildCaches) { ICache child = childCache; ICache parent = ((ChildCache)child).Parent; while (parent != null) { ICache currentParent = parent.CurrentCache; if (!allCachesSet.Add(currentParent)) { // skip this cache. we handled it already break; } CheckParentCache(parent, currentParent, child, cacheToChildCaches, cacheToProxyCache); parent = ((IRootCache)currentParent).Parent; child = currentParent; } CheckParentCache(CommittedRootCache, currentCommittedRootCache, child, cacheToChildCaches, cacheToProxyCache); } if (objRefs != allEntityRefs) { objRefs = new CHashSet <IObjRef>(objRefs).ToArray(); Array.Sort(objRefs, ObjRef.comparator); } CacheWalkerResult rootEntry = BuildWalkedEntry(currentCommittedRootCache, objRefs, cacheToChildCaches, cacheToProxyCache); if (objRefs == allEntityRefs) { HashMap <IObjRef, int?> allObjRefs = new HashMap <IObjRef, int?>(); CollectAllObjRefs(rootEntry, allObjRefs); objRefs = allObjRefs.Count > 0 ? ListUtil.ToArray(allObjRefs.KeyList()) : ObjRef.EMPTY_ARRAY; Array.Sort(objRefs, ObjRef.comparator); for (int a = objRefs.Length; a-- > 0;) { allObjRefs.Put(objRefs[a], a); } ReallocateObjRefsAndCacheValues(rootEntry, objRefs, allObjRefs); } return(rootEntry); }
protected CacheWalkerResult BuildWalkedEntry(ICache cache, IObjRef[] objRefs, IdentityHashMap <ICache, List <ICache> > cacheToChildCaches, IdentityHashMap <ICache, ICache> cacheToProxyCache) { List <ICache> childCaches = cacheToChildCaches.Get(cache); CacheWalkerResult[] childCacheEntries; if (childCaches == null) { childCacheEntries = null; } else { childCacheEntries = new CacheWalkerResult[childCaches.Count]; for (int a = childCaches.Count; a-- > 0;) { childCacheEntries[a] = BuildWalkedEntry(childCaches[a], objRefs, cacheToChildCaches, cacheToProxyCache); } } ICache proxyCache = cacheToProxyCache.Get(cache); bool transactional = false, threadLocal = false; if (proxyCache != null) { threadLocal = true; if (TransactionState != null && TransactionState.IsTransactionActive) { transactional = true; } } IList <Object> cacheValues; if (objRefs != allEntityRefs) { if (cache is ChildCache) { cacheValues = cache.GetObjects(objRefs, CacheDirective.FailEarly | CacheDirective.ReturnMisses); } else { cacheValues = cache.GetObjects(objRefs, CacheDirective.FailEarly | CacheDirective.CacheValueResult | CacheDirective.ReturnMisses); } } else { IdentityHashSet <Object> fCacheValues = new IdentityHashSet <Object>(); cache.GetContent(new HandleContentDelegate(delegate(Type entityType, sbyte idIndex, Object id, Object value) { fCacheValues.Add(value); })); cacheValues = fCacheValues.ToList(); // generate ad-hoc objRefs objRefs = cacheValues.Count > 0 ? ListUtil.ToArray(ObjRefHelper.ExtractObjRefList(cacheValues, null)) : ObjRef.EMPTY_ARRAY; } Object childEntries = childCacheEntries; if (childCacheEntries != null && childCacheEntries.Length == 1) { childEntries = childCacheEntries[0]; } CacheWalkerResult parentEntry = new CacheWalkerResult(cache, transactional, threadLocal, objRefs, ListUtil.ToArray(cacheValues), childEntries); if (childCacheEntries != null) { for (int a = childCacheEntries.Length; a-- > 0;) { childCacheEntries[a].ParentEntry = parentEntry; } } if (objRefs != allEntityRefs) { parentEntry.UpdatePendingChanges(); } return(parentEntry); }
protected void ToStringIntern(StringBuilder sb, IPrintable preSpace, bool?entityDescriptionAtRoot) { Object[] cacheValues = this.cacheValues; if (entityDescriptionAtRoot == null) { IObjRef[] objRefs = this.objRefs; for (int a = 0, size = objRefs.Length; a < size; a++) { IObjRef objRef = objRefs[a]; sb.Append(pipe).Append(' ').Append(a + 1); sb.Append(". Type=").Append(objRef.RealType.Name); sb.Append(" Id("); if (objRef.IdNameIndex == ObjRef.PRIMARY_KEY_INDEX) { sb.Append("PK"); } else { sb.Append("AK-").Append(objRef.IdNameIndex); } sb.Append(")=").Append(objRef.Id); entityDescriptionAtRoot = true; preSpace.ToString(sb); } } sb.Append(pipe).Append(" Cache"); bool firstSuffix = true; if (!privileged) { firstSuffix = AppendSuffix("SEC", firstSuffix, sb); } if (transactional) { firstSuffix = AppendSuffix("TX", firstSuffix, sb); } if (threadLocal) { firstSuffix = AppendSuffix("L", firstSuffix, sb); } if (parentEntry == null) { firstSuffix = AppendSuffix("G", firstSuffix, sb); } sb.Append("--#0x").Append(ToHexString(cache)); IPrintable oldPreSpace = preSpace; preSpace = new PrintableDelegateWrapper(new PrintableDelegate(delegate(StringBuilder sb2) { oldPreSpace.ToString(sb2); sb2.Append('\t'); })); IPrintable preSpaceForCacheValue; if (childEntries == null) { preSpaceForCacheValue = new PrintableDelegateWrapper(new PrintableDelegate(delegate(StringBuilder sb2) { preSpace.ToString(sb2); sb2.Append(" "); })); } else { preSpaceForCacheValue = new PrintableDelegateWrapper(new PrintableDelegate(delegate(StringBuilder sb2) { preSpace.ToString(sb2); sb2.Append("| "); })); } for (int a = 0, size = cacheValues.Length; a < size; a++) { preSpaceForCacheValue.ToString(sb); sb.Append(a + 1).Append('.'); Object cacheValue = cacheValues[a]; if (cacheValue == null) { sb.Append(" n/a"); continue; } IEntityMetaData metaData = ((IEntityMetaDataHolder)cacheValue).Get__EntityMetaData(); Object id, version = null; bool hasVersion = metaData.VersionMember != null; bool hasPendingChanges = false; if (cacheValue is AbstractCacheValue) { AbstractCacheValue cacheValueCasted = (AbstractCacheValue)cacheValue; id = cacheValueCasted.Id; if (hasVersion) { version = cacheValueCasted.Version; } } else { id = metaData.IdMember.GetValue(cacheValue); if (hasVersion) { version = metaData.VersionMember.GetValue(cacheValue); } hasPendingChanges = this.pendingChanges != null && this.pendingChanges[a]; } if (!entityDescriptionAtRoot.HasValue || !entityDescriptionAtRoot.Value) { sb.Append(" Type=").Append(metaData.EntityType.Name); sb.Append(" Id=").Append(id); } if (hasVersion) { sb.Append(" Version=").Append(version); } if (hasPendingChanges) { sb.Append(" (m)"); } } if (this.childEntries is CacheWalkerResult[]) { CacheWalkerResult[] childEntries2 = (CacheWalkerResult[])this.childEntries; for (int a = 0, size = childEntries2.Length; a < size; a++) { bool hasSuccessor = a < size - 1; CacheWalkerResult entry = childEntries2[a]; IPrintable preSpaceForChildEntry = new PrintableDelegateWrapper(new PrintableDelegate(delegate(StringBuilder sb2) { preSpace.ToString(sb2); if (hasSuccessor) { sb2.Append("|"); } })); preSpace.ToString(sb); entry.ToStringIntern(sb, preSpaceForChildEntry, entityDescriptionAtRoot); } } else if (this.childEntries != null) { CacheWalkerResult entry = (CacheWalkerResult)this.childEntries; preSpace.ToString(sb); entry.ToStringIntern(sb, preSpace, entityDescriptionAtRoot); } }