Package com.isomorphic.sql

# Class SQLTransaction

java.lang.Object
com.isomorphic.base.Base
com.isomorphic.sql.SQLTransaction

All Implemented Interfaces:
  `com.isomorphic.base.IAutoConfigurable`

public class SQLTransaction extends com.isomorphic.base.Base
A class containing various static methods for managing transactional updates on SQL DataSources. This class is part of the Automatic Transactions feature, which is effective only in Power edition and above.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `commitTransaction(DSTransaction dsTransaction)`
  Commit the current transaction
  `static void`
  `commitTransaction(RPCManager rpcManager)`
  Commit the current transaction
  `static void`
  `endTransaction(DSTransaction dsTransaction)`
  End the current transaction.
  `static void`
  `endTransaction(RPCManager rpcManager)`
  End the current transaction.
  `static Connection`
  `getConnection(DSTransaction dsTransaction)`
  Returns the connection participating in the transaction.
  `static Connection`
  `getConnection(RPCManager rpcManager)`
  Returns the connection participating in the transaction.
  `static boolean`
  `isConnectionAvailable(DSTransaction dsTransaction, String dbName)`
  Checks if a SQL connection object is available for the specified `DSTransaction`.
  `static boolean`
  `isConnectionAvailable(RPCManager rpcManager, String dbName)`
  Checks if a SQL connection object is available for the specified `DSTransaction`.
  `static void`
  `rollbackTransaction(DSTransaction dsTransaction)`
  Rollback the current transaction
  `static void`
  `rollbackTransaction(RPCManager rpcManager)`
  Rollback the current transaction
  `static void`
  `setAutoEndTransactions(boolean autoEnd)`
  Sets automatic transaction end support.
  `static boolean`
  `startTransaction(DSTransaction dsTransaction)`
  Starts a new database transaction.
  `static boolean`
  `startTransaction(RPCManager rpcManager)`
  Starts a new database transaction.

- ## Method Details

  - ### setAutoEndTransactions

    public static void setAutoEndTransactions(boolean autoEnd)
    Sets automatic transaction end support. When this is on, transaction support is ended when you commit or rollback a transaction; any further database operations in this HTTP request will be auto-committed. When this is off, transaction support persists beyond a commit or rollback boundary, so further database operations in this HTTP request will be part of a new transaction and must be committed manually. By default, automatic transaction end support is off. This means that your code is responsible for calling endTransaction().
    Parameters:
      `autoEnd` - If true, switches on auto-end support

  - ### startTransaction

    public static boolean startTransaction(RPCManager rpcManager) throws Exception
    Starts a new database transaction. Note that when you use transactional support, your code is responsible for calling endTransaction() - if you neglect to do so, you will cause connection leaks. It is possible to have the transaction manager end transactions automatically for you after a commit or rollback - this facility is controlled by the static SQLTransaction.setAutoEndTransactions() method.

    Please note that if you are manually handling the transaction you should have set it on the `RPCManager` before calling this method or use `startTransaction(DSTransaction)` instead.

    Returns:
      true if we started transaction support, or false if transaction support was already active
    Throws:
      `Exception`

  - ### startTransaction

    public static boolean startTransaction(DSTransaction dsTransaction) throws Exception
    Starts a new database transaction. Note that when you use transactional support, your code is responsible for calling endTransaction() - if you neglect to do so, you will cause connection leaks. It is possible to have the transaction manager end transactions automatically for you after a commit or rollback - this facility is controlled by the static SQLTransaction.setAutoEndTransactions() method.
    Returns:
      true if we started transaction support, or false if transaction support was already active
    Throws:
      `Exception`

  - ### getConnection

    public static Connection getConnection(RPCManager rpcManager) throws Exception
    Returns the connection participating in the transaction. This will be null until startTransaction() is called.

    Please note that if you are manually handling the transaction you should have set it on the `RPCManager` before calling this method or use `getConnection(DSTransaction)` instead.

    Throws:
      `Exception` - if there is a configuration error with one of the underlying datasources

  - ### getConnection

    public static Connection getConnection(DSTransaction dsTransaction) throws Exception
    Returns the connection participating in the transaction. This will be null until startTransaction() is called.
    Throws:
      `Exception` - if there is a configuration error with one of the underlying datasources

  - ### rollbackTransaction

    public static void rollbackTransaction(RPCManager rpcManager) throws Exception
    Rollback the current transaction

    Please note that if you are manually handling the transaction you should have set it on the `RPCManager` before calling this method or use `rollbackTransaction(DSTransaction)` instead.

    Throws:
      `Exception` - if problems were found rolling back the transaction

  - ### rollbackTransaction

    public static void rollbackTransaction(DSTransaction dsTransaction) throws Exception
    Rollback the current transaction
    Throws:
      `Exception` - if problems were found rolling back the transaction

  - ### commitTransaction

    public static void commitTransaction(RPCManager rpcManager) throws Exception
    Commit the current transaction

    Please note that if you are manually handling the transaction you should have set it on the `RPCManager` before calling this method or use `commitTransaction(DSTransaction)` instead.

    Throws:
      `Exception` - if problems were found committing the transaction

  - ### commitTransaction

    public static void commitTransaction(DSTransaction dsTransaction) throws Exception
    Commit the current transaction
    Throws:
      `Exception` - if problems were found committing the transaction

  - ### isConnectionAvailable

    public static boolean isConnectionAvailable(RPCManager rpcManager, String dbName)
    Checks if a SQL connection object is available for the specified `DSTransaction`.

    Please note that if you are manually handling the transaction you should have set it on the `RPCManager` before calling this method or use `isConnectionAvailable(DSTransaction, String)` instead.

    Parameters:
      `rpcManager` - the RPCManager to check for a SQL connection on.
      `dbName` - the name of the database.
    Returns:
      true if a connections exists (not null) or false if there is no connection available.

  - ### isConnectionAvailable

    public static boolean isConnectionAvailable(DSTransaction dsTransaction, String dbName)
    Checks if a SQL connection object is available for the specified `DSTransaction`.
    Parameters:
      `dsTransaction` - the DSTransaction to check for a SQL connection on.
      `dbName` - the name of the database.
    Returns:
      true if a connections exists (not null) or false if there is no connection available.

  - ### endTransaction

    public static void endTransaction(RPCManager rpcManager) throws Exception
    End the current transaction. "Ending" a transaction simply means surrendering the database connection we are using to represent the transaction back to the pool. Any further database operations in this HTTP request will take place on an auto-commit basis, unless you issue another startTransaction call. Note that startTransaction() calls MUST be paired with endTransaction() calls, unless you have set the transaction manager into auto-end mode (see SQLTransaction.setAutoEndTransactions()).

    Please note that if you are manually handling the transaction you should have set it on the `RPCManager` before calling this method or use `endTransaction(DSTransaction, String)` instead.

    Throws:
      `Exception` - if problems were found ending the transaction

  - ### endTransaction

    public static void endTransaction(DSTransaction dsTransaction) throws Exception
    End the current transaction. "Ending" a transaction simply means surrendering the database connection we are using to represent the transaction back to the pool. Any further database operations in this HTTP request will take place on an auto-commit basis, unless you issue another startTransaction call. Note that startTransaction() calls MUST be paired with endTransaction() calls, unless you have set the transaction manager into auto-end mode (see SQLTransaction.setAutoEndTransactions()).
    Throws:
      `Exception` - if problems were found ending the transaction