ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: Statement Batching
Date Thu, 26 Apr 2007 03:18:46 GMT
There isn't any prohibiting you from using Ayende's example code with IBatisNet now:

// his reflection sample...you could also use the delegate code
for (int i = 0; i < products.Count; i++)
{
 appendInfo.Invoke(sqlCmdSet, new object[] {
  SqlMapperAdapter.BuildDbCommand(sqlMapper, "Product.Update", products[i]});
}
executeNonQueryInfo.Invoke(sqlCmdSet,null);

Its just a matter of asking IBatisNet for the IDbCommand it generates internally:

public static IDbCommand BuildDbCommand(ISqlMapper sqlMapper, string statement, object parameter)
{
// retrieve the specific <update>, <delete>, or <insert> statement
MappedStatement mappedStatement = (MappedStatement) sqlMapper.MappedStatements[statement];

// instanciate a new IDbConnection and set its ConnectionString property
SqlMapSession session = new SqlMapSession(sqlMapper);
session.CreateConnection();

// set the CommandText and Connection property of an IDbCommand
RequestScope request = mappedStatement.Statement.Sql.GetRequestScope(mappedStatement, parameterObject,
session);

// fill the Parameters property of the IDbCommand
mappedStatement.PreparedCommand.Create(request, session, mappedStatement.Statement, parameterObject);
          

// DbCommandDecorator should expose its inner command as a property
FieldInfo fieldInfo = typeof(DbCommandDecorator).GetField("_innerDbCommand", BindingFlags.NonPublic
| BindingFlags.Instance);
return (IDbCommand)fieldInfo.GetValue(request.IDbCommand);
}

A property needs to be added to one of the internal classes so the last line is just:

return mappedStatement.PreparedCommand.InnerCommand;

Is the batching supported on Sql Server 2000? 

IBatisNet is focused on using the ADO.Net interfaces for data access. Is it a good idea to
make special cases for specific drivers and make calls to non-public members?

Perhaps we could extend SqlMapper and create a BatchSqlMapper that supports StartBatch() and
ExecuteBatch() or modify MappedStatement.ExecuteUpdate to accept an execution strategy that
chooses between ExecuteNonQuery or a custom stragey that relies on calling the non-public
members of SqlCommandSet.

----- Original Message ----

From: "Tan, Lee" <Lee.Tan@qg.com>

To: user-cs@ibatis.apache.org

Sent: Tuesday, April 24, 2007 2:55:21 PM

Subject: Statement Batching



      Has there been much  interest in implementing batching in iBatis?

 http://ayende.com/Blog/archive/2006/09/13/7276.aspx has some good statistics on possible
performance gains  accessing these included batching methods via reflection and  delegates.

 We're looking at the same problems and right now the  prevailing winds are pushing us to
use iBatis only for Selects with all Updates, Inserts, and Deletes being handled manually
and I'd like to avoid that if  possible.

 Thoughts?





 Lee Tan  

Information  Systems - Software Development 

 Quad/Graphics  

 Sussex,  Wisconsin 

414-566-6716 phone 

414-566-4010x6716 beeper  

lee.tan@qg.com 

www.QG.com 

  










Mime
View raw message