SqlMappers do two tasks: building/executing dynamic sql and translating
the result set into domain objects. It might be useful to expose more
of the "building dynamic sql" code to the user:

 IDictionary map = new Hashtable();
 map["StartDate"] = DateTime.Now;
 map["EndDate"] = endDate;
 map["Users"] = new int[] {4, 7, 6, 9, 10};

 IMappedStatement mappedStatement = 
  sqlMapper.GetMappedStatement("Calendar.Search");

 // CreateIDbCommand(object parameterObject)
 IDbCommand cmd = mappedStatement.CreateIDbCommand(map);

The returned IDbCommand would have its IDataParameters collection
populated and could be forwarded off to another framework (the
Microsoft Enterprise Library DAAB for example). I've haven't used the
DAAB in a very long time but from the samples on-line I'd envision it
looking something like this:

 IDbCommand cmd = generateCommandFromIBatisNet();
 Database db = DatabaseFactory.CreateDatabase();
 IDataReader reader = db.ExecuteReader(cmd);

This might also be an entry point for generic data mapping:

 // produce some sort of Ldap object that will be executed
 // by another system
 LdapResult result = (LdapResult)mappedStatement.Process(
  ldapHandler, 5);

 // hibernate will use the hqlCriteria object in one of its queries
 HqlCriteria hqlCriteria = (HqlCriteria)mappedStatement.Process(
  hibernateCriteriaHandler, new int[] {5, 6, 9});

 // general text processing
 string dynamicText = (string)mappedStatement.Process(
  dynamicTextHandler, new int[] {5, 6, 9});

Getting back on track, I think this is somewhat possible (long and
ugly!) today with IBatisNet:

 // untested

 int parameter = 5;
 
 IMappedStatement mappedStatement = 
  sqlMapper.GetMappedStatement("Calendar.Search");

 RequestScope request = 
  mappedStatement.Statement.Sql.GetRequestScope(
   parameter, 
   sqlMapper.LocalSession);

 mappedStatement.PreparedCommand.Create(
  request, 
  sqlMapper.LocalSession, 
  mappedStatement.Statement, 
  parameter);

 IDbCommand cmd = request.IDbCommand;

Thoughts, ideas?

- Ron

Reply via email to