You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by Ron Grabowski <ro...@yahoo.com> on 2006/02/16 05:56:10 UTC

IBatisNet: Generating IDbCommand objects from IMappedStatements

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

Re: IBatisNet: Generating IDbCommand objects from IMappedStatements

Posted by Chad Humphries <ch...@gmail.com>.
cool.  I figured that's what you were meaning/going after, I just
wanted to get a clearer picture.

-chad

On 2/16/06, Ron Grabowski <ro...@yahoo.com> wrote:
> I meant something closer to this:
>
>  // general text processing
>  string dynamicText = (string)mappedStatement.Process(
>  velocityHandler, new int[] {5, 6, 9});
>
> --- Chad Humphries <ch...@gmail.com> wrote:
>
> > Sounds like this would be a good extension point as a whole.  One
> > thing stuck out in your message though.
> >
> > ========
> > // general text processing
> >  string dynamicText = (string)mappedStatement.Process(
> >  dynamicTextHandler, new int[] {5, 6, 9});
> > ============
> >
> > The idea that iBatis might handle general text processing (I'm
> > assuming this was just an example to show various uses that could be)
> > as a primary duty is a little worrying, when there are many template
> > processing engines laying about
> > (velocity/nvelocity/stringtemplate/etc).
> >
> > All in all seperating out the two distinct sets of functionality
> > could
> > be very useful I agree.  If nothing else it could make iBatis useful
> > to a whole new set of people.
> >
> > -Chad
> >
> >
> >
> > On 2/15/06, Ron Grabowski <ro...@yahoo.com> wrote:
> > > 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
> > >
> >
>
>

Re: IBatisNet: Generating IDbCommand objects from IMappedStatements

Posted by Ron Grabowski <ro...@yahoo.com>.
I meant something closer to this:

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

--- Chad Humphries <ch...@gmail.com> wrote:

> Sounds like this would be a good extension point as a whole.  One
> thing stuck out in your message though.
> 
> ========
> // general text processing
>  string dynamicText = (string)mappedStatement.Process(
>  dynamicTextHandler, new int[] {5, 6, 9});
> ============
> 
> The idea that iBatis might handle general text processing (I'm
> assuming this was just an example to show various uses that could be)
> as a primary duty is a little worrying, when there are many template
> processing engines laying about
> (velocity/nvelocity/stringtemplate/etc).
> 
> All in all seperating out the two distinct sets of functionality
> could
> be very useful I agree.  If nothing else it could make iBatis useful
> to a whole new set of people.
> 
> -Chad
> 
> 
> 
> On 2/15/06, Ron Grabowski <ro...@yahoo.com> wrote:
> > 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
> >
> 


Re: IBatisNet: Generating IDbCommand objects from IMappedStatements

Posted by Chad Humphries <ch...@gmail.com>.
Sounds like this would be a good extension point as a whole.  One
thing stuck out in your message though.

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

The idea that iBatis might handle general text processing (I'm
assuming this was just an example to show various uses that could be)
as a primary duty is a little worrying, when there are many template
processing engines laying about
(velocity/nvelocity/stringtemplate/etc).

All in all seperating out the two distinct sets of functionality could
be very useful I agree.  If nothing else it could make iBatis useful
to a whole new set of people.

-Chad



On 2/15/06, Ron Grabowski <ro...@yahoo.com> wrote:
> 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
>