示例#1
0
        protected override void Arrange()
        {
            base.Arrange();

            parameterMapper = new ParameterMapper();
            rowMapper       = new RowMapper();
        }
示例#2
0
        protected override void Arrange()
        {
            base.Arrange();

            parameterMapper = new ParameterMapper();
            resultSetMapper = new ResultSetMapper();
        }
 public void SetUp()
 {
     _mapper = MockRepository.GenerateMock<IParameterMapper>();
     _mapper.Stub(arg => arg.CanMapType(Arg<HttpRequestBase>.Is.Anything, Arg<Type>.Is.Anything)).Return(false);
     _retriever = new ParameterValueRetriever(new[] { _mapper });
     _request = MockRepository.GenerateMock<HttpRequestBase>();
 }
示例#4
0
 public static DataAccessor <TResult> CreateSqlStringAccessor <TResult>(
     this Database database,
     string sqlString,
     IParameterMapper parameterMapper,
     IResultSetMapper <TResult> resultSetMapper)
 {
     return((DataAccessor <TResult>) new SqlStringAccessor <TResult>(database, sqlString, parameterMapper, resultSetMapper));
 }
示例#5
0
 /// <summary>
 /// Initialize a new instance of a generic ADO transaction. Use
 /// a provider-specific subclass for better performance.
 /// </summary>
 /// <param name="connectionFactory">Factory to create connections for current database.</param>
 /// <param name="parameterMapper">Provides parameter value from input object instances.</param>
 /// <param name="tracer">The OpenTracing tracer instance to use. If this value is null the global tracer will
 /// be used instead.</param>
 public SqlCommandManager(
     IConnectionFactory connectionFactory,
     IParameterMapper parameterMapper,
     ITracer?tracer)
 {
     _connectionFactory = connectionFactory;
     ParameterMapper    = parameterMapper;
     _tracer            = tracer ?? GlobalTracer.Instance;
 }
示例#6
0
 public static IEnumerable <TResult> ExecuteSprocAccessor <TResult>(
     this Database database,
     string procedureName,
     IParameterMapper parameterMapper,
     params object[] parameterValues)
     where TResult : new()
 {
     return(database.CreateSprocAccessor <TResult>(procedureName, parameterMapper).Execute(parameterValues));
 }
示例#7
0
        public static DataAccessor <TResult> CreateSprocAccessor <TResult>(
            this Database database,
            string procedureName,
            IParameterMapper parameterMapper)
            where TResult : new()
        {
            IRowMapper <TResult> rowMapper = MapBuilder <TResult> .BuildAllProperties();

            return(database.CreateSprocAccessor <TResult>(procedureName, parameterMapper, rowMapper));
        }
示例#8
0
        public static DataAccessor <TResult> CreateSqlStringAccessor <TResult>(
            this Database database,
            string sqlString,
            IParameterMapper parameterMapper)
            where TResult : new()
        {
            IRowMapper <TResult> rowMapper = MapBuilder <TResult> .BuildAllProperties();

            return((DataAccessor <TResult>) new SqlStringAccessor <TResult>(database, sqlString, parameterMapper, rowMapper));
        }
 public void SetUp()
 {
     _parameterMapper = MockRepository.GenerateMock<IParameterMapper>();
     _responseMethodReturnTypeMapper = new ResponseMethodReturnTypeMapper(_parameterMapper);
     _container = MockRepository.GenerateMock<IContainer>();
     _container.Stub(arg => arg.GetInstance(typeof(Endpoint))).Return(new Endpoint());
     _route = new Route.Routing.Route("name", Guid.NewGuid(), "relative");
     _responseMethodReturnTypeMapper.Map(() => _container, typeof(Endpoint), typeof(Endpoint).GetMethod("Method"), _route);
     _request = MockRepository.GenerateMock<HttpRequestBase>();
     _response = _route.ProcessResponse(_request);
 }
示例#10
0
 public static DataAccessor <TResult> CreateSprocAccessor <TResult>(
     this Database database,
     string procedureName,
     IParameterMapper parameterMapper,
     IResultSetMapper <TResult> resultSetMapper)
 {
     if (string.IsNullOrEmpty(procedureName))
     {
         throw new ArgumentException(Resources.ExceptionNullOrEmptyString);
     }
     return((DataAccessor <TResult>) new SprocAccessor <TResult>(database, procedureName, parameterMapper, resultSetMapper));
 }
