You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "H.E. Sum" <ha...@yahoo.com> on 2005/10/27 04:34:46 UTC

Multiple Statements in one transaction/command

What's a good pattern to perform multiple statements
on a single DAO method. Suppose I have a bunch of
"User" objects each containing a list of "Group"
objects. Right now I'm doing the following:

(Pseudocode)

AddUser(User) {
[BeginTransaction]
   Mapper.Instance().Insert("InsertUser", user);
   foreach (Group in user.Groups) {
      Mapper.Instance().Insert("InsertGroup", group);
   }
[CommitTransaction]

Is there a way to move this type of transaction to
iBatis. I'm thinking along the lines of a hypothetical
construct like:

<batchStatement id="InsertUserAndGroups"
useTransaction="true" parameterClass="User">
   <insert id="InsertUser">
      INSERT INTO user ...
   </insert>
   <foreach property="Groups">
      <insert id="InsertGroup">
          INSERT INTO group ...
      </insert>
   </foreach>
</batchStatement>

In the example, the <insert> statements are the same
as usual except they implicitly take the parameter
specified in the <batchStatement> tag.

Is there something like this already in iBatis or
planned for the future, or is this a misguided
strategy?

Thanks,
H.E.


	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Re: Multiple Statements in one transaction/command

Posted by Ben Munat <be...@munat.com>.
Clinton Begin wrote:
> Don't worry, we don't intend to abandon XML.  But instead, we intend to 
> support a more robust Java API to allow developers to do both full 
> mapped statement configuration from Java, as well as execute ad-hoc SQL 
> statements.
> 
> Cheers,
> Clinton
> 
Sounds great! Thanks for the reassurance. :-)

b

Re: Multiple Statements in one transaction/command

Posted by Clinton Begin <cl...@gmail.com>.
Don't worry, we don't intend to abandon XML. But instead, we intend to
support a more robust Java API to allow developers to do both full mapped
statement configuration from Java, as well as execute ad-hoc SQL statements.

Cheers,
Clinton

On 11/2/05, Ben Munat <be...@munat.com> wrote:
>
> Clinton Begin wrote:
> >
> > No, I would avoid that. I'm not sure what the appeal is of doing
> > something like this. More XML and less Java? I'm finding the opposite
> > opinion is more common these days....less XML and more Java. In fact,
> > one of the highest priority features of iBATIS 3.0 is XML-less iBATIS.
> ;-)
> >
> Please don't fall for the anti-XML hype! I cannot fathom this whole "xml
> is too verbose"
> crap. Yes, it is possible to push too much responsibility into the XML
> (and yes, alarm
> bells should be going off when you're talking about putting a logic notion
> like "foreach"
> in XML), but that does not mean we should abandon XML... and for what? Yet
> another markup
> language (Ruby-bash fully intended) but without the "scary" pointy
> brackets? Hardcoding
> our configuration in the code?
>
> In any case, from one (mostly) satisfied iBatis user, your use of XML is
> *just fine*!
> Don't fix what ain't broke!
>
> b
>

Re: Multiple Statements in one transaction/command

Posted by Ben Munat <be...@munat.com>.
Clinton Begin wrote:
> 
> No, I would avoid that.  I'm not sure what the appeal is of doing 
> something like this.  More XML and less Java?  I'm finding the opposite 
> opinion is more common these days....less XML and more Java.  In fact, 
> one of the highest priority features of iBATIS 3.0 is XML-less iBATIS.  ;-)
> 
Please don't fall for the anti-XML hype! I cannot fathom this whole "xml is too verbose" 
crap. Yes, it is possible to push too much responsibility into the XML (and yes, alarm 
bells should be going off when you're talking about putting a logic notion like "foreach" 
in XML), but that does not mean we should abandon XML... and for what? Yet another markup 
language (Ruby-bash fully intended) but without the "scary" pointy brackets? Hardcoding 
our configuration in the code?

In any case, from one (mostly) satisfied iBatis user, your use of XML is *just fine*! 
Don't fix what ain't broke!

b

Re: Multiple Statements in one transaction/command

Posted by Clinton Begin <cl...@gmail.com>.
No, I would avoid that. I'm not sure what the appeal is of doing something
like this. More XML and less Java? I'm finding the opposite opinion is more
common these days....less XML and more Java. In fact, one of the highest
priority features of iBATIS 3.0 is XML-less iBATIS. ;-)

Cheers,
Clinton


On 10/26/05, H.E. Sum <ha...@yahoo.com> wrote:
>
> What's a good pattern to perform multiple statements
> on a single DAO method. Suppose I have a bunch of
> "User" objects each containing a list of "Group"
> objects. Right now I'm doing the following:
>
> (Pseudocode)
>
> AddUser(User) {
> [BeginTransaction]
> Mapper.Instance().Insert("InsertUser", user);
> foreach (Group in user.Groups) {
> Mapper.Instance().Insert("InsertGroup", group);
> }
> [CommitTransaction]
>
> Is there a way to move this type of transaction to
> iBatis. I'm thinking along the lines of a hypothetical
> construct like:
>
> <batchStatement id="InsertUserAndGroups"
> useTransaction="true" parameterClass="User">
> <insert id="InsertUser">
> INSERT INTO user ...
> </insert>
> <foreach property="Groups">
> <insert id="InsertGroup">
> INSERT INTO group ...
> </insert>
> </foreach>
> </batchStatement>
>
> In the example, the <insert> statements are the same
> as usual except they implicitly take the parameter
> specified in the <batchStatement> tag.
>
> Is there something like this already in iBatis or
> planned for the future, or is this a misguided
> strategy?
>
> Thanks,
> H.E.
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>