org.midao.jdbc.core.transaction
Class BaseTransactionHandler

java.lang.Object
  extended by org.midao.jdbc.core.transaction.BaseTransactionHandler
All Implemented Interfaces:
TransactionHandler

public class BaseTransactionHandler
extends java.lang.Object
implements TransactionHandler

Base TransactionHandler implementation. Is responsible for keeping session configuration and managing connection. Is initialized with DataSource/Connection. Allows retrieval of Connection, but this connection is wrapped in Proxy and Connection.close() won't be invoked on it (unless it would be explicitly cast to Implementation class)


Constructor Summary
BaseTransactionHandler(java.sql.Connection conn)
          Creates new BaseTransactionHandler instance
BaseTransactionHandler(javax.sql.DataSource ds)
          Creates new BaseTransactionHandler instance
 
Method Summary
 void closeConnection()
          Informs Transaction Handler that connection is no longer used.
 void commit()
          Commits current Transaction Usable only when TransactionHandler.setManualMode(boolean) set as true
 java.sql.Connection getConnection()
          Returns wrapped(proxy) connection.
 java.lang.Integer getIsolationLevel()
          Returns current Transaction Isolation level
 boolean getManualMode()
          Returns current Transaction mode
 TransactionHandler newInstance(java.sql.Connection conn)
          Creates new TransactionHandler instance.
 TransactionHandler newInstance(javax.sql.DataSource ds)
          Creates new TransactionHandler instance.
 void releaseSavepoint(java.sql.Savepoint savepoint)
          Removes the specified Savepoint and subsequent Savepoint objects from the current transaction.
 void rollback()
          Rollbacks current Transaction Usable only when TransactionHandler.setManualMode(boolean) set as true
 void rollback(java.sql.Savepoint savepoint)
          Undoes all changes made after the given Savepoint object was set.
 void setIsolationLevel(java.lang.Integer level)
          Transaction Isolation level.
 void setManualMode(boolean manualMode)
          Allows switching on/off Manual Transaction mode.
 java.sql.Savepoint setSavepoint()
          Creates an unnamed savepoint in the current transaction and returns the new Savepoint object that represents it.
 java.sql.Savepoint setSavepoint(java.lang.String name)
          Creates a savepoint with the given name in the current transaction and returns the new Savepoint object that represents it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseTransactionHandler

public BaseTransactionHandler(java.sql.Connection conn)
Creates new BaseTransactionHandler instance

Parameters:
conn - SQL Connection

BaseTransactionHandler

public BaseTransactionHandler(javax.sql.DataSource ds)
Creates new BaseTransactionHandler instance

Parameters:
ds - SQL DataSource
Method Detail

newInstance

public TransactionHandler newInstance(java.sql.Connection conn)
Creates new TransactionHandler instance. Might be removed in future

Specified by:
newInstance in interface TransactionHandler
Parameters:
conn - SQL Connection
Returns:

newInstance

public TransactionHandler newInstance(javax.sql.DataSource ds)
Creates new TransactionHandler instance. Might be removed in future

Specified by:
newInstance in interface TransactionHandler
Parameters:
ds - SQL DataSource
Returns:

setManualMode

public void setManualMode(boolean manualMode)
Allows switching on/off Manual Transaction mode. This allows to group more that one operation into one Transaction and allows commit/rollback transaction manually

Specified by:
setManualMode in interface TransactionHandler
Parameters:
manualMode - new Transaction Mode

getManualMode

public boolean getManualMode()
Returns current Transaction mode

Specified by:
getManualMode in interface TransactionHandler
Returns:
current Transaction mode

setIsolationLevel

public void setIsolationLevel(java.lang.Integer level)
Transaction Isolation level. For general information please look at Java Tutorials (docs.oracle.com/javase/tutorial/index.html) JDBC basics / Using Transactions For detailed information please look at vendor JDBC driver description

Specified by:
setIsolationLevel in interface TransactionHandler
Parameters:
level - Transaction Isolation level

getIsolationLevel

public java.lang.Integer getIsolationLevel()
Returns current Transaction Isolation level

Specified by:
getIsolationLevel in interface TransactionHandler
Returns:
current Transaction Isolation level

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Returns wrapped(proxy) connection. Proxy protects Connection from being closed as this is managed by Transaction Handler already and might create exception if Connection would be closed outside it. In case you need to perform some unorthodox manipulation with it - it is allowed simply to be casted to Implementation class.

Specified by:
getConnection in interface TransactionHandler
Returns:
Proxy of SQL Connection
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

closeConnection

public void closeConnection()
Informs Transaction Handler that connection is no longer used. Actual close might not be performed as it depends on TransactionHandler mode.

Specified by:
closeConnection in interface TransactionHandler

commit

public void commit()
            throws java.sql.SQLException
Commits current Transaction Usable only when TransactionHandler.setManualMode(boolean) set as true

Specified by:
commit in interface TransactionHandler
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

rollback

public void rollback()
              throws java.sql.SQLException
Rollbacks current Transaction Usable only when TransactionHandler.setManualMode(boolean) set as true

Specified by:
rollback in interface TransactionHandler
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
Creates an unnamed savepoint in the current transaction and returns the new Savepoint object that represents it. Connection.setSavepoint() Usable only when TransactionHandler.setManualMode(boolean) set as true

Specified by:
setSavepoint in interface TransactionHandler
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String name)
                                throws java.sql.SQLException
Creates a savepoint with the given name in the current transaction and returns the new Savepoint object that represents it. Connection.setSavepoint(String) Usable only when TransactionHandler.setManualMode(boolean) set as true

Specified by:
setSavepoint in interface TransactionHandler
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
Removes the specified Savepoint and subsequent Savepoint objects from the current transaction. Connection.releaseSavepoint(java.sql.Savepoint) Usable only when TransactionHandler.setManualMode(boolean) set as true

Specified by:
releaseSavepoint in interface TransactionHandler
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

rollback

public void rollback(java.sql.Savepoint savepoint)
              throws java.sql.SQLException
Undoes all changes made after the given Savepoint object was set. Connection.rollback(java.sql.Savepoint) Usable only when TransactionHandler.setManualMode(boolean) set as true

Specified by:
rollback in interface TransactionHandler
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database


Copyright © 2013. All Rights Reserved.