示例#1
0
        public IList <IObjRelationResult> GetRelations(IList <IObjRelation> objRelations)
        {
            IList <IObjRelation> orelToLoadWithVersion = new List <IObjRelation>();
            IList <IObjRelation> missedOrels           = new List <IObjRelation>();

            for (int i = objRelations.Count; i-- > 0;)
            {
                IObjRelation orel = objRelations[i];
                if (orel.Version != null)
                {
                    orelToLoadWithVersion.Add(orel);
                }
                else
                {
                    missedOrels.Add(orel);
                }
            }
            IList <IObjRelationResult> relationResults = CommittedRootCache.GetObjRelations(orelToLoadWithVersion, committedRootCacheCD);
            List <IObjRelationResult>  result          = new List <IObjRelationResult>();

            for (int a = relationResults.Count; a-- > 0;)
            {
                IObjRelationResult relationResult = relationResults[a];
                if (relationResult == null)
                {
                    missedOrels.Add(orelToLoadWithVersion[a]);
                }
                else
                {
                    result.Add(relationResult);
                }
            }
            if (missedOrels.Count > 0)
            {
                IList <IObjRelationResult> uncommittedRelationResult = UncommittedCacheRetriever.GetRelations(missedOrels);
                result.AddRange(uncommittedRelationResult);
            }
            return(result);
        }
示例#2
0
        protected void ChangeSecondLevelCacheIntern(CacheDependencyNode node, CacheDirective cacheDirective)
        {
            IRootCache rootCache = node.rootCache;
            HashMap <IObjRef, CacheValueAndPrivilege> objRefToLoadContainerDict = node.objRefToCacheValueMap;
            CHashSet <IObjRef> objRefsToLoad = new CHashSet <IObjRef>(node.objRefsToLoad);

            if (node.cacheChangeItems != null)
            {
                foreach (CacheChangeItem cci in node.cacheChangeItems)
                {
                    if (cci == null)
                    {
                        continue;
                    }
                    objRefsToLoad.AddAll(cci.UpdatedObjRefs);
                }
            }
            IList <IObjRef> objRefs       = objRefsToLoad.ToList();
            IList <Object>  refreshResult = rootCache.GetObjects(objRefs, cacheDirective);

            IPrivilege[] privileges = null;
            if (SecurityActivation != null && PrivilegeProvider != null && SecurityActivation.FilterActivated)
            {
                privileges = PrivilegeProvider.GetPrivilegesByObjRef(objRefs).GetPrivileges();
            }
            for (int a = refreshResult.Count; a-- > 0;)
            {
                RootCacheValue cacheValue = (RootCacheValue)refreshResult[a];
                if (cacheValue == null)
                {
                    continue;
                }
                objRefToLoadContainerDict.Put(objRefs[a], new CacheValueAndPrivilege(cacheValue, privileges != null ? privileges[a] : null));
            }
            CheckCascadeRefreshNeeded(node);

            CHashSet <IObjRef>      cascadeRefreshObjRefsSet      = node.cascadeRefreshObjRefsSet;
            CHashSet <IObjRelation> cascadeRefreshObjRelationsSet = node.cascadeRefreshObjRelationsSet;

            if (cascadeRefreshObjRelationsSet.Count > 0)
            {
                IList <IObjRelationResult> relationsResult = rootCache.GetObjRelations(cascadeRefreshObjRelationsSet.ToList(), cacheDirective);
                for (int a = relationsResult.Count; a-- > 0;)
                {
                    IObjRelationResult relationResult = relationsResult[a];
                    cascadeRefreshObjRefsSet.AddAll(relationResult.Relations);
                }
                // apply gathered information of unknown relations to the rootCache
                rootCache.Put(relationsResult);
            }
            if (cascadeRefreshObjRefsSet.Count > 0)
            {
                IList <IObjRef> cascadeRefreshObjRefsSetList = cascadeRefreshObjRefsSet.ToList();
                refreshResult = rootCache.GetObjects(cascadeRefreshObjRefsSetList, cacheDirective);
            }
            List <CacheDependencyNode> childNodes = node.childNodes;

            for (int a = childNodes.Count; a-- > 0;)
            {
                ChangeSecondLevelCacheIntern(childNodes[a], failInCacheHierarchyAndCacheValueResultAndReturnMissesSet);
            }
        }
