public AttributeIndex(ArrayList attribList, string cacheName, string type, TypeInfoMap typeMap) { _indexTable = new HashVector(); _cacheName = cacheName; _type = type; _typeMap = typeMap; Initialize(attribList); }
/// <summary> /// Inicializa a instancia. /// </summary> /// <returns></returns> internal virtual bool Initialize() { bool flag = false; if (_props != null) { if (_props.Contains("index-for-all")) { _indexForAll = Convert.ToBoolean(_props["index-for-all"]); flag = _indexForAll; } if (_props.Contains("index-classes")) { Hashtable indexClasses = _props["index-classes"] as Hashtable; _typeMap = new TypeInfoMap(indexClasses); IDictionaryEnumerator enumerator = indexClasses.GetEnumerator(); while (enumerator.MoveNext()) { Hashtable hashtable2 = enumerator.Value as Hashtable; string type = ""; if (hashtable2 != null) { type = (string)hashtable2["id"]; var attributes = new List <string>(); IDictionaryEnumerator enumerator2 = hashtable2.GetEnumerator(); while (enumerator2.MoveNext()) { Hashtable hashtable3 = enumerator2.Value as Hashtable; if (hashtable3 != null) { IDictionaryEnumerator enumerator3 = hashtable3.GetEnumerator(); while (enumerator3.MoveNext()) { Hashtable hashtable4 = enumerator3.Value as Hashtable; if (hashtable4 != null) { attributes.Add(hashtable4["id"] as string); } } } } if (attributes.Count > 0) { _indexMap[type] = new AttributeIndex(attributes, _cacheName); } else { _indexMap[type] = new TypeIndex(type, _indexForAll); } flag = true; } } } else { _typeMap = new TypeInfoMap(new Hashtable()); } } else { _indexMap["default"] = new VirtualQueryIndex(_cache); _typeMap = new TypeInfoMap(new Hashtable()); } _typeMap.HandleAdded += new Action <int>(TypeMap_HandleAdded); if (flag) { _asyncProcessor = new AsyncProcessor("Cache.QueryIndexManager", _cache.Context.Logger); _asyncProcessor.Start(); } return(flag); }
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); }
/// <summary> /// Recupera uma entrada do cache. /// </summary> /// <param name="key"></param> /// <param name="item"></param> /// <param name="flag"></param> /// <param name="group"></param> /// <param name="subGroup"></param> /// <param name="cacheEntry"></param> /// <returns></returns> public UserBinaryObject GetCacheEntry(string key, ProviderCacheItem item, ref BitSet flag, string group, string subGroup, out CacheEntry cacheEntry) { UserBinaryObject val = null; cacheEntry = null; object serializableObject = null; if ((item != null) && (item.Value != null)) { if ((item.Group == null) && (item.SubGroup != null)) { throw new OperationFailedException("Error occurred while synchronization with data source; group must be specified for sub group"); } if ((group != null) && !CacheHelper.CheckDataGroupsCompatibility(new GroupInfo(item.Group, item.SubGroup), new GroupInfo(group, subGroup))) { throw new OperationFailedException("Error occurred while synchronization with data source; groups are incompatible"); } if (flag == null) { flag = new BitSet(); } serializableObject = item.Value; Hashtable hashtable = new Hashtable(); TypeInfoMap typeInfoMap = _context.CacheRoot.GetTypeInfoMap(); hashtable["query-info"] = CacheLoaderUtil.GetQueryInfo(item.Value, typeInfoMap); if (item.Tags != null) { Hashtable tagInfo = CacheLoaderUtil.GetTagInfo(item.Value, item.Tags); if (tagInfo != null) { hashtable.Add("tag-info", tagInfo); } } if (item.NamedTags != null) { try { Hashtable hashtable3 = CacheLoaderUtil.GetNamedTagsInfo(item.Value, item.NamedTags, typeInfoMap); if (hashtable3 != null) { hashtable.Add("named-tag-info", hashtable3); } } catch (Exception exception) { throw new OperationFailedException("Error occurred while synchronization with data source; " + exception.Message); } } if (!item.Value.GetType().IsSerializable&& !_type.IsAssignableFrom(item.Value.GetType())) { throw new OperationFailedException("Read through provider returned an object that is not serializable."); } serializableObject = SerializationUtil.SafeSerialize(serializableObject, _context.SerializationContext, ref flag); if (_context.CompressionEnabled) { item.Value = CompressionUtil.Compress(item.Value as byte[], ref flag, _context.CompressionThreshold); } val = UserBinaryObject.CreateUserBinaryObject(serializableObject as byte[]); EvictionHint evictionHint = new PriorityEvictionHint(item.ItemPriority); ExpirationHint expiryHint = DependencyHelper.GetExpirationHint(item.Dependency, item.AbsoluteExpiration, item.SlidingExpiration); if (expiryHint != null) { expiryHint.CacheKey = key; if (item.ResyncItemOnExpiration) { expiryHint.SetBit(2); } } cacheEntry = new CacheEntry(val, expiryHint, evictionHint); cacheEntry.Flag = flag; cacheEntry.GroupInfo = new GroupInfo(item.Group, item.SubGroup); cacheEntry.QueryInfo = hashtable; cacheEntry.ResyncProviderName = (item.ResyncProviderName == null) ? null : item.ResyncProviderName.ToLower(); } return(val); }
/// <summary> /// Processa os dados carregados do LoadNext. /// </summary> /// <param name="data"></param> private void ProcessDataFromLoadNext(OrderedDictionary data) { int num = 0; byte[] buffer = null; foreach (DictionaryEntry entry in data) { EvictionHint hint2; num = 0; object key = null; ProviderCacheItem item = null; Colosoft.Caching.Expiration.ExpirationHint expiryHint = null; string resyncProviderName = null; Hashtable queryInfo = null; try { if ((!(entry.Key is string) || !(entry.Value is ProviderCacheItem))) { throw new InvalidOperationException("Invalid Key/Value type specified"); } key = entry.Key; item = (ProviderCacheItem)entry.Value; if (item == null) { continue; } CacheLoaderUtil.EvaluateExpirationParameters(item.AbsoluteExpiration, item.SlidingExpiration); expiryHint = Expiration.DependencyHelper.GetExpirationHint(item.Dependency, item.AbsoluteExpiration, item.SlidingExpiration); if ((expiryHint != null) && item.ResyncItemOnExpiration) { expiryHint.SetBit(2); } resyncProviderName = (item.ResyncProviderName == null) ? null : item.ResyncProviderName.ToLower(); queryInfo = new Hashtable(); TypeInfoMap typeInfoMap = _cache.GetTypeInfoMap(); if (typeInfoMap != null) { queryInfo["query-info"] = CacheLoaderUtil.GetQueryInfo(item.Value, typeInfoMap); } if (item.Tags != null) { queryInfo["tag-info"] = CacheLoaderUtil.GetTagInfo(item.Value, item.Tags); } if (item.NamedTags != null) { Hashtable hashtable2 = CacheLoaderUtil.GetNamedTagsInfo(item.Value, item.NamedTags, typeInfoMap); if (hashtable2 != null) { queryInfo["named-tag-info"] = hashtable2; } } } catch (Exception exception3) { OnProcessEntryError(entry, exception3); continue; } var set = new BitSet(); object currentValue = item.Value; try { hint2 = new PriorityEvictionHint(item.ItemPriority); if (!(currentValue is ICacheItemRecord)) { buffer = this.SafeSerialize(currentValue) as byte[]; if ((buffer != null) && _cache.CompressionEnabled) { buffer = IO.Compression.CompressionUtil.Compress(buffer, ref set, _cache.CompressThresholdSize); } if (buffer != null) { currentValue = UserBinaryObject.CreateUserBinaryObject(buffer); } } } catch (Exception ex) { OnLoadProcessingError(ex); continue; } while (num <= this.NoOfRetries) { if (_cache.IsRunning) { if (!CanInsertEntry(key, currentValue)) { break; } try { _cache.Insert(key, currentValue, expiryHint, null, hint2, item.Group, item.SubGroup, queryInfo, set, null, 0, LockAccessType.IGNORE_LOCK, null, resyncProviderName, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation)); } catch (Exception exception4) { num++; System.Threading.Thread.Sleep(this.RetryInterval); if (num > this.NoOfRetries) { OnInsertEntryError(key, currentValue, exception4); if (exception4 is OperationFailedException) { if (((OperationFailedException)exception4).IsTracable || !_logger.IsErrorEnabled) { continue; } _logger.Error("CacheStartupLoader.Load()".GetFormatter(), exception4); break; } if (_logger.IsErrorEnabled) { _logger.Error("CacheStartupLoader.Load()".GetFormatter(), exception4); break; } } continue; } OnInsertedEntry(key, currentValue); } break; } } }
internal static Hashtable GetQueryInfo(Object value, TypeInfoMap typeMap) { Hashtable queryInfo = null; if (typeMap == null) { return(null); } try { int handleId = typeMap.GetHandleId(value.GetType().FullName); if (handleId != -1) { queryInfo = new Hashtable(); ArrayList attribValues = new ArrayList(); ArrayList attributes = typeMap.GetAttribList(handleId); for (int i = 0; i < attributes.Count; i++) { PropertyInfo propertyAttrib = value.GetType().GetProperty((string)attributes[i]); if (propertyAttrib != null) { Object attribValue = propertyAttrib.GetValue(value, null); if (attribValue is String) //add all strings as lower case in index tree { attribValue = attribValue.ToString(); //.ToLower(); } if (attribValue is DateTime) //add all DateTime as ticks { attribValue = ((DateTime)(attribValue)).Ticks.ToString(CultureInfo.InvariantCulture); } attribValues.Add(attribValue); } else { BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance; FieldInfo fieldAttrib = value.GetType().GetField((string)attributes[i], flags); if (fieldAttrib != null) { Object attribValue = fieldAttrib.GetValue(value); if (attribValue is String) //add all strings as lower case in index tree { attribValue = attribValue.ToString(); } if (attribValue is DateTime) //add all DateTime as ticks { attribValue = ((DateTime)(attribValue)).Ticks.ToString(CultureInfo.InvariantCulture); } attribValues.Add(attribValue); } else { throw new Exception("Unable extracting query information from user object."); } } } queryInfo.Add(handleId, attribValues); } } catch (Exception) { } return(queryInfo); }
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); } } }
//- internal static Hashtable GetNamedTagsInfo(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap) { CheckDuplicateIndexName(value, namedTags, typeMap); if (namedTags == null || namedTags.Count == 0) { return(null); } Hashtable tagInfo = new Hashtable(); Hashtable tagsList = new Hashtable(); foreach (DictionaryEntry nameValue in namedTags) { if (nameValue.Key != null && string.IsNullOrEmpty(nameValue.Key.ToString().Trim())) { throw new ArgumentException("Named Tag key cannot be null or empty"); } if (nameValue.Value == null) { throw new ArgumentNullException("Named Tag value cannot be null"); } tagsList.Add(nameValue.Key, nameValue.Value); } string typeName = value.GetType().FullName; typeName = typeName.Replace("+", "."); tagInfo["type"] = typeName; tagInfo["named-tags-list"] = tagsList; return(tagInfo); }
private static void CheckDuplicateIndexName(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap) { if (namedTags == null || value == null || typeMap == null) { return; } string typeName = value.GetType().FullName; typeName = typeName.Replace("+", "."); int handleId = typeMap.GetHandleId(typeName); if (handleId != -1) { ArrayList attributes = typeMap.GetAttribList(handleId); foreach (string name in attributes) { if (namedTags.Contains(name)) //@UH whether this should be case insensitive { throw new Exception("Key in named tags conflicts with the indexed attribute name of the specified object."); } } } }
private static void CheckJavaDuplicateIndexName(string fullName, NamedTagsDictionary namedTags, TypeInfoMap typeMap) { if (namedTags == null || typeMap == null) { return; } string typeName = fullName; typeName = typeName.Replace("+", "."); int handleId = typeMap.GetHandleId(typeName); if (handleId != -1) { ArrayList attributes = typeMap.GetAttribList(handleId); foreach (string name in attributes) { if (namedTags.Contains(name)) { throw new Exception("Key in named tags conflicts with the indexed attribute name of the specified object."); } } } }
internal static Hashtable GetJavaNamedTagsInfo(string fullName, NamedTagsDictionary namedTags, TypeInfoMap typeMap) { CheckJavaDuplicateIndexName(fullName, namedTags, typeMap); if (namedTags == null || namedTags.Count == 0) { return(null); } Hashtable tagInfo = new Hashtable(); Hashtable tagsList = new Hashtable(); foreach (DictionaryEntry nameValue in namedTags) { if (nameValue.Value == null) { throw new ArgumentNullException("Named Tag value cannot be null"); } tagsList.Add(nameValue.Key, nameValue.Value); } string typeName = fullName; typeName = typeName.Replace("+", "."); tagInfo["type"] = typeName; tagInfo["named-tags-list"] = tagsList; return(tagInfo); }
/// <summary> /// Verifica se existem itens com o nome publicados. /// </summary> /// <param name="value">Instancia.</param> /// <param name="namedTags">Dicionário com as tags nomeadas.</param> /// <param name="typeMap"></param> private static void CheckDuplicateIndexName(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap) { if (namedTags != null && value != null && typeMap != null) { int handleId = 0; if (value is CacheItemRecord) { handleId = typeMap.GetHandleId(((CacheItemRecord)value).TypeName); } else { handleId = typeMap.GetHandleId(value.GetType()); } if (handleId != -1) { foreach (string str2 in typeMap.GetAttribList(handleId)) { if (namedTags.Contains(str2)) { throw new Exception(ResourceMessageFormatter.Create(() => Properties.Resources.Exception_DuplicateIndexName).Format()); } } } } }
/// <summary> /// Recupera as informações de consulta. /// </summary> /// <param name="value"></param> /// <param name="typeMap"></param> /// <returns></returns> internal static Hashtable GetQueryInfo(object value, TypeInfoMap typeMap) { Hashtable hashtable = null; ArrayList list = null; if (typeMap == null) { return(null); } try { int handleId = -1; if (value is ICacheItemRecord) { var record = (ICacheItemRecord)value; handleId = typeMap.GetHandleId(record.TypeName); if (handleId == -1) { return(hashtable); } hashtable = new Hashtable(); list = new ArrayList(); var attribList = typeMap.GetAttribList(handleId); for (int i = 0; i < attribList.Count; i++) { var fieldIndex = -1; for (int j = 0; j < record.Descriptor.Count; j++) { if (record.Descriptor[j].Name == attribList[i]) { fieldIndex = j; break; } } if (fieldIndex >= 0) { object obj2 = record.GetValue(fieldIndex); if (obj2 is string) { obj2 = obj2.ToString().ToLower(); } else if (obj2 is DateTime) { DateTime time = (DateTime)obj2; obj2 = time.Ticks.ToString(); } list.Add(obj2); } else { list.Add(null); } } } else { handleId = typeMap.GetHandleId(value.GetType()); if (handleId == -1) { return(hashtable); } hashtable = new Hashtable(); list = new ArrayList(); var attribList = typeMap.GetAttribList(handleId); for (int i = 0; i < attribList.Count; i++) { var property = value.GetType().GetProperty(attribList[i]); if (property != null) { object obj2 = property.GetValue(value, null); if (obj2 is string) { obj2 = obj2.ToString().ToLower(); } if (obj2 is DateTime) { DateTime time = (DateTime)obj2; obj2 = time.Ticks.ToString(); } list.Add(obj2); } else { var field = value.GetType().GetField((string)attribList[i]); if (field == null) { throw new Exception("Unable extracting query information from user object."); } object obj3 = field.GetValue(value); if (obj3 is string) { obj3 = obj3.ToString().ToLower(); } if (obj3 is DateTime) { DateTime time2 = (DateTime)obj3; obj3 = time2.Ticks.ToString(); } list.Add(obj3); } } } hashtable.Add(handleId, list); } catch (Exception ex) { System.Diagnostics.Debug.Fail("An error ocurred when get query info", Colosoft.Diagnostics.ExceptionFormatter.FormatException(ex, true)); throw; } return(hashtable); }
/// <summary> /// Recupera as informações das tags nomeadas. /// </summary> /// <param name="value"></param> /// <param name="namedTags"></param> /// <param name="typeMap"></param> /// <returns></returns> internal static Hashtable GetNamedTagsInfo(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap) { CheckDuplicateIndexName(value, namedTags, typeMap); if ((namedTags == null) || (namedTags.Count == 0)) { return(null); } Hashtable hashtable = new Hashtable(); Hashtable hashtable2 = new Hashtable(); foreach (DictionaryEntry entry in namedTags) { if (entry.Value == null) { throw new ArgumentNullException("Named Tag value cannot be null"); } hashtable2.Add(entry.Key, entry.Value); } hashtable["is-itemrecord"] = value is CacheItemRecord; string str = null; if (value is CacheItemRecord) { str = ((CacheItemRecord)value).TypeName.FullName; } else { str = value.GetType().FullName.Replace("+", "."); } hashtable["type"] = str; hashtable["named-tags-list"] = hashtable2; return(hashtable); }