You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by Arunkumar Pillai <ar...@gmail.com> on 2016/02/04 05:22:04 UTC

Batch insert using Apache metamodel

Hi

Do we have any better way to insert multiple records together. current i'm
using loop?
Please suggest if there any better ways

-- 
Thanks and Regards
        Arun

Re: Batch insert using Apache metamodel

Posted by Arunkumar Pillai <ar...@gmail.com>.
Thanks Kasper

On Fri, Feb 5, 2016 at 12:00 PM, Kasper Sørensen <
i.am.kasper.sorensen@gmail.com> wrote:

> That looks correct. You're inserting it in one go.
> Consider BatchUpdateScript instead of UpdateScript if it's just a big bulk
> like this.
> Den 05/02/2016 5.23 AM skrev "Arunkumar Pillai" <ar...@gmail.com>:
>
> > Hi
> > PFB my code snippet
> >
> > dataContext.executeUpdate(new UpdateScript() {
> >
> >         def run(callback: UpdateCallback): Unit = {
> >
> >
> >           val table: Table = schema.getTableByName(tablename)
> >
> >          for(i =1;i< n ;i ++){
> >           callback.insertInto(table).value(columns, value)
> >             .value(column, value)
> >             .execute()
> >         }
> > }
> >       }
> >       )
> >
> > On Fri, Feb 5, 2016 at 12:23 AM, Kasper Sørensen <
> > i.am.kasper.sorensen@gmail.com> wrote:
> >
> > > Hi Arun,
> > >
> > > It depends on where your loop is... Can you share a code snippet?
> > >
> > > Basically the loop should be inside an UpdateScript - then everything
> is
> > > happening in one big bulk/transaction. If the loop is outside then
> you're
> > > likely to suffer under a very chatty (and non-transactional)
> interaction
> > > with the DB.
> > >
> > > Kasper
> > >
> > > 2016-02-04 5:22 GMT+01:00 Arunkumar Pillai <ar...@gmail.com>:
> > >
> > > > Hi
> > > >
> > > > Do we have any better way to insert multiple records together.
> current
> > > i'm
> > > > using loop?
> > > > Please suggest if there any better ways
> > > >
> > > > --
> > > > Thanks and Regards
> > > >         Arun
> > > >
> > >
> >
> >
> >
> > --
> > Thanks and Regards
> >         Arun
> >
>



-- 
Thanks and Regards
        Arun

Re: Batch insert using Apache metamodel

Posted by Kasper Sørensen <i....@gmail.com>.
That looks correct. You're inserting it in one go.
Consider BatchUpdateScript instead of UpdateScript if it's just a big bulk
like this.
Den 05/02/2016 5.23 AM skrev "Arunkumar Pillai" <ar...@gmail.com>:

> Hi
> PFB my code snippet
>
> dataContext.executeUpdate(new UpdateScript() {
>
>         def run(callback: UpdateCallback): Unit = {
>
>
>           val table: Table = schema.getTableByName(tablename)
>
>          for(i =1;i< n ;i ++){
>           callback.insertInto(table).value(columns, value)
>             .value(column, value)
>             .execute()
>         }
> }
>       }
>       )
>
> On Fri, Feb 5, 2016 at 12:23 AM, Kasper Sørensen <
> i.am.kasper.sorensen@gmail.com> wrote:
>
> > Hi Arun,
> >
> > It depends on where your loop is... Can you share a code snippet?
> >
> > Basically the loop should be inside an UpdateScript - then everything is
> > happening in one big bulk/transaction. If the loop is outside then you're
> > likely to suffer under a very chatty (and non-transactional) interaction
> > with the DB.
> >
> > Kasper
> >
> > 2016-02-04 5:22 GMT+01:00 Arunkumar Pillai <ar...@gmail.com>:
> >
> > > Hi
> > >
> > > Do we have any better way to insert multiple records together. current
> > i'm
> > > using loop?
> > > Please suggest if there any better ways
> > >
> > > --
> > > Thanks and Regards
> > >         Arun
> > >
> >
>
>
>
> --
> Thanks and Regards
>         Arun
>

Re: Batch insert using Apache metamodel

Posted by Arunkumar Pillai <ar...@gmail.com>.
Hi
PFB my code snippet

dataContext.executeUpdate(new UpdateScript() {

        def run(callback: UpdateCallback): Unit = {


          val table: Table = schema.getTableByName(tablename)

         for(i =1;i< n ;i ++){
          callback.insertInto(table).value(columns, value)
            .value(column, value)
            .execute()
        }
}
      }
      )

On Fri, Feb 5, 2016 at 12:23 AM, Kasper Sørensen <
i.am.kasper.sorensen@gmail.com> wrote:

> Hi Arun,
>
> It depends on where your loop is... Can you share a code snippet?
>
> Basically the loop should be inside an UpdateScript - then everything is
> happening in one big bulk/transaction. If the loop is outside then you're
> likely to suffer under a very chatty (and non-transactional) interaction
> with the DB.
>
> Kasper
>
> 2016-02-04 5:22 GMT+01:00 Arunkumar Pillai <ar...@gmail.com>:
>
> > Hi
> >
> > Do we have any better way to insert multiple records together. current
> i'm
> > using loop?
> > Please suggest if there any better ways
> >
> > --
> > Thanks and Regards
> >         Arun
> >
>



-- 
Thanks and Regards
        Arun

Re: Batch insert using Apache metamodel

Posted by Kasper Sørensen <i....@gmail.com>.
Hi Arun,

It depends on where your loop is... Can you share a code snippet?

Basically the loop should be inside an UpdateScript - then everything is
happening in one big bulk/transaction. If the loop is outside then you're
likely to suffer under a very chatty (and non-transactional) interaction
with the DB.

Kasper

2016-02-04 5:22 GMT+01:00 Arunkumar Pillai <ar...@gmail.com>:

> Hi
>
> Do we have any better way to insert multiple records together. current i'm
> using loop?
> Please suggest if there any better ways
>
> --
> Thanks and Regards
>         Arun
>