[SetUp] public void SetUp()
 {
     _mockery           = new MockRepository();
     _rowMapper         = _mockery.StrictMock <IRowMapper <T> >();
     _rowMapperDelegate = _mockery.StrictMock <RowMapperDelegate <T> >();
     _dataReader        = _mockery.StrictMock <IDataReader>();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtendedRowMapperResultSetExtractor{T}"/>
 /// class, which will use the given <paramref name="rowMapperDelegate"/> to extract the result.
 /// </summary>
 public ExtendedRowMapperResultSetExtractor(RowMapperDelegate <T> rowMapperDelegate)
 {
     if (rowMapperDelegate == null)
     {
         throw new ArgumentNullException("rowMapperDelegate");
     }
     _rowMapperDelegate = rowMapperDelegate;
 }
Ejemplo n.º 3
0
        public RowMapperResultSetExtractor(RowMapperDelegate <T> rowMapperDelegate, int rowsExpected, IDataReaderWrapper dataReaderWrapper)
        {
            //TODO use datareaderwrapper

            AssertUtils.ArgumentNotNull(rowMapperDelegate, "rowMapperDelegate");

            this.rowMapperDelegate = rowMapperDelegate;
            this.rowsExpected      = rowsExpected;
        }
 private static IResultSetExtractor <IList <T> > MakeResultSetExtractor <T>(
     RowMapperDelegate <T> rowMapperDelegate, IDataRecordOrdinalCache ordinalCache, int rowsExpected)
 {
     return(new ExtendedRowMapperResultSetExtractor <T>(rowMapperDelegate)
     {
         OrdinalCache = ordinalCache,
         RowsExpected = rowsExpected
     });
 }
Ejemplo n.º 5
0
 public RowMapperResultSetExtractor(RowMapperDelegate rowMapperDelegate, int rowsExpected, IDataReaderWrapper dataReaderWrapper)
 {
     //TODO use datareaderwrapper
     if (rowMapperDelegate == null)
     {
         throw new ArgumentNullException("rowMapperDelegate");
     }
     this.rowMapperDelegate = rowMapperDelegate;
     this.rowsExpected      = rowsExpected;
 }
        /// <summary>
        /// Query database with given SQL command and mapping each row to a
        /// object via a <see cref="RowMapperDelegate{T}"/> with help of optional
        /// ordinal cache and/or the rows expected value for better performance.
        /// </summary>
        /// <typeparam name="T">The type of object that each row maps to.</typeparam>
        /// <param name="operations">
        /// An <see cref="Spring.Data.Generic.IAdoOperations"/> object to
        /// perform database operation.
        /// </param>
        /// <param name="cmdType">
        /// The type of command.
        /// </param>
        /// <param name="cmdText">
        /// The text of command.
        /// </param>
        /// <param name="rowMapperDelegate">
        /// The row mapper delegate that maps each row to object of type
        /// <typeparamref name="T"/>.
        /// </param>
        /// <param name="ordinalCache">
        /// The <see cref="IDataRecordOrdinalCache"/> that caches the mapping
        /// from field name to field index.
        /// </param>
        /// <param name="rowsExpected">
        /// Number of rows this query is expected to return. This doesn't need
        /// to be accurate but estimating at the higer end for best performance.
        /// </param>
        /// <returns>
        /// A list of object of type <typeparamref name="T"/> that were mapped
        /// for the rows.
        /// </returns>
        public static IList <T> QueryWithRowMapperDelegate <T>(
            this IAdoOperations operations,
            CommandType cmdType,
            string cmdText,
            RowMapperDelegate <T> rowMapperDelegate,
            IDataRecordOrdinalCache ordinalCache,
            int rowsExpected)
        {
            var extractor = MakeResultSetExtractor(rowMapperDelegate, ordinalCache, rowsExpected);

            return(operations.QueryWithResultSetExtractor(cmdType, cmdText, extractor));
        }
        public static IList <T> QueryWithRowMapperDelegate <T>(
            this IAdoOperations operations,
            CommandType cmdType,
            string cmdText,
            RowMapperDelegate <T> rowMapperDelegate,
            Action <IDbCommand> commandSetterDelegate,
            IDataRecordOrdinalCache ordinalCache,
            int rowsExpected)
        {
            var commandSetter = new DelegateCommandSetter(commandSetterDelegate);

            return(QueryWithRowMapperDelegate(operations, cmdType, cmdText, rowMapperDelegate,
                                              commandSetter, ordinalCache, rowsExpected));
        }
Ejemplo n.º 8
0
 public RowMapperResultSetExtractor(RowMapperDelegate <T> rowMapperDelegate)
     : this(rowMapperDelegate, 0, null)
 {
 }
Ejemplo n.º 9
0
 public RowMapperResultSetExtractor(RowMapperDelegate rowMapperDelegate, int rowsExpected, IDataReaderWrapper dataReaderWrapper)
 {
     //TODO use datareaderwrapper
     this.rowMapperDelegate = rowMapperDelegate ?? throw new ArgumentNullException(nameof(rowMapperDelegate));
     this.rowsExpected      = rowsExpected;
 }
Ejemplo n.º 10
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="rowMapperDelegate">delegate 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 QueryForObjectDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelegate, string parameterName, Enum dbType, int size,
                                              object parameterValue)
 {
     IList results = QueryWithRowMapperDelegate(cmdType, cmdText, rowMapperDelegate, parameterName, dbType, size, parameterValue);
     return DataAccessUtils.RequiredUniqueResultSet(results);
 }
 public RowMapperResultSetExtractor(RowMapperDelegate rowMapperDelegate, int rowsExpected)
     : this(rowMapperDelegate, rowsExpected, null)
 {
 }
