Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this really a batch update

 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this code snippet from web --



what confused me is

for (int i = 0; i < count; i++) {
batchInsert.update(new Object[] { i + 100L, "a" + i, "b" + i, null });
}


It seems it is updating the records one by one instead of at batch size. can someone explain this to me ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setBatchSize(10);

Looks like the batch size is set. So after 10 updates, those 10 will be sent to the database in one call. So if you loop 5000 times then you will have 500 database calls based on that batch size.

Mark
 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still don't get it. So what does "update" method exactly do ? when it executes the "updte" on record 1, based on what you said, it does not immediately insert and hold it until record 10 is done with its "update" and then it inserts records 1 to 10 at same time. is that right ?
Then again what does "update" do on record 1 ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj Ohadi wrote:still don't get it. So what does "update" method exactly do ? when it executes the "updte" on record 1, based on what you said, it does not immediately insert and hold it until record 10 is done with its "update" and then it inserts records 1 to 10 at same time. is that right ?
Then again what does "update" do on record 1 ?


Yes, exactly. It will hold onto all ten statements then send all ten in one call to the database.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic