[jboss-svn-commits] JBL Code SVN: r16909 - labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Nov 29 03:09:02 EST 2007
Author: mark.little at jboss.com
Date: 2007-11-29 03:09:02 -0500 (Thu, 29 Nov 2007)
New Revision: 16909
Modified:
labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/ConnectionImple.java
Log:
Modified: labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/ConnectionImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/ConnectionImple.java 2007-11-29 06:20:08 UTC (rev 16908)
+++ labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/ConnectionImple.java 2007-11-29 08:09:02 UTC (rev 16909)
@@ -57,807 +57,910 @@
/**
* A transactional JDBC 2.0 connection. This wraps the real connection and
- * registers it with the transaction at appropriate times to ensure that
- * all worked performed by it may be committed or rolled back.
- *
+ * registers it with the transaction at appropriate times to ensure that all
+ * worked performed by it may be committed or rolled back.
+ *
* Once a connection is used within a transaction, that instance is bound to
* that transaction for the duration. It can be used by any number of threads,
* as long as they all have the same notion of the "current" transaction. When
* the transaction terminates, the connection is freed for use in another
* transaction.
- *
+ *
* Applications must not use this class directly.
- *
+ *
* @author Mark Little (mark at arjuna.com)
- * @version $Id: ConnectionImple.java 2342 2006-03-30 13:06:17Z $
+ * @version $Id: ConnectionImple.java 2342 2006-03-30 13:06:17Z $
* @since JTS 2.0.
*/
public class ConnectionImple implements java.sql.Connection
{
- public ConnectionImple (String dbName, Properties info) throws SQLException
- {
- if (jdbcLogger.logger.isDebugEnabled())
+ public ConnectionImple(String dbName, Properties info) throws SQLException
{
- jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC,
- com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC, "ConnectionImple.ConnectionImple ( "+dbName+" )");
- }
+ if (jdbcLogger.logger.isDebugEnabled())
+ {
+ jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS,
+ VisibilityLevel.VIS_PUBLIC,
+ com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC,
+ "ConnectionImple.ConnectionImple ( " + dbName + " )");
+ }
- String user = null;
- String passwd = null;
- String dynamic = null;
+ String user = null;
+ String passwd = null;
+ String dynamic = null;
- if (info != null)
- {
- user = info.getProperty(TransactionalDriver.userName);
- passwd = info.getProperty(TransactionalDriver.password);
- dynamic = info.getProperty(TransactionalDriver.dynamicClass);
- }
+ if (info != null)
+ {
+ user = info.getProperty(TransactionalDriver.userName);
+ passwd = info.getProperty(TransactionalDriver.password);
+ dynamic = info.getProperty(TransactionalDriver.dynamicClass);
+ }
- if ((dynamic == null) || (dynamic.equals("")))
- {
- _recoveryConnection = new IndirectRecoverableConnection(dbName, user, passwd, this);
- }
- else
- {
- _recoveryConnection = new DirectRecoverableConnection(dbName, user, passwd, dynamic, this);
- }
+ if ((dynamic == null) || (dynamic.equals("")))
+ {
+ _recoveryConnection = new IndirectRecoverableConnection(dbName,
+ user, passwd, this);
+ }
+ else
+ {
+ _recoveryConnection = new DirectRecoverableConnection(dbName, user,
+ passwd, dynamic, this);
+ }
- /*
- * Is there any "modifier" we are required to work with?
- */
+ /*
+ * Is there any "modifier" we are required to work with?
+ */
- _theModifier = null;
- _theConnection = null;
- }
+ _theModifier = null;
+ _theConnection = null;
+ }
- public ConnectionImple (String dbName, String user, String passwd) throws SQLException
- {
- this(dbName, user, passwd, null);
- }
-
- public ConnectionImple (String dbName, String user, String passwd, String dynamic) throws SQLException
- {
- if (jdbcLogger.logger.isDebugEnabled())
+ public ConnectionImple(String dbName, String user, String passwd)
+ throws SQLException
{
- jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC,
- com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC, "ConnectionImple.ConnectionImple ( "+dbName+", "+user+", "+passwd+", "+dynamic+" )");
+ this(dbName, user, passwd, null);
}
- if ((dynamic == null) || (dynamic.equals("")))
+ public ConnectionImple(String dbName, String user, String passwd,
+ String dynamic) throws SQLException
{
- _recoveryConnection = new IndirectRecoverableConnection(dbName, user, passwd, this);
- }
- else
- {
- _recoveryConnection = new DirectRecoverableConnection(dbName, user, passwd, dynamic, this);
- }
+ if (jdbcLogger.logger.isDebugEnabled())
+ {
+ jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS,
+ VisibilityLevel.VIS_PUBLIC,
+ com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC,
+ "ConnectionImple.ConnectionImple ( " + dbName + ", " + user
+ + ", " + passwd + ", " + dynamic + " )");
+ }
- /*
- * Any "modifier" required to work with?
- */
+ if ((dynamic == null) || (dynamic.equals("")))
+ {
+ _recoveryConnection = new IndirectRecoverableConnection(dbName,
+ user, passwd, this);
+ }
+ else
+ {
+ _recoveryConnection = new DirectRecoverableConnection(dbName, user,
+ passwd, dynamic, this);
+ }
- _theModifier = null;
- _theConnection = null;
- }
+ /*
+ * Any "modifier" required to work with?
+ */
- public void finalize ()
- {
- if (jdbcLogger.logger.isDebugEnabled())
- {
- jdbcLogger.logger.debug(DebugLevel.DESTRUCTORS, VisibilityLevel.VIS_PUBLIC,
- com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC, "ConnectionImple.finalize ()");
+ _theModifier = null;
+ _theConnection = null;
}
- _recoveryConnection = null;
- _theConnection = null;
- }
+ public void finalize()
+ {
+ if (jdbcLogger.logger.isDebugEnabled())
+ {
+ jdbcLogger.logger.debug(DebugLevel.DESTRUCTORS,
+ VisibilityLevel.VIS_PUBLIC,
+ com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC,
+ "ConnectionImple.finalize ()");
+ }
- public Statement createStatement () throws SQLException
- {
- checkTransaction();
+ _recoveryConnection = null;
+ _theConnection = null;
+ }
- registerDatabase();
+ public Statement createStatement() throws SQLException
+ {
+ checkTransaction();
- return getConnection().createStatement();
- }
+ registerDatabase();
- public Statement createStatement (int rs, int rc) throws SQLException
- {
- checkTransaction();
+ return getConnection().createStatement();
+ }
- registerDatabase();
+ public Statement createStatement(int rs, int rc) throws SQLException
+ {
+ checkTransaction();
- return getConnection().createStatement(rs, rc);
- }
+ registerDatabase();
- public PreparedStatement prepareStatement (String sql) throws SQLException
- {
- checkTransaction();
+ return getConnection().createStatement(rs, rc);
+ }
- registerDatabase();
+ public PreparedStatement prepareStatement(String sql) throws SQLException
+ {
+ checkTransaction();
- return getConnection().prepareStatement(sql);
- }
+ registerDatabase();
- public PreparedStatement prepareStatement (String sql, int rs, int rc) throws SQLException
- {
- checkTransaction();
+ return getConnection().prepareStatement(sql);
+ }
- registerDatabase();
+ public PreparedStatement prepareStatement(String sql, int rs, int rc)
+ throws SQLException
+ {
+ checkTransaction();
- return getConnection().prepareStatement(sql, rs, rc);
- }
+ registerDatabase();
- public CallableStatement prepareCall (String sql) throws SQLException
- {
- checkTransaction();
+ return getConnection().prepareStatement(sql, rs, rc);
+ }
- registerDatabase();
+ public CallableStatement prepareCall(String sql) throws SQLException
+ {
+ checkTransaction();
- return getConnection().prepareCall(sql);
- }
+ registerDatabase();
- public CallableStatement prepareCall (String sql, int rs, int rc) throws SQLException
- {
- checkTransaction();
+ return getConnection().prepareCall(sql);
+ }
- registerDatabase();
+ public CallableStatement prepareCall(String sql, int rs, int rc)
+ throws SQLException
+ {
+ checkTransaction();
- return getConnection().prepareCall(sql, rs, rc);
- }
+ registerDatabase();
- public String nativeSQL (String sql) throws SQLException
- {
- checkTransaction();
+ return getConnection().prepareCall(sql, rs, rc);
+ }
- registerDatabase();
+ public String nativeSQL(String sql) throws SQLException
+ {
+ checkTransaction();
- return getConnection().nativeSQL(sql);
- }
+ registerDatabase();
- public Map getTypeMap () throws SQLException
- {
- return getConnection().getTypeMap();
- }
+ return getConnection().nativeSQL(sql);
+ }
- public void setTypeMap (Map map) throws SQLException
- {
- getConnection().setTypeMap(map);
- }
-
- /**
- * Not allowed if within a transaction.
- *
- * @message com.arjuna.ats.internal.jdbc.autocommit AutoCommit is not allowed by the transaction service.
- */
-
- public void setAutoCommit (boolean autoCommit) throws SQLException
- {
- if (transactionRunning())
+ public Map getTypeMap() throws SQLException
{
- if (autoCommit)
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.autocommit"));
+ return getConnection().getTypeMap();
}
- else
+
+ public void setTypeMap(Map map) throws SQLException
{
- getConnection().setAutoCommit(autoCommit);
+ getConnection().setTypeMap(map);
}
- }
- public boolean getAutoCommit () throws SQLException
- {
- return getConnection().getAutoCommit();
- }
-
- /**
- * @message com.arjuna.ats.internal.jdbc.commiterror Commit not allowed by transaction service.
- */
-
- public void commit () throws SQLException
- {
- /*
- * If there is a transaction running, then it cannot be terminated
- * via the driver - the user must go through current.
+ /**
+ * Not allowed if within a transaction.
+ *
+ * @message com.arjuna.ats.internal.jdbc.autocommit AutoCommit is not
+ * allowed by the transaction service.
*/
- if (transactionRunning())
+ public void setAutoCommit(boolean autoCommit) throws SQLException
{
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.commiterror"));
+ if (transactionRunning())
+ {
+ if (autoCommit)
+ throw new SQLException(jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.autocommit"));
+ }
+ else
+ {
+ getConnection().setAutoCommit(autoCommit);
+ }
}
- else
- getConnection().commit();
- }
- /**
- * @message com.arjuna.ats.internal.jdbc.aborterror Rollback not allowed by transaction service.
- */
-
- public void rollback () throws SQLException
- {
- if (transactionRunning())
+ public boolean getAutoCommit() throws SQLException
{
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.aborterror"));
+ return getConnection().getAutoCommit();
}
- else
- getConnection().rollback();
- }
- /*
- * This needs to be reworked in light of experience and requirements.
- */
+ /**
+ * @message com.arjuna.ats.internal.jdbc.commiterror Commit not allowed by
+ * transaction service.
+ */
- /**
- * @message com.arjuna.ats.internal.jdbc.delisterror Delist of resource failed.
- * @message com.arjuna.ats.internal.jdbc.closeerror An error occurred during close:
- */
-
- public void close () throws SQLException
- {
- try
+ public void commit() throws SQLException
{
- /*
- * Need to know whether this particular connection has
- * outstanding resources waiting for it. If not then we
- * can close, otherwise we can't.
- */
+ /*
+ * If there is a transaction running, then it cannot be terminated via
+ * the driver - the user must go through current.
+ */
- if (!_recoveryConnection.inuse())
- {
- ConnectionManager.remove(this); // finalize?
- }
+ if (transactionRunning())
+ {
+ throw new SQLException(jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.commiterror"));
+ }
+ else
+ getConnection().commit();
+ }
- /*
- * Delist resource if within a transaction.
- */
+ /**
+ * @message com.arjuna.ats.internal.jdbc.aborterror Rollback not allowed by
+ * transaction service.
+ */
- javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
- javax.transaction.Transaction tx = tm.getTransaction();
-
- /*
- * Don't delist if transaction not running. Rely on exception
- * for this. Also only delist if the transaction is the one
- * the connection is enlisted with!
- */
-
- if (tx != null)
- {
- if (_recoveryConnection.validTransaction(tx))
+ public void rollback() throws SQLException
+ {
+ if (transactionRunning())
{
- XAResource xares = _recoveryConnection.getResource();
-
- if (!tx.delistResource(xares, XAResource.TMSUCCESS))
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.delisterror"));
-
- /*
- * We can't close the connection until the transaction
- * has terminated, so register a synchronisation here.
- */
- getModifier();
-
- if (_theModifier != null && ((ConnectionModifier) _theModifier).supportsMultipleConnections())
- {
- tx.registerSynchronization(new ConnectionSynchronization(_theConnection, _recoveryConnection));
- _theConnection = null;
- }
+ throw new SQLException(jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.aborterror"));
}
- }
- else
- {
- _recoveryConnection.close();
- _theConnection = null;
- }
-
- // what about connections without xaCon?
+ else
+ getConnection().rollback();
}
- catch (IllegalStateException ex)
- {
- // transaction not running, so ignore.
- }
- catch (SQLException sqle)
- {
- throw sqle;
- }
- catch (Exception e1)
- {
- e1.printStackTrace();
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.closeerror")+e1);
- }
- }
-
- public boolean isClosed () throws SQLException
- {
/*
- * A connection may appear closed to a thread if another thread
- * has bound it to a different transaction.
+ * This needs to be reworked in light of experience and requirements.
*/
- checkTransaction();
+ /**
+ * @message com.arjuna.ats.internal.jdbc.delisterror Delist of resource
+ * failed.
+ * @message com.arjuna.ats.internal.jdbc.closeerror An error occurred during
+ * close:
+ */
- if (_theConnection == null)
- return false; // not opened yet.
- else
- return _theConnection.isClosed();
- }
+ public void close() throws SQLException
+ {
+ try
+ {
+ /*
+ * Need to know whether this particular connection has outstanding
+ * resources waiting for it. If not then we can close, otherwise we
+ * can't.
+ */
- public DatabaseMetaData getMetaData () throws SQLException
- {
- return getConnection().getMetaData();
- }
+ if (!_recoveryConnection.inuse())
+ {
+ ConnectionManager.remove(this); // finalize?
+ }
- /**
- * Can only set readonly before we use the connection in a
- * given transaction!
- *
- * @message com.arjuna.ats.internal.jdbc.setreadonly Cannot set readonly when within a transaction!
- */
+ /*
+ * Delist resource if within a transaction.
+ */
- public void setReadOnly (boolean ro) throws SQLException
- {
- if (!_recoveryConnection.inuse())
- {
- getConnection().setReadOnly(ro);
- }
- else
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.setreadonly"));
- }
+ javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager
+ .transactionManager();
+ javax.transaction.Transaction tx = tm.getTransaction();
- public boolean isReadOnly () throws SQLException
- {
- return getConnection().isReadOnly();
- }
+ /*
+ * Don't delist if transaction not running. Rely on exception for
+ * this. Also only delist if the transaction is the one the
+ * connection is enlisted with!
+ */
- public void setCatalog (String cat) throws SQLException
- {
- checkTransaction();
+ if (tx != null)
+ {
+ if (_recoveryConnection.validTransaction(tx))
+ {
+ XAResource xares = _recoveryConnection.getResource();
- registerDatabase();
+ if (!tx.delistResource(xares, XAResource.TMSUCCESS))
+ throw new SQLException(
+ jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.delisterror"));
- getConnection().setCatalog(cat);
- }
+ /*
+ * We can't close the connection until the transaction has
+ * terminated, so register a synchronisation here.
+ */
+ getModifier();
- public String getCatalog () throws SQLException
- {
- checkTransaction();
+ if (_theModifier != null
+ && ((ConnectionModifier) _theModifier)
+ .supportsMultipleConnections())
+ {
+ tx
+ .registerSynchronization(new ConnectionSynchronization(
+ _theConnection, _recoveryConnection));
+ _theConnection = null;
+ }
+ }
+ }
+ else
+ {
+ _recoveryConnection.close();
+ _theConnection = null;
+ }
- registerDatabase();
+ // what about connections without xaCon?
+ }
+ catch (IllegalStateException ex)
+ {
+ // transaction not running, so ignore.
+ }
+ catch (SQLException sqle)
+ {
+ throw sqle;
+ }
+ catch (Exception e1)
+ {
+ e1.printStackTrace();
- return getConnection().getCatalog();
- }
+ throw new SQLException(jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.closeerror")
+ + e1);
+ }
+ }
- /**
- * @message com.arjuna.ats.internal.jdbc.stateerror State must be:
- */
+ public boolean isClosed() throws SQLException
+ {
+ /*
+ * A connection may appear closed to a thread if another thread has
+ * bound it to a different transaction.
+ */
- public void setTransactionIsolation (int iso) throws SQLException
- {
- checkTransaction();
+ checkTransaction();
- /*
- if (iso != Connection.TRANSACTION_SERIALIZABLE)
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.stateerror")+"Connection.TRANSACTION_SERIALIZABLE");
- */
+ if (_theConnection == null)
+ return false; // not opened yet.
+ else
+ return _theConnection.isClosed();
+ }
- getConnection().setTransactionIsolation(iso);
- }
+ public DatabaseMetaData getMetaData() throws SQLException
+ {
+ return getConnection().getMetaData();
+ }
- public int getTransactionIsolation () throws SQLException
- {
- return getConnection().getTransactionIsolation();
- }
+ /**
+ * Can only set readonly before we use the connection in a given
+ * transaction!
+ *
+ * @message com.arjuna.ats.internal.jdbc.setreadonly Cannot set readonly
+ * when within a transaction!
+ */
- public SQLWarning getWarnings () throws SQLException
- {
- return getConnection().getWarnings();
- }
+ public void setReadOnly(boolean ro) throws SQLException
+ {
+ if (!_recoveryConnection.inuse())
+ {
+ getConnection().setReadOnly(ro);
+ }
+ else
+ throw new SQLException(jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.setreadonly"));
+ }
- public void clearWarnings () throws SQLException
- {
- getConnection().clearWarnings();
- }
+ public boolean isReadOnly() throws SQLException
+ {
+ return getConnection().isReadOnly();
+ }
- /**
- * @return the Arjuna specific recovery connection information. This
- * should not be used by anything other than Arjuna.
- */
+ public void setCatalog(String cat) throws SQLException
+ {
+ checkTransaction();
- public final RecoverableXAConnection recoveryConnection ()
- {
- return _recoveryConnection;
- }
+ registerDatabase();
- /*
- ********************************************************************
- ** JDBC 3.0 section, needed to compile under jdk1.4
- ** We don't support this stuff yet, so we just throw exceptions.
- */
+ getConnection().setCatalog(cat);
+ }
- public void setHoldability(int holdability) throws SQLException {
- throw new SQLException("feature not supported");
- }
+ public String getCatalog() throws SQLException
+ {
+ checkTransaction();
- public int getHoldability() throws SQLException {
- throw new SQLException("feature not supported");
- }
+ registerDatabase();
- public Savepoint setSavepoint() throws SQLException {
- throw new SQLException("feature not supported");
- }
+ return getConnection().getCatalog();
+ }
- public Savepoint setSavepoint(String name) throws SQLException {
- throw new SQLException("feature not supported");
- }
+ /**
+ * @message com.arjuna.ats.internal.jdbc.stateerror State must be:
+ */
- public void rollback(Savepoint savepoint) throws SQLException {
- throw new SQLException("feature not supported");
- }
+ public void setTransactionIsolation(int iso) throws SQLException
+ {
+ checkTransaction();
- public void releaseSavepoint(Savepoint savepoint) throws SQLException {
- throw new SQLException("feature not supported");
- }
+ /*
+ * if (iso != Connection.TRANSACTION_SERIALIZABLE) throw new
+ * SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.stateerror")+"Connection.TRANSACTION_SERIALIZABLE");
+ */
- public Statement createStatement(int resultSetType, int resultSetConcurrency,
- int resultSetHoldability) throws SQLException {
- throw new SQLException("feature not supported");
- }
+ getConnection().setTransactionIsolation(iso);
+ }
- public PreparedStatement prepareStatement(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability) throws SQLException {
- throw new SQLException("feature not supported");
- }
+ public int getTransactionIsolation() throws SQLException
+ {
+ return getConnection().getTransactionIsolation();
+ }
- public CallableStatement prepareCall(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability) throws SQLException {
- throw new SQLException("feature not supported");
- }
+ public SQLWarning getWarnings() throws SQLException
+ {
+ return getConnection().getWarnings();
+ }
- public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
- throws SQLException {
- throw new SQLException("feature not supported");
- }
+ public void clearWarnings() throws SQLException
+ {
+ getConnection().clearWarnings();
+ }
- public PreparedStatement prepareStatement(String sql, int columnIndexes[])
- throws SQLException {
- throw new SQLException("feature not supported");
- }
+ /**
+ * @return the Arjuna specific recovery connection information. This should
+ * not be used by anything other than Arjuna.
+ */
- public PreparedStatement prepareStatement(String sql, String columnNames[])
- throws SQLException {
- throw new SQLException("feature not supported");
- }
+ public final RecoverableXAConnection recoveryConnection()
+ {
+ return _recoveryConnection;
+ }
- /* end of the JDBC 3.0 section
- ********************************************************************
- */
+ /*
+ * ******************************************************************* *
+ * JDBC 3.0 section, needed to compile under jdk1.4 * We don't support this
+ * stuff yet, so we just throw exceptions.
+ */
- /**
- * @return the XAResource associated with the current XAConnection.
- */
+ public void setHoldability(int holdability) throws SQLException
+ {
+ throw new SQLException("feature not supported");
+ }
- protected final XAResource getXAResource ()
- {
- try
+ public int getHoldability() throws SQLException
{
- return _recoveryConnection.getResource();
+ throw new SQLException("feature not supported");
}
- catch (Exception e)
+
+ public Savepoint setSavepoint() throws SQLException
{
- return null;
+ throw new SQLException("feature not supported");
}
- }
- /**
- * Remove this connection so that we have to get another one when
- * asked. Some drivers allow connections to be reused once any
- * transactions have finished with them.
- */
+ public Savepoint setSavepoint(String name) throws SQLException
+ {
+ throw new SQLException("feature not supported");
+ }
- final void reset ()
- {
- try
+ public void rollback(Savepoint savepoint) throws SQLException
{
- if (_theConnection != null)
- _theConnection.close();
+ throw new SQLException("feature not supported");
}
- catch (Exception ex)
+
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException
{
+ throw new SQLException("feature not supported");
}
- finally
+
+ public Statement createStatement(int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException
{
- _theConnection = null;
+ throw new SQLException("feature not supported");
}
- }
- /**
- * @message com.arjuna.ats.internal.jdbc.isolationlevelfailget {0} - failed to set isolation level: {1}
- * @message com.arjuna.ats.internal.jdbc.isolationlevelfailset {0} - failed to set isolation level: {1}
- * @message com.arjuna.ats.internal.jdbc.conniniterror JDBC2 connection initialisation problem
- */
+ public PreparedStatement prepareStatement(String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException
+ {
+ throw new SQLException("feature not supported");
+ }
- final java.sql.Connection getConnection () throws SQLException
- {
- if (_theConnection != null)
- return _theConnection;
+ public CallableStatement prepareCall(String sql, int resultSetType,
+ int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException
+ {
+ throw new SQLException("feature not supported");
+ }
- XAConnection xaConn = _recoveryConnection.getConnection();
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
+ throws SQLException
+ {
+ throw new SQLException("feature not supported");
+ }
- if (xaConn != null)
+ public PreparedStatement prepareStatement(String sql, int columnIndexes[])
+ throws SQLException
{
- _theConnection = xaConn.getConnection();
+ throw new SQLException("feature not supported");
+ }
- try
- {
- getModifier();
+ public PreparedStatement prepareStatement(String sql, String columnNames[])
+ throws SQLException
+ {
+ throw new SQLException("feature not supported");
+ }
- if (_theModifier != null)
+ /*
+ * end of the JDBC 3.0 section
+ * *******************************************************************
+ */
+
+ /**
+ * @return the XAResource associated with the current XAConnection.
+ */
+
+ protected final XAResource getXAResource()
+ {
+ try
{
- ((ConnectionModifier) _theModifier).setIsolationLevel(_theConnection, _currentIsolationLevel);
+ return _recoveryConnection.getResource();
}
- }
- catch (SQLException ex)
- {
- throw ex;
- }
- catch (Exception e)
- {
- if (jdbcLogger.loggerI18N.isWarnEnabled())
+ catch (Exception e)
{
- jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.isolationlevelfailset",
- new Object[] {"ConnectionImple.getConnection", e});
+ return null;
}
+ }
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.conniniterror")+":"+e);
- }
+ /**
+ * Remove this connection so that we have to get another one when asked.
+ * Some drivers allow connections to be reused once any transactions have
+ * finished with them.
+ */
- return _theConnection;
+ final void reset()
+ {
+ try
+ {
+ if (_theConnection != null)
+ _theConnection.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ finally
+ {
+ _theConnection = null;
+ }
}
- else
- return null;
- }
- final ConnectionControl connectionControl ()
- {
- return (ConnectionControl) _recoveryConnection;
- }
+ /**
+ * @message com.arjuna.ats.internal.jdbc.isolationlevelfailget {0} - failed
+ * to set isolation level: {1}
+ * @message com.arjuna.ats.internal.jdbc.isolationlevelfailset {0} - failed
+ * to set isolation level: {1}
+ * @message com.arjuna.ats.internal.jdbc.conniniterror JDBC2 connection
+ * initialisation problem
+ */
- protected final boolean transactionRunning () throws SQLException
- {
- try
+ final java.sql.Connection getConnection() throws SQLException
{
- if (com.arjuna.ats.jta.TransactionManager.transactionManager().getTransaction() != null)
- {
- return true;
- }
- else
- {
- return false;
- }
+ if (_theConnection != null)
+ return _theConnection;
+
+ XAConnection xaConn = _recoveryConnection.getConnection();
+
+ if (xaConn != null)
+ {
+ _theConnection = xaConn.getConnection();
+
+ try
+ {
+ getModifier();
+
+ if (_theModifier != null)
+ {
+ ((ConnectionModifier) _theModifier).setIsolationLevel(
+ _theConnection, _currentIsolationLevel);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw ex;
+ }
+ catch (Exception e)
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N
+ .warn(
+ "com.arjuna.ats.internal.jdbc.isolationlevelfailset",
+ new Object[]
+ { "ConnectionImple.getConnection", e });
+ }
+
+ throw new SQLException(
+ jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.conniniterror")
+ + ":" + e);
+ }
+
+ return _theConnection;
+ }
+ else
+ return null;
}
- catch (Exception e)
+
+ final ConnectionControl connectionControl()
{
- throw new SQLException(e.toString());
+ return (ConnectionControl) _recoveryConnection;
}
- }
- /**
- * Whenever a JDBC call is invoked on us we get an XAResource and
- * try to register it with the transaction. If the same thread
- * causes this to happen many times within the same transaction then
- * we will currently attempt to get and register many redundant XAResources
- * for it. The JTA implementation will detect this and ignore all but the
- * first for each thread. However, a further optimisation would be to trap
- * such calls here and not do a registration at all. This would require the
- * connection object to be informed whenever a transaction completes so
- * that it could flush its cache of XAResources though.
- *
- * @message com.arjuna.ats.internal.jdbc.rollbackerror {0} - could not mark transaction rollback
- * @message com.arjuna.ats.internal.jdbc.enlistfailed enlist of resource failed
- * @message com.arjuna.ats.internal.jdbc.alreadyassociated Connection is already associated with a different transaction! Obtain a new connection for this transaction.
- */
-
- protected final synchronized void registerDatabase () throws SQLException
- {
- if (jdbcLogger.logger.isDebugEnabled())
+ protected final boolean transactionRunning() throws SQLException
{
- jdbcLogger.logger.debug(DebugLevel.FUNCTIONS, VisibilityLevel.VIS_PRIVATE,
- com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC, "ConnectionImple.registerDatabase ()");
+ try
+ {
+ if (com.arjuna.ats.jta.TransactionManager.transactionManager()
+ .getTransaction() != null)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ catch (Exception e)
+ {
+ throw new SQLException(e.toString());
+ }
}
- Connection theConnection = getConnection();
+ /**
+ * Whenever a JDBC call is invoked on us we get an XAResource and try to
+ * register it with the transaction. If the same thread causes this to
+ * happen many times within the same transaction then we will currently
+ * attempt to get and register many redundant XAResources for it. The JTA
+ * implementation will detect this and ignore all but the first for each
+ * thread. However, a further optimisation would be to trap such calls here
+ * and not do a registration at all. This would require the connection
+ * object to be informed whenever a transaction completes so that it could
+ * flush its cache of XAResources though.
+ *
+ * @message com.arjuna.ats.internal.jdbc.rollbackerror {0} - could not mark
+ * transaction rollback
+ * @message com.arjuna.ats.internal.jdbc.enlistfailed enlist of resource
+ * failed
+ * @message com.arjuna.ats.internal.jdbc.alreadyassociated Connection is
+ * already associated with a different transaction! Obtain a new
+ * connection for this transaction.
+ */
- if (theConnection != null)
+ protected final synchronized void registerDatabase() throws SQLException
{
- XAResource xares = null;
+ if (jdbcLogger.logger.isDebugEnabled())
+ {
+ jdbcLogger.logger.debug(DebugLevel.FUNCTIONS,
+ VisibilityLevel.VIS_PRIVATE,
+ com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC,
+ "ConnectionImple.registerDatabase ()");
+ }
- try
- {
- javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
- javax.transaction.Transaction tx = tm.getTransaction();
+ Connection theConnection = getConnection();
- if (tx == null)
- return;
+ if (theConnection != null)
+ {
+ XAResource xares = null;
- /*
- * Already enlisted with this transaction?
- */
+ try
+ {
+ javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager
+ .transactionManager();
+ javax.transaction.Transaction tx = tm.getTransaction();
- if (!_recoveryConnection.setTransaction(tx))
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.alreadyassociated"));
+ if (tx == null)
+ return;
- Object[] params;
+ /*
+ * Already enlisted with this transaction?
+ */
- if (_theModifier != null)
- params = new Object[2];
- else
- params = new Object[1];
+ if (!_recoveryConnection.setTransaction(tx))
+ throw new SQLException(
+ jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.alreadyassociated"));
- params[com.arjuna.ats.jta.transaction.Transaction.XACONNECTION] = _recoveryConnection;
+ Object[] params;
- if (_theModifier != null)
- params[com.arjuna.ats.jta.transaction.Transaction.XAMODIFIER] = (XAModifier) _theModifier;
+ if (_theModifier != null)
+ params = new Object[2];
+ else
+ params = new Object[1];
- /*
- * Use our extended version of enlistResource.
- */
+ params[com.arjuna.ats.jta.transaction.Transaction.XACONNECTION] = _recoveryConnection;
- xares = _recoveryConnection.getResource();
+ if (_theModifier != null)
+ params[com.arjuna.ats.jta.transaction.Transaction.XAMODIFIER] = (XAModifier) _theModifier;
- if (!((com.arjuna.ats.jta.transaction.Transaction) tx).enlistResource(xares, params))
- {
- /*
- * Failed to enlist, so mark transaction as rollback only.
- */
+ /*
+ * Use our extended version of enlistResource.
+ */
- try
- {
- tx.setRollbackOnly();
- }
- catch (Exception e)
- {
- if (jdbcLogger.loggerI18N.isWarnEnabled())
- {
- jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.rollbackerror",
- new Object[] {"ConnectionImple.registerDatabase"});
- }
+ xares = _recoveryConnection.getResource();
- throw new SQLException(e.toString());
- }
+ if (!((com.arjuna.ats.jta.transaction.Transaction) tx)
+ .enlistResource(xares, params))
+ {
+ /*
+ * Failed to enlist, so mark transaction as rollback only.
+ */
- throw new SQLException("ConnectionImple.registerDatabase - " + jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.enlistfailed"));
- }
+ try
+ {
+ tx.setRollbackOnly();
+ }
+ catch (Exception e)
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N
+ .warn(
+ "com.arjuna.ats.internal.jdbc.rollbackerror",
+ new Object[]
+ { "ConnectionImple.registerDatabase" });
+ }
- params = null;
- xares = null;
- tx = null;
- tm = null;
- }
- catch (RollbackException e1)
- {
- throw new SQLException("ConnectionImple.registerDatabase - "+e1);
- }
- catch (SystemException e2)
- {
- throw new SQLException("ConnectionImple.registerDatabase - "+e2);
- }
- catch (SQLException e3)
- {
- throw e3;
- }
- catch (Exception e4)
- {
- throw new SQLException(e4.toString());
- }
- }
- }
+ throw new SQLException(e.toString());
+ }
- /**
- * @message com.arjuna.ats.internal.jdbc.alreadyassociatedcheck Checking transaction and found that this connection is already associated with a different transaction! Obtain a new connection for this transaction.
- * @message com.arjuna.ats.internal.jdbc.infoerror Could not get transaction information.
- */
+ throw new SQLException(
+ "ConnectionImple.registerDatabase - "
+ + jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.enlistfailed"));
+ }
- protected final void checkTransaction () throws SQLException
- {
- if (jdbcLogger.logger.isDebugEnabled())
- {
- jdbcLogger.logger.debug(DebugLevel.FUNCTIONS, VisibilityLevel.VIS_PRIVATE,
- com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC, "ConnectionImple.checkTransaction ()");
+ params = null;
+ xares = null;
+ tx = null;
+ tm = null;
+ }
+ catch (RollbackException e1)
+ {
+ throw new SQLException("ConnectionImple.registerDatabase - "
+ + e1);
+ }
+ catch (SystemException e2)
+ {
+ throw new SQLException("ConnectionImple.registerDatabase - "
+ + e2);
+ }
+ catch (SQLException e3)
+ {
+ throw e3;
+ }
+ catch (Exception e4)
+ {
+ throw new SQLException(e4.toString());
+ }
+ }
}
- try
+ /**
+ * @message com.arjuna.ats.internal.jdbc.alreadyassociatedcheck Checking
+ * transaction and found that this connection is already associated
+ * with a different transaction! Obtain a new connection for this
+ * transaction.
+ * @message com.arjuna.ats.internal.jdbc.infoerror Could not get transaction
+ * information.
+ * @message com.arjuna.ats.internal.jdbc.inactivetransaction Transaction is
+ * not active on the thread!
+ */
+
+ protected final void checkTransaction() throws SQLException
{
- javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
- javax.transaction.Transaction tx = tm.getTransaction();
+ if (jdbcLogger.logger.isDebugEnabled())
+ {
+ jdbcLogger.logger.debug(DebugLevel.FUNCTIONS,
+ VisibilityLevel.VIS_PRIVATE,
+ com.arjuna.ats.jdbc.logging.FacilityCode.FAC_JDBC,
+ "ConnectionImple.checkTransaction ()");
+ }
- if (tx == null)
- return;
+ try
+ {
+ javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager
+ .transactionManager();
+ javax.transaction.Transaction tx = tm.getTransaction();
- /*
- * Now check that we are not already associated with a transaction.
- */
+ if (tx == null)
+ return;
+
+ if (tx.getStatus() != Status.STATUS_ACTIVE)
+ throw new SQLException(jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.inactivetransaction"));
- if (!_recoveryConnection.validTransaction(tx))
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.alreadyassociatedcheck"));
+ /*
+ * Now check that we are not already associated with a transaction.
+ */
+
+ if (!_recoveryConnection.validTransaction(tx))
+ throw new SQLException(
+ jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.alreadyassociatedcheck"));
+ }
+ catch (SQLException ex)
+ {
+ throw ex;
+ }
+ catch (Exception e3)
+ {
+ throw new SQLException(jdbcLogger.logMesg
+ .getString("com.arjuna.ats.internal.jdbc.infoerror"));
+ }
}
- catch (SQLException ex)
- {
- throw ex;
- }
- catch (Exception e3)
- {
- throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.infoerror"));
- }
- }
- /**
- * @message com.arjuna.ats.internal.jdbc.getmoderror Failed to get modifier for driver:
- */
+ /**
+ * @message com.arjuna.ats.internal.jdbc.getmoderror Failed to get modifier
+ * for driver:
+ */
- private final void getModifier ()
- {
- if (_theModifier == null)
+ private final void getModifier()
{
- try
- {
- DatabaseMetaData md = _theConnection.getMetaData();
+ if (_theModifier == null)
+ {
+ try
+ {
+ DatabaseMetaData md = _theConnection.getMetaData();
- String name = md.getDriverName();
- int major = md.getDriverMajorVersion();
- int minor = md.getDriverMinorVersion();
+ String name = md.getDriverName();
+ int major = md.getDriverMajorVersion();
+ int minor = md.getDriverMinorVersion();
- _theModifier = ModifierFactory.getModifier(name, major, minor);
+ _theModifier = ModifierFactory.getModifier(name, major, minor);
- ((ConnectionControl) _recoveryConnection).setModifier((ConnectionModifier) _theModifier);
- }
- catch (Exception ex)
- {
- if (jdbcLogger.loggerI18N.isWarnEnabled())
- {
- jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.getmoderror", ex);
+ ((ConnectionControl) _recoveryConnection)
+ .setModifier((ConnectionModifier) _theModifier);
+ }
+ catch (Exception ex)
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N.warn(
+ "com.arjuna.ats.internal.jdbc.getmoderror", ex);
+ }
+ }
}
- }
}
- }
- private RecoverableXAConnection _recoveryConnection;
- private java.lang.Object _theModifier;
- private Connection _theConnection;
+ private RecoverableXAConnection _recoveryConnection;
- private static final int defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
+ private java.lang.Object _theModifier;
- private static int _currentIsolationLevel = defaultIsolationLevel;
+ private Connection _theConnection;
- /**
- * @message com.arjuna.ats.internal.jdbc.isolationerror Unknown isolation level {0}. Will use default of TRANSACTION_SERIALIZABLE.
- */
+ private static final int defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
- static
- {
- String isolationLevel = jdbcPropertyManager.propertyManager.getProperty(com.arjuna.ats.jdbc.common.Environment.ISOLATION_LEVEL);
+ private static int _currentIsolationLevel = defaultIsolationLevel;
- if (isolationLevel != null)
+ /**
+ * @message com.arjuna.ats.internal.jdbc.isolationerror Unknown isolation
+ * level {0}. Will use default of TRANSACTION_SERIALIZABLE.
+ */
+
+ static
{
- if (isolationLevel.equals("TRANSACTION_READ_COMMITTED"))
- _currentIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
- else if (isolationLevel.equals("TRANSACTION_READ_UNCOMMITTED"))
- _currentIsolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
- else if (isolationLevel.equals("TRANSACTION_REPEATABLE_READ"))
- _currentIsolationLevel = Connection.TRANSACTION_REPEATABLE_READ;
- else if (isolationLevel.equals("TRANSACTION_SERIALIZABLE"))
- _currentIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
- else
- {
- if (jdbcLogger.loggerI18N.isWarnEnabled())
+ String isolationLevel = jdbcPropertyManager.propertyManager
+ .getProperty(com.arjuna.ats.jdbc.common.Environment.ISOLATION_LEVEL);
+
+ if (isolationLevel != null)
{
- jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.isolationerror",
- new Object[] {isolationLevel});
+ if (isolationLevel.equals("TRANSACTION_READ_COMMITTED"))
+ _currentIsolationLevel = Connection.TRANSACTION_READ_COMMITTED;
+ else if (isolationLevel.equals("TRANSACTION_READ_UNCOMMITTED"))
+ _currentIsolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
+ else if (isolationLevel.equals("TRANSACTION_REPEATABLE_READ"))
+ _currentIsolationLevel = Connection.TRANSACTION_REPEATABLE_READ;
+ else if (isolationLevel.equals("TRANSACTION_SERIALIZABLE"))
+ _currentIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
+ else
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N.warn(
+ "com.arjuna.ats.internal.jdbc.isolationerror",
+ new Object[]
+ { isolationLevel });
+ }
+
+ _currentIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
+ }
}
-
- _currentIsolationLevel = Connection.TRANSACTION_SERIALIZABLE;
- }
}
- }
}
-
More information about the jboss-svn-commits
mailing list