com.isomorphic.sql

## Class SQLTransaction

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

-     public class SQLTransaction
      extends 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

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and 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 java.sql.Connection` | `getConnection(DSTransaction dsTransaction)` Returns the connection participating in the transaction.
    `static java.sql.Connection` | `getConnection(RPCManager rpcManager)` Returns the connection participating in the transaction.
    `static boolean` | `isConnectionAvailable(DSTransaction dsTransaction, java.lang.String dbName)` Checks if a SQL connection object is available for the specified `DSTransaction`.
    `static boolean` | `isConnectionAvailable(RPCManager rpcManager, java.lang.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 Detail

    - #### 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 java.lang.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 `SQLTransaction.startTransaction(DSTransaction)` instead.

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

    - #### startTransaction

          public static boolean startTransaction(DSTransaction dsTransaction)
                                          throws java.lang.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:
        `java.lang.Exception`

    - #### getConnection

          public static java.sql.Connection getConnection(RPCManager rpcManager)
                                                   throws java.lang.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 `SQLTransaction.getConnection(DSTransaction)` instead.

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

    - #### getConnection

          public static java.sql.Connection getConnection(DSTransaction dsTransaction)
                                                   throws java.lang.Exception

      Returns the connection participating in the transaction. This will be null until startTransaction() is called.
      Throws:
        `java.lang.Exception` - if there is a configuration error with one of the underlying datasources

    - #### rollbackTransaction

          public static void rollbackTransaction(RPCManager rpcManager)
                                          throws java.lang.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 `SQLTransaction.rollbackTransaction(DSTransaction)` instead.

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

    - #### rollbackTransaction

          public static void rollbackTransaction(DSTransaction dsTransaction)
                                          throws java.lang.Exception

      Rollback the current transaction
      Throws:
        `java.lang.Exception` - if problems were found rolling back the transaction

    - #### commitTransaction

          public static void commitTransaction(RPCManager rpcManager)
                                        throws java.lang.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 `SQLTransaction.commitTransaction(DSTransaction)` instead.

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

    - #### commitTransaction

          public static void commitTransaction(DSTransaction dsTransaction)
                                        throws java.lang.Exception

      Commit the current transaction
      Throws:
        `java.lang.Exception` - if problems were found committing the transaction

    - #### isConnectionAvailable

          public static boolean isConnectionAvailable(RPCManager rpcManager,
                                                      java.lang.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 `SQLTransaction.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,
                                                      java.lang.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 java.lang.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 `SQLTransaction.endTransaction(DSTransaction, String)` instead.

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

    - #### endTransaction

          public static void endTransaction(DSTransaction dsTransaction)
                                     throws java.lang.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:
        `java.lang.Exception` - if problems were found ending the transaction