Actually it is a bit quick and dirty and should be refined and provided with better error handling. This code is implemented in my DAO class outside myBatis.
I usually map the resultClass as map, but it is not important at this point (when doing reporting I often use the same select statement used for mapping class objects.
Heavy reports require specially crafted and optimized sql queries (lots of join. groupby etc etc) and have them bind to datatable is a must-have in order to naturally bind to report documents or when lists of objects leads to performance issues.
In the code the dataTableName parameter could be optional, cannot remember if I use in client code...
---------------------------------------
public DataTable SelectDataTable(String dataTableName, string statementName, object parameters)
{
DataTable dt = null;
if (!String.IsNullOrEmpty(dataTableName))
dt = new DataTable(dataTableName);
else
dt = new DataTable();
IMappedStatement statement = _mapper.GetMappedStatement(statementName);
RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, parameters, _mapper.OpenConnection());
statement.PreparedCommand.Create(scope, _mapper.LocalSession, statement.Statement, parameters);
using (scope.IDbCommand)
{
dt.Load(scope.IDbCommand.ExecuteReader());
}
_mapper.CloseConnection();
return dt;
}
----------------
this is not my stuff, I found somewhere in the web and just adapted to my needs.
hope this help
andrea
--
--
regards
Andrea Tassinari