示例#1
0
        public virtual void RemoveFromIndex(object key, object value)
        {
            lock (_mutex)
            {
                bool             isNodeRemoved = false;
                CacheEntry       entry         = (CacheEntry)value;
                IndexInformation indexInfo     = entry.IndexInfo;
                if (indexInfo != null)
                {
                    foreach (IndexStoreInformation indexStoreInfo in indexInfo.IndexStoreInformations)
                    {
                        isNodeRemoved = false;
                        IIndexStore store = indexStoreInfo.Store;
                        if (indexStoreInfo.IndexPosition != null)
                        {
                            long prevSize = store.IndexInMemorySize;
                            isNodeRemoved        = store.Remove(key, indexStoreInfo.IndexPosition);
                            _attributeIndexSize += store.IndexInMemorySize - prevSize;
                        }
                    }
                    _keyIndexInformationSize -= indexInfo.IndexInMemorySize;
                }

                entry.IndexInfo = null;
            }
        }
示例#2
0
        public object GetAttributeValue(string key, string attributeName, IndexInformation indexInfo)
        {
            string storeName = attributeName;

            if (!_indexTable.Contains(storeName))
            {
                throw new Exception("Index is not defined for attribute '" + attributeName + "'");
            }

            IndexInformation indexInformation = indexInfo;

            object value = null;

            lock (_mutex)
            {
                foreach (IndexStoreInformation indexStoreInfo in indexInformation.IndexStoreInformations)
                {
                    if (indexStoreInfo.StoreName == storeName)
                    {
                        if (indexStoreInfo.IndexPosition != null)
                        {
                            value = indexStoreInfo.IndexPosition.GetKey();
                        }
                        else
                        {
                            return(null);
                        }
                        break;
                    }
                }
            }
            return(value);
        }
示例#3
0
 public virtual void RemoveFromIndex(object key, object value)
 {
     lock (_mutex)
     {
         CacheEntry       entry     = (CacheEntry)value;
         IndexInformation indexInfo = entry.IndexInfo;
         if (indexInfo != null && indexInfo.IndexStoreInformations != null)
         {
             foreach (IndexStoreInformation indexStoreInfo in indexInfo.IndexStoreInformations)
             {
                 IIndexStore store = indexStoreInfo.Store;
                 if (indexStoreInfo.IndexPosition != null)
                 {
                     long prevSize = store.IndexInMemorySize;
                     store.Remove(key, indexStoreInfo.IndexPosition);
                     _attributeIndexSize += store.IndexInMemorySize - prevSize;
                     string possibleNamedTagKey = ConvertToNamedTagKey(store.Name);
                     if (store.Count == 0 && IndexTable.ContainsKey(possibleNamedTagKey))
                     {
                         IndexTable.Remove(possibleNamedTagKey);
                     }
                 }
             }
             _keyIndexInformationSize -= indexInfo.IndexInMemorySize;
         }
         entry.IndexInfo = null;
     }
 }
示例#4
0
        public object GetAttributeValue(string key, string attributeName)
        {
            string storeName = attributeName;

            if (!_indexTable.Contains(storeName))
            {
                throw new Exception("Index is not defined for attribute '" + attributeName + "'");
            }

            IndexInformation indexInformation = GetIndexInformation(key);

            IComparable value = null;

            foreach (IndexStoreInformation indexStoreInfo in indexInformation.IndexStoreInformations)
            {
                if (indexStoreInfo.StoreName == storeName)
                {
                    if (indexStoreInfo.IndexPosition != null)
                    {
                        value = indexStoreInfo.IndexPosition.RBReference.Key;
                    }
                    else
                    {
                        return(null);
                    }
                    break;
                }
            }
            return(value);
        }
示例#5
0
        public virtual Hashtable GetQueryInfo(object key, object value)
        {
            Hashtable  queryInfo  = new Hashtable();
            Hashtable  queryIndex = new Hashtable();
            CacheEntry entry      = (CacheEntry)value;

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

            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;
                }
            }
            return(queryInfo);
        }
