Beispiel #1
0
        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);
        }