Example #1
0
        protected void Initialize()
        {
            HashMap <Type, IISet <Type> >     typeRelatedByTypes = new HashMap <Type, IISet <Type> >();
            IdentityHashSet <IEntityMetaData> extensions         = new IdentityHashSet <IEntityMetaData>(GetExtensions().Values());

            foreach (IEntityMetaData metaData in extensions)
            {
                if (Object.ReferenceEquals(metaData, alreadyHandled))
                {
                    continue;
                }
                foreach (RelationMember relationMember in metaData.RelationMembers)
                {
                    AddTypeRelatedByTypes(typeRelatedByTypes, metaData.EntityType, relationMember.ElementType);
                }
            }
            foreach (IEntityMetaData metaData in extensions)
            {
                if (Object.ReferenceEquals(metaData, alreadyHandled))
                {
                    continue;
                }
                Type         entityType     = metaData.EntityType;
                IISet <Type> relatedByTypes = typeRelatedByTypes.Get(entityType);
                if (relatedByTypes == null)
                {
                    relatedByTypes = new CHashSet <Type>();
                }
                ((EntityMetaData)metaData).TypesRelatingToThis = relatedByTypes.ToArray();
                RefreshMembers(metaData);
            }
        }
Example #2
0
 public void RemoveObjRef(IObjRef objRef)
 {
     if (((ICollection)removedORIs).Count == 0)
     {
         removedORIs = new CHashSet <IObjRef>();
     }
     removedORIs.Add(objRef);
 }
Example #3
0
 public void AddObjRef(IObjRef objRef)
 {
     if (((ICollection)addedORIs).Count == 0)
     {
         addedORIs = new CHashSet <IObjRef>();
     }
     addedORIs.Add(objRef);
 }
Example #4
0
        protected void LoadAndAddOris(ICacheIntern cache, ISet <IObjRef> orisToLoad, IList <Object> hardRefList,
                                      IMap <ICacheIntern, IISet <IObjRef> > cacheToOrisLoadedHistory)
        {
            IList <Object> result = cache.GetObjects(ListUtil.ToList(orisToLoad), CacheDirective.None);

            hardRefList.Add(result);
            IISet <IObjRef> orisLoadedHistory = cacheToOrisLoadedHistory.Get(cache);

            if (orisLoadedHistory == null)
            {
                orisLoadedHistory = new CHashSet <IObjRef>();
                cacheToOrisLoadedHistory.Put(cache, orisLoadedHistory);
            }
            orisLoadedHistory.AddAll(orisToLoad);
        }
Example #5
0
        protected void LoadAndAddOris(IMap <ICacheIntern, IISet <IObjRef> > cacheToOrisToLoad, IList <Object> hardRefList,
                                      IMap <ICacheIntern, IISet <IObjRef> > cacheToOrisLoadedHistory)
        {
            Iterator <Entry <ICacheIntern, IISet <IObjRef> > > iter = cacheToOrisToLoad.Iterator();

            while (iter.MoveNext())
            {
                Entry <ICacheIntern, IISet <IObjRef> > entry = iter.Current;
                ICacheIntern    cache      = entry.Key;
                IISet <IObjRef> orisToLoad = entry.Value;
                iter.Remove();

                LoadAndAddOris(cache, orisToLoad, hardRefList, cacheToOrisLoadedHistory);
            }
        }
Example #6
0
        protected void AddTypeRelatedByTypes(IMap <Type, IISet <Type> > typeRelatedByTypes, Type relating, Type relatedTo)
        {
            IEntityMetaData metaData = GetMetaData(relatedTo, true);

            if (metaData != null)
            {
                relatedTo = metaData.EntityType;
            }
            IISet <Type> relatedByTypes = typeRelatedByTypes.Get(relatedTo);

            if (relatedByTypes == null)
            {
                relatedByTypes = new CHashSet <Type>();
                typeRelatedByTypes.Put(relatedTo, relatedByTypes);
            }
            relatedByTypes.Add(relating);
        }