示例#11
0
 /// <summary>
 /// Initialize a new instance of a generic ADO transaction. Use
 /// a provider-specific subclass for better performance.
 /// </summary>
 /// <param name="rollingCredentials">A connection string provider which uses rolling credentials.</param>
 /// <param name="connectionFactory">Delegate to create connections for current database.</param>
 /// <param name="parameterMapper">Provides parameter value from input object instances.</param>
 /// <param name="tracer">The OpenTracing tracer instance to use. If this value is null the global tracer will
 /// be used instead.</param>
 /// <param name="dbInfoFactory">The information about the connection string being used.</param>
 public SqlCommandManager(
     RollingCredentials rollingCredentials,
     Func <DbConnection> connectionFactory,
     IParameterMapper parameterMapper,
     ITracer tracer,
     Func <string, DbInfo> dbInfoFactory)
     : this((string)null, connectionFactory, parameterMapper, tracer, null)
 {
     _rollingCredentials = rollingCredentials;
     _connectionMode     = ConnectionMode.AsyncFactory;
     _dbInfoFactory      = dbInfoFactory;
 }
示例#12
0
 // IParameterMapperに指定したパラメータマッピングルールでSQL文を実行する
 public static int ExecuteUpdate(
     this Database self,
     string sql,
     IParameterMapper mapper,
     params object[] parameters)
 {
     using (var command = self.GetSqlStringCommand(sql))
     {
         mapper.AssignParameters(command, parameters);
         return(self.ExecuteNonQuery(command));
     }
 }
示例#13
0
 // IParameterMapperに指定したパラメータマッピングルールでSQL文を実行する
 public static int ExecuteUpdate(
     this Database self,
     string sql,
     IParameterMapper mapper,
     params object[] parameters)
 {
     using (var command = self.GetSqlStringCommand(sql))
     {
         mapper.AssignParameters(command, parameters);
         return self.ExecuteNonQuery(command);
     }
 }
示例#14
0
 /// <summary>
 /// Initialize a new instance of a generic ADO transaction. Use
 /// a provider-specific subclass for better performance.
 /// </summary>
 /// <param name="connectionString">Connection string to target database.</param>
 /// <param name="connectionFactory">Delegate to create connections for current database.</param>
 /// <param name="parameterMapper">Provides parameter value from input object instances.</param>
 /// <param name="tracer">The OpenTracing tracer instance to use. If this value is null the global tracer will
 /// be used instead.</param>
 /// <param name="dbInfo">The information about the connection string being used.</param>
 public SqlCommandManager(
     string connectionString,
     Func <DbConnection> connectionFactory,
     IParameterMapper parameterMapper,
     ITracer tracer,
     DbInfo dbInfo)
 {
     _connectionString = connectionString;
     ConnectionFactory = connectionFactory;
     ParameterMapper   = parameterMapper;
     _tracer           = tracer ?? GlobalTracer.Instance;
     _dbInfo           = dbInfo;
 }
示例#15
0
        /// <summary>
        /// Creates a new instance of <see cref="SprocAccessor&lt;TResult&gt;"/> that works for a specific <paramref name="database"/>
        /// and uses <paramref name="resultSetMapper"/> to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.
        /// The <paramref name="parameterMapper"/> will be used to interpret the parameters passed to the Execute method.
        /// </summary>
        /// <param name="database">The <see cref="Database"/> used to execute the Transact-SQL.</param>
        /// <param name="procedureName">The stored procedure that will be executed.</param>
        /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param>
        /// <param name="resultSetMapper">The <see cref="IResultSetMapper&lt;TResult&gt;"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param>
        public SprocAccessor(Database database, string procedureName, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper)
            : base(database, resultSetMapper)
        {
            if (string.IsNullOrEmpty(procedureName))
            {
                throw new ArgumentException(Resources.ExceptionNullOrEmptyString);
            }
            if (parameterMapper == null)
            {
                throw new ArgumentNullException("parameterMapper");
            }

            this.procedureName   = procedureName;
            this.parameterMapper = parameterMapper;
        }
示例#16
0
        /// <summary>
        /// Creates a new instance of <see cref="SqlStringAccessor&lt;TResult&gt;"/> that works for a specific <paramref name="database"/>
        /// and uses <paramref name="resultSetMapper"/> to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.
        /// The <paramref name="parameterMapper"/> will be used to interpret the parameters passed to the Execute method.
        /// </summary>
        /// <param name="database">The <see cref="Database"/> used to execute the SQL.</param>
        /// <param name="sqlString">The SQL that will be executed.</param>
        /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param>
        /// <param name="resultSetMapper">The <see cref="IResultSetMapper&lt;TResult&gt;"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param>
        public SqlStringAccessor(Database database, string sqlString, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper)
            : base(database, resultSetMapper)
        {
            if (string.IsNullOrEmpty(sqlString))
            {
                throw new ArgumentException(Resources.ExceptionNullOrEmptyString);
            }
            if (parameterMapper == null)
            {
                throw new ArgumentNullException("parameterMapper");
            }

            this.parameterMapper = parameterMapper;
            this.sqlString       = sqlString;
        }
示例#17
0
        /// <summary>
        /// Creates a new instance of <see cref="SprocAccessor&lt;TResult&gt;"/> that works for a specific <paramref name="database"/>
        /// and uses <paramref name="resultSetMapper"/> to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.
        /// The <paramref name="parameterMapper"/> will be used to interpret the parameters passed to the Execute method.
        /// </summary>
        /// <param name="database">The <see cref="Database"/> used to execute the Transact-SQL.</param>
        /// <param name="procedureName">The stored procedure that will be executed.</param>
        /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param>
        /// <param name="resultSetMapper">The <see cref="IResultSetMapper&lt;TResult&gt;"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param>
        public Db2SprocAccessor(Db2Database database, string procedureName, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper)
            : base(database, resultSetMapper)
        {
            if (string.IsNullOrEmpty(procedureName))
            {
                throw new ArgumentException("The value can not be a null or empty string.");
            }
            if (parameterMapper == null)
            {
                throw new ArgumentNullException(nameof(parameterMapper));
            }

            _procedureName   = procedureName;
            _parameterMapper = parameterMapper;
        }
示例#18
0
        /// <summary>
        /// Creates a new instance of <see cref="SprocAccessor&lt;TResult&gt;"/> that works for a specific <paramref name="database"/>
        /// and uses <paramref name="rowMapper"/> to convert the returned rows to clr type <typeparamref name="TResult"/>.
        /// The <paramref name="parameterMapper"/> will be used to interpret the parameters passed to the Execute method.
        /// </summary>
        /// <param name="database">The <see cref="Database"/> used to execute the Transact-SQL.</param>
        /// <param name="procedureName">The stored procedure that will be executed.</param>
        /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param>
        /// <param name="rowMapper">The <see cref="IRowMapper&lt;TResult&gt;"/> that will be used to convert the returned data to clr type <typeparamref name="TResult"/>.</param>
        public OracleSprocAccessor(OracleDatabase database, string procedureName, IParameterMapper parameterMapper, IRowMapper <TResult> rowMapper)
            : base(database, rowMapper)
        {
            if (string.IsNullOrEmpty(procedureName))
            {
                throw new ArgumentException("The value can not be a null or empty string.");
            }
            if (parameterMapper == null)
            {
                throw new ArgumentNullException("parameterMapper");
            }

            this.procedureName   = procedureName;
            this.parameterMapper = parameterMapper;
        }
 public DataAccess(IParameterMapper parameterMapper)
 {
     _parameterMapper = parameterMapper;
 }
示例#20
0
 /// <summary>
 /// Creates command parameters for a MySQL database reference.
 /// </summary>
 /// <param name="rollingCredentials">
 /// A connection string provider which uses rolling credentials such as
 /// dynamic credentials from a Vault database provider.
 /// </param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 public MySqlDatabase(MySqlRollingCredentials rollingCredentials, IParameterMapper parameterMapper)
     : this(rollingCredentials, parameterMapper, null)
 {
 }
示例#21
0
        /// <summary>
        /// Creates a <see cref="SprocAccessor&lt;TResult&gt;"/> for the given stored procedure.
        /// </summary>
        /// <typeparam name="TResult">The type the <see cref="SprocAccessor&lt;TResult&gt;"/> should return when executing.</typeparam>
        /// <param name="resultSetMapper">The <see cref="IResultSetMapper&lt;TResult&gt;"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param>
        /// <param name="procedureName">The name of the stored procedure that should be executed by the <see cref="SprocAccessor&lt;TResult&gt;"/>. </param>
        /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param>
        /// <returns>A new instance of <see cref="SprocAccessor&lt;TResult&gt;"/>.</returns>
        public DataAccessor <TResult> CreateDb2SprocAccessor <TResult>(string procedureName, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper)
        {
            if (string.IsNullOrEmpty(procedureName))
            {
                throw new ArgumentException();
            }

            return(new Db2SprocAccessor <TResult>(this, procedureName, parameterMapper, resultSetMapper));
        }
示例#22
0
        /// <summary>
        /// Creates a <see cref="SprocAccessor&lt;TResult&gt;"/> for the given stored procedure.
        /// The conversion from <see cref="IDataRecord"/> to <typeparamref name="TResult"/> will be done for each property based on matching property name to column name.
        /// </summary>
        /// <typeparam name="TResult">The type the <see cref="SprocAccessor&lt;TResult&gt;"/> should return when executing.</typeparam>
        /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param>
        /// <param name="procedureName">The name of the stored procedure that should be executed by the <see cref="SprocAccessor&lt;TResult&gt;"/>. </param>
        /// <returns>A new instance of <see cref="SprocAccessor&lt;TResult&gt;"/>.</returns>
        public DataAccessor <TResult> CreateDb2SprocAccessor <TResult>(string procedureName, IParameterMapper parameterMapper)
            where TResult : new()
        {
            IRowMapper <TResult> defaultRowMapper = MapBuilder <TResult> .BuildAllProperties();

            return(CreateDb2SprocAccessor(procedureName, parameterMapper, defaultRowMapper));
        }
示例#23
0
 /// <summary>
 /// Executes a stored procedure and returns the result as an enumerable of <typeparamref name="TResult"/>.
 /// </summary>
 /// <typeparam name="TResult">The element type that will be returned when executing.</typeparam>
 /// <param name="procedureName">The name of the stored procedure that will be executed.</param>
 /// <param name="parameterMapper">The <see cref="IParameterMapper"/> that will be used to interpret the parameters passed to the Execute method.</param>
 /// <param name="resultSetMapper">The <see cref="IResultSetMapper&lt;TResult&gt;"/> that will be used to convert the returned set to an enumerable of clr type <typeparamref name="TResult"/>.</param>
 /// <param name="parameterValues">Parameter values passsed to the stored procedure.</param>
 /// <returns>An enumerable of <typeparamref name="TResult"/>.</returns>
 public IEnumerable <TResult> ExecuteDb2SprocAccessor <TResult>(string procedureName, IParameterMapper parameterMapper, IResultSetMapper <TResult> resultSetMapper, params object[] parameterValues)
     where TResult : new()
 {
     return(CreateDb2SprocAccessor(procedureName, parameterMapper, resultSetMapper).Execute(parameterValues));
 }
示例#24
0
 /// <summary>
 /// Creates command parameters for a Microsoft SQL Server database reference.
 /// </summary>
 /// <param name="rollingCredentials">
 /// A connection string provider which uses rolling credentials such as
 /// dynamic credentials from a Vault database provider.
 /// </param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 /// <param name="tracer">The OpenTracing tracer instance to use. If this value is null the global tracer will
 /// be used instead.</param>
 public OracleDatabase(OracleRollingCredentials rollingCredentials, IParameterMapper parameterMapper, ITracer tracer)
     : base(new SqlCommandManager(rollingCredentials, GetConnection, parameterMapper ?? new DefaultParameterMapper(), tracer, ExtractDbInfo), new OracleDialect())
 {
 }
示例#25
0
 /// <summary>
 /// Creates command parameters for a Microsoft SQL Server database reference.
 /// </summary>
 /// <param name="rollingCredentials">
 /// A connection string provider which uses rolling credentials such as
 /// dynamic credentials from a Vault database provider.
 /// </param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 public OracleDatabase(OracleRollingCredentials rollingCredentials, IParameterMapper parameterMapper)
     : this(rollingCredentials, parameterMapper, null)
 {
 }
示例#26
0
 /// <summary>
 /// Creates command parameters for a Oracle database reference.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 /// <param name="tracer">
 /// The OpenTracing tracer instance to use. If this value is null the global tracer will
 /// be used instead.
 /// </param>
 public OracleDatabase(string connectionString, IParameterMapper parameterMapper, ITracer tracer)
     : base(new SqlCommandManager(connectionString, GetConnection, parameterMapper ?? new DefaultParameterMapper(), tracer, ExtractDbInfo(connectionString)), new OracleDialect())
 {
 }
示例#27
0
 /// <summary>
 /// Helper method to kick off execution of an asynchronous database operation.
 /// This method handles the boilerplate of setting up the parameters and invoking
 /// the operation on the database with the right options.
 /// </summary>
 /// <param name="command">The <see cref="DbCommand"/> to execute.</param>
 /// <param name="parameterMapper">The <see cref="IParameterMapper"/> to use to set the parameter
 /// values.</param>
 /// <param name="callback">Callback to execute when the operation's result is available.</param>
 /// <param name="state">State to pass to the callback.</param>
 /// <param name="parameterValues">Input parameter values.</param>
 /// <returns>An <see cref='IAsyncResult'/> object representing the outstanding async request.</returns>
 protected IAsyncResult BeginExecute(DbCommand command, IParameterMapper parameterMapper,
                                     AsyncCallback callback, object state, object[] parameterValues)
 {
     parameterMapper.AssignParameters(command, parameterValues);
     return(database.BeginExecuteReader(command, callback, state));
 }
示例#28
0
 /// <summary>
 /// Creates command parameters for a SQLite connection.
 /// </summary>
 /// <param name="connectionFactory">
 /// A connection factory that returns a Sqlite DB connection.
 /// </param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 /// <param name="tracer">
 /// The OpenTracing tracer instance to use. If this value is null the global tracer will
 /// be used instead.
 /// </param>
 public SqliteDatabase(IConnectionFactory connectionFactory, IParameterMapper parameterMapper, ITracer tracer)
     : base(new SqlCommandManager(connectionFactory, parameterMapper ?? new DefaultParameterMapper(), tracer), new SqliteDialect())
 {
 }
示例#29
0
 /// <summary>
 /// Creates command parameters for Postgres database reference.
 /// </summary>
 /// <param name="connectionFactory">
 /// A connection factory that returns a Postgres DB connection.
 /// </param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 public PostgresDatabase(IConnectionFactory connectionFactory, IParameterMapper parameterMapper)
     : this(connectionFactory, parameterMapper, null)
 {
 }
示例#30
0
 /// <summary>
 /// Creates command parameters for a Postgres database reference.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 public PostgresDatabase(string connectionString, IParameterMapper parameterMapper)
     : this(connectionString, parameterMapper, null)
 {
 }
示例#31
0
 /// <summary>
 /// Creates command parameters for an Oracle database reference.
 /// </summary>
 /// <param name="connectionFactory">
 /// A connection factory that returns an Oracle DB connection.
 /// </param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 public OracleDatabase(IConnectionFactory connectionFactory, IParameterMapper parameterMapper)
     : this(connectionFactory, parameterMapper, null)
 {
 }
 public void SetUp()
 {
     _mapper1 = MockRepository.GenerateMock<IParameterMapper>();
     _mapper1.Stub(arg => arg.CanMapType(Arg<HttpRequestBase>.Is.Anything, Arg<Type>.Is.Anything)).Return(false);
     _mapper2 = MockRepository.GenerateMock<IParameterMapper>();
     _mapper2.Stub(arg => arg.CanMapType(Arg<HttpRequestBase>.Is.Anything, Arg<Type>.Is.Anything)).Return(true);
     _mapper2
         .Stub(arg => arg.Map(Arg<HttpRequestBase>.Is.Anything, Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything, Arg<ParameterInfo>.Is.Anything))
         .WhenCalled(arg => arg.ReturnValue = MapResult.ValueMapped(100))
         .Return(null);
     _mapper3 = MockRepository.GenerateMock<IParameterMapper>();
     _mapper3.Stub(arg => arg.CanMapType(Arg<HttpRequestBase>.Is.Anything, Arg<Type>.Is.Anything)).Return(false);
     _retriever = new ParameterValueRetriever(new[] { _mapper1, _mapper2, _mapper3 });
     _request = MockRepository.GenerateMock<HttpRequestBase>();
     _values = _retriever.GetParameterValues(_request, typeof(Endpoint), typeof(Endpoint).GetMethod("Method"));
 }
示例#33
0
 /// <summary>
 /// Creates command parameters for a Oracle database reference.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 public OracleDatabase(string connectionString, IParameterMapper parameterMapper)
     : this(connectionString, parameterMapper, null)
 {
 }
示例#34
0
 /// <summary>
 /// Creates command parameters for a Microsoft SQL Server database reference.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="parameterMapper">The parameter mapper.</param>
 public SqlServerDatabase(string connectionString, IParameterMapper parameterMapper)
     : this(connectionString, parameterMapper, null)
 {
 }