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 Premanand Kumarapillai <Pr...@igate.com> on 2006/11/21 10:37:41 UTC

Passing ArrayList of Object for insert

 


 
Hi,
 
I have a ArrayList of value objects. Is it possible to pass such an array to iBATIS for insert?
 
The Value object can be mapped to a table in the DB.
 
Thanks in advance,
Prem
 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Information transmitted by this EMAIL is proprietary to iGATE Group of Companies and is intended for use only by the individual 
or entity to whom it is addressed and may contain information that is privileged, confidential, or exempt from disclosure under 
applicable law. If you are not the intended recipient of this EMAIL immediately notify the sender at iGATE or mailadmin@igate.com 
and delete this EMAIL including any attachments
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Re: Passing ArrayList of Object for insert

Posted by prakashsahu1 <pr...@gmail.com>.
We can use the batch update.


nmaves wrote:
> 
> Even better would be to iterate as Brandon stated but use the batch
> functionality of ibatis.  This will dramatically increase your
> performance.
> 
> Nathan
> 
> On 11/21/06, Brandon Goodin <br...@gmail.com> wrote:
>>
>> If you database supports multiple inserts in a single jdbc call. But I
>> don't know which databases support that. Is there a reason you can't
>> iterate
>> over your list and save each record via your dao?
>>
>> Brandon
>>
>> On 11/21/06, Premanand Kumarapillai <Pr...@igate.com>
>> wrote:
>> >
>> >
>> >
>> >
>> >
>> > Hi,
>> >
>> > I have a ArrayList of value objects. Is it possible to pass such an
>> > array to iBATIS for insert?
>> >
>> > The Value object can be mapped to a table in the DB.
>> >
>> > Thanks in advance,
>> > Prem
>> >
>> >
>> >
>> >
>> > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>> >
>> >
>> >
>> > Information transmitted by this EMAIL is proprietary to iGATE Group of
>> Companies and is intended for use only by the individual
>> >
>> > or entity to whom it is addressed and may contain information that is
>> privileged, confidential, or exempt from disclosure under
>> >
>> > applicable law. If you are not the intended recipient of this EMAIL
>> immediately notify the sender at iGATE or mailadmin@igate.com
>> >
>> > and delete this EMAIL including any attachments
>> >
>> > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>> >
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Passing-ArrayList-of-Object-for-insert-tf2677771.html#a14212024
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Passing ArrayList of Object for insert

Posted by Koka Kiknadze <22...@gmail.com>.
Here's how I use it:
Lets assume insertObjects is an array of InsertObject -s that we want to
persist
            try
            {
                sqlMapClient.startTransaction();
                sqlMapClient.startBatch();
                for (InsertObject insertObject : insertObjects)
                {
                    sqlMapClient.insert("XMLFile.insertStatement",
insertObject);
                }
                sqlMapClient.executeBatch();
            }
            catch (SQLException ex)
            {
                 // log error etc. but note no explicit rollback needed
            }
            finally
            {
                try
                {
                    sqlMapClient.endTransaction();
                }
                catch (SQLException ex)
                {
                      \\ wow something's very very wrong
                }
            }
Please not that if the array is quite large (more than couple of hundred
objects) you'd better use startBatch-executeBatch-commits not for entire
loop, but slice it to say every 100. Of course these numbers are usually
determined by simply trying several values in the range  ~20-1000

Re: Passing ArrayList of Object for insert

Posted by Warren <wa...@clarksnutrition.com>.
Can someone give an example of doing this?

Nathan Maves wrote:
> Even better would be to iterate as Brandon stated but use the batch 
> functionality of ibatis.  This will dramatically increase your 
> performance.
>
> Nathan
>
> On 11/21/06, * Brandon Goodin* <brandon.goodin@gmail.com 
> <ma...@gmail.com>> wrote:
>
>     If you database supports multiple inserts in a single jdbc call.
>     But I don't know which databases support that. Is there a reason
>     you can't iterate over your list and save each record via your dao?
>
>     Brandon
>
>
>     On 11/21/06, *Premanand Kumarapillai*
>     <Premanand.Kumarapillai@igate.com
>     <ma...@igate.com>> wrote:
>
>          
>
>
>          
>         Hi,
>          
>         I have a ArrayList of value objects. Is it possible to pass
>         such an array to iBATIS for insert?
>          
>         The Value object can be mapped to a table in the DB.
>          
>         Thanks in advance,
>         Prem
>          
>
>
>
>         _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
>
>         Information transmitted by this EMAIL is proprietary to iGATE Group of Companies and is intended for use only by the individual 
>         or entity to whom it is addressed and may contain information that is privileged, confidential, or exempt from disclosure under 
>         applicable law. If you are not the intended recipient of this EMAIL immediately notify the sender at iGATE or mailadmin@igate.com
>         <ma...@igate.com> 
>         and delete this EMAIL including any attachments
>         _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
>
>
>


Re: Passing ArrayList of Object for insert

Posted by Nathan Maves <na...@gmail.com>.
Even better would be to iterate as Brandon stated but use the batch
functionality of ibatis.  This will dramatically increase your performance.

Nathan

On 11/21/06, Brandon Goodin <br...@gmail.com> wrote:
>
> If you database supports multiple inserts in a single jdbc call. But I
> don't know which databases support that. Is there a reason you can't iterate
> over your list and save each record via your dao?
>
> Brandon
>
> On 11/21/06, Premanand Kumarapillai <Pr...@igate.com>
> wrote:
> >
> >
> >
> >
> >
> > Hi,
> >
> > I have a ArrayList of value objects. Is it possible to pass such an
> > array to iBATIS for insert?
> >
> > The Value object can be mapped to a table in the DB.
> >
> > Thanks in advance,
> > Prem
> >
> >
> >
> >
> > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> >
> >
> >
> > Information transmitted by this EMAIL is proprietary to iGATE Group of Companies and is intended for use only by the individual
> >
> > or entity to whom it is addressed and may contain information that is privileged, confidential, or exempt from disclosure under
> >
> > applicable law. If you are not the intended recipient of this EMAIL immediately notify the sender at iGATE or mailadmin@igate.com
> >
> > and delete this EMAIL including any attachments
> >
> > _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> >
>
>

Re: Passing ArrayList of Object for insert

Posted by Brandon Goodin <br...@gmail.com>.
If you database supports multiple inserts in a single jdbc call. But I don't
know which databases support that. Is there a reason you can't iterate over
your list and save each record via your dao?

Brandon

On 11/21/06, Premanand Kumarapillai <Pr...@igate.com>
wrote:
>
>
>
>
>
> Hi,
>
> I have a ArrayList of value objects. Is it possible to pass such an array
> to iBATIS for insert?
>
> The Value object can be mapped to a table in the DB.
>
> Thanks in advance,
> Prem
>
>
>
>
>
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
>
> Information transmitted by this EMAIL is proprietary to iGATE Group of Companies and is intended for use only by the individual
>
> or entity to whom it is addressed and may contain information that is privileged, confidential, or exempt from disclosure under
>
> applicable law. If you are not the intended recipient of this EMAIL immediately notify the sender at iGATE or
> mailadmin@igate.com
> and delete this EMAIL including any attachments
>
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>