Example #7
0
        public IRelationUpdateItem CreateRUI(String memberName, IList <IObjRef> oldOriList, IList <IObjRef> newOriList)
        {
            if (oldOriList.Count == 0 && newOriList.Count == 0)
            {
                return(null);
            }
            IISet <IObjRef> oldSet = oldOriList.Count > 0 ? new CHashSet <IObjRef>(oldOriList) : EmptySet.Empty <IObjRef>();
            IISet <IObjRef> newSet = newOriList.Count > 0 ? new CHashSet <IObjRef>(newOriList) : EmptySet.Empty <IObjRef>();

            IISet <IObjRef> smallerSet = ((ICollection)oldSet).Count > ((ICollection)newSet).Count ? newSet : oldSet;
            IISet <IObjRef> greaterSet = ((ICollection)oldSet).Count > ((ICollection)newSet).Count ? oldSet : newSet;

            // Check unchanged ORIs
            Iterator <IObjRef> smallerIter = smallerSet.Iterator();

            while (smallerIter.MoveNext())
            {
                // Old ORIs, which exist as new ORIs, too, are unchanged
                IObjRef objRef = smallerIter.Current;
                if (greaterSet.Remove(objRef))
                {
                    smallerIter.Remove();
                }
            }
            if (((ICollection)oldSet).Count == 0 && ((ICollection)newSet).Count == 0)
            {
                return(null);
            }
            // Old ORIs are now handled as REMOVE, New ORIs as ADD
            RelationUpdateItem rui = new RelationUpdateItem();

            rui.MemberName = memberName;
            if (((ICollection)oldSet).Count > 0)
            {
                rui.RemovedORIs = oldSet.ToArray();
            }
            if (((ICollection)newSet).Count > 0)
            {
                rui.AddedORIs = newSet.ToArray();
            }
            return(rui);
        }
Example #8
0
        protected void FilterWrongRelationMappings(IISet <RelationMember> relationMembers)
        {
            // filter all relations which can not be a relation because of explicit embedded property mapping
            IdentityHashSet <RelationMember> toRemove = new IdentityHashSet <RelationMember>();

            foreach (RelationMember relationMember in relationMembers)
            {
                String[] memberPath = EmbeddedMember.Split(relationMember.Name);
                foreach (RelationMember otherRelationMember in relationMembers)
                {
                    if (Object.ReferenceEquals(relationMember, otherRelationMember) || toRemove.Contains(otherRelationMember))
                    {
                        continue;
                    }
                    if (!(otherRelationMember is IEmbeddedMember))
                    {
                        // only embedded members can help identifying other wrong relation members
                        continue;
                    }
                    String[] otherMemberPath = ((IEmbeddedMember)otherRelationMember).GetMemberPathToken();
                    if (memberPath.Length > otherMemberPath.Length)
                    {
                        continue;
                    }
                    bool match = true;
                    for (int a = 0, size = memberPath.Length; a < size; a++)
                    {
                        if (!memberPath[a].Equals(otherMemberPath[a]))
                        {
                            match = false;
                            break;
                        }
                    }
                    if (match)
                    {
                        toRemove.Add(relationMember);
                        break;
                    }
                }
            }
            relationMembers.RemoveAll(toRemove);
        }
Example #9
0
        protected void AddBoTypeAfter(Type boType, Type afterBoType, IMap <Type, IISet <Type> > boTypeBeforeBoTypes,
                                      IMap <Type, IISet <Type> > boTypeToAfterBoTypes)
        {
            IISet <Type> afterBoTypes = boTypeToAfterBoTypes.Get(afterBoType);

            if (afterBoTypes == null)
            {
                afterBoTypes = new CHashSet <Type>();
                boTypeToAfterBoTypes.Put(afterBoType, afterBoTypes);
            }
            afterBoTypes.Add(boType);

            ISet <Type> beforeBoTypes = boTypeBeforeBoTypes.Get(afterBoType);

            if (beforeBoTypes != null)
            {
                // Add afterBoType as a after BO for all BOs which are BEFORE boType (similar to: if 1<3 and 3<4 then 1<4)
                foreach (Type beforeBoType in beforeBoTypes)
                {
                    AddBoTypeAfter(beforeBoType, afterBoType, boTypeBeforeBoTypes, boTypeToAfterBoTypes);
                }
            }
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
0
 public InterfaceAdder(IClassVisitor cv, params Type[] newInterfaces)
     : base(cv)
 {
     this.newInterfaces = new CHashSet <Type>(newInterfaces);
 }
Example #13
0
 public InterfaceAdder(IClassVisitor cv, IISet <Type> newInterfaces)
     : base(cv)
 {
     this.newInterfaces = newInterfaces;
 }