示例#6
0
        public virtual void AddToIndex(object key, object value)
        {
            lock (_mutex)
            {
                QueryItemContainer    container       = (QueryItemContainer)value;
                CacheEntry            entry           = container.Item;
                Hashtable             attributeValues = container.ItemArrtributes;
                IDictionaryEnumerator valuesDic       = attributeValues.GetEnumerator();
                INodeReference        keyNode         = null;
                while (valuesDic.MoveNext())
                {
                    string      indexKey  = (string)valuesDic.Key;
                    string      storeName = indexKey;
                    IIndexStore store     = _indexTable[indexKey] as IIndexStore;
                    keyNode = null;

                    if (store != null)
                    {
                        long   prev = store.IndexInMemorySize;
                        object val  = valuesDic.Value;

                        if (val != null)
                        {
                            keyNode = (INodeReference)store.Add(val, key);
                        }

                        _attributeIndexSize += store.IndexInMemorySize - prev;
                    }

                    storeName = Common.Util.StringPool.PoolString(storeName);

                    IndexInformation info;

                    if (entry.IndexInfo != null)
                    {
                        info = entry.IndexInfo;
                    }
                    else
                    {
                        info = new IndexInformation();
                    }

                    long prevSize = info.IndexInMemorySize;

                    info.Add(storeName, store, keyNode);

                    this._keyIndexInformationSize += info.IndexInMemorySize - prevSize;
                    entry.IndexInfo = info;
                }
            }
        }
示例#7
0
        public virtual void AddToIndex(object key, object value)
        {
            Hashtable             attributeValues = value as Hashtable;
            IDictionaryEnumerator valuesDic       = attributeValues.GetEnumerator();
            RedBlackNodeReference keyNode         = null;

            while (valuesDic.MoveNext())
            {
                string      indexKey  = (string)valuesDic.Key;
                string      storeName = indexKey;
                IIndexStore store     = _indexTable[indexKey] as IIndexStore;
                keyNode = null;

                if (store != null)
                {
                    long   prev = store.IndexInMemorySize;
                    object val  = valuesDic.Value;

                    if (val != null)
                    {
                        keyNode = (RedBlackNodeReference)store.Add(val, key);
                    }

                    _attributeIndexSize += store.IndexInMemorySize - prev;
                }

                storeName = Common.Util.StringPool.PoolString(storeName);

                IndexInformation info;

                if (_keyIndexTable.Contains(key))
                {
                    info = _keyIndexTable[key] as IndexInformation;
                }
                else
                {
                    info = new IndexInformation();
                }

                long prevSize = info.IndexInMemorySize;

                info.Add(storeName, store, keyNode);
                _keyIndexTable[key] = info;

                this._keyIndexInformationSize += info.IndexInMemorySize - prevSize;
                if (_keyIndexTable.Count > _keyIndexTableMaxCount)
                {
                    _keyIndexTableMaxCount = _keyIndexTable.Count;
                }
            }
        }
示例#8
0
        public virtual void RemoveFromIndex(object key)
        {
            bool             isNodeRemoved = false;
            IndexInformation indexInfo     = (IndexInformation)_keyIndexTable[key];

            if (indexInfo != null)
            {
                foreach (IndexStoreInformation indexStoreInfo in indexInfo.IndexStoreInformations)
                {
                    isNodeRemoved = false;
                    IIndexStore store = indexStoreInfo.Store;
                    if (indexStoreInfo.IndexPosition != null)
                    {
                        long prevSize = store.IndexInMemorySize;
                        isNodeRemoved        = store.Remove(key, indexStoreInfo.IndexPosition);
                        _attributeIndexSize += store.IndexInMemorySize - prevSize;
                    }
                }
                _keyIndexInformationSize -= indexInfo.IndexInMemorySize;
            }

            _keyIndexTable.Remove(key);
        }
示例#9
0
        public virtual void AddToIndex(object key, object value)
        {
            lock (_mutex)
            {
                QueryItemContainer    container       = (QueryItemContainer)value;
                CacheEntry            entry           = container.Item;
                Hashtable             attributeValues = container.ItemArrtributes;
                IDictionaryEnumerator valuesDic       = attributeValues.GetEnumerator();
                INodeReference        keyNode;
                while (valuesDic.MoveNext())
                {
                    string indexKey = (string)valuesDic.Key;
                    object val      = valuesDic.Value;

                    string      storeName = indexKey;
                    IIndexStore store     = IndexTable[indexKey] as IIndexStore;
                    keyNode = null;

                    if (store == null)
                    {
                        if (indexKey == TAG_INDEX_KEY)
                        {
                            Type genericType =
                                typeof(RBStore <>).MakeGenericType(
                                    Common.MemoryUtil.GetDataType(Common.MemoryUtil.Net_System_String));
                            store =
                                (IIndexStore)
                                Activator.CreateInstance(genericType,
                                                         new object[]
                                                         { CacheName, Common.MemoryUtil.Net_System_String, indexKey, _haveDuplicateKeys });
                            IndexTable[indexKey] = store;
                        }
                        else
                        {
                            string namedTagIndexKey = ConvertToNamedTagKey(indexKey);
                            storeName = namedTagIndexKey;
                            store     = IndexTable[namedTagIndexKey] as IIndexStore;


                            if (store == null)
                            {
                                String storeDataType = String.Empty;
                                if (val != null)
                                {
                                    Type type = val.GetType();
                                    storeDataType = type.FullName;
                                }
                                Type genericType =
                                    typeof(RBStore <>).MakeGenericType(Common.MemoryUtil.GetDataType(storeDataType));
                                store =
                                    (IIndexStore)
                                    Activator.CreateInstance(genericType,
                                                             new object[]
                                                             { CacheName, storeDataType, namedTagIndexKey, _haveDuplicateKeys });

                                IndexTable.Add(namedTagIndexKey, store);
                            }
                        }
                    }

                    if (store != null)
                    {
                        long prev = store.IndexInMemorySize;

                        if (val != null)
                        {
                            keyNode = (INodeReference)store.Add(val, key);
                        }
                        _attributeIndexSize += store.IndexInMemorySize - prev;
                    }

                    storeName = StringPool.PoolString(storeName);

                    IndexInformation info;

                    if (entry.IndexInfo != null)
                    {
                        info = entry.IndexInfo;
                    }
                    else
                    {
                        info = new IndexInformation();
                    }
                    long prevSize = info.IndexInMemorySize;

                    info.Add(storeName, store, keyNode);

                    _keyIndexInformationSize += info.IndexInMemorySize - prevSize;
                    entry.IndexInfo           = info;
                }
            }
        }
