Class AbstractBatchQuery<T extends AbstractBatchQuery<T>>

java.lang.Object
com.github.darksoulq.abyssallib.common.database.relational.AbstractBatchQuery<T>
Type Parameters:
T - The specific implementation type, allowing for fluent method chaining.
Direct Known Subclasses:
BatchQuery, BatchQuery, BatchQuery, BatchQuery, BatchQuery

public abstract class AbstractBatchQuery<T extends AbstractBatchQuery<T>> extends Object
An abstract base class for handling batch database operations such as INSERT, REPLACE, or INSERT IGNORE. This class provides a fluent API to build a collection of records and execute them in a single batch to optimize performance and reduce database round-trips.
  • Constructor Details

    • AbstractBatchQuery

      public AbstractBatchQuery(Connection connection, String table, ExecutorService asyncPool, String... columns)
      Constructs a new AbstractBatchQuery instance.
      Parameters:
      connection - The JDBC Connection to be used.
      table - The name of the target table.
      asyncPool - The ExecutorService for asynchronous tasks.
      columns - The specific column names to be populated in this batch.
  • Method Details

    • insert

      public T insert()
      Sets the batch operation mode to standard INSERT.
      Returns:
      The current instance cast to type T for chaining.
    • replace

      public T replace()
      Sets the batch operation mode to REPLACE.
      Returns:
      The current instance cast to type T for chaining.
    • insertIgnore

      public T insertIgnore()
      Sets the batch operation mode to INSERT IGNORE.
      Returns:
      The current instance cast to type T for chaining.
    • add

      public T add(Object... values)
      Adds a single row of data to the internal batch list.
      Parameters:
      values - The values to be inserted. The length must match the number of columns defined.
      Returns:
      The current instance cast to type T for chaining.
      Throws:
      IllegalArgumentException - If the number of values does not match the number of columns.
    • execute

      public int execute()
      Compiles the SQL statement and executes the batch against the database.
      Returns:
      The sum of all rows affected by the batch operation.
      Throws:
      RuntimeException - If a SQLException occurs during execution.
    • executeAsync

      public CompletableFuture<Integer> executeAsync()
      Executes the batch operation asynchronously using the internal thread pool.
      Returns:
      A CompletableFuture that resolves to the total number of affected rows.