Package db

# Class Transaction

java.lang.Object
db.Transaction

All Implemented Interfaces:
  `AutoCloseable`

public abstract class Transaction extends Object implements AutoCloseable
Provides syntax for opening a database transaction using a try-with-resources block

For example, using `DBHandle.startTransaction()` directly:

     int txid = dbHandle.startTransaction();
     try {
            // ... Do something
     }
     finally {
            program.endTransaction(txid, true);
     }

Can be expressed using a `Transaction` instead:

     try (Transaction tx = dbHandle.openTransaction(dbErrorHandler)) {
            // ... Do something
     }

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Transaction()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `abort()`
  Mark transaction for rollback/non-commit and end transaction if active.
  `void`
  `abortOnClose()`
  Mark transaction for rollback/non-commit upon closing.
  `void`
  `close()`
  End this transaction if active using the current commit state.
  `void`
  `commit()`
  Mark transaction for commit and end transaction if active.
  `void`
  `commitOnClose()`
  Mark transaction for commit upon closing.
  `protected abstract boolean`
  `endTransaction(boolean commit)`
  End this transaction if currently active.
  `boolean`
  `isSubTransaction()`
  Determine if this is a sub-transaction to a larger transaction.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Transaction

    protected Transaction()

- ## Method Details

  - ### endTransaction

    protected abstract boolean endTransaction(boolean commit)
    End this transaction if currently active.
    Parameters:
      `commit` - true if changes should be committed, false if all changes in this transaction should be discarded (i.e., rollback). If this is a "sub-transaction" and commit is false, the larger transaction will rollback upon completion.
    Returns:
      true if changes have been committed or false if nothing to commit or commit parameter was specified as false.

  - ### isSubTransaction

    public boolean isSubTransaction()
    Determine if this is a sub-transaction to a larger transaction.

    If true is returned the larger transaction will not complete until all sub-transactions have ended. The larger transaction will rollback upon completion if any of the sub-transactions do not commit.

    Returns:
      true if this is a sub-transaction, else false.

  - ### abortOnClose

    public void abortOnClose()
    Mark transaction for rollback/non-commit upon closing.

    A subsequent invocation of `commitOnClose()` will alter this state prior to closing.

  - ### commitOnClose

    public void commitOnClose()
    Mark transaction for commit upon closing.

    This state is assumed by default. A subsequent invocation of `abortOnClose()` will alter this state prior to closing.

  - ### abort

    public void abort()
    Mark transaction for rollback/non-commit and end transaction if active.

  - ### commit

    public void commit()
    Mark transaction for commit and end transaction if active.

  - ### close

    public void close()
    End this transaction if active using the current commit state.
    Specified by:
      `close` in interface `AutoCloseable`
    See Also:
      - `commitOnClose()`
      - `abortOnClose()`