Пример #1
0
        /// <summary>
        /// Executa a ação para atualizar os dados do registro no cache.
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        private PersistenceActionResult ExecuteUpdateAction(PersistenceAction action)
        {
            var typeName     = new Reflection.TypeName(action.EntityFullName);
            var typeMetadata = _typeSchema.GetTypeMetadata(action.EntityFullName);

            if (typeMetadata == null)
            {
                return new PersistenceActionResult {
                           Success        = false,
                           FailureMessage = ResourceMessageFormatter.Create(() => Properties.Resources.CachePersistenceExecuter_TypeMetadataNotFound, action.EntityFullName).Format(),
                }
            }
            ;
            var query = GetActionQuery(action, typeMetadata).CreateQueryInfo();

            Queries.QueryResultSet queryResult = null;
            try
            {
                queryResult = ((CacheDataSource)_sourceContext.DataSource).ExecuteInCache(query);
            }
            catch (Exception ex)
            {
                return(new PersistenceActionResult {
                    Success = false,
                    FailureMessage = ResourceMessageFormatter.Create(() => Properties.Resources.CachePersistenceExecuter_ExecuteQueryInCacheError, Colosoft.Diagnostics.ExceptionFormatter.FormatException(ex, true)).Format()
                });
            }
            Colosoft.Query.Record.RecordDescriptor recordDescriptor = null;
            try
            {
                recordDescriptor = new Colosoft.Query.Record.RecordDescriptor(action.EntityFullName, GetRecordFields(action.EntityFullName, typeMetadata));
            }
            catch (Exception ex)
            {
                return(new PersistenceActionResult {
                    Success = false,
                    FailureMessage = ex.Message
                });
            }
            var keyGenerator = _keyFactory.Value.CreateGenerator(typeName);
            var typeInfoMap  = Cache.GetTypeInfoMap();
            var keysResult   = queryResult.SearchKeysResult.ToArray();

            if (keysResult.Length > 0)
            {
                foreach (var key in keysResult)
                {
                    var record       = CacheDataSource.CreateRecord(Cache, key, ref recordDescriptor, query);
                    var recordValues = new object[recordDescriptor.Count];
                    record.GetValues(recordValues);
                    foreach (var actionParameter in action.Parameters)
                    {
                        var indexOf = 0;
                        for (; indexOf < recordDescriptor.Count; indexOf++)
                        {
                            if (StringComparer.InvariantCultureIgnoreCase.Equals(recordDescriptor[indexOf].Name, actionParameter.Name))
                            {
                                break;
                            }
                        }
                        if (indexOf < recordDescriptor.Count)
                        {
                            recordValues[indexOf] = actionParameter.Value;
                        }
                    }
                    var newRecord = new CacheItemRecord(new Reflection.TypeName(action.EntityFullName), recordValues, recordDescriptor);
                    var newKey    = keyGenerator.GetKey(newRecord);
                    try
                    {
                        var queryInfo = GetCacheEntryQueryInfo(Cache, typeInfoMap, newRecord);
                        Cache.Remove(key, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
                        var insertResult = Cache.Insert(newKey, newRecord, null, null, new Colosoft.Caching.Policies.PriorityEvictionHint(CacheItemPriority.Normal), null, null, queryInfo, new BitSet(), null, 0, LockAccessType.IGNORE_LOCK, null, null, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));
                    }
                    catch (Exception ex)
                    {
                        return(new PersistenceActionResult {
                            Success = false,
                            FailureMessage = ex.Message
                        });
                    }
                }
            }
            else
            {
            }
            return(new PersistenceActionResult {
                Success = true
            });
        }
Пример #2
0
 /// <summary>
 /// Cria uma instancia com dados já existentes.
 /// </summary>
 /// <param name="typeName">Nome do tipo.</param>
 /// <param name="values">Valores do registro.</param>
 /// <param name="descriptor"></param>
 public CacheItemRecord(Colosoft.Reflection.TypeName typeName, object[] values, Colosoft.Query.Record.RecordDescriptor descriptor) : base(descriptor, values)
 {
     _typeName = typeName;
 }
Пример #3
0
        /// <summary>
        /// Executa a ação para inserir um novo registro no cache.
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        private PersistenceActionResult ExecuteInsertAction(PersistenceAction action)
        {
            var typeMetadata = _typeSchema.GetTypeMetadata(action.EntityFullName);

            if (typeMetadata == null)
            {
                return new PersistenceActionResult {
                           Success        = false,
                           FailureMessage = ResourceMessageFormatter.Create(() => Properties.Resources.CachePersistenceExecuter_TypeMetadataNotFound, action.EntityFullName).Format(),
                }
            }
            ;
            IEnumerable <Colosoft.Query.Record.Field> recordFields = null;

            try
            {
                recordFields = GetRecordFields(action.EntityFullName, typeMetadata);
            }
            catch (Exception ex)
            {
                return(new PersistenceActionResult {
                    Success = false,
                    FailureMessage = ex.Message
                });
            }
            var recordDescriptor = new Colosoft.Query.Record.RecordDescriptor(action.EntityFullName, recordFields);
            var recordValues     = new object[recordDescriptor.Count];

            foreach (var actionParameter in action.Parameters)
            {
                var indexOf = 0;
                for (; indexOf < recordDescriptor.Count; indexOf++)
                {
                    if (StringComparer.InvariantCultureIgnoreCase.Equals(recordDescriptor[indexOf].Name, actionParameter.Name))
                    {
                        break;
                    }
                }
                if (indexOf < recordDescriptor.Count)
                {
                    recordValues[indexOf] = actionParameter.Value;
                }
                else
                {
                    return new PersistenceActionResult {
                               Success        = false,
                               FailureMessage = ResourceMessageFormatter.Create(() => Properties.Resources.CachePersistenceExecuter_PropertyMetadataNotFound, actionParameter.Name, action.EntityFullName).Format()
                    }
                };
            }
            var record       = new CacheItemRecord(new Reflection.TypeName(action.EntityFullName), recordValues, recordDescriptor);
            var typeName     = new Reflection.TypeName(action.EntityFullName);
            var keyGenerator = _keyFactory.Value.CreateGenerator(typeName);
            var key          = keyGenerator.GetKey(record);
            var queryInfo    = GetCacheEntryQueryInfo(Cache, Cache.GetTypeInfoMap(), record);
            var insertResult = Cache.Insert(key, record, null, null, new Colosoft.Caching.Policies.PriorityEvictionHint(CacheItemPriority.Normal), null, null, queryInfo, new BitSet(), null, 0, LockAccessType.IGNORE_LOCK, null, null, new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));

            return(new PersistenceActionResult {
                Success = true
            });
        }
 /// <summary>
 /// Cria uma sessão de estratégia de vinculação para o descritor informado.
 /// </summary>
 /// <param name="recordDescriptor">Descritor dos registros para fazer a vinculação.</param>
 /// <returns></returns>
 public Colosoft.Query.IQueryResultBindStrategySession CreateSession(Colosoft.Query.Record.RecordDescriptor recordDescriptor)
 {
     return(new EntityDescriptorQueryResultBindStrategySession(this));
 }