示例#3
0
        protected bool HandleValueHolder(DirectValueHolderRef vhr, PrefetchPath[] cachePaths, IMap <ICacheIntern, IISet <IObjRef> > cacheToOrisToLoad,
                                         IMap <ICacheIntern, IMap <IObjRelation, bool> > cacheToOrelsToLoad, IMap <ICacheIntern, IISet <IObjRef> > cacheToOrisLoadedHistory,
                                         IMap <ICacheIntern, IISet <IObjRelation> > cacheToOrelsLoadedHistory, AlreadyHandledSet alreadyHandledSet, IList <PrefetchCommand> cascadeLoadItems)
        {
            RelationMember member       = vhr.Member;
            bool           newOriToLoad = false;

            if (vhr is IndirectValueHolderRef)
            {
                RootCacheValue  rcv           = (RootCacheValue)vhr.Vhc;
                ICacheIntern    rootCache     = ((IndirectValueHolderRef)vhr).RootCache;
                IEntityMetaData metaData      = EntityMetaDataProvider.GetMetaData(rcv.EntityType);
                int             relationIndex = metaData.GetIndexByRelation(member);
                IObjRef[]       rcvObjRefs    = rcv.GetRelation(relationIndex);
                if (rcvObjRefs == null)
                {
                    IObjRelation        self = ValueHolderContainerMixin.GetSelf(rcv, member.Name);
                    ISet <IObjRelation> orelsLoadedHistory = cacheToOrelsLoadedHistory.Get(rootCache);
                    if (orelsLoadedHistory == null || !orelsLoadedHistory.Contains(self))
                    {
                        IMap <IObjRelation, bool> orelsToLoad = cacheToOrelsToLoad.Get(rootCache);
                        if (orelsToLoad == null)
                        {
                            orelsToLoad = new HashMap <IObjRelation, bool>();
                            cacheToOrelsToLoad.Put(rootCache, orelsToLoad);
                        }
                        orelsToLoad.Put(self, vhr.ObjRefsOnly);
                        AddCascadeLoadItem(vhr, cachePaths, cascadeLoadItems);
                    }
                    return(false);
                }
                else if (!vhr.ObjRefsOnly && rcvObjRefs.Length > 0)
                {
                    ISet <IObjRef> orisLoadedHistory = cacheToOrisLoadedHistory.Get(rootCache);
                    for (int b = rcvObjRefs.Length; b-- > 0;)
                    {
                        IObjRef ori = rcvObjRefs[b];
                        if (orisLoadedHistory != null && orisLoadedHistory.Contains(ori))
                        {
                            // Object has been tried to load before but it is obviously not in the cache
                            // So the load must have been failed somehow. It is assumed that the entity
                            // is not persisted in the database anymore (deleted before) so the ORI is illegal.
                            // We cleanup the ValueHolder so that future calls will not lead to
                            // another unnecessary roundtrip to the server
                            rcvObjRefs[b] = null;
                            continue;
                        }
                        IISet <IObjRef> orisToLoad = cacheToOrisToLoad.Get(rootCache);
                        if (orisToLoad == null)
                        {
                            orisToLoad = new CHashSet <IObjRef>();
                            cacheToOrisToLoad.Put(rootCache, orisToLoad);
                        }
                        orisToLoad.Add(ori);
                        newOriToLoad = true;
                    }
                    if (newOriToLoad)
                    {
                        AddCascadeLoadItem(vhr, cachePaths, cascadeLoadItems);
                    }
                }
                return(false);
            }
            IValueHolderContainer vhc = (IValueHolderContainer)vhr.Vhc;
            int relationIndex2        = vhc.Get__EntityMetaData().GetIndexByRelationName(member.Name);

            if (ValueHolderState.INIT == vhc.Get__State(relationIndex2))
            {
                return(true);
            }
            ICacheIntern cache = vhc.__TargetCache;

            IObjRef[] objRefs = vhc.Get__ObjRefs(relationIndex2);
            if (objRefs == null)
            {
                IObjRelation        self  = vhc.Get__Self(relationIndex2);
                List <IObjRelation> orels = new List <IObjRelation>();
                orels.Add(self);
                IList <IObjRelationResult> orelResults = cache.GetObjRelations(orels, cache, failEarlyReturnMisses);
                IObjRelationResult         orelResult  = orelResults[0];
                if (orelResult == null)
                {
                    ISet <IObjRelation> orelsLoadedHistory = cacheToOrelsLoadedHistory.Get(cache);
                    if (orelsLoadedHistory == null || !orelsLoadedHistory.Contains(self))
                    {
                        IMap <IObjRelation, bool> orelsToLoad = cacheToOrelsToLoad.Get(cache);
                        if (orelsToLoad == null)
                        {
                            orelsToLoad = new HashMap <IObjRelation, bool>();
                            cacheToOrelsToLoad.Put(cache, orelsToLoad);
                        }
                        orelsToLoad.Put(self, vhr.ObjRefsOnly);
                        AddCascadeLoadItem(vhr, cachePaths, cascadeLoadItems);
                    }
                    return(false);
                }
                objRefs = orelResult.Relations;
                if (objRefs != null)
                {
                    vhc.Set__ObjRefs(relationIndex2, objRefs);
                }
            }
            if (!vhr.ObjRefsOnly && objRefs != null && objRefs.Length > 0)
            {
                IList <Object> loadedObjects = cache.GetObjects(new List <IObjRef>(objRefs), cache, failEarlyReturnMisses);
                try
                {
                    for (int b = objRefs.Length; b-- > 0;)
                    {
                        IObjRef ori          = objRefs[b];
                        Object  loadedObject = loadedObjects[b];
                        if (loadedObject != null)
                        {
                            continue;
                        }
                        ISet <IObjRef> orisLoadedHistory = cacheToOrisLoadedHistory.Get(cache);
                        if (orisLoadedHistory != null && orisLoadedHistory.Contains(ori))
                        {
                            // Object has been tried to load before but it is obviously not in the cache
                            // So the load must have been failed somehow. It is assumed that the entity
                            // is not persisted in the database anymore (deleted before) so the ORI is illegal.
                            // We cleanup the ValueHolder so that future calls will not lead to
                            // another unnecessary roundtrip to the server
                            objRefs[b] = null;
                            continue;
                        }
                        IISet <IObjRef> orisToLoad = cacheToOrisToLoad.Get(cache);
                        if (orisToLoad == null)
                        {
                            orisToLoad = new CHashSet <IObjRef>();
                            cacheToOrisToLoad.Put(cache, orisToLoad);
                        }
                        orisToLoad.Add(ori);
                        newOriToLoad = true;
                    }
                }
                finally
                {
                    loadedObjects.Clear();
                    loadedObjects = null;
                }
            }
            if (objRefs == null || newOriToLoad)
            {
                AddCascadeLoadItem(vhr, cachePaths, cascadeLoadItems);
                return(false);
            }
            return(true);
        }
