コード例 #1
0
        private static string GetParametersToken(EntityCommand entityCommand)
        {
            if (entityCommand.Parameters == null || entityCommand.Parameters.Count == 0)
            {
                return("@@0");
            }
            Dictionary <string, TypeUsage> parameterTypeUsage = entityCommand.GetParameterTypeUsage();

            if (1 == parameterTypeUsage.Count)
            {
                return("@@1:" + entityCommand.Parameters[0].ParameterName + ":" + EntityClientCacheKey.GetTypeUsageToken(parameterTypeUsage[entityCommand.Parameters[0].ParameterName]));
            }
            StringBuilder stringBuilder = new StringBuilder(entityCommand.Parameters.Count * 20);

            stringBuilder.Append("@@");
            stringBuilder.Append(entityCommand.Parameters.Count);
            stringBuilder.Append(":");
            string str = "";

            foreach (KeyValuePair <string, TypeUsage> keyValuePair in parameterTypeUsage)
            {
                stringBuilder.Append(str);
                stringBuilder.Append(keyValuePair.Key);
                stringBuilder.Append(":");
                stringBuilder.Append(EntityClientCacheKey.GetTypeUsageToken(keyValuePair.Value));
                str = ";";
            }
            return(stringBuilder.ToString());
        }
コード例 #2
0
 internal EntityClientCacheKey(EntityCommand entityCommand)
 {
     this._commandType     = entityCommand.CommandType;
     this._eSqlStatement   = entityCommand.CommandText;
     this._parametersToken = EntityClientCacheKey.GetParametersToken(entityCommand);
     this._parameterCount  = entityCommand.Parameters.Count;
     this._hashCode        = this._commandType.GetHashCode() ^ this._eSqlStatement.GetHashCode() ^ this._parametersToken.GetHashCode();
 }
コード例 #3
0
        public override bool Equals(object otherObject)
        {
            if (typeof(EntityClientCacheKey) != otherObject.GetType())
            {
                return(false);
            }
            EntityClientCacheKey entityClientCacheKey = (EntityClientCacheKey)otherObject;

            if (this._commandType == entityClientCacheKey._commandType && this._parameterCount == entityClientCacheKey._parameterCount && this.Equals(entityClientCacheKey._eSqlStatement, this._eSqlStatement))
            {
                return(this.Equals(entityClientCacheKey._parametersToken, this._parametersToken));
            }
            return(false);
        }
コード例 #4
0
        // <summary>
        // Gets an entitycommanddefinition from cache if a match is found for the given cache key.
        // </summary>
        // <param name="entityCommandDefinition"> out param. returns the entitycommanddefinition for a given cache key </param>
        // <returns> true if a match is found in cache, false otherwise </returns>
        private bool TryGetEntityCommandDefinitionFromQueryCache(out EntityCommandDefinition entityCommandDefinition)
        {
            Debug.Assert(null != _connection, "Connection must not be null at this point");
            entityCommandDefinition = null;

            // if EnableQueryCaching is false, then just return to force the CommandDefinition to be created
            if (!_enableQueryPlanCaching
                || string.IsNullOrEmpty(_esqlCommandText))
            {
                return false;
            }

            // Create cache key
            var queryCacheKey = new EntityClientCacheKey(this);

            // Try cache lookup
            var queryCacheManager = _connection.GetMetadataWorkspace().GetQueryCacheManager();
            Debug.Assert(null != queryCacheManager, "QuerycacheManager instance cannot be null");
            if (!queryCacheManager.TryCacheLookup(queryCacheKey, out entityCommandDefinition))
            {
                // if not, construct the command definition using no special options;
                entityCommandDefinition = CreateCommandDefinition();

                // add to the cache
                QueryCacheEntry outQueryCacheEntry = null;
                if (queryCacheManager.TryLookupAndAdd(new QueryCacheEntry(queryCacheKey, entityCommandDefinition), out outQueryCacheEntry))
                {
                    entityCommandDefinition = (EntityCommandDefinition)outQueryCacheEntry.GetTarget();
                }
            }

            Debug.Assert(null != entityCommandDefinition, "out entityCommandDefinition must not be null");

            return true;
        }