public void TestQueryWithCommandCreators()
        {
            IDbCommandCreatorFactory ccf         = new IDbCommandCreatorFactory(adoTemplate.DbProvider, CommandType.Text, "select TestObjectNo, Age, Name from TestObjects", null);
            IDbCommandCreator        cc          = ccf.NewDbCommandCreator(null);
            IList <TestObject>       testObjects = adoTemplate.QueryWithCommandCreator(cc,
                                                                                       new TestObjectResultSetExtractor <List <TestObject> >());

            Assert.IsNotNull(testObjects);
            Assert.AreEqual(2, testObjects.Count);
            foreach (TestObject o in testObjects)
            {
                Console.WriteLine(o);
            }
        }
예제 #2
0
 public virtual object QueryWithCommandCreator(IDbCommandCreator cc, IResultSetExtractor rse)
 {
     return QueryWithCommandCreator(cc, rse, null);
 }
예제 #3
0
        /// <summary>
        /// Executes a non query with a command created via IDbCommandCreator and
        /// parameters.
        /// </summary>
        /// <remarks>Output parameters can be retrieved via the returned
        /// dictionary.
        /// <para>
        /// More commonly used as a lower level support method within the framework,
        /// for example StoredProcedure/AdoScalar.
        /// </para>
        /// </remarks>
        /// <param name="commandCreator">The callback to create a IDbCommand.</param>
        /// <returns>The number of rows affected.</returns>
        public virtual IDictionary ExecuteNonQuery(IDbCommandCreator commandCreator)
        {

            return (IDictionary)Execute(commandCreator, new AdoNonQueryWithOutputParamsCommandCallback());

        }
예제 #4
0
 /// <summary>
 /// Execute the query with a command created via IDbCommandCreator and
 /// parameters
 /// </summary>
 /// <remarks>Output parameters can be retrieved via the returned
 /// dictionary.
 /// <para>
 /// More commonly used as a lower level support method within the framework,
 /// for example for StoredProcedure/AdoScalar.
 /// </para></remarks>
 /// <param name="commandCreator">The callback to create a IDbCommand.</param>
 /// <returns>A dictionary containing output parameters, if any</returns>
 public virtual IDictionary ExecuteScalar(IDbCommandCreator commandCreator)
 {
     return (IDictionary)Execute(commandCreator, new AdoStoredProcedureScalarCommandCallback());
 }
예제 #5
0
 public IDictionary QueryWithCommandCreator(IDbCommandCreator cc, IList namedResultSetProcessors)
 {
     return (IDictionary)Execute(cc, new AdoResultProcessorsQueryCommandCallback(this, namedResultSetProcessors));
 }
예제 #6
0
        /// <summary>
        /// Executes ADO.NET operations on a command object, created by the provided IDbCommandCreator,
        /// using the interface based callback IDbCommandCallback.
        /// </summary>
        /// <param name="commandCreator">The command creator.</param>
        /// <param name="action">The callback to execute based on IDbCommand</param>
        /// <returns>A result object returned by the action or null</returns>
        public virtual object Execute(IDbCommandCreator commandCreator, ICommandCallback action)
        {
            AssertUtils.ArgumentNotNull(commandCreator, "commandCreator", "IDbCommandCreator must not be null");
            AssertUtils.ArgumentNotNull(action, "action", "Callback object must not be null");

            ConnectionTxPair connectionTxPairToUse = GetConnectionTxPair(DbProvider);


            IDbCommand command = null;
            try
            {
                command = commandCreator.CreateDbCommand(DbProvider);
                command.Connection = connectionTxPairToUse.Connection;
                command.Transaction = connectionTxPairToUse.Transaction;
                ApplyCommandSettings(command);
                //TODO collect warnings...
                //RegisterEventHandlers(command.Connection);
                Object result = action.DoInCommand(command);

                //SqlWarnings sqlWarnings = GetSqlWarnings()
                //ThrowExceptionOnWarningIfNotIgnoringWarnings(sqlWarnings);

                return result;
            }
            catch (Exception e)
            {
                commandCreator = null;
                DisposeCommand(command);
                command = null;
                DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
                connectionTxPairToUse.Connection = null;
                if (DbProvider.IsDataAccessException(e))
                {
                    throw ExceptionTranslator.Translate("CommandCallback", GetCommandText(action), e);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                DisposeCommand(command);
                DisposeConnection(connectionTxPairToUse.Connection, DbProvider);
            }

        }
예제 #7
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));
        }
예제 #8
0
 public virtual void QueryWithCommandCreator(IDbCommandCreator cc, IRowCallback rowCallback, IDictionary returnedParameters)
 {
     if (rowCallback == null)
     {
         throw new ArgumentNullException("RowCallback must not be null");
     }
     Execute(cc, new AdoRowCallbackCommandCallback(this, rowCallback, returnedParameters));
 }
예제 #9
0
        public virtual object QueryWithCommandCreator(IDbCommandCreator cc, IResultSetExtractor rse, IDictionary returnedParameters)
        {
            if (rse == null)
            {
                throw new ArgumentNullException("Result Set Extractor must not be null");
            }

            return Execute(cc, new AdoResultSetExtractorWithOutputParamsCommandCallback(this, rse, returnedParameters));
        }
예제 #10
0
 public virtual IList QueryWithCommandCreator(IDbCommandCreator cc, IRowMapper rowMapper)
 {
     return QueryWithCommandCreator(cc, rowMapper, null);
 }
예제 #11
0
 public virtual void QueryWithCommandCreator(IDbCommandCreator cc, IRowCallback rowCallback)
 {
     QueryWithCommandCreator(cc, rowCallback, null);
 }