private static Exception GETMOREINFO(Type t, int size, CHashSet <int> xdone)
        {
            StringBuilder sb = new StringBuilder(4096);

            sb.AppendLine("------- BEGIN INFORMATION -------");

            MethodInfo[] vs = t.GetMethods(flag_i);

            int len = vs.Length - 1;
            int x   = 0;

            for (; x < len; x++)
            {
                if (!xdone.Contains(x))
                {
                    sb.AppendLine(vs[x].ToString());
                    sb.AppendLine();
                }
            }
            if (!xdone.Contains(len))
            {
                sb.AppendLine(vs[len].ToString());
            }

            sb.AppendLine("------- END INFOMATION -------");

            return
                (new Exception($"Number of methods not implemented: {size - xdone.Count}",
                               new Exception(sb.ToString())));
        }
Exemple #2
0
        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);
            }
        }
        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);
            }
        }
Exemple #4
0
 public LRxItem(int produce, ExpressInt express, int index, CHashSet <int> lookahead)
 {
     this.produce   = produce;
     this.express   = express;
     this.index     = index;
     this.lookahead = lookahead;
 }
Exemple #5
0
        public ISet <IEntityConfig> LoadFromDocument(XDocument doc)
        {
            ISet <IEntityConfig> entities = new CHashSet <IEntityConfig>();

            LoadFromDocument(doc, entities, entities);
            return(entities);
        }
Exemple #6
0
        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;
            }
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        protected PrefetchPath[] BuildCachePath(Type entityType, IList <String> membersToInitialize)
        {
            CHashSet <AppendableCachePath> cachePaths = new CHashSet <AppendableCachePath>();

            for (int a = membersToInitialize.Count; a-- > 0;)
            {
                String memberName = membersToInitialize[a];
                CachePathHelper.BuildCachePath(entityType, memberName, cachePaths);
            }
            return(CachePathHelper.CopyAppendableToCachePath(cachePaths));
        }
Exemple #9
0
        public static void Closure(CachedGrammar inst, LinkedHashSet <LRxItem> items)
        {
            Grammar g = inst.m_value;
            IForwardIterator <LRxItem> e1 = items.Begin();
            IForwardIterator <LRxItem> e2 = items.Begin();

            for (; e1.IsAlive; e1.Add())
            {
                LRxItem current = e1.Value;
                if (current.IsEnd)
                {
                    continue;
                }

                int ms = current.MarkSymbol;
                if (!ms.IsTerminal())
                {
                    CHashSet <int> la =
                        current.IsLast
                        ? new CHashSet <int>(current.lookahead)
                        : inst.GetFirst(current.express, current.index + 1);

                    IForwardIterator <GItem> e3 = g.Find(ms);
                    do
                    {
                        LRxItem newit = new LRxItem(e3.Value, la);

                        for (; e2.IsAlive; e2.Add())
                        {
                            if (newit.CoreEquals(e2.Value))
                            {
                                CHashSet <int> ela = e2.Value.lookahead;
                                if (!ela.IsSupersetOf(la))
                                {
                                    ela.UnionWith(la);
                                }

                                goto exit;
                            }
                        }

                        items.Add(newit);

exit:
                        e2.Reset();
                    } while (e3.LazyAdd());
                    e3.Dispose();
                }
            }

            e1.Dispose();
        }
        public override void Visit(TypeAttributes access, String name, Type superName, Type[] interfaces)
        {
            Type originalType = State.OriginalType;

            access &= ~TypeAttributes.Abstract;
            access &= ~TypeAttributes.Interface;
            if (originalType.IsInterface)
            {
                CHashSet <Type> interfaceSet = new CHashSet <Type>(interfaces);
                interfaceSet.Add(originalType);
                interfaces = interfaceSet.ToArray();
            }
            base.Visit(access, name, superName, interfaces);
        }
        protected void CleanupSecondLevelCaches(CacheDependencyNode node, IList <IObjRef> deletesList, IList <IDataChangeEntry> updates,
                                                CHashSet <Type> occuringTypes)
        {
            List <IObjRef> objRefsRemovePriorVersions = new List <IObjRef>(updates.Count);

            for (int a = updates.Count; a-- > 0;)
            {
                IDataChangeEntry updateEntry = updates[a];
                Type             entityType  = updateEntry.EntityType;
                occuringTypes.Add(entityType);
                objRefsRemovePriorVersions.Add(new ObjRef(entityType, updateEntry.IdNameIndex, updateEntry.Id, updateEntry.Version));
            }
            CleanupSecondLevelCachesIntern(node, deletesList, objRefsRemovePriorVersions);
        }