Ejemplo n.º 12
0
 public virtual IList QueryWithRowMapperDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelegate,
                                                 string parameterName, Enum dbType, int size, object parameterValue)
 {
     return (IList)QueryWithResultSetExtractor(cmdType, cmdText, new RowMapperResultSetExtractor(rowMapperDelegate), parameterName, dbType, size, parameterValue);
 }
Ejemplo n.º 13
0
 public virtual IList QueryWithRowMapperDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelegate, ICommandSetter commandSetter)
 {
     return (IList)QueryWithResultSetExtractor(cmdType, cmdText, new RowMapperResultSetExtractor(rowMapperDelegate), commandSetter);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Reads the entire SqlDataReader asynchronously and returns the entire list of row objects when complete.
        /// </summary>
        /// <param name="method"></param>
        /// <param name="dr"></param>
        /// <param name="rowMapper"></param>
        /// <returns></returns>
        async Task<List<Dictionary<string, object>>> ReadResult(Method method, SqlDataReader dr, RowMapperDelegate rowMapper)
        {
            int fieldCount = dr.FieldCount;

            var names = new string[fieldCount];
            var columns = new object[fieldCount];
            for (int i = 0; i < fieldCount; ++i)
            {
                names[i] = dr.GetName(i);
            }

            var nameLookup = (
                from i in Enumerable.Range(0, fieldCount)
                select new { i, name = dr.GetName(i) }
            ).ToLookup(p => p.name, p => p.i);

            var list = new List<Dictionary<string, object>>();

            // Enumerate rows asynchronously:
            while (await dr.ReadAsync())
            {
                // Enumerate columns asynchronously:
                for (int i = 0; i < fieldCount; ++i)
                {
                    columns[i] = await dr.GetFieldValueAsync<object>(i);
                }

                // Map all the columns to a single object:
                var result = rowMapper(method, names, nameLookup, columns);
                list.Add(result);
            }
            return list;
        }
Ejemplo n.º 15
0
 public RowMapperResultSetExtractor(RowMapperDelegate <T> rowMapperDelegate, int rowsExpected)
     : this(rowMapperDelegate, rowsExpected, null)
 {
 }
 public RowMapperResultSetExtractor(RowMapperDelegate rowMapperDelegate)
     : this(rowMapperDelegate, 0, null)
 {
 }
Ejemplo n.º 17
0
 public virtual IList QueryWithRowMapperDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelegate,
                                                 IDbParameters parameters)
 {
     return (IList)QueryWithResultSetExtractor(cmdType, cmdText, new RowMapperResultSetExtractor(rowMapperDelegate), parameters);
 }
 public RowMapperResultSetExtractor(RowMapperDelegate rowMapperDelegate, int rowsExpected, IDataReaderWrapper dataReaderWrapper)
 {
     //TODO use datareaderwrapper
     if (rowMapperDelegate == null)
     {
         throw new ArgumentNullException("rowMapperDelegate");
     }
     this.rowMapperDelegate = rowMapperDelegate;
     this.rowsExpected = rowsExpected;
 }
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="rowMapperDelegate">delegate 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 QueryForObjectDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelegate, IDbParameters parameters)
 {
     IList results = QueryWithRowMapperDelegate(cmdType, cmdText, rowMapperDelegate, parameters);
     return DataAccessUtils.RequiredUniqueResultSet(results);
 }