示例#10
0
        public virtual void AddToIndex(object key, object value)
        {
            Hashtable attributeValues = value as Hashtable;
            IDictionaryEnumerator valuesDic = attributeValues.GetEnumerator();
            RedBlackNodeReference keyNode = null;
            while (valuesDic.MoveNext())
            {
                string indexKey = (string)valuesDic.Key;
                string storeName = indexKey;
                IIndexStore store = _indexTable[indexKey] as IIndexStore;
                keyNode = null;

                if (store != null)
                {
                    long prev = store.IndexInMemorySize;
                    object val = valuesDic.Value;

                    if (val != null)
                        keyNode = (RedBlackNodeReference)store.Add(val, key);

                    _attributeIndexSize += store.IndexInMemorySize - prev;
                }

                storeName = Common.Util.StringPool.PoolString(storeName);

                IndexInformation info;

                if (_keyIndexTable.Contains(key))
                {
                    info = _keyIndexTable[key] as IndexInformation;
                }
                else
                {
                    info = new IndexInformation();
                }

                long prevSize = info.IndexInMemorySize;

                info.Add(storeName, store, keyNode);
                _keyIndexTable[key] = info;

                this._keyIndexInformationSize += info.IndexInMemorySize - prevSize;
                if (_keyIndexTable.Count > _keyIndexTableMaxCount)
                    _keyIndexTableMaxCount = _keyIndexTable.Count;

            }
        }
示例#11
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);
        }
示例#12
0
        public object GetAttributeValue(string key, string attributeName, IndexInformation indexInfo)
        {
            string storeName = attributeName;
            if (!_indexTable.Contains(storeName))
                throw new Exception("Index is not defined for attribute '" + attributeName + "'");

            IndexInformation indexInformation = indexInfo;

            object value = null;
            foreach (IndexStoreInformation indexStoreInfo in indexInformation.IndexStoreInformations)
            {
                if (indexStoreInfo.StoreName == storeName)
                {
                    if (indexStoreInfo.IndexPosition != null)
                        value = indexStoreInfo.IndexPosition.GetKey();
                    else
                        return null;
                    break;
                }
            }
            return value;
        }
示例#13
0
        public virtual void AddToIndex(object key, object value)
        {
            QueryItemContainer container = (QueryItemContainer)value;
            CacheEntry entry = container.Item;
            Hashtable attributeValues = container.ItemArrtributes;
            IDictionaryEnumerator valuesDic = attributeValues.GetEnumerator();
            INodeReference keyNode = null;
            while (valuesDic.MoveNext())
            {
                string indexKey = (string)valuesDic.Key;
                string storeName = indexKey;
                IIndexStore store = _indexTable[indexKey] as IIndexStore;
                keyNode = null;

                if (store != null)
                {
                    long prev = store.IndexInMemorySize;
                    object val = valuesDic.Value;

                    if (val != null)
                        keyNode = (INodeReference)store.Add(val, key);

                    _attributeIndexSize += store.IndexInMemorySize - prev;
                }

                storeName = Common.Util.StringPool.PoolString(storeName);

                IndexInformation info;

                if (entry.IndexInfo != null)
                {
                    info = entry.IndexInfo;
                }
                else
                {
                    info = new IndexInformation();
                }

                long prevSize = info.IndexInMemorySize;

                info.Add(storeName, store, keyNode);

                this._keyIndexInformationSize += info.IndexInMemorySize - prevSize;
                entry.IndexInfo = info;

            }
        }