Exemple #12
0
        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));
        }
Exemple #13
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);
        }
Exemple #14
0
        public PrefetchPath[] CopyAppendableToCachePath(CHashSet <AppendableCachePath> children)
        {
            if (children == null)
            {
                return(null);
            }
            PrefetchPath[] clonedChildren = new PrefetchPath[children.Count];
            int            index          = 0;

            foreach (AppendableCachePath child in children)
            {
                clonedChildren[index] = CopyAppendableToCachePath(child);
                index++;
            }
            return(clonedChildren);
        }
Exemple #15
0
        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()));
        }
        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);
        }
Exemple #17
0
        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);
        }
Exemple #18
0
        static void Main()
        {
            var hashSet = new CHashSet<int>();

            hashSet.Add(1);
            hashSet.Add(1);
            hashSet.Add(2);
            hashSet.Add(1);

            foreach (var item in hashSet)
            {
                Console.Write(item + " ");
            }

            Console.WriteLine();
            hashSet.Remove(1);

            foreach (var item in hashSet)
            {
                Console.Write(item + " ");
            }

            Console.WriteLine();
            var secondHashSet = new CHashSet<int>();
            secondHashSet.Add(3);
            secondHashSet.Add(4);
            secondHashSet.Add(2);

            var unionTest = hashSet.Union(secondHashSet);

            foreach (var item in unionTest)
            {
                Console.Write(item + " ");
            }

            Console.WriteLine();
            var intersectTest = hashSet.Intersect(secondHashSet);

            foreach (var item in intersectTest)
            {
                Console.Write(item + " ");
            }
        }
        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);
                }
            }
        }
Exemple #20
0
        public ISet <IObjRef> lookForIntermediateDeletes()
        {
            CHashSet <IObjRef> intermediateDeletes = new CHashSet <IObjRef>();
            // Hold cache values as hard ref to prohibit cache loss due to GC
            IList <IObjRef> hardRefRequest = hardRefObjRefsToLoad.ToList();
            IList <Object>  hardRefResult  = rootCache.GetObjects(hardRefRequest, cacheValueResultAndReturnMissesSet);

            for (int a = hardRefResult.Count; a-- > 0;)
            {
                Object hardRef = hardRefResult[a];
                if (hardRef != null)
                {
                    continue;
                }
                // Objects are marked as UPDATED in the DCE, but could not be newly retrieved from the server
                // This occurs if a fast DELETE event on the server happened but has not been processed, yet
                IObjRef hardRefObjRefToLoad = hardRefRequest[a];
                intermediateDeletes.Add(hardRefObjRefToLoad);
            }
            this.privilegedHardRefResult = hardRefResult;
            RemoveNotFoundObjRefs(intermediateDeletes.ToArray());

            return(intermediateDeletes);
        }
Exemple #21
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);
        }
