Package groovy.sql

Class BatchingStatementWrapper

java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.sql.BatchingStatementWrapper
All Implemented Interfaces:
GroovyObject, AutoCloseable
Direct Known Subclasses:
BatchingPreparedStatementWrapper

public class BatchingStatementWrapper
extends GroovyObjectSupport
implements AutoCloseable
Class which delegates to a Statement but keeps track of a batch count size. If the batch count reaches the predefined number, this Statement does an executeBatch() automatically. If batchSize is zero, then no batching is performed.
  • Field Details

    • batchSize

      protected int batchSize
    • batchCount

      protected int batchCount
    • log

      protected Logger log
    • results

      protected List<Integer> results
  • Constructor Details

    • BatchingStatementWrapper

      public BatchingStatementWrapper​(Statement delegate, int batchSize, Logger log)
  • Method Details

    • reset

      protected void reset()
    • invokeMethod

      public Object invokeMethod​(String name, Object args)
      Description copied from interface: GroovyObject
      Invokes the given method.
      Specified by:
      invokeMethod in interface GroovyObject
      Parameters:
      name - the name of the method to call
      args - the arguments to use for the method call
      Returns:
      the result of invoking the method
    • addBatch

      public void addBatch​(String sql) throws SQLException
      Throws:
      SQLException
    • incrementBatchCount

      protected void incrementBatchCount() throws SQLException
      Increments batch count (after addBatch(..) has been called) and execute delegate.executeBatch() if batchSize has been reached.
      Throws:
      SQLException
    • clearBatch

      public void clearBatch() throws SQLException
      Throws:
      SQLException
    • executeBatch

      public int[] executeBatch() throws SQLException
      Throws:
      SQLException
    • processResult

      protected void processResult​(int[] lastResult)
    • close

      public void close() throws SQLException
      Specified by:
      close in interface AutoCloseable
      Throws:
      SQLException