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 Felipe Maza <fe...@felipem.com> on 2007/09/25 19:45:01 UTC

Array or List in a ParameterClass

Hi,

I'm trying send a array to ibatis for do multiple updates in a sentence

I read examples of <iterate> for List, but i don't know how apply to my xml




for example, i have some users for update

<update id="example" parameterClass="???">
    update users set user= ??? where id_user= ???
</update>




other solution is do a bucle in the DAO, but i need do more 1000 updates and
this system is more slow for the server and bbdd :(

thanks.

Re: Array or List in a ParameterClass

Posted by Felipe Maza <fe...@felipem.com>.
oh, yes, i want the batch mode :)

thanks Christopher and Adam for your help :-)

On 9/25/07, Adam Zimowski <zi...@gmail.com> wrote:
>
> It sounds like what you really want to do is a batched update
> (developer's guide pages 55-57). You don't need to pass in the array
> or a list, you simply pass in a bean instance or a parameter map for a
> single update. You start a batch inside a transaction, make your 1000
> updates, then you call execute batch. Example from dev guide:
>
> try {
>   sqlMap.startTransaction();
>   sqlMap.startBatch();
>   // … execute statements in between
>   int rowsUpdated = sqlMap.executeBatch(); //optional
>   sqlMap.commitTransaction();
> } finally {
>   sqlMap.endTransaction();
> }
>
> If you use something like Spring to do your transactions you may have
> to do some abstract base classes to cover the boilerplate code, but
> I'd keep things simple and get everything working in iBatis natively.
> For all I know, you may want to use iBatis for entire DAO layer.
>
> Hope this helps.
> -adam
>
> On 9/25/07, Christopher Lamey <cl...@localmatters.com> wrote:
> > Hello,
> >
> > Take a look at pages 49 and 50 of the developer's guide.  It has
> examples of
> > what you're trying to do.
> >
> >      http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_en.pdf
> >
> > Cheers,
> > Chris
> >
> > On 9/25/07 11:45 AM, "Felipe Maza" <fe...@felipem.com> wrote:
> >
> > > Hi,
> > >
> > > I'm trying send a array to ibatis for do multiple updates in a
> sentence
> > >
> > > I read examples of <iterate> for List, but i don't know how apply to
> my xml
> > >
> > >
> > >
> > >
> > > for example, i have some users for update
> > >
> > > <update id="example" parameterClass="???">
> > >     update users set user= ??? where id_user= ???
> > > </update>
> > >
> > >
> > >
> > >
> > > other solution is do a bucle in the DAO, but i need do more 1000
> updates and
> > > this system is more slow for the server and bbdd :(
> > >
> > > thanks.
> >
> >
>

Re: Array or List in a ParameterClass

Posted by Adam Zimowski <zi...@gmail.com>.
It sounds like what you really want to do is a batched update
(developer's guide pages 55-57). You don't need to pass in the array
or a list, you simply pass in a bean instance or a parameter map for a
single update. You start a batch inside a transaction, make your 1000
updates, then you call execute batch. Example from dev guide:

try {
  sqlMap.startTransaction();
  sqlMap.startBatch();
  // … execute statements in between
  int rowsUpdated = sqlMap.executeBatch(); //optional
  sqlMap.commitTransaction();
} finally {
  sqlMap.endTransaction();
}

If you use something like Spring to do your transactions you may have
to do some abstract base classes to cover the boilerplate code, but
I'd keep things simple and get everything working in iBatis natively.
For all I know, you may want to use iBatis for entire DAO layer.

Hope this helps.
-adam

On 9/25/07, Christopher Lamey <cl...@localmatters.com> wrote:
> Hello,
>
> Take a look at pages 49 and 50 of the developer's guide.  It has examples of
> what you're trying to do.
>
>      http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_en.pdf
>
> Cheers,
> Chris
>
> On 9/25/07 11:45 AM, "Felipe Maza" <fe...@felipem.com> wrote:
>
> > Hi,
> >
> > I'm trying send a array to ibatis for do multiple updates in a sentence
> >
> > I read examples of <iterate> for List, but i don't know how apply to my xml
> >
> >
> >
> >
> > for example, i have some users for update
> >
> > <update id="example" parameterClass="???">
> >     update users set user= ??? where id_user= ???
> > </update>
> >
> >
> >
> >
> > other solution is do a bucle in the DAO, but i need do more 1000 updates and
> > this system is more slow for the server and bbdd :(
> >
> > thanks.
>
>

Re: Array or List in a ParameterClass

Posted by Christopher Lamey <cl...@localmatters.com>.
Hello,

Take a look at pages 49 and 50 of the developer's guide.  It has examples of
what you're trying to do.

     http://ibatis.apache.org/docs/java/pdf/iBATIS-SqlMaps-2_en.pdf

Cheers,
Chris

On 9/25/07 11:45 AM, "Felipe Maza" <fe...@felipem.com> wrote:

> Hi,
> 
> I'm trying send a array to ibatis for do multiple updates in a sentence
> 
> I read examples of <iterate> for List, but i don't know how apply to my xml
> 
> 
> 
> 
> for example, i have some users for update
> 
> <update id="example" parameterClass="???">
>     update users set user= ??? where id_user= ???
> </update>
> 
> 
> 
> 
> other solution is do a bucle in the DAO, but i need do more 1000 updates and
> this system is more slow for the server and bbdd :(
> 
> thanks.