示例#4
0
        protected void LoadAndAddOrels(ICacheIntern cache, IMap <IObjRelation, bool> orelsToLoad, IList <Object> hardRefList,
                                       IMap <ICacheIntern, IISet <IObjRelation> > cacheToOrelsLoadedHistory, ILinkedMap <ICacheIntern, IISet <IObjRef> > cacheToOrisToLoad,
                                       IdentityLinkedSet <Member> prioMembers)
        {
            IList <IObjRelation> objRelList;

            if (prioMembers.Count > 0)
            {
                objRelList = new List <IObjRelation>(orelsToLoad.Count);
                IEntityMetaDataProvider entityMetaDataProvider = this.EntityMetaDataProvider;
                foreach (Entry <IObjRelation, Boolean> entry in orelsToLoad)
                {
                    IObjRelation    objRel       = entry.Key;
                    IEntityMetaData metaData     = entityMetaDataProvider.GetMetaData(objRel.RealType);
                    RelationMember  memberByName = (RelationMember)metaData.GetMemberByName(objRel.MemberName);
                    if (!prioMembers.Contains(memberByName))
                    {
                        continue;
                    }
                    objRelList.Add(objRel);
                }
            }
            else
            {
                objRelList = orelsToLoad.KeyList();
            }
            IList <IObjRelationResult> objRelResults = cache.GetObjRelations(objRelList, cache, CacheDirective.ReturnMisses);

            IISet <IObjRef> orisToLoad = null;

            for (int a = 0, size = objRelResults.Count; a < size; a++)
            {
                IObjRelation       objRel       = objRelList[a];
                IObjRelationResult objRelResult = objRelResults[a];
                bool objRefsOnly = orelsToLoad.Remove(objRel);
                if (objRelResult == null)
                {
                    continue;
                }
                if (orelsToLoad.Get(objRel))
                {
                    // fetch only the objRefs, not the objects themselves
                    continue;
                }
                IObjRef[] relations = objRelResult.Relations;

                if (relations.Length == 0 || objRefsOnly)
                {
                    // fetch only the objRefs, not the objects themselves
                    continue;
                }
                if (orisToLoad == null)
                {
                    orisToLoad = cacheToOrisToLoad.Get(cache);
                    if (orisToLoad == null)
                    {
                        orisToLoad = new CHashSet <IObjRef>();
                        cacheToOrisToLoad.Put(cache, orisToLoad);
                    }
                }
                orisToLoad.AddAll(relations);
            }
            IISet <IObjRelation> orelsLoadedHistory = cacheToOrelsLoadedHistory.Get(cache);

            if (orelsLoadedHistory == null)
            {
                orelsLoadedHistory = new CHashSet <IObjRelation>();
                cacheToOrelsLoadedHistory.Put(cache, orelsLoadedHistory);
            }
            orelsLoadedHistory.AddAll(objRelList);
        }