[jboss-cvs] JBossAS SVN: r71462 - branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 31 05:16:28 EDT 2008
Author: vicky.kak at jboss.com
Date: 2008-03-31 05:16:28 -0400 (Mon, 31 Mar 2008)
New Revision: 71462
Modified:
branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedResultSet.java
branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java
Log:
[JBPAPP-662]Add transaction active tests to the jdbc resource adapter
Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java 2008-03-31 09:15:38 UTC (rev 71461)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java 2008-03-31 09:16:28 UTC (rev 71462)
@@ -34,6 +34,8 @@
import java.util.Iterator;
import java.util.Map;
+import javax.resource.spi.ManagedConnection;
+
import org.jboss.logging.Logger;
import org.jboss.util.NestedSQLException;
@@ -71,7 +73,25 @@
if (mc != null)
trackStatements = mc.getTrackStatements();
}
+
+ protected void lock() throws SQLException
+ {
+ BaseWrapperManagedConnection mc = this.mc;
+ if (mc != null)
+ mc.tryLock();
+ else
+ throw new SQLException("Connection is not associated with a managed connection." + this);
+ }
+ protected void unlock()
+ {
+ BaseWrapperManagedConnection mc = this.mc;
+ if (mc != null)
+ mc.unlock();
+ // We recreate the lock when returned to the pool
+ // so missing the unlock after disassociation is not important
+ }
+
public WrapperDataSource getDataSource()
{
return dataSource;
@@ -84,8 +104,16 @@
public void setReadOnly(boolean readOnly) throws SQLException
{
- checkStatus();
- mc.setJdbcReadOnly(readOnly);
+ lock();
+ try
+ {
+ checkStatus();
+ mc.setJdbcReadOnly(readOnly);
+ }
+ finally
+ {
+ unlock();
+ }
}
public boolean isReadOnly() throws SQLException
@@ -139,384 +167,645 @@
public Statement createStatement() throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedStatement(this, mc.getConnection().createStatement());
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedStatement(this, mc.getConnection().createStatement());
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedStatement(this, mc.getConnection().createStatement(resultSetType, resultSetConcurrency));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedStatement(this, mc.getConnection().createStatement(resultSetType, resultSetConcurrency));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException
{
-
- checkTransaction();
- try
- {
- return new WrappedStatement(this, mc.getConnection()
- .createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedStatement(this, mc.getConnection()
+ .createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public PreparedStatement prepareStatement(String sql) throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedPreparedStatement(this, mc.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedPreparedStatement(this, mc.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedPreparedStatement(this, mc.prepareStatement(sql, resultSetType, resultSetConcurrency));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedPreparedStatement(this, mc.prepareStatement(sql, resultSetType, resultSetConcurrency));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedPreparedStatement(this, mc.getConnection()
- .prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedPreparedStatement(this, mc.getConnection()
+ .prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, autoGeneratedKeys));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, autoGeneratedKeys));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, columnIndexes));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, columnIndexes));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
{
-
- checkTransaction();
- try
- {
- return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, columnNames));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, columnNames));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public CallableStatement prepareCall(String sql) throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedCallableStatement(this, mc.prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedCallableStatement(this, mc.prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
{
- checkTransaction();
- try
- {
- return new WrappedCallableStatement(this, mc.prepareCall(sql, resultSetType, resultSetConcurrency));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedCallableStatement(this, mc.prepareCall(sql, resultSetType, resultSetConcurrency));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException
{
-
- checkTransaction();
- try
- {
- return new WrappedCallableStatement(this, mc.getConnection()
- .prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return new WrappedCallableStatement(this, mc.getConnection()
+ .prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public String nativeSQL(String sql) throws SQLException
{
- checkTransaction();
- try
- {
- return mc.getConnection().nativeSQL(sql);
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return mc.getConnection().nativeSQL(sql);
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public void setAutoCommit(boolean autocommit) throws SQLException
{
- checkStatus();
- mc.setJdbcAutoCommit(autocommit);
+ lock();
+ try
+ {
+ checkStatus();
+ mc.setJdbcAutoCommit(autocommit);
+ }
+ finally
+ {
+ unlock();
+ }
}
public boolean getAutoCommit() throws SQLException
{
- checkStatus();
- return mc.isJdbcAutoCommit();
+ lock();
+ try
+ {
+ checkStatus();
+ return mc.isJdbcAutoCommit();
+ }
+ finally
+ {
+ unlock();
+ }
}
public void commit() throws SQLException
{
- checkTransaction();
- mc.jdbcCommit();
+ lock();
+ try
+ {
+ checkTransaction();
+ mc.jdbcCommit();
+ }
+ finally
+ {
+ unlock();
+ }
}
public void rollback() throws SQLException
{
- checkTransaction();
- mc.jdbcRollback();
+ lock();
+ try
+ {
+ checkTransaction();
+ mc.jdbcRollback();
+ }
+ finally
+ {
+ unlock();
+ }
}
public void rollback(Savepoint savepoint) throws SQLException
{
- checkTransaction();
- mc.jdbcRollback(savepoint);
+ lock();
+ try
+ {
+ checkTransaction();
+ mc.jdbcRollback(savepoint);
+ }
+ finally
+ {
+ unlock();
+ }
}
public DatabaseMetaData getMetaData() throws SQLException
{
- checkTransaction();
- try
- {
- return mc.getConnection().getMetaData();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return mc.getConnection().getMetaData();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public void setCatalog(String catalog) throws SQLException
{
- checkTransaction();
- try
- {
- mc.getConnection().setCatalog(catalog);
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ mc.getConnection().setCatalog(catalog);
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public String getCatalog() throws SQLException
{
- checkTransaction();
- try
- {
- return mc.getConnection().getCatalog();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return mc.getConnection().getCatalog();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public void setTransactionIsolation(int isolationLevel) throws SQLException
{
- checkStatus();
- mc.setJdbcTransactionIsolation(isolationLevel);
+ lock();
+ try
+ {
+ checkStatus();
+ mc.setJdbcTransactionIsolation(isolationLevel);
+ }
+ finally
+ {
+ unlock();
+ }
}
public int getTransactionIsolation() throws SQLException
{
- checkStatus();
- return mc.getJdbcTransactionIsolation();
+ lock();
+ try
+ {
+ checkStatus();
+ return mc.getJdbcTransactionIsolation();
+ }
+ finally
+ {
+ unlock();
+ }
}
public SQLWarning getWarnings() throws SQLException
{
- checkTransaction();
- try
- {
- return mc.getConnection().getWarnings();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return mc.getConnection().getWarnings();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public void clearWarnings() throws SQLException
{
- checkTransaction();
- try
- {
- mc.getConnection().clearWarnings();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ mc.getConnection().clearWarnings();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public Map getTypeMap() throws SQLException
{
- checkTransaction();
- try
- {
- return mc.getConnection().getTypeMap();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return mc.getConnection().getTypeMap();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public void setTypeMap(Map typeMap) throws SQLException
{
- checkTransaction();
- try
- {
- mc.getConnection().setTypeMap(typeMap);
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ mc.getConnection().setTypeMap(typeMap);
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public void setHoldability(int holdability) throws SQLException
{
- checkTransaction();
- try
- {
- mc.getConnection().setHoldability(holdability);
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ mc.getConnection().setHoldability(holdability);
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public int getHoldability() throws SQLException
{
- checkTransaction();
- try
- {
- return mc.getConnection().getHoldability();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return mc.getConnection().getHoldability();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public Savepoint setSavepoint() throws SQLException
{
- checkTransaction();
- try
- {
- return mc.getConnection().setSavepoint();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return mc.getConnection().setSavepoint();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public Savepoint setSavepoint(String name) throws SQLException
{
- checkTransaction();
- try
- {
- return mc.getConnection().setSavepoint(name);
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ return mc.getConnection().setSavepoint(name);
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public void releaseSavepoint(Savepoint savepoint) throws SQLException
{
- checkTransaction();
- try
- {
- mc.getConnection().releaseSavepoint(savepoint);
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ mc.getConnection().releaseSavepoint(savepoint);
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ unlock();
+ }
}
public Connection getUnderlyingConnection() throws SQLException
{
- checkTransaction();
- return mc.getConnection();
+ lock();
+ try
+ {
+ checkTransaction();
+ return mc.getConnection();
+ }
+ finally
+ {
+ unlock();
+ }
}
void checkTransaction() throws SQLException
@@ -525,6 +814,12 @@
mc.checkTransaction();
}
+ void checkTransactionActive() throws SQLException
+ {
+ dataSource.checkTransactionActive();
+ }
+
+
/**
* The checkStatus method checks that the handle has not been closed and
* that it is associated with a managed connection.
@@ -537,6 +832,7 @@
throw new SQLException("Connection handle has been closed and is unusable");
if (mc == null)
throw new SQLException("Connection handle is not currently associated with a ManagedConnection");
+ checkTransactionActive();
}
/**
Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedResultSet.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedResultSet.java 2008-03-31 09:15:38 UTC (rev 71461)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedResultSet.java 2008-03-31 09:16:28 UTC (rev 71462)
@@ -102,8 +102,16 @@
public ResultSet getUnderlyingResultSet() throws SQLException
{
- checkState();
- return resultSet;
+ statement.lock();
+ try
+ {
+ checkTransaction();
+ return resultSet;
+ }
+ finally
+ {
+ statement.unlock();
+ }
}
public boolean absolute(int row) throws SQLException
@@ -186,15 +194,23 @@
public void deleteRow() throws SQLException
{
- checkState();
- try
- {
- resultSet.deleteRow();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ statement.lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ resultSet.deleteRow();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ statement.unlock();
+ }
}
public int findColumn(String columnName) throws SQLException
@@ -1074,15 +1090,23 @@
public void insertRow() throws SQLException
{
- checkState();
- try
- {
- resultSet.insertRow();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ statement.lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ resultSet.insertRow();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ statement.unlock();
+ }
}
public boolean isAfterLast() throws SQLException
@@ -1789,15 +1813,23 @@
public void updateRow() throws SQLException
{
- checkState();
- try
- {
- resultSet.updateRow();
- }
- catch (Throwable t)
- {
- throw checkException(t);
- }
+ statement.lock();
+ try
+ {
+ checkTransaction();
+ try
+ {
+ resultSet.updateRow();
+ }
+ catch (Throwable t)
+ {
+ throw checkException(t);
+ }
+ }
+ finally
+ {
+ statement.unlock();
+ }
}
public void updateShort(int columnIndex, short x) throws SQLException
@@ -1939,4 +1971,10 @@
throw new SQLException("The result set is closed.");
}
}
+
+ void checkTransaction() throws SQLException
+ {
+ checkState();
+ statement.checkTransactionActive();
+ }
}
\ No newline at end of file
Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java 2008-03-31 09:15:38 UTC (rev 71461)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java 2008-03-31 09:16:28 UTC (rev 71462)
@@ -33,7 +33,9 @@
import javax.resource.spi.ConnectionRequestInfo;
import javax.sql.DataSource;
import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import org.jboss.resource.connectionmanager.JTATransactionChecker;
import org.jboss.tm.TransactionTimeoutConfiguration;
import org.jboss.util.NestedSQLException;
@@ -144,4 +146,24 @@
throw new NestedSQLException(e);
}
}
+
+ /**
+ * Check whether a tranasction is active
+ *
+ * @throws SQLException if the transaction is not active, preparing, prepared or committing or for any error in the transaction manager
+ */
+ protected void checkTransactionActive() throws SQLException
+ {
+ if (cm == null)
+ throw new SQLException("No connection manager");
+ try
+ {
+ if (cm instanceof JTATransactionChecker)
+ ((JTATransactionChecker) cm).checkTransactionActive();
+ }
+ catch (Exception e)
+ {
+ throw new NestedSQLException(e);
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list