change the batch implementation with following benefits

 fix the connection leak, which requires the connection to be opened, so it can used to addBatch().
   The new implementation delay the addBatch at the every end, so the transaction/connection can be closed with closure.

   Since it delayed the connection opening, we don't hold long connections as the result.