Пример #1
0
        private void GetCombinedKeysFromEveryType(string tag, HashVector finalResult)
        {
            if (_indexMap == null)
            {
                return;
            }
            IDictionaryEnumerator typeEnumerator;

            lock (_indexMap.SyncRoot)
            {
                typeEnumerator = _indexMap.GetEnumerator();
            }

            while (typeEnumerator.MoveNext())
            {
                AttributeIndex index = typeEnumerator.Value as AttributeIndex;
                IIndexStore    store = index.GetStore("$Tag$");

                if (store != null)
                {
                    IKeyFilter keyFilter = _cache != null?_cache.GetBucketFilter() : null;

                    IKeyFilter compoundFilter = _cache != null?_cache.GetCompoundFilter() : null;

                    IQueryResult result = new ListQueryResult(keyFilter, compoundFilter);
                    store.GetData(tag.ToLower(), ComparisonType.EQUALS, result, CollectionOperation.Union);
                    foreach (string key in result)
                    {
                        finalResult[key] = null;
                    }
                }
            }
        }
Пример #2
0
        private void AddNamedTag(object key, Hashtable value, CacheEntry entry, OperationContext operationContext)
        {
            string    type     = value["type"] as string;
            Hashtable tagsList = ((Hashtable)value["named-tags-list"]).Clone() as Hashtable;

            if (tagsList != null && type != null)
            {
                Hashtable   metaInfoAttribs = (Hashtable)tagsList.Clone();
                IQueryIndex index;

                lock (_indexMap.SyncRoot)
                {
                    if (!_indexMap.Contains(type))
                    {
                        if (_sharedAttributeIndex != null && _sharedAttributeIndex.ContainsKey(type))
                        {
                            AttributeIndex tempAttrib = _sharedAttributeIndex[type];
                            tempAttrib.Initialize(new ArrayList());
                            _indexMap.Add(type, tempAttrib);
                        }
                        else
                        {
                            _indexMap[type] = new AttributeIndex(null, _cacheName, type, true);
                        }
                    }

                    index = _indexMap[type] as IQueryIndex;

                    if (index != null)
                    {
                        long prevSize = index.IndexInMemorySize;

                        index.AddToIndex(key, new QueryItemContainer(entry, tagsList));

                        _queryIndexMemorySize += index.IndexInMemorySize - prevSize;
                    }
                }

                if (operationContext.Contains(OperationContextFieldName.IndexMetaInfo))
                {
                    MetaInformation metaInformation =
                        (MetaInformation)operationContext.GetValueByField(OperationContextFieldName.IndexMetaInfo);
                    metaInformation.Add(metaInfoAttribs);
                }
                else
                {
                    MetaInformation metaInformation = new MetaInformation(metaInfoAttribs);
                    metaInformation.CacheKey = key as string;
                    metaInformation.Type     = value["type"] as string;
                    operationContext.Add(OperationContextFieldName.IndexMetaInfo, metaInformation);
                    entry.ObjectType = value["type"] as string;
                }
            }
        }
Пример #3
0
        private void GetCombinedKeysFromEveryType(string tag, HashVector finalResult, CancellationToken token, bool wildCardSupport = false)
        {
            if (_indexMap == null)
            {
                return;
            }
            IDictionaryEnumerator typeEnumerator;

            lock (_indexMap.SyncRoot)
            {
                typeEnumerator = _indexMap.GetEnumerator();
            }

            while (typeEnumerator.MoveNext())
            {
                if (token != null && token.IsCancellationRequested)
                {
                    throw new OperationCanceledException(ExceptionsResource.OperationFailed);
                }

                AttributeIndex index = typeEnumerator.Value as AttributeIndex;
                IIndexStore    store = index.GetStore("$Tag$");

                if (store != null)
                {
                    IKeyFilter keyFilter = _cache != null?_cache.GetBucketFilter() : null;

                    IKeyFilter compoundFilter = _cache != null?_cache.GetCompoundFilter() : null;

                    IQueryResult result = new ListQueryResult(keyFilter, compoundFilter);

                    if (wildCardSupport)
                    {
                        store.GetData(tag.ToLower(), ComparisonType.LIKE, result, CollectionOperation.Union, token);
                    }
                    else
                    {
                        store.GetData(tag.ToLower(), ComparisonType.EQUALS, result, CollectionOperation.Union, token);
                    }


                    foreach (string key in result)
                    {
                        finalResult[key] = null;
                    }
                }
            }
        }
Пример #4
0
        private void AddTag(object key, QueryItemContainer value)
        {
            if (value != null)
            {
                Hashtable tagAttribs = value.ItemArrtributes;
                string    type       = tagAttribs["type"] as string;
                ArrayList tagsList   = tagAttribs["tags-list"] as ArrayList;

                if (type != null)
                {
                    IQueryIndex index;
                    lock (_indexMap.SyncRoot)
                    {
                        if (!_indexMap.Contains(type))
                        {
                            _indexMap[type] = new AttributeIndex(null, _cacheName, type, true);
                        }
                        index = _indexMap[type] as IQueryIndex;

                        if (index != null)
                        {
                            long prevSize = index.IndexInMemorySize;
                            if (tagsList != null)
                            {
                                foreach (string tag in tagsList)
                                {
                                    Hashtable tmp = new Hashtable();
                                    tmp["$Tag$"]          = tag;
                                    value.ItemArrtributes = tmp;
                                    index.AddToIndex(key, value);
                                }
                            }
                            _queryIndexMemorySize += index.IndexInMemorySize - prevSize;
                        }
                    }
                }
            }
        }
Пример #5
0
        internal virtual bool Initialize()
        {
            bool indexedDefined = false;

            if (_props != null)
            {
                if (_props.Contains("index-for-all"))
                {
                    _indexForAll   = Convert.ToBoolean(_props["index-for-all"]);
                    indexedDefined = _indexForAll;
                }

                if (_props.Contains("index-classes"))
                {
                    Hashtable indexClasses = _props["index-classes"] as Hashtable;
                    _typeMap = new TypeInfoMap(indexClasses);

                    IDictionaryEnumerator ie = indexClasses.GetEnumerator();
                    while (ie.MoveNext())
                    {
                        Hashtable innerProps = ie.Value as Hashtable;
                        string    typename   = "";

                        if (innerProps != null)
                        {
                            typename = (string)innerProps["id"];
                            ArrayList             attribList = new ArrayList();
                            IDictionaryEnumerator en         = innerProps.GetEnumerator();
                            while (en.MoveNext())
                            {
                                Hashtable attribs = en.Value as Hashtable;
                                if (attribs != null)
                                {
                                    IDictionaryEnumerator ide = attribs.GetEnumerator();
                                    while (ide.MoveNext())
                                    {
                                        Hashtable attrib = ide.Value as Hashtable;
                                        if (attrib != null)
                                        {
                                            attribList.Add(attrib["id"] as string);
                                        }
                                    }
                                }
                            }

                            //attrib level index.
                            if (attribList.Count > 0)
                            {
                                _indexMap[typename] = new AttributeIndex(attribList, _cacheName, typename, _typeMap);
                            }
                            //just a key level index.
                            else
                            {
                                _indexMap[typename] = new TypeIndex(typename, _indexForAll);
                            }
                            indexedDefined = true;
                        }
                    }
                }
            }
            else
            {
                _indexMap["default"] = new VirtualQueryIndex(_cache);
            }
            if (indexedDefined)
            {
                _asyncProcessor = new AsyncProcessor(_cache.Context.NCacheLog);
                _asyncProcessor.Start();
            }
            return(indexedDefined);
        }
Пример #6
0
        public virtual Hashtable GetQueryInfo(object key, object value)
        {
            Hashtable queryInfo     = new Hashtable();
            Hashtable queryIndex    = new Hashtable();
            Hashtable namedTagInfo  = new Hashtable();
            Hashtable namedTagsList = new Hashtable();

            Hashtable  tagInfo  = new Hashtable();
            ArrayList  tagsList = new ArrayList();
            CacheEntry entry    = (CacheEntry)value;

            if (entry.ObjectType == null)
            {
                return(queryInfo);
            }
            IQueryIndex      index            = (IQueryIndex)_indexMap[entry.ObjectType];
            IndexInformation indexInformation = entry.IndexInfo;

            lock (_indexMap.SyncRoot)
            {
                if (indexInformation != null)
                {
                    if (_typeMap != null)
                    {
                        int handleId = _typeMap.GetHandleId(entry.ObjectType);
                        if (handleId > -1)
                        {
                            ArrayList attributes = _typeMap.GetAttribList(handleId);

                            ArrayList attributeValues = new ArrayList();

                            for (int i = 0; i < attributes.Count; i++)
                            {
                                foreach (IndexStoreInformation indexStoreInfo in indexInformation.IndexStoreInformations)
                                {
                                    if (attributes[i].ToString() == indexStoreInfo.StoreName)
                                    {
                                        if (indexStoreInfo.IndexPosition == null)
                                        {
                                            attributeValues.Add(null);
                                        }
                                        else
                                        {
                                            object val = indexStoreInfo.IndexPosition.GetKey();

                                            string objValue = null;

                                            if (val is DateTime)
                                            {
                                                objValue = ((DateTime)val).Ticks.ToString();
                                            }
                                            else
                                            {
                                                objValue = val.ToString();
                                            }

                                            attributeValues.Add(objValue);
                                        }
                                        break;
                                    }
                                }
                            }
                            queryIndex.Add(handleId, attributeValues);
                            queryInfo["query-info"] = queryIndex;
                        }
                    }
                }


                if (indexInformation != null)
                {
                    foreach (IndexStoreInformation indexStoreinfo in indexInformation.IndexStoreInformations)
                    {
                        if (AttributeIndex.IsNamedTagKey(indexStoreinfo.StoreName))
                        {
                            if (indexStoreinfo.IndexPosition != null)
                            {
                                namedTagsList.Add(ConvertToNamedTag(indexStoreinfo.StoreName.ToString()), indexStoreinfo.IndexPosition.GetKey());
                            }
                        }
                        else if (indexStoreinfo.StoreName.Equals(TAG_INDEX_KEY))
                        {
                            if (indexStoreinfo.IndexPosition != null)
                            {
                                tagsList.Add(indexStoreinfo.IndexPosition.GetKey());
                            }
                        }
                    }
                }
                namedTagInfo["type"]            = entry.ObjectType;
                namedTagInfo["named-tags-list"] = namedTagsList;
                queryInfo["named-tag-info"]     = namedTagInfo;

                tagInfo["type"]       = entry.ObjectType;
                tagInfo["tags-list"]  = tagsList;
                queryInfo["tag-info"] = tagInfo;
            }
            return(queryInfo);
        }
