org.lateralnz.simpletrans
Class TransConnection

java.lang.Object
  extended by org.lateralnz.simpletrans.TransConnection
All Implemented Interfaces:
java.io.Serializable, java.sql.Connection, javax.transaction.xa.XAResource

public class TransConnection
extends java.lang.Object
implements java.sql.Connection, javax.transaction.xa.XAResource, java.io.Serializable

a 'transaction-aware' wrapper for a JDBC connection. This is used to ensure that a connection is only commited, rolled back or closed until required by a transaction

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
TransConnection(java.lang.String name, java.sql.Connection conn, boolean inTrans)
          wrap a JDBC connection with the specified name
 
Method Summary
 void clearWarnings()
           
 void close()
          if not in a transaction, this closes the connection immediately, otherwise just flags that a close is required
 void commit()
          if not in a transaction, a commit is performed immediately, otherwise nothing happens
 void commit(javax.transaction.xa.Xid xid, boolean param)
          these methods need implementation
 java.sql.Statement createStatement()
           
 java.sql.Statement createStatement(int param, int param1)
           
 java.sql.Statement createStatement(int param, int param1, int param2)
           
protected  void doClose()
          performs the actual close on the underlying connection
 void doCommit()
          performs the actual commit on the underlying connection
 void doRollback(java.sql.Savepoint savepoint)
          performs the actual rollback on the underlying Connection
 void end(javax.transaction.xa.Xid xid, int param)
           
 void forget(javax.transaction.xa.Xid xid)
           
 boolean getAutoCommit()
           
 java.lang.String getCatalog()
           
 int getHoldability()
           
 java.sql.DatabaseMetaData getMetaData()
           
 java.lang.String getName()
          get the name of this connection
 int getTransactionIsolation()
           
 int getTransactionTimeout()
           
 java.util.Map getTypeMap()
           
 java.sql.SQLWarning getWarnings()
           
 boolean isClosed()
           
 boolean isCloseFlagged()
          check if close has been flagged on this connection
 boolean isReadOnly()
           
 boolean isSameRM(javax.transaction.xa.XAResource xAResource)
           
 java.lang.String nativeSQL(java.lang.String str)
           
 int prepare(javax.transaction.xa.Xid xid)
           
 java.sql.CallableStatement prepareCall(java.lang.String str)
           
 java.sql.CallableStatement prepareCall(java.lang.String str, int param, int param2)
           
 java.sql.CallableStatement prepareCall(java.lang.String str, int param, int param2, int param3)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String str)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String str, int param)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String str, int[] values)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String str, int param, int param2)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String str, int param, int param2, int param3)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String str, java.lang.String[] str1)
           
 javax.transaction.xa.Xid[] recover(int param)
           
 void releaseSavepoint(java.sql.Savepoint savepoint)
           
 void rollback()
          if not in a transaction, this rolls back the underlying connection immediately, otherwise nothing is done
 void rollback(java.sql.Savepoint savepoint)
          if not in a transaction, this rolls back the underlying connection immediately, otherwise nothing is done
 void rollback(javax.transaction.xa.Xid xid)
           
 void setAutoCommit(boolean param)
           
 void setCatalog(java.lang.String str)
           
 void setHoldability(int param)
           
 void setReadOnly(boolean param)
           
 java.sql.Savepoint setSavepoint()
           
 java.sql.Savepoint setSavepoint(java.lang.String str)
           
 void setTransactionIsolation(int param)
           
 boolean setTransactionTimeout(int param)
           
 void setTypeMap(java.util.Map map)
           
 void start(javax.transaction.xa.Xid xid, int param)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransConnection

public TransConnection(java.lang.String name,
                       java.sql.Connection conn,
                       boolean inTrans)
                throws java.sql.SQLException
wrap a JDBC connection with the specified name

Throws:
java.sql.SQLException
Method Detail

getName

public java.lang.String getName()
get the name of this connection


clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.clearWarnings()

close

public void close()
           throws java.sql.SQLException
if not in a transaction, this closes the connection immediately, otherwise just flags that a close is required

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.close()

isCloseFlagged

public boolean isCloseFlagged()
check if close has been flagged on this connection


doClose

protected void doClose()
                throws java.sql.SQLException
performs the actual close on the underlying connection

Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
if not in a transaction, a commit is performed immediately, otherwise nothing happens

Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.commit()

