protected override void Arrange() { base.Arrange(); parameterMapper = new ParameterMapper(); rowMapper = new RowMapper(); }
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>(); }
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)); }
/// <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; }
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)); }
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)); }
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); }
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)); }
/// <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; }
// 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)); } }
// 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); } }
/// <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; }
/// <summary> /// Creates a new instance of <see cref="SprocAccessor<TResult>"/> 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<TResult>"/> 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; }
/// <summary> /// Creates a new instance of <see cref="SqlStringAccessor<TResult>"/> 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<TResult>"/> 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; }
/// <summary> /// Creates a new instance of <see cref="SprocAccessor<TResult>"/> 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<TResult>"/> 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; }
/// <summary> /// Creates a new instance of <see cref="SprocAccessor<TResult>"/> 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<TResult>"/> 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; }
/// <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) { }
/// <summary> /// Creates a <see cref="SprocAccessor<TResult>"/> for the given stored procedure. /// </summary> /// <typeparam name="TResult">The type the <see cref="SprocAccessor<TResult>"/> should return when executing.</typeparam> /// <param name="resultSetMapper">The <see cref="IResultSetMapper<TResult>"/> 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<TResult>"/>. </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<TResult>"/>.</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)); }
/// <summary> /// Creates a <see cref="SprocAccessor<TResult>"/> 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<TResult>"/> 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<TResult>"/>. </param> /// <returns>A new instance of <see cref="SprocAccessor<TResult>"/>.</returns> public DataAccessor <TResult> CreateDb2SprocAccessor <TResult>(string procedureName, IParameterMapper parameterMapper) where TResult : new() { IRowMapper <TResult> defaultRowMapper = MapBuilder <TResult> .BuildAllProperties(); return(CreateDb2SprocAccessor(procedureName, parameterMapper, defaultRowMapper)); }
/// <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<TResult>"/> 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)); }
/// <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()) { }
/// <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) { }
/// <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()) { }
/// <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)); }
/// <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()) { }
/// <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) { }
/// <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) { }
/// <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")); }
/// <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) { }
/// <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) { }