Exemple #22
0
        protected Type CreateGpType(AccessorClassLoader loader, Type proxyType, Type[] additionalProxyTypes, String className)
        {
            String classNameInternal = className.Replace('.', '/');
            Type   abstractType      = typeof(GCProxy);

            List <Type> interfaceClasses = new List <Type>();

            interfaceClasses.Add(proxyType);
            foreach (Type additionalProxyType in additionalProxyTypes)
            {
                interfaceClasses.Add(additionalProxyType);
            }

            TypeBuilder cw = loader.CreateNewType(TypeAttributes.Public, classNameInternal, abstractType, Type.EmptyTypes);
            {
                ConstructorInfo baseConstructor = abstractType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(Object), typeof(IDisposable) }, null);
                if (baseConstructor == null)
                {
                    throw new Exception("Constructor not found: " + abstractType.FullName);
                }
                ILGenerator mv = cw.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, TypeUtil.GetParameterTypesToTypes(baseConstructor.GetParameters())).GetILGenerator();
                mv.Emit(OpCodes.Ldarg_0);
                mv.Emit(OpCodes.Ldarg_1);
                mv.Emit(OpCodes.Ldarg_2);
                mv.Emit(OpCodes.Call, baseConstructor);
                mv.Emit(OpCodes.Ret);
            }
            {
                ConstructorInfo baseConstructor = abstractType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(IDisposable) }, null);
                if (baseConstructor == null)
                {
                    throw new Exception("Constructor not found: " + abstractType.FullName);
                }
                ILGenerator mv = cw.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, TypeUtil.GetParameterTypesToTypes(baseConstructor.GetParameters())).GetILGenerator();
                mv.Emit(OpCodes.Ldarg_0);
                mv.Emit(OpCodes.Ldarg_1);
                mv.Emit(OpCodes.Call, baseConstructor);
                mv.Emit(OpCodes.Ret);
            }
            MethodInfo targetMethod = ReflectUtil.GetDeclaredMethod(false, typeof(GCProxy), typeof(Object), "ResolveTarget");

            CHashSet <MethodInfo> alreadyImplementedMethods = new CHashSet <MethodInfo>();

            foreach (Type interfaceClass in interfaceClasses)
            {
                MethodInfo[] methods = interfaceClass.GetMethods();
                foreach (MethodInfo method in methods)
                {
                    if (GCProxy.disposeMethod.Equals(method))
                    {
                        // will remain implemented by the GCProxy class
                        continue;
                    }
                    if (!alreadyImplementedMethods.Add(method))
                    {
                        continue;
                    }
                    MethodAttributes attributes = 0;

                    Type[]      paramTypes = TypeUtil.GetParameterTypesToTypes(method.GetParameters());
                    ILGenerator mv         = cw.DefineMethod(method.Name, attributes, CallingConventions.HasThis, method.ReturnType, paramTypes).GetILGenerator();
                    mv.Emit(OpCodes.Ldarg_0);
                    mv.Emit(OpCodes.Callvirt, targetMethod);
                    mv.Emit(OpCodes.Castclass, method.DeclaringType);
                    for (int a = 0, size = paramTypes.Length; a < size; a++)
                    {
                        mv.Emit(OpCodes.Ldarg, a + 1);
                    }
                    mv.Emit(OpCodes.Callvirt, method);
                    mv.Emit(OpCodes.Ret);
                }
            }
            return(loader.GetType(classNameInternal, cw));
        }
        /// <exception cref="Exception">Thrown when TargetField attribute cannot be found in the property</exception>
        /// <exception cref="InvalidOperationException">Thrown when try to invalid operation</exception>
        /// <summary>
        /// Create an interface implementation for dynamic type <paramref name="t"/>
        /// </summary>
        /// <typeparam name="T">Interface type</typeparam>
        /// <param name="t">
        /// Find only public static fields and methods
        /// Using static types(as opposed to dynamic types) is inefficient
        /// </param>
        /// <returns>Is not null if the method succeeds</returns>
        public static T Make <T>(Type t) where T : class
        {
            Type temp = typeof(T);

            if (!temp.IsInterface || temp.IsNotPublic || t == null || !(t.IsAbstract && t.IsSealed))
            {
                return(null);
            }
            if (cached.TryGetValue(t, out object obj))
            {
                return((T)obj);
            }

            PropertyInfo[] implPpt = temp.GetProperties(flag_i);
            SpMI[]         impl    = Array.ConvertAll(temp.GetMethods(flag_i), CONV_SPI);
            OnlyMI[]       code    = Array.ConvertAll(t.GetMethods(flag_s), CONV_OMI);

            int init_x = impl.Length;
            int init_p = implPpt.Length;

            if (init_x == 0 && init_p == 0)
            {
                return(null);
            }

            CHashSet <int> xdone =
                init_x == 0
                ? null
                : new CHashSet <int>(init_x);

            StringBuilder sb = new StringBuilder(t.FullName);

            sb.Append("__ClassWrapper__");
            sb.Append(cached.Count);

            TypeBuilder tb = mdb.DefineType(sb.ToString(), tattrb, null, new Type[1] {
                temp
            });

            int clen = code.Length;
            int z    = 0;

            for (; z < init_x; z++)
            {
                SilmMI k = impl[z];
                int    x = clen;

                while (--x >= 0)
                {
                    if (code[x].Equals(k) && xdone.Add(x))
                    {
                        SomeMethod(tb, k, code[x]);
                        break;
                    }
                }
            }
            if (xdone != null && init_x != xdone.Count)
            {
                throw new InvalidOperationException("Some methods could not be implemented", GETMOREINFO(temp, init_x, xdone));
            }

            for (z = 0; z < init_p; z++)
            {
                if (implPpt[z].GetCustomAttribute <TargetFieldAttribute>() is TargetFieldAttribute tfa)
                {
                    PropertyInfo pp = implPpt[z];
                    temp = pp.PropertyType;
                    if (tfa.refm ^ temp.IsByRef)
                    {
                        throw new InvalidOperationException("Incorrect attribute declare", GETMOREINFO(temp.IsByRef));
                    }
                    else if (pp.GetSetMethod() != null)
                    {
                        throw new InvalidOperationException("use ref return type instead of set accessor", GETMOREINFO());
                    }

                    if (t.GetField(pp.GetCustomAttribute <TargetFunctionAttribute>()?.name ?? tfa.name, flag_sa) is FieldInfo fd)
                    {
                        FieldMethod(tb, pp.GetGetMethod(false), fd, tfa.refm);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Field not found: {tfa.name}");
                    }
                }
                else
                {
                    throw new Exception("Missing attribute");
                }
            }

            obj = FormatterServices.GetUninitializedObject(tb.CreateType());
            cached.Add(t, obj);

            return((T)obj);
        }
