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); } }
public virtual object QueryWithCommandCreator(IDbCommandCreator cc, IResultSetExtractor rse) { return QueryWithCommandCreator(cc, rse, null); }
/// <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()); }
/// <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()); }
public IDictionary QueryWithCommandCreator(IDbCommandCreator cc, IList namedResultSetProcessors) { return (IDictionary)Execute(cc, new AdoResultProcessorsQueryCommandCallback(this, namedResultSetProcessors)); }
/// <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); } }
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)); }
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)); }
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)); }
public virtual IList QueryWithCommandCreator(IDbCommandCreator cc, IRowMapper rowMapper) { return QueryWithCommandCreator(cc, rowMapper, null); }
public virtual void QueryWithCommandCreator(IDbCommandCreator cc, IRowCallback rowCallback) { QueryWithCommandCreator(cc, rowCallback, null); }