Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="Radischevo.Wahha.Data.DbCommandResult"/> class.
 /// </summary>
 /// <param name="provider">The <see cref="Radischevo.Wahha.Data.IDbDataProvider"/>
 /// instance used to access the database.</param>
 /// <param name="command">The <see cref="Radischevo.Wahha.Data.DbCommandDescriptor"/>
 /// describing the command to execute.</param>
 public DbCommandResult(IDbDataProvider provider, DbCommandDescriptor command)
 {
     Precondition.Require(provider, () => Error.ArgumentNull("provider"));
     _provider = provider;
     _command  = command;
     _behavior = CommandBehavior.Default;
 }
        /// <summary>
        /// Executes the operation against the provided data source
        /// and returns the result.
        /// </summary>
        /// <param name="context">Provides the current operation context.</param>
        protected override TResult ExecuteInternal(DbOperationContext context)
        {
            DbCommandDescriptor command = CreateCommand();

            Precondition.Require(command, () => Error.CommandIsNotInitialized());

            return(ExecuteCommand(context, command));
        }
        /// <summary>
        /// Executes the provided <paramref name="command"/>
        /// against the provided data source and returns the result.
        /// </summary>
        /// <param name="context">Provides the current operation context.</param>
        /// <param name="command">The command instance to execute.</param>
        protected override TEntity ExecuteCommand(DbOperationContext context,
                                                  DbCommandDescriptor command)
        {
            return(context.Provider.Execute(command).AsDataReader <TEntity>(reader => {
                if (reader.Read())
                {
                    return Materializer.Materialize(reader);
                }

                return default(TEntity);
            }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Executes the operation against the provided data source
        /// and returns the result.
        /// </summary>
        /// <param name="context">Provides the current operation context.</param>
        protected override TResult ExecuteInternal(DbOperationContext context)
        {
            DbCommandDescriptor command = CreateCommand();

            Precondition.Require(command, () => Error.CommandIsNotInitialized());

            string cacheKey = CreateCacheKey(command);

            return(context.Cache.Get <TResult>(cacheKey,
                                               () => ExecuteCommand(context, command),
                                               DateTime.Now.Add(_expirationTimeout),
                                               Tags));
        }
        /// <summary>
        /// Executes the provided <paramref name="command"/>
        /// against the provided data source and returns the result.
        /// </summary>
        /// <param name="context">Provides the current operation context.</param>
        /// <param name="command">The command instance to execute.</param>
        protected override IEnumerable <TEntity> ExecuteCommand(DbOperationContext context,
                                                                DbCommandDescriptor command)
        {
            return(context.Provider.Execute(command).AsDataReader(reader => {
                List <TEntity> collection = new List <TEntity>(BufferSize);
                while (reader.Read())
                {
                    collection.Add(Materializer.Materialize(reader));
                }

                return collection;
            }));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Executes the provided <paramref name="command"/>
        /// against the provided data source and returns the result.
        /// </summary>
        /// <param name="context">Provides the current operation context.</param>
        /// <param name="command">The command instance to execute.</param>
        protected override IEnumerable <TEntity> ExecuteCommand(DbOperationContext context,
                                                                DbCommandDescriptor command)
        {
            return(context.Provider.Execute(command).AsDataReader(reader => {
                List <TEntity> collection = new List <TEntity>(BufferSize);
                int count = 0;

                while (reader.Read())
                {
                    collection.Add(Materializer.Materialize(reader));
                }

                if (reader.NextResult() && reader.Read())
                {
                    count = reader.GetValue <int>(0);
                }

                return collection.ToSubset(count);
            }));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates the unique cache key based on the text representation
        /// of the provided command and its parameters values.
        /// </summary>
        /// <param name="command">The command to create fingerprint from.</param>
        protected virtual string CreateCacheKey(DbCommandDescriptor command)
        {
            StringBuilder sb       = new StringBuilder();
            MD5           md5      = MD5.Create();
            Encoding      encoding = Encoding.UTF8;

            sb.Append(GetType().FullName).Append("::")
            .Append(command.Text).Append("::")
            .Append(command.Type.ToString());

            sb.Append("=>{");

            foreach (DbParameterDescriptor parameter in command.Parameters)
            {
                sb.Append("[").Append(parameter.Name).Append("=")
                .Append((parameter.Value == DBNull.Value) ? "<NULL>" :
                        Convert.ToString(parameter.Value, CultureInfo.InvariantCulture))
                .Append("]");
            }
            sb.Append("}");
            return(Converter.ToBase16String(md5.ComputeHash(encoding.GetBytes(sb.ToString()))));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a <see cref="Radischevo.Wahha.Data.DbCommandResult"/> wrapper for
 /// the specified <paramref name="command"/>.
 /// </summary>
 /// <param name="provider">An instance of data provider being extended.</param>
 /// <param name="command">The object, describing the command to execute.</param>
 public static DbCommandResult Execute(this IDbDataProvider provider, DbCommandDescriptor command)
 {
     Precondition.Require(provider, () => Error.ArgumentNull("provider"));
     return(new DbCommandResult(provider, command));
 }
		/// <summary>
		/// Creates a <see cref="Radischevo.Wahha.Data.DbCommandResult"/> wrapper for 
		/// the specified <paramref name="command"/>.
		/// </summary>
		/// <param name="provider">An instance of data provider being extended.</param>
		/// <param name="command">The object, describing the command to execute.</param>
		public static DbCommandResult Execute(this IDbDataProvider provider, DbCommandDescriptor command)
		{
			Precondition.Require(provider, () => Error.ArgumentNull("provider"));
			return new DbCommandResult(provider, command);
		}
Ejemplo n.º 10
0
 /// <summary>
 /// Executes the operation against the provided data source
 /// and returns a number of rows affected.
 /// </summary>
 /// <param name="context">Provides the current operation context.</param>
 /// <param name="command">The command instance to execute.</param>
 protected override int ExecuteCommand(DbOperationContext context,
                                       DbCommandDescriptor command)
 {
     return(context.Provider.Execute(command).AsNonQuery());
 }
 /// <summary>
 /// When overridden in a derived class, executes the provided <paramref name="command"/>
 /// against the provided data source and returns the result.
 /// </summary>
 /// <param name="context">Provides the current operation context.</param>
 /// <param name="command">The command instance to execute.</param>
 protected abstract TResult ExecuteCommand(DbOperationContext context, DbCommandDescriptor command);
Ejemplo n.º 12
0
 /// <summary>
 /// Executes the operation against the provided data source
 /// and returns the scalar result.
 /// </summary>
 /// <param name="context">Provides the current operation context.</param>
 /// <param name="command">The command instance to execute.</param>
 protected override TResult ExecuteCommand(DbOperationContext context,
                                           DbCommandDescriptor command)
 {
     return(context.Provider.Execute(command).AsScalar <TResult>());
 }