Exemple #24
0
        protected IOriCollection Intern(ICUDResult cudResult, IMethodDescription methodDescription, IList <MergeOperation> mergeOperationSequence,
                                        IncrementalMergeState state)
        {
            IList <IChangeContainer> allChanges   = cudResult.AllChanges;
            IList <Object>           originalRefs = cudResult.GetOriginalRefs();
            IdentityHashMap <IChangeContainer, int> changeToChangeIndexDict = new IdentityHashMap <IChangeContainer, int>();

            for (int a = allChanges.Count; a-- > 0;)
            {
                changeToChangeIndexDict.Put(allChanges[a], a);
            }
            IObjRef[] objRefs      = new IObjRef[allChanges.Count];
            long[]    allChangedOn = new long[allChanges.Count];
            String[]  allChangedBy = new String[allChanges.Count];

            CHashSet <long>   changedOnSet = new CHashSet <long>();
            CHashSet <String> changedBySet = new CHashSet <String>();

            for (int a = 0, size = mergeOperationSequence.Count; a < size; a++)
            {
                MergeOperation         mergeOperation        = mergeOperationSequence[a];
                IMergeServiceExtension mergeServiceExtension = mergeOperation.MergeServiceExtension;

                IList <IChangeContainer> changesForMergeService = mergeOperation.ChangeContainer;
                ICUDResult msCudResult = BuildCUDResult(changesForMergeService, changeToChangeIndexDict, originalRefs);

                IOriCollection msOriCollection = mergeServiceExtension.Merge(msCudResult, methodDescription);

                MergeController.ApplyChangesToOriginals(msCudResult, msOriCollection, state.GetStateCache());

                IList <IObjRef> allChangeORIs = msOriCollection.AllChangeORIs;

                long?  msDefaultChangedOn = msOriCollection.ChangedOn;
                String msDefaultChangedBy = msOriCollection.ChangedBy;

                long[]   msAllChangedOn = msOriCollection.AllChangedOn;
                String[] msAllChangedBy = msOriCollection.AllChangedBy;
                for (int b = changesForMergeService.Count; b-- > 0;)
                {
                    int index = changeToChangeIndexDict.Get(changesForMergeService[b]);
                    objRefs[index] = allChangeORIs[b];

                    if (msAllChangedOn != null)
                    {
                        long msChangedOn = msAllChangedOn[b];
                        allChangedOn[index] = msChangedOn;
                        changedOnSet.Add(msChangedOn);
                    }
                    else
                    {
                        allChangedOn[index] = msDefaultChangedOn.Value;
                    }
                    if (msAllChangedBy != null)
                    {
                        String msChangedBy = msAllChangedBy[b];
                        allChangedBy[index] = msChangedBy;
                        changedBySet.Add(msChangedBy);
                    }
                    else
                    {
                        allChangedBy[index] = msDefaultChangedBy;
                    }
                }
                if (msDefaultChangedOn != null)
                {
                    changedOnSet.Add(msDefaultChangedOn.Value);
                }
                if (msDefaultChangedBy != null)
                {
                    changedBySet.Add(msDefaultChangedBy);
                }
            }
            OriCollection oriCollection = new OriCollection();

            oriCollection.AllChangeORIs = new List <IObjRef>(objRefs);

            if (changedBySet.Count == 1)
            {
                Iterator <String> iter = changedBySet.Iterator();
                iter.MoveNext();
                oriCollection.ChangedBy = iter.Current;
            }
            else
            {
                oriCollection.AllChangedBy = allChangedBy;
            }
            if (changedOnSet.Count == 1)
            {
                Iterator <long> iter = changedOnSet.Iterator();
                iter.MoveNext();
                oriCollection.ChangedOn = iter.Current;
            }
            else
            {
                oriCollection.AllChangedOn = allChangedOn;
            }
            foreach (IMergeListener mergeListener in mergeListeners.GetExtensions())
            {
                mergeListener.PostMerge(cudResult, objRefs);
            }
            if (originalRefs != null)
            {
                // Set each original ref to null in order to suppress a post-processing in a potentially calling IMergeProcess
                for (int a = originalRefs.Count; a-- > 0;)
                {
                    originalRefs[a] = null;
                }
            }
            // TODO DCE must be fired HERE <---
            return(oriCollection);
        }
Exemple #25
0
 public LRxItem(GItem source, CHashSet <int> la)
 {
     produce   = source.produce;
     express   = source.express;
     lookahead = la;
 }
        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);
            }
        }
        protected void DataChangedIntern(IDataChange dataChange, IList <Object> pausedEventTargets, IProcessResumeItem processResumeItem, CacheDependencyNode rootNode)
        {
            try
            {
                bool isLocalSource = dataChange.IsLocalSource;
                IList <IDataChangeEntry> deletes = dataChange.Deletes;
                IList <IDataChangeEntry> updates = dataChange.Updates;
                IList <IDataChangeEntry> inserts = dataChange.Inserts;

                CHashSet <Type>    occuringTypes       = new CHashSet <Type>();
                CHashSet <IObjRef> deletesSet          = new CHashSet <IObjRef>();
                CHashSet <Type>    directRelatingTypes = new CHashSet <Type>();
                bool acquirementSuccessful             = rootNode.rootCache.AcquireHardRefTLIfNotAlready();
                try
                {
                    for (int a = deletes.Count; a-- > 0;)
                    {
                        IDataChangeEntry deleteEntry = deletes[a];
                        Type             entityType  = deleteEntry.EntityType;
                        occuringTypes.Add(entityType);
                        if (deleteEntry is DirectDataChangeEntry)
                        {
                            // Ignore delete entries of unpersisted objects here
                            continue;
                        }
                        ObjRef tempORI = new ObjRef(entityType, deleteEntry.IdNameIndex, deleteEntry.Id, deleteEntry.Version);
                        deletesSet.Add(tempORI);
                    }
                    // Remove items from the cache only if they are really deleted/updates by a remote event
                    // And not 'simulated' by a local source
                    bool cleanupSecondLevelCaches = false;
                    if (pausedEventTargets != null && (deletes.Count > 0 || updates.Count > 0) && !isLocalSource)
                    {
                        cleanupSecondLevelCaches = true;
                    }
                    else if (updates.Count > 0)
                    {
                        for (int a = updates.Count; a-- > 0;)
                        {
                            IDataChangeEntry updateEntry = updates[a];
                            Type             entityType  = updateEntry.EntityType;
                            occuringTypes.Add(entityType);
                        }
                    }
                    for (int a = inserts.Count; a-- > 0;)
                    {
                        IDataChangeEntry insertEntry = inserts[a];
                        Type             entityType  = insertEntry.EntityType;
                        occuringTypes.Add(entityType);
                    }
                    EnsureMetaDataIsLoaded(occuringTypes, directRelatingTypes);

                    if (cleanupSecondLevelCaches)
                    {
                        CleanupSecondLevelCaches(rootNode, deletesSet.ToList(), updates, occuringTypes);
                    }

                    BuildCacheChangeItems(rootNode, dataChange);

                    rootNode.AggregateAllCascadedObjRefs();

                    ISet <IObjRef> intermediateDeletes = rootNode.lookForIntermediateDeletes();

                    ChangeSecondLevelCache(rootNode);

                    if (rootNode.IsPendingChangeOnAnyChildCache())
                    {
                        GuiThreadHelper.InvokeInGuiAndWait(delegate()
                        {
                            bool oldFailEarlyModeActive = AbstractCache.FailInCacheHierarchyModeActive;
                            AbstractCache.FailInCacheHierarchyModeActive = true;
                            try
                            {
                                ChangeFirstLevelCaches(rootNode, intermediateDeletes);
                            }
                            finally
                            {
                                AbstractCache.FailInCacheHierarchyModeActive = oldFailEarlyModeActive;
                            }
                        });
                    }
                }
                finally
                {
                    rootNode.rootCache.ClearHardRefs(acquirementSuccessful);
                }
            }
            finally
            {
                if (processResumeItem != null)
                {
                    processResumeItem.ResumeProcessingFinished();
                }
            }
        }
Exemple #28
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);
        }