Class SQLTransaction
- All Implemented Interfaces:
com.isomorphic.base.IAutoConfigurable
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
commitTransaction
(DSTransaction dsTransaction) Commit the current transactionstatic void
commitTransaction
(RPCManager rpcManager) Commit the current transactionstatic 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 specifiedDSTransaction
.static boolean
isConnectionAvailable
(RPCManager rpcManager, String dbName) Checks if a SQL connection object is available for the specifiedDSTransaction
.static void
rollbackTransaction
(DSTransaction dsTransaction) Rollback the current transactionstatic void
rollbackTransaction
(RPCManager rpcManager) Rollback the current transactionstatic 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
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 usestartTransaction(DSTransaction)
instead.- Returns:
- true if we started transaction support, or false if transaction support was already active
- Throws:
Exception
-
startTransaction
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
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 usegetConnection(DSTransaction)
instead.- Throws:
Exception
- if there is a configuration error with one of the underlying datasources
-
getConnection
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
Rollback the current transactionPlease note that if you are manually handling the transaction you should have set it on the
RPCManager
before calling this method or userollbackTransaction(DSTransaction)
instead.- Throws:
Exception
- if problems were found rolling back the transaction
-
rollbackTransaction
Rollback the current transaction- Throws:
Exception
- if problems were found rolling back the transaction
-
commitTransaction
Commit the current transactionPlease note that if you are manually handling the transaction you should have set it on the
RPCManager
before calling this method or usecommitTransaction(DSTransaction)
instead.- Throws:
Exception
- if problems were found committing the transaction
-
commitTransaction
Commit the current transaction- Throws:
Exception
- if problems were found committing the transaction
-
isConnectionAvailable
Checks if a SQL connection object is available for the specifiedDSTransaction
.Please note that if you are manually handling the transaction you should have set it on the
RPCManager
before calling this method or useisConnectionAvailable(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
Checks if a SQL connection object is available for the specifiedDSTransaction
.- 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
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 useendTransaction(DSTransaction, String)
instead.- Throws:
Exception
- if problems were found ending the transaction
-
endTransaction
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
-