Пример #7
0
        public void createSharedTypeAttributeIndex(Hashtable knownSharedClasses, Hashtable indexedClasses)
        {
            Hashtable commonRBStore = new Hashtable();
            Dictionary <string, AttributeIndex> sharedAttributeIndexMap = new Dictionary <string, AttributeIndex>();
            IEnumerator iteouterSharedTypes = knownSharedClasses.GetEnumerator();
            Type        genericType         = typeof(RBStore <>).MakeGenericType(Common.MemoryUtil.GetDataType(Common.MemoryUtil.Net_System_String));
            IIndexStore store = (IIndexStore)Activator.CreateInstance(genericType, new object[] { _cacheName, Common.MemoryUtil.Net_System_String, this.TAG_INDEX_KEY });

            commonRBStore.Add(this.TAG_INDEX_KEY, store);

            while (iteouterSharedTypes.MoveNext())
            {
                DictionaryEntry outerEntry      = (DictionaryEntry)iteouterSharedTypes.Current;
                Hashtable       outerEntryValue = (Hashtable)outerEntry.Value;
                string          name            = (string)outerEntryValue["name"];
                string[]        temp            = StringHelperClass.StringSplit(name, ":", true);
                string          outerTypeName   = temp[0];
                //Create Attribute Index even if not queryindexed
                sharedAttributeIndexMap.Add(outerTypeName, new AttributeIndex(_cacheName, outerTypeName));

                sharedAttributeIndexMap[outerTypeName].TypeMap = _typeMap;

                if (indexedClasses.Count > 0 && isQueryindexed(outerTypeName, indexedClasses))
                {
                    Hashtable outerTypeAttributes = (Hashtable)outerEntryValue["attribute"];
                    if (outerTypeAttributes != null)
                    {
                        IEnumerator iteOuterTypeAttribute = outerTypeAttributes.GetEnumerator();
                        while (iteOuterTypeAttribute.MoveNext())
                        {
                            DictionaryEntry tempEntry          = (DictionaryEntry)iteOuterTypeAttribute.Current;
                            Hashtable       outerAttributeMeta = (Hashtable)tempEntry.Value;

                            string outerOrderNo       = (string)outerAttributeMeta["order"];
                            string outerAttributeName = (string)outerAttributeMeta["name"];
                            if (isQueryindexedAttribute(outerTypeName, outerAttributeName, indexedClasses))
                            {
                                IEnumerator iteInnerSharedTypes = knownSharedClasses.GetEnumerator();
                                while (iteInnerSharedTypes.MoveNext())
                                {
                                    DictionaryEntry innerEntry = (DictionaryEntry)iteInnerSharedTypes.Current;

                                    Hashtable innerEntryValue = (Hashtable)innerEntry.Value;
                                    string    name1           = (string)innerEntryValue["name"];
                                    string[]  temp1           = StringHelperClass.StringSplit(name1, ":", true);
                                    string    innerTypeName   = temp1[0];
                                    if (!outerTypeName.Equals(innerTypeName) && isQueryindexed(innerTypeName, indexedClasses))
                                    {
                                        Hashtable innerTypeAttributes = (Hashtable)((Hashtable)innerEntry.Value)["attribute"];

                                        IEnumerator iteInnerTypeAttribute = innerTypeAttributes.GetEnumerator();
                                        while (iteInnerTypeAttribute.MoveNext())
                                        {
                                            DictionaryEntry tempEntry1         = (DictionaryEntry)iteInnerTypeAttribute.Current;
                                            Hashtable       innerAttributeMeta = (Hashtable)tempEntry1.Value;

                                            string innerorderNo       = (string)innerAttributeMeta["order"];
                                            string innerAttributeName = (string)innerAttributeMeta["name"];
                                            if (innerorderNo.Equals(outerOrderNo) && isQueryindexedAttribute(innerTypeName, innerAttributeName, indexedClasses))
                                            {
                                                if (commonRBStore.ContainsKey(outerTypeName + ":" + outerAttributeName))
                                                {
                                                    if (!commonRBStore.ContainsKey(innerTypeName + ":" + innerAttributeName))
                                                    {
                                                        IIndexStore commonRB = (IIndexStore)commonRBStore[outerTypeName + ":" + outerAttributeName];
                                                        commonRBStore.Add(innerTypeName + ":" + innerAttributeName, commonRB);
                                                    }
                                                    break;
                                                }
                                                else
                                                {
                                                    String storeDataType = TypeInfoMap.GetAttributeType(innerTypeName, innerAttributeName);
                                                    genericType = typeof(RBStore <>).MakeGenericType(Common.MemoryUtil.GetDataType(storeDataType));
                                                    IIndexStore commonRB = (IIndexStore)Activator.CreateInstance(genericType, new object[] { _cacheName, storeDataType, innerAttributeName });

                                                    commonRBStore.Add(innerTypeName + ":" + innerAttributeName, commonRB);
                                                    commonRBStore.Add(outerTypeName + ":" + outerAttributeName, commonRB);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }


            if (sharedAttributeIndexMap.Count > 0)
            {
                IEnumerator iteSharedIndexMap = sharedAttributeIndexMap.GetEnumerator();
                while (iteSharedIndexMap.MoveNext())
                {
                    List <AttributeIndex> sharedTypes = new List <AttributeIndex>();
                    System.Collections.Generic.KeyValuePair <string, AttributeIndex> outerEntry = (System.Collections.Generic.KeyValuePair <string, AttributeIndex>)iteSharedIndexMap.Current;
                    string         outerTypeName    = (string)outerEntry.Key;
                    AttributeIndex outerSharedIndex = (AttributeIndex)outerEntry.Value;
                    foreach (System.Collections.Generic.KeyValuePair <string, AttributeIndex> innerEntry in sharedAttributeIndexMap)
                    {
                        string innerTypeName = (string)innerEntry.Key;
                        if (!innerTypeName.Equals(outerTypeName))
                        {
                            AttributeIndex innerSharedIndex = (AttributeIndex)innerEntry.Value;
                            sharedTypes.Add(innerSharedIndex);
                        }
                    }
                    outerSharedIndex.CommonRBStores = commonRBStore;
                    _sharedAttributeIndex.Add(outerTypeName, outerSharedIndex);
                }
            }
        }
Пример #8
0
        internal virtual bool Initialize()
        {
            bool indexedDefined = false;
            if (_props != null)
            {
                if (_props.Contains("index-for-all"))
                {
                    _indexForAll = Convert.ToBoolean(_props["index-for-all"]);
                    indexedDefined = _indexForAll;
                }

                if (_props.Contains("index-classes"))
                {
                    Hashtable indexClasses = _props["index-classes"] as Hashtable;
                    _typeMap = new TypeInfoMap(indexClasses);

                    IDictionaryEnumerator ie = indexClasses.GetEnumerator();
                    while (ie.MoveNext())
                    {
                        Hashtable innerProps = ie.Value as Hashtable;
                        string typename = "";

                        if (innerProps != null)
                        {
                            typename = (string)innerProps["id"];
                            ArrayList attribList = new ArrayList();
                            IDictionaryEnumerator en = innerProps.GetEnumerator();
                            while (en.MoveNext())
                            {
                                Hashtable attribs = en.Value as Hashtable;
                                if (attribs != null)
                                {
                                    IDictionaryEnumerator ide = attribs.GetEnumerator();
                                    while (ide.MoveNext())
                                    {
                                        Hashtable attrib = ide.Value as Hashtable;
                                        if (attrib != null)
                                        {
                                            attribList.Add(attrib["id"] as string);
                                        }
                                    }
                                }
                            }

                            //attrib level index.
                            if (attribList.Count > 0)
                            {
                                _indexMap[typename] = new AttributeIndex(attribList, _cacheName, typename, _typeMap);
                            }
                            //just a key level index.
                            else
                                _indexMap[typename] = new TypeIndex(typename, _indexForAll);
                            indexedDefined = true;
                        }
                    }
                }
            }
            else
            {
                _indexMap["default"] = new VirtualQueryIndex(_cache);
            }
            if (indexedDefined)
            {
                _asyncProcessor = new AsyncProcessor(_cache.Context.NCacheLog);
                _asyncProcessor.Start();
            }
            return indexedDefined;
        }