|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.framework.jdto.transaction.TransactionContextManager
TransactionContextManager class is mainly responsible for managing the transactions. it is responsible for begining the transaction and ending the transaction based on the current transaction status.
User needs to call the beginTransaction() method to begin the transaction and should end the transaction by calling the endTransaction() method. All the DAO's which are executed after the beginTransaction() method and before the endTransaction() method by default runs in a transaction, Provided the DAO's use the PreparedStatementWrapper or StatementWrapper classes to interact with the database (i.e., Insert, Update, Delete and Select Queries) instead of the actual PreparedStatement and Statement class of java.sql package.
Field Summary | |
static int |
CONTEXT_MANAGER
|
Method Summary | |
static Transaction |
beginTransaction()
The beginTransaction() method begins the transaction. |
static void |
clear()
Clear the current transactionContext. |
static void |
commitTransaction()
This method commits the Transaction provided the current Transaction Status is STATUS_MARKED_COMMIT. |
static void |
endTransaction()
The endTransaction() method ends the transaction. |
static Transaction |
getCurrentTransaction()
This method gets the currently running Transaction |
static TransactionContextManager |
getInstance()
This method ensures there is one and only one TransactionContextManager available to handle all the transactions. |
static void |
rollbackTransaction()
This method rollback's the Transaction provided the current Transaction Status is STATUS_MARKED_ROLLBACK. |
static void |
setCurrentTransactionStatus(int status)
Sets the status of the current transaction. |
static void |
setRollbackOnly()
This method sets the current Transaction Status as STATUS_MARKED_ROLLBACK, so that the framework rollback's the transaction. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int CONTEXT_MANAGER
Method Detail |
public static TransactionContextManager getInstance()
public static Transaction beginTransaction() throws NotSupportedException
NotSupportedException
- when a transaction is already running and user requests for a nested transaction.public static void endTransaction()
This method rollback's the transaction if any SQLException or DAOException occurs in the DAO Classes, otherwise commits the transaction. The developer doesnt need to worry about setting the current Transaction Status, as this framework takes care of setting the Transaction Status by itself, based on the success or failure of each query exection in the DAO's.
It is always recommended to use this endTransaction() method in the finally block, so as to avoid the ambiguity.
SQLException
- if database error occurspublic static void setCurrentTransactionStatus(int status)
This method is called by the framework on success or failure of each SQL Query. On successful execution of each SQL Query, the framework sets the current Transaction Status as STATUS_MARKED_COMMIT. if atleast one failure occurs the current Transaction Status is set as STATUS_MARKED_ROLLBACK and the transaction will be rolledback by the framework.
public static Transaction getCurrentTransaction()
public static void setRollbackOnly()
public static void commitTransaction() throws SQLException
SQLException
public static void rollbackTransaction() throws SQLException
SQLException
public static void clear()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |