Record Class CommitStrategy

java.lang.Object
java.lang.Record
io.bloviate.db.CommitStrategy
Record Components:
mode - the commit mode
batches - the batch cadence for CommitStrategy.Mode.EVERY_N_BATCHES (ignored otherwise)

public record CommitStrategy(CommitStrategy.Mode mode, int batches) extends Record
How a TableFiller commits the rows it inserts.

By default (connectionDefault()) the fill engine does not touch the connection's transaction state at all — it relies on whatever autocommit the caller's connection has, which for a typical autocommit connection means a commit per executeBatch(). Disabling autocommit and committing less often cuts commit overhead and is usually faster.

  • connectionDefault() — the engine leaves autocommit alone (back-compatible default).
  • perTable() — autocommit off, a single commit once the table is fully filled.
  • everyNBatches(int) — autocommit off, commit after every n JDBC batches (and once more for the trailing partial batch), bounding the size of an open transaction.

For anything other than connectionDefault() the engine sets autocommit off for the fill, rolls back on error, and restores the connection's prior autocommit setting when done.

Since:
2.10.0
See Also:
  • Constructor Details

  • Method Details

    • connectionDefault

      public static CommitStrategy connectionDefault()
      The back-compatible default: the engine never changes the connection's autocommit state.
      Returns:
      a CommitStrategy.Mode.CONNECTION_DEFAULT strategy
    • perTable

      public static CommitStrategy perTable()
      Autocommit off, a single commit once the table is fully filled.
      Returns:
      a CommitStrategy.Mode.PER_TABLE strategy
    • everyNBatches

      public static CommitStrategy everyNBatches(int n)
      Autocommit off, commit after every n JDBC batches.
      Parameters:
      n - the number of batches between commits; must be >= 1
      Returns:
      the strategy
    • managesTransaction

      public boolean managesTransaction()
      Whether the engine manages the transaction (i.e. anything other than CommitStrategy.Mode.CONNECTION_DEFAULT).
      Returns:
      whether the engine drives autocommit and commits/rolls back itself
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • mode

      public CommitStrategy.Mode mode()
      Returns the value of the mode record component.
      Returns:
      the value of the mode record component
    • batches

      public int batches()
      Returns the value of the batches record component.
      Returns:
      the value of the batches record component