public RowMapperResultSetExtractor(IRowMapper rowMapper, int rowsExpected, IDataReaderWrapper dataReaderWrapper)
 {
     //TODO use datareaderwrapper
     if (rowMapper == null)
     {
         throw new ArgumentNullException("rowMapper");
     }
     this.rowMapper = rowMapper;
     this.rowsExpected = rowsExpected;
 }
Ejemplo n.º 2
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="rowMapper">The <see cref="IRowMapper&lt;TResult&gt;"/> that will be used to convert the returned data to 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> ExecuteOracleSprocAccessor <TResult>(string procedureName, IParameterMapper parameterMapper, IRowMapper <TResult> rowMapper, params object[] parameterValues)
     where TResult : new()
 {
     return(CreateOracleSprocAccessor(procedureName, parameterMapper, rowMapper).Execute(parameterValues));
 }
Ejemplo n.º 3
0
        // -- Async stuff here!!!


        protected async Task <IList <T> > ReadAsync <T>(IRowMapper <T> mapper, string commandText,
                                                        CommandType commandType, DbParameter[] parameters)
        {
            return(await Database.ReadAsync(mapper, commandText, commandType, parameters));
        }
Ejemplo n.º 4
0
 protected IList <T> Read <T>(IRowMapper <T> mapper, string commandText,
                              CommandType commandType, DbParameter[] parameters)
 {
     return(Database.Read(mapper, commandText, commandType, parameters));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Executes the rowmapper with a single input parameter.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="dbHelper">Database helper</param>
 /// <param name="commandText">Store procedure name. E.g. "Posts_GetPostsByUser</param>
 /// <param name="commandType">StoredProcedure</param>
 /// <param name="rowMapper">The mapper that maps a record to an object.</param>
 /// <returns></returns>
 public static IList <T> QueryNoParams <T>(this IDBHelper dbHelper, string commandText, CommandType commandType, IRowMapper <IDataReader, T> rowMapper)
 {
     return(Query <T>(dbHelper, commandText, commandType, null, rowMapper));
 }
 public RowMapperResultSetExtractor(IRowMapper rowMapper, int rowsExpected) : this(rowMapper, rowsExpected, null)
 {
 }
Ejemplo n.º 7
0
 public void AddRowMapper(string name, IRowMapper rowMapper)
 {
     if (Compiled)
     {
         throw new InvalidDataAccessApiUsageException("Cannot add RowMappers once operation is compiled");
     }
     resultProcessors.Add(new NamedResultSetProcessor(name,rowMapper));
 }
Ejemplo n.º 8
0
 public virtual IList QueryWithRowMapper(CommandType cmdType, string cmdText, IRowMapper rowMapper,
                                         string name, Enum dbType, int size, object parameterValue)
 {
     return (IList)QueryWithResultSetExtractor(cmdType, cmdText, new RowMapperResultSetExtractor(rowMapper), name, dbType, size, parameterValue);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Execute reader and create instance of provided type using IRowMapper interface.
        /// </summary>
        /// <typeparam name="T">Type of object to create.</typeparam>
        /// <param name="args">Sql Parameters.</param>
        /// <param name="query">Sql Query.</param>
        /// <param name="rowMapper">IRowMapper used to map object instance from reader.</param>
        /// <returns>Instance of object type.</returns>
        public T SelectValue <T>(string query, IEnumerable <QueryParameter> args = null, IRowMapper <T> rowMapper = null)
        {
            object obj = null;

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                obj = SelectValueInternal(query, args, rowMapper, connection);
            }

            if (obj == null)
            {
                return(default(T));
            }

            return((T)obj);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Execute reader and create list of provided type using IRowMapper interface within existing transaction.
 /// </summary>
 /// <typeparam name="T">Type of object to create.</typeparam>
 /// <param name="query">Sql Query.</param>
 /// <param name="args">Sql Parameters.</param>
 /// <param name="rowMapper">IRowMapper used to map object instance from reader.</param>
 /// <param name="transaction">Existing <see cref="SqlTransaction"/> to use with this command.</param>
 /// <returns>List of provided object type.</returns>
 public IEnumerable <T> Select <T>(string query, IEnumerable <QueryParameter> args, IRowMapper <T> rowMapper, SqlTransaction transaction)
 {
     return(SelectInternal(query, args, rowMapper, transaction.Connection, transaction));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Execute reader and create list of provided type using IRowMapper interface.
        /// </summary>
        /// <typeparam name="T">Type of object to create.</typeparam>
        /// <param name="query">Sql Query.</param>
        /// <param name="args">Sql Parameters.</param>
        /// <param name="rowMapper">IRowMapper used to map object instance from reader.</param>
        /// <returns>List of provided object type.</returns>
        public IEnumerable <T> Select <T>(string query, IEnumerable <QueryParameter> args = null, IRowMapper <T> rowMapper = null)
        {
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                foreach (T item in SelectInternal(query, args, rowMapper, connection))
                {
                    yield return(item);
                }
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Execute reader and create list of provided type using IRowMapper interface.
 /// </summary>
 /// <typeparam name="T">Type of object to create.</typeparam>
 /// <param name="query">Sql Query.</param>
 /// <param name="rowMapper">IRowMapper used to map object instance from reader.</param>
 /// <returns>List of provided object type.</returns>
 public IEnumerable <T> Select <T>(string query, IRowMapper <T> rowMapper)
 {
     return(Select <T>(query, null, rowMapper));
 }
Ejemplo n.º 13
0
        private IEnumerable <T> SelectInternal <T>(string query, IEnumerable <QueryParameter> args, IRowMapper <T> rowMapper, SqlConnection connection, SqlTransaction transaction = null)
        {
            using (SqlCommand command = connection.CreateCommand())
            {
                command.CommandText = query;

                if (transaction != null)
                {
                    command.Transaction = transaction;
                }

                PrepareCommandParameters(command, args);

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    var isNullable = Nullable.GetUnderlyingType(typeof(T)) != null;

                    while (reader.Read())
                    {
                        if (rowMapper != null)
                        {
                            yield return(rowMapper.Map(reader));
                        }
                        else
                        {
                            // Check for null values and return default instance of T (should be nullable)
                            // If not checked for NULL values, conversion will fail, resulting in InvalidCastException being thrown
                            if (isNullable && reader[0] == Convert.DBNull)
                            {
                                yield return(default(T));
                            }
                            else
                            {
                                yield return((T)reader[0]);
                            }
                        }
                    }

                    reader.Close();
                }
            }
        }
Ejemplo n.º 14
0
        private object SelectValueInternal <T>(string query, IEnumerable <QueryParameter> args, IRowMapper <T> rowMapper, SqlConnection connection, SqlTransaction transaction = null)
        {
            object obj = null;

            using (SqlCommand command = connection.CreateCommand())
            {
                command.CommandText = query;

                if (transaction != null)
                {
                    command.Transaction = transaction;
                }

                PrepareCommandParameters(command, args);

                using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult))
                {
                    reader.Read();

                    if (reader.HasRows)
                    {
                        if (rowMapper != null)
                        {
                            obj = rowMapper.Map(reader);
                        }
                        else
                        {
                            // Used for primitive types
                            obj = reader[0];
                        }
                    }

                    reader.Close();
                }
            }

            return(obj);
        }
Ejemplo n.º 15
0
 private static IEnumerable <T> GetListWithRowMapper <T>(string query, IEnumerable <QueryParameter> args, IRowMapper <T> rowMapper)
 {
     using (var connector = new Connector())
     {
         return(connector.Select(query, args, rowMapper));
     }
 }
Ejemplo n.º 16
0
 public virtual IList QueryWithCommandCreator(IDbCommandCreator cc, IRowMapper rowMapper)
 {
     return QueryWithCommandCreator(cc, rowMapper, null);
 }
Ejemplo n.º 17
0
 public AdoRowMapperQueryCommandCallback(AdoTemplate adoTemplate, IRowMapper rowMapper, IDictionary returnedParameters)
 {
     this.adoTemplate = adoTemplate;
     this.rowMapper = rowMapper;
     //this.declaredParameters = declaredParameters;
     this.returnedParameters = returnedParameters;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Protected constructor to give subclass the flexibility of how row
 /// mapper is set. It also sets the <see cref="_rowMapper"/> to itself
 /// if subclass also implements <see cref="IRowMapper{T}"/>.
 /// </summary>
 protected ExtendedRowMapperResultSetExtractor()
 {
     _rowMapper = this as IRowMapper <T>;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Execute a query with the specified command text and parameters, mapping a single result row
 /// to an object via a RowMapper.
 /// </summary>
 /// <param name="cmdType">The command type.</param>
 /// <param name="cmdText">The command text to execute.</param>
 /// <param name="rowMapper">object that will map one object per row</param>
 /// <param name="parameters">The parameter collection to use in the query.</param>
 /// <returns>The single mapped object.</returns>
 /// <exception cref="Spring.Dao.IncorrectResultSizeDataAccessException">
 /// If the query does not return exactly one row.
 /// </exception>
 /// <exception cref="Spring.Dao.DataAccessException">
 /// If there is any problem executing the query.
 /// </exception>
 public virtual object QueryForObject(CommandType cmdType, string cmdText, IRowMapper rowMapper, IDbParameters parameters)
 {
     IList results = QueryWithRowMapper(cmdType, cmdText, rowMapper, parameters);
     return DataAccessUtils.RequiredUniqueResultSet(results);
 }
Ejemplo n.º 20
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="rowMapper">The <see cref="IRowMapper&lt;TResult&gt;"/> that will be used to convert the returned data to clr type <typeparamref name="TResult"/>.</param>
        /// <param name="database">The <see cref="Database"/> that contains the stored procedure.</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 static DataAccessor <TResult> CreateSprocAccessor <TResult>(this Database database, string procedureName, IParameterMapper parameterMapper, IRowMapper <TResult> rowMapper)
        {
            if (string.IsNullOrEmpty(procedureName))
            {
                throw new ArgumentException(Resources.ExceptionNullOrEmptyString);
            }

            return(new SprocAccessor <TResult>(database, procedureName, parameterMapper, rowMapper));
        }
Ejemplo n.º 21
0
	    /// <summary>
        /// Initializes a new instance of the <see cref="NamedResultSetProcessor"/> class with a
        /// IRowMapper instance
	    /// </summary>
	    /// <param name="name">The name of the associated row mapper.</param>
	    /// <param name="rowMapper">A IRowMapper instance.</param>
	    public NamedResultSetProcessor(string name, IRowMapper rowMapper)
	    {
	        this.name = name;
	        resultSetProcessor = rowMapper;
	    }
Ejemplo n.º 22
0
 /// <summary>
 /// Executes a Transact-SQL query and returns the result as an enumerable of <typeparamref name="TResult"/>.
 /// 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 element type that will be returned when executing.</typeparam>
 /// <param name="database">The <see cref="Database"/> that contains the stored procedure.</param>
 /// <param name="sqlString">The Transact-SQL query that will be executed.</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>
 /// <returns>An enumerable of <typeparamref name="TResult"/>.</returns>
 public static IEnumerable <TResult> ExecuteSqlStringAccessor <TResult>(this Database database, string sqlString, IRowMapper <TResult> rowMapper)
 {
     return(CreateSqlStringAccessor(database, sqlString, rowMapper).Execute());
 }
Ejemplo n.º 23
0
 public MappingFactory(PocoData pocoData, DbDataReader dataReader)
 {
     _pocoData = pocoData;
     _rowMapper = RowMappers.Select(mapper => mapper()).First(x => x.ShouldMap(pocoData));
     _rowMapper.Init(dataReader, pocoData);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Creates a <see cref="SqlStringAccessor&lt;TResult&gt;"/> for the given Transact-SQL query.
 /// </summary>
 /// <typeparam name="TResult">The type the <see cref="SprocAccessor&lt;TResult&gt;"/> should return when executing.</typeparam>
 /// <param name="database">The <see cref="Database"/> that contains the stored procedure.</param>
 /// <param name="sqlString">The Transact-SQL query that will be executed by the <see cref="SqlStringAccessor&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>
 /// <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>
 /// <returns>A new instance of <see cref="SprocAccessor&lt;TResult&gt;"/>.</returns>
 public static DataAccessor <TResult> CreateSqlStringAccessor <TResult>(this Database database, string sqlString, IParameterMapper parameterMapper, IRowMapper <TResult> rowMapper)
 {
     return(new SqlStringAccessor <TResult>(database, sqlString, parameterMapper, rowMapper));
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Executes the rowmappers
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dbHelper">Database helper</param>
        /// <param name="commandText">Store procedure name. E.g. "Posts_GetPostsByUser</param>
        /// <param name="commandType">StoredProcedure</param>
        /// <param name="rowMapper">The mapper that maps a record to an object.</param>
        /// <param name="dbParameters">Array of parameters for the query.</param>
        /// <returns></returns>
        public static IList <T> Query <T>(IDBHelper dbHelper, string commandText, CommandType commandType, DbParameter[] dbParameters, IRowMapper <IDataReader, T> rowMapper)
        {
            DbCommand command = dbHelper.BuildCommand(commandText, commandType, dbParameters);

            IList <T> items = null;

            using (command.Connection)
            {
                command.Connection.Open();
                IDataReader reader = command.ExecuteReader();

                // Map the workshops.
                items = rowMapper.MapRows(reader);

                reader.Close();
                command.Dispose();
            }
            return(items);
        }
Ejemplo n.º 26
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="database">The <see cref="Database"/> that contains the stored procedure.</param>
 /// <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="rowMapper">The <see cref="IRowMapper&lt;TResult&gt;"/> that will be used to convert the returned data to clr type <typeparamref name="TResult"/>.</param>
 /// <param name="parameterValues">Parameter values passed to the stored procedure.</param>
 /// <returns>An enumerable of <typeparamref name="TResult"/>.</returns>
 public static IEnumerable <TResult> ExecuteSprocAccessor <TResult>(this Database database, string procedureName, IParameterMapper parameterMapper, IRowMapper <TResult> rowMapper, params object[] parameterValues)
     where TResult : new()
 {
     return(CreateSprocAccessor(database, procedureName, parameterMapper, rowMapper).Execute(parameterValues));
 }
Ejemplo n.º 27
0
 protected IList <T> Read <T>(DbConnection connection, IRowMapper <T> mapper, string commandText,
                              CommandType commandType, DbParameter[] parameters, DbTransaction transaction = null)
 {
     return(Database.Read(connection, mapper, commandText, commandType, parameters, transaction));
 }
 public SequentialDataTransform(IHost host, SequentialTransformerBase <TInput, TOutput, TState> parent, IDataView input, IRowMapper mapper)
     : base(parent.Host, input)
 {
     _parent    = parent;
     _transform = CreateLambdaTransform(_parent.Host, input, _parent.InputColumnName,
                                        _parent.OutputColumnName, InitFunction, _parent.WindowSize > 0, _parent.OutputColumnType);
     _mapper   = mapper;
     _bindings = new ColumnBindings(Schema.Create(input.Schema), _mapper.GetOutputColumns());
 }
Ejemplo n.º 29
0
 protected async Task <IList <T> > ReadAsync <T>(DbConnection connection, IRowMapper <T> mapper, string commandText,
                                                 CommandType commandType, DbParameter[] parameters, DbTransaction transaction = null)
 {
     return(await Database.ReadAsync(connection, mapper, commandText, commandType, parameters, transaction));
 }
Ejemplo n.º 30
0
 protected override void Arrange()
 {
     base.Arrange();
     mapper = builder.Build();
 }
Ejemplo n.º 31
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="rowMapper">The <see cref="IRowMapper&lt;TResult&gt;"/> that will be used to convert the returned data to 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> CreateOracleSprocAccessor <TResult>(string procedureName, IParameterMapper parameterMapper, IRowMapper <TResult> rowMapper)
        {
            if (string.IsNullOrEmpty(procedureName))
            {
                throw new ArgumentException();
            }

            return(new OracleSprocAccessor <TResult>(this, procedureName, parameterMapper, rowMapper));
        }
Ejemplo n.º 32
0
 public MappingFactory(PocoData pocoData, DbDataReader dataReader)
 {
     _pocoData  = pocoData;
     _rowMapper = RowMappers.Select(mapper => mapper()).First(x => x.ShouldMap(pocoData));
     _rowMapper.Init(dataReader, pocoData);
 }
Ejemplo n.º 33
0
        public virtual IList QueryWithCommandCreator(IDbCommandCreator cc, IRowMapper rowMapper, IDictionary returnedParameters)
        {
            if (rowMapper == null)
            {
                throw new ArgumentNullException("rowMapper must not be null");
            }

            return (IList)Execute(cc, new AdoRowMapperQueryCommandCallback(this, rowMapper, returnedParameters));
        }
Ejemplo n.º 34
0
 public CustomSprocAccessor(Database database, DbCommand command, IRowMapper <TResult> rowMapper)
     : base(database, command.CommandText, rowMapper)
 {
     Command   = command;
     RowMapper = rowMapper;
 }
Ejemplo n.º 35
0
        public virtual IList QueryWithRowMapper(CommandType cmdType, string cmdText, IRowMapper rowMapper, ICommandSetter commandSetter)
        {

            return (IList)QueryWithResultSetExtractor(cmdType, cmdText,
                                                      new RowMapperResultSetExtractor(rowMapper), commandSetter);

        }
Ejemplo n.º 36
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="rowMapper"/> to convert the returned rows to clr type <typeparamref name="TResult"/>.
 /// </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="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 SqlStringAccessor(Database database, string sqlString, IRowMapper <TResult> rowMapper)
     : this(database, sqlString, new DefaultSqlStringParameterMapper(), rowMapper)
 {
 }
Ejemplo n.º 37
0
 public virtual IList QueryWithRowMapper(CommandType cmdType, string cmdText, IRowMapper rowMapper, IDbParameters parameters)
 {
     return (IList)QueryWithResultSetExtractor(cmdType, cmdText, new RowMapperResultSetExtractor(rowMapper), parameters);
 }
Ejemplo n.º 38
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="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 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="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 SqlStringAccessor(Database database, string sqlString, IParameterMapper parameterMapper, IRowMapper <TResult> rowMapper)
            : base(database, rowMapper)
        {
            if (string.IsNullOrEmpty(sqlString))
            {
                throw new ArgumentException(Resources.ExceptionNullOrEmptyString);
            }
            if (parameterMapper == null)
            {
                throw new ArgumentNullException("parameterMapper");
            }

            this.parameterMapper = parameterMapper;
            this.sqlString       = sqlString;
        }
Ejemplo n.º 39
0
 /// <summary>
 /// Execute a query with the specified command text and parameter, mapping a single result row
 /// to an object via a RowMapper.
 /// </summary>
 /// <param name="cmdType">The command type.</param>
 /// <param name="cmdText">The command text to execute.</param>
 /// <param name="rowMapper">object that will map one object per row</param>
 /// <param name="parameterName">The name of the parameter to map.</param>
 /// <param name="dbType">One of the database parameter type enumerations.</param>
 /// <param name="size">The length of the parameter. 0 if not applicable to parameter type.</param>
 /// <param name="parameterValue">The parameter value.</param>
 /// <returns>The single mapped object.</returns>
 /// <exception cref="Spring.Dao.IncorrectResultSizeDataAccessException">
 /// If the query does not return exactly one row.
 /// </exception>
 /// <exception cref="Spring.Dao.DataAccessException">
 /// If there is any problem executing the query.
 /// </exception>
 public virtual object QueryForObject(CommandType cmdType, string cmdText, IRowMapper rowMapper, string parameterName, Enum dbType, int size,
                                      object parameterValue)
 {
     IList results = QueryWithRowMapper(cmdType, cmdText, rowMapper, parameterName, dbType, size, parameterValue);
     return DataAccessUtils.RequiredUniqueResultSet(results);
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Initializes a new instance of the class with a
 /// IRowMapper instance
 /// </summary>
 /// <param name="name">The name of the associated row mapper.</param>
 /// <param name="rowMapper">A IRowMapper instance.</param>
 public NamedResultSetProcessor(string name, IRowMapper <T> rowMapper)
 {
     this.name      = name;
     this.rowMapper = rowMapper;
 }
Ejemplo n.º 41
0
        protected List<Model> queryBySql(String sql, IRowMapper mapper)
        {
            //经测试没有问题
            SqlConnection conn = null;//数据库连接
            //  SqlDataReader dr = null;
            DataSet ds = null;//数据集
            SqlCommand cmd = null;//
            List<Model> retList = new List<Model>();
            try
            {
                conn = dbConn.getConnection();
                cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandText = sql;             
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                ds = new DataSet();
                adp.Fill(ds);

                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    Model obj = (Model)mapper.mappingRow(row);
                    retList.Add(obj);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                dbConn.closeConnection(conn);

            }
            return retList;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Spring.Data.Core.RowMapperResultSetExtractor"/> class.
 /// </summary>
 public RowMapperResultSetExtractor(IRowMapper <T> rowMapper) : this(rowMapper, 0, null)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RowMapperResultSetExtractor"/> class.
 /// </summary>
 public RowMapperResultSetExtractor(IRowMapper rowMapper) : this(rowMapper,0, null)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RowMapperResultSetExtractor&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="rowMapper">The row mapper.</param>
 /// <param name="rowsExpected">The rows expected.</param>
 public RowMapperResultSetExtractor(IRowMapper <T> rowMapper, int rowsExpected) : this(rowMapper, rowsExpected, null)
 {
 }
Ejemplo n.º 45
0
        /// <summary>
        /// Executes the rowmapper with a single input parameter.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="commandText">Store procedure name. E.g. "Posts_GetPostsByUser</param>
        /// <param name="commandType">StoredProcedure</param>
        /// <param name="rowMapper">The mapper that maps a record to an object.</param>
        /// <param name="paramName">E.g. "userName"</param>
        /// <param name="paramType">string</param>
        /// <param name="paramValue">user001</param>
        /// <returns></returns>
        public static IList <T> Query <T>(this IDBHelper dbHelper, string commandText, CommandType commandType, string paramName, DbType paramType, object paramValue, IRowMapper <IDataReader, T> rowMapper)
        {
            DbParameter parameter = dbHelper.BuildInParam(paramName, paramType, paramValue);

            return(Query <T>(dbHelper, commandText, commandType, new DbParameter[1] {
                parameter
            }, rowMapper));
        }
Ejemplo n.º 46
0
 static CustomerRepository()
 {
     _rowMapper = MapBuilder<Customer>
                                 .MapAllProperties()
                                 .Build();
 }