doCommit

public void doCommit()
              throws java.sql.SQLException
performs the actual commit on the underlying connection

Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.createStatement()

createStatement

public java.sql.Statement createStatement(int param,
                                          int param1)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.createStatement()

createStatement

public java.sql.Statement createStatement(int param,
                                          int param1,
                                          int param2)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.createStatement()

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Specified by:
getAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.getAutoCommit()

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Specified by:
getCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.getCatalog()

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
Specified by:
getHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.getHoldability()

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Specified by:
getMetaData in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.getMetaData()

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Specified by:
getTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.getTransactionIsolation()

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Specified by:
getTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.getTypeMap()

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Specified by:
getWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.getWarnings()

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Specified by:
isClosed in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.isClosed()

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Specified by:
isReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.isReadOnly()

nativeSQL

public java.lang.String nativeSQL(java.lang.String str)
                           throws java.sql.SQLException
Specified by:
nativeSQL in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.nativeSQL(java.lang.String)

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String str)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareCall(java.lang.String)

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String str,
                                              int param,
                                              int param2)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareCall(java.lang.String)

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String str,
                                              int param,
                                              int param2,
                                              int param3)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareCall(java.lang.String)

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String str)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareStatement(java.lang.String)

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String str,
                                                   int param)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareStatement(java.lang.String)

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String str,
                                                   int[] values)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareStatement(java.lang.String)

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String str,
                                                   java.lang.String[] str1)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareStatement(java.lang.String)

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String str,
                                                   int param,
                                                   int param2)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareStatement(java.lang.String)

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String str,
                                                   int param,
                                                   int param2,
                                                   int param3)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.prepareStatement(java.lang.String)

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
Specified by:
releaseSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.releaseSavepoint(java.sql.Savepoint)

rollback

public void rollback()
              throws java.sql.SQLException
if not in a transaction, this rolls back the underlying connection immediately, otherwise nothing is done

Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.rollback()

rollback

public void rollback(java.sql.Savepoint savepoint)
              throws java.sql.SQLException
if not in a transaction, this rolls back the underlying connection immediately, otherwise nothing is done

Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.rollback()

doRollback

public void doRollback(java.sql.Savepoint savepoint)
                throws java.sql.SQLException
performs the actual rollback on the underlying Connection

Throws:
java.sql.SQLException
See Also:
Connection.rollback()

setAutoCommit

public void setAutoCommit(boolean param)
                   throws java.sql.SQLException
Specified by:
setAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.setAutoCommit(boolean)

setCatalog

public void setCatalog(java.lang.String str)
                throws java.sql.SQLException
Specified by:
setCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.setCatalog(java.lang.String)

setHoldability

public void setHoldability(int param)
                    throws java.sql.SQLException
Specified by:
setHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.setHoldability(int)

setReadOnly

public void setReadOnly(boolean param)
                 throws java.sql.SQLException
Specified by:
setReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.setReadOnly(boolean)

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.setSavepoint()

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String str)
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.setSavepoint()

setTransactionIsolation

public void setTransactionIsolation(int param)
                             throws java.sql.SQLException
Specified by:
setTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.setTransactionIsolation(int)

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
Specified by:
setTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.setTypeMap(java.util.Map>)

commit

public void commit(javax.transaction.xa.Xid xid,
                   boolean param)
            throws javax.transaction.xa.XAException
these methods need implementation

Specified by:
commit in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

end

public void end(javax.transaction.xa.Xid xid,
                int param)
         throws javax.transaction.xa.XAException
Specified by:
end in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

forget

public void forget(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Specified by:
forget in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException
Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource xAResource)
                 throws javax.transaction.xa.XAException
Specified by:
isSameRM in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

prepare

public int prepare(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException
Specified by:
prepare in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

recover

public javax.transaction.xa.Xid[] recover(int param)
                                   throws javax.transaction.xa.XAException
Specified by:
recover in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

rollback

public void rollback(javax.transaction.xa.Xid xid)
              throws javax.transaction.xa.XAException
Specified by:
rollback in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

setTransactionTimeout

public boolean setTransactionTimeout(int param)
                              throws javax.transaction.xa.XAException
Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

start

public void start(javax.transaction.xa.Xid xid,
                  int param)
           throws javax.transaction.xa.XAException
Specified by:
start in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException