All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gruelbox.transactionoutbox.Transaction Maven / Gradle / Ivy

There is a newer version: 6.0.553
Show newest version
package com.gruelbox.transactionoutbox;

import java.sql.Connection;
import java.sql.PreparedStatement;

/** Access and manipulation of a currently-active transaction. */
public interface Transaction {

  /**
   * @return The connection for the transaction.
   */
  Connection connection();

  /**
   * @param  The context type. Coerced on read.
   * @return A {@link TransactionManager}-specific object representing the context of this
   *     transaction. Intended for use with {@link TransactionManager} implementations that support
   *     explicitly-passed transaction context injection into method arguments.
   */
  default  T context() {
    return null;
  }

  /**
   * Creates a prepared statement which will be cached and re-used within a transaction. Any batch
   * on these statements is executed before the transaction is committed, and automatically closed.
   *
   * @param sql The SQL statement
   * @return The statement.
   */
  PreparedStatement prepareBatchStatement(String sql);

  /**
   * Will be called to perform work immediately after the current transaction is committed. This
   * should occur in the same thread and will generally not be long-lasting.
   *
   * @param runnable The code to run post-commit.
   */
  void addPostCommitHook(Runnable runnable);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy