[jboss-cvs] JBossAS SVN: r71788 - in trunk/connector/src/main/org/jboss/resource/adapter/jdbc: jdk6 and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 8 09:31:34 EDT 2008


Author: adrian at jboss.org
Date: 2008-04-08 09:31:34 -0400 (Tue, 08 Apr 2008)
New Revision: 71788

Modified:
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnectionFactory.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedCallableStatement.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedPreparedStatement.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedResultSet.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedStatement.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedConnectionJDK6.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedPreparedStatementJDK6.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedStatementJDK6.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/local/LocalManagedConnection.java
   trunk/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java
Log:
[JBAS-5278] - Port SQL fixes from 4.2

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -34,6 +34,8 @@
 import java.util.Iterator;
 import java.util.Properties;
 import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
 
 import javax.resource.ResourceException;
 import javax.resource.spi.ConnectionEvent;
@@ -72,6 +74,8 @@
 
    private final boolean readOnly;
 
+   private ReentrantLock lock = new ReentrantLock();
+
    private final Collection cels = new ArrayList();
 
    private final Set handles = new HashSet();
@@ -236,8 +240,42 @@
             }
          }
       }
+      // I'm recreating the lock object when we return to the pool
+      // because it looks too nasty to expect the connection handle
+      // to unlock properly in certain race conditions
+      // where the dissociation of the managed connection is "random".
+      lock = new ReentrantLock();
    }
 
+   protected void lock()
+   {
+      lock.lock();
+   }
+
+   protected void tryLock() throws SQLException
+   {
+      int tryLock = mcf.getUseTryLock();
+      if (tryLock <= 0)
+      {
+         lock();
+         return;
+      }
+      try
+      {
+         if (lock.tryLock(tryLock, TimeUnit.SECONDS) == false)
+            throw new SQLException("Unable to obtain lock in " + tryLock + " seconds: " + this);
+      }
+      catch (InterruptedException e)
+      {
+         throw new SQLException("Interrupted attempting lock: " + this);
+      }
+   }
+   
+   protected void unlock()
+   {
+      lock.unlock();
+   }
+
    public Object getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
    {
       checkIdentity(subject, cri);

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnectionFactory.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnectionFactory.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnectionFactory.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -142,7 +142,10 @@
    private URLSelectorStrategy urlSelectorStrategy;
 
    private boolean validateOnMatch = true;
-   
+
+   /** Whether to use a try lock */
+   private int useTryLock = 0;
+
    public BaseWrapperManagedConnectionFactory ()
    {
 
@@ -358,6 +361,26 @@
    }
    
    /**
+    * Get the useTryLock.
+    * 
+    * @return the useTryLock.
+    */
+   public int getUseTryLock()
+   {
+      return useTryLock;
+   }
+
+   /**
+    * Set the useTryLock.
+    * 
+    * @param useTryLock the useTryLock.
+    */
+   public void setUseTryLock(int useTryLock)
+   {
+      this.useTryLock = useTryLock;
+   }
+   
+   /**
     * Get the urlDelimiter.
     * 
     * @return the urlDelimiter.

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedCallableStatement.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedCallableStatement.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedCallableStatement.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -1092,6 +1092,6 @@
 
    protected CallableStatement getWrappedObject() throws SQLException
    {
-      return cs;
+      return (CallableStatement) super.getWrappedObject();
    }
 }

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -72,6 +72,24 @@
          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 +102,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
@@ -141,43 +167,66 @@
    
    public Statement createStatement() throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapStatement(mc.getConnection().createStatement());
+         checkTransaction();
+         try
+         {
+            return wrapStatement(mc.getConnection().createStatement());
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapStatement(mc.getConnection().createStatement(resultSetType, resultSetConcurrency));
+         checkTransaction();
+         try
+         {
+            return wrapStatement(mc.getConnection().createStatement(resultSetType, resultSetConcurrency));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          throws SQLException
    {
-
-      checkTransaction();
+      lock();
       try
       {
-         return wrapStatement(mc.getConnection()
-               .createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
+         checkTransaction();
+         try
+         {
+            return wrapStatement(mc.getConnection()
+                  .createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
@@ -185,83 +234,130 @@
 
    public PreparedStatement prepareStatement(String sql) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapPreparedStatement(mc.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
+         checkTransaction();
+         try
+         {
+            return wrapPreparedStatement(mc.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
          throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapPreparedStatement(mc.prepareStatement(sql, resultSetType, resultSetConcurrency));
+         checkTransaction();
+         try
+         {
+            return wrapPreparedStatement(mc.prepareStatement(sql, resultSetType, resultSetConcurrency));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
          int resultSetHoldability) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapPreparedStatement(mc.getConnection()
-               .prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
+         checkTransaction();
+         try
+         {
+            return wrapPreparedStatement(mc.getConnection()
+                  .prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapPreparedStatement(mc.getConnection().prepareStatement(sql, autoGeneratedKeys));
+         checkTransaction();
+         try
+         {
+            return wrapPreparedStatement(mc.getConnection().prepareStatement(sql, autoGeneratedKeys));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapPreparedStatement(mc.getConnection().prepareStatement(sql, columnIndexes));
+         checkTransaction();
+         try
+         {
+            return wrapPreparedStatement(mc.getConnection().prepareStatement(sql, columnIndexes));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
    {
-
-      checkTransaction();
+      lock();
       try
       {
-         return wrapPreparedStatement(mc.getConnection().prepareStatement(sql, columnNames));
+         checkTransaction();
+         try
+         {
+            return wrapPreparedStatement(mc.getConnection().prepareStatement(sql, columnNames));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
@@ -269,262 +365,454 @@
 
    public CallableStatement prepareCall(String sql) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapCallableStatement(mc.prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
+         checkTransaction();
+         try
+         {
+            return wrapCallableStatement(mc.prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return wrapCallableStatement(mc.prepareCall(sql, resultSetType, resultSetConcurrency));
+         checkTransaction();
+         try
+         {
+            return wrapCallableStatement(mc.prepareCall(sql, resultSetType, resultSetConcurrency));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
          int resultSetHoldability) throws SQLException
    {
-
-      checkTransaction();
+      lock();
       try
       {
-         return wrapCallableStatement(mc.getConnection()
-               .prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
+         checkTransaction();
+         try
+         {
+            return wrapCallableStatement(mc.getConnection()
+                  .prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public String nativeSQL(String sql) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return mc.getConnection().nativeSQL(sql);
+         checkTransaction();
+         try
+         {
+            return mc.getConnection().nativeSQL(sql);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         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();
+      lock();
       try
       {
-         return mc.getConnection().getMetaData();
+         checkTransaction();
+         try
+         {
+            return mc.getConnection().getMetaData();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setCatalog(String catalog) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         mc.getConnection().setCatalog(catalog);
+         checkTransaction();
+         try
+         {
+            mc.getConnection().setCatalog(catalog);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
+
    public String getCatalog() throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return mc.getConnection().getCatalog();
+         checkTransaction();
+         try
+         {
+            return mc.getConnection().getCatalog();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         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();
+      lock();
       try
       {
-         return mc.getConnection().getWarnings();
+         checkTransaction();
+         try
+         {
+            return mc.getConnection().getWarnings();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void clearWarnings() throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         mc.getConnection().clearWarnings();
+         checkTransaction();
+         try
+         {
+            mc.getConnection().clearWarnings();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    @SuppressWarnings("unchecked")
    public Map getTypeMap() throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return mc.getConnection().getTypeMap();
+         checkTransaction();
+         try
+         {
+            return mc.getConnection().getTypeMap();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    @SuppressWarnings("unchecked")
    public void setTypeMap(Map typeMap) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         mc.getConnection().setTypeMap(typeMap);
+         checkTransaction();
+         try
+         {
+            mc.getConnection().setTypeMap(typeMap);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setHoldability(int holdability) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         mc.getConnection().setHoldability(holdability);
+         checkTransaction();
+         try
+         {
+            mc.getConnection().setHoldability(holdability);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getHoldability() throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return mc.getConnection().getHoldability();
+         checkTransaction();
+         try
+         {
+            return mc.getConnection().getHoldability();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Savepoint setSavepoint() throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return mc.getConnection().setSavepoint();
+         checkTransaction();
+         try
+         {
+            return mc.getConnection().setSavepoint();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Savepoint setSavepoint(String name) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         return mc.getConnection().setSavepoint(name);
+         checkTransaction();
+         try
+         {
+            return mc.getConnection().setSavepoint(name);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void releaseSavepoint(Savepoint savepoint) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         mc.getConnection().releaseSavepoint(savepoint);
+         checkTransaction();
+         try
+         {
+            mc.getConnection().releaseSavepoint(savepoint);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Connection getUnderlyingConnection() throws SQLException
    {
-      checkTransaction();
-      return mc.getConnection();
+      lock();
+      try
+      {
+         checkTransaction();
+         return mc.getConnection();
+      }
+      finally
+      {
+         unlock();
+      }
    }
 
    protected Connection getWrappedObject() throws SQLException
@@ -538,6 +826,11 @@
       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.
@@ -550,6 +843,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: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedPreparedStatement.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedPreparedStatement.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedPreparedStatement.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -58,506 +58,810 @@
 
    public PreparedStatement getUnderlyingStatement() throws SQLException
    {
-      checkState();
-      if (ps instanceof CachedPreparedStatement)
+      lock();
+      try
       {
-         return ((CachedPreparedStatement)ps).getUnderlyingPreparedStatement();
+         checkState();
+         if (ps instanceof CachedPreparedStatement)
+         {
+            return ((CachedPreparedStatement)ps).getUnderlyingPreparedStatement();
+         }
+         else
+         {
+            return ps;
+         }
       }
-      else
+      finally
       {
-         return ps;
+         unlock();
       }
    }
 
    public void setBoolean(int parameterIndex, boolean value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setBoolean(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setBoolean(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setByte(int parameterIndex, byte value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setByte(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setByte(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setShort(int parameterIndex, short value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setShort(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setShort(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setInt(int parameterIndex, int value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setInt(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setInt(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setLong(int parameterIndex, long value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setLong(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setLong(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setFloat(int parameterIndex, float value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setFloat(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setFloat(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setDouble(int parameterIndex, double value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setDouble(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setDouble(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setURL(int parameterIndex, URL value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setURL(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setURL(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setTime(int parameterIndex, Time value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setTime(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setTime(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setTime(int parameterIndex, Time value, Calendar calendar) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setTime(parameterIndex, value, calendar);         
+         checkState();
+         try 
+         {
+            ps.setTime(parameterIndex, value, calendar);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public boolean execute() throws SQLException
    {
-      checkTransaction();
-      try 
+      lock();
+      try
       {
-         checkConfiguredQueryTimeout();
-         return ps.execute();         
+         checkTransaction();
+         try 
+         {
+            checkConfiguredQueryTimeout();
+            return ps.execute();         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public ResultSetMetaData getMetaData() throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         return ps.getMetaData();         
+         checkState();
+         try 
+         {
+            return ps.getMetaData();         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public ResultSet executeQuery() throws SQLException
    {
-      checkTransaction();
-      try 
+      lock();
+      try
       {
-         checkConfiguredQueryTimeout();
-         ResultSet resultSet = ps.executeQuery();
-         return registerResultSet(resultSet);
+         checkTransaction();
+         try 
+         {
+            checkConfiguredQueryTimeout();
+            ResultSet resultSet = ps.executeQuery();
+            return registerResultSet(resultSet);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int executeUpdate() throws SQLException
    {
-      checkTransaction();
-      try 
+      lock();
+      try
       {
-         checkConfiguredQueryTimeout();
-         return ps.executeUpdate();         
+         checkTransaction();
+         try 
+         {
+            checkConfiguredQueryTimeout();
+            return ps.executeUpdate();         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void addBatch() throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.addBatch();         
+         checkState();
+         try 
+         {
+            ps.addBatch();         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setNull(int parameterIndex, int sqlType) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setNull(parameterIndex, sqlType);         
+         checkState();
+         try 
+         {
+            ps.setNull(parameterIndex, sqlType);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setNull(parameterIndex, sqlType, typeName);         
+         checkState();
+         try 
+         {
+            ps.setNull(parameterIndex, sqlType, typeName);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setBigDecimal(int parameterIndex, BigDecimal value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setBigDecimal(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setBigDecimal(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setString(int parameterIndex, String value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setString(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setString(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setBytes(int parameterIndex, byte[] value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setBytes(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setBytes(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setDate(int parameterIndex, Date value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setDate(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setDate(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setDate(int parameterIndex, Date value, Calendar calendar) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setDate(parameterIndex, value, calendar);         
+         checkState();
+         try 
+         {
+            ps.setDate(parameterIndex, value, calendar);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setTimestamp(int parameterIndex, Timestamp value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setTimestamp(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setTimestamp(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setTimestamp(int parameterIndex, Timestamp value, Calendar calendar) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setTimestamp(parameterIndex, value, calendar);         
+         checkState();
+         try 
+         {
+            ps.setTimestamp(parameterIndex, value, calendar);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    @Deprecated
    public void setAsciiStream(int parameterIndex, InputStream stream, int length) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setAsciiStream(parameterIndex, stream, length);         
+         checkState();
+         try 
+         {
+            ps.setAsciiStream(parameterIndex, stream, length);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    @Deprecated
    public void setUnicodeStream(int parameterIndex, InputStream stream, int length) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setUnicodeStream(parameterIndex, stream, length);         
+         checkState();
+         try 
+         {
+            ps.setUnicodeStream(parameterIndex, stream, length);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setBinaryStream(int parameterIndex, InputStream stream, int length) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setBinaryStream(parameterIndex, stream, length);         
+         checkState();
+         try 
+         {
+            ps.setBinaryStream(parameterIndex, stream, length);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void clearParameters() throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.clearParameters();         
+         checkState();
+         try 
+         {
+            ps.clearParameters();         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setObject(int parameterIndex, Object value, int sqlType, int scale) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setObject(parameterIndex, value, sqlType, scale);         
+         checkState();
+         try 
+         {
+            ps.setObject(parameterIndex, value, sqlType, scale);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setObject(int parameterIndex, Object value, int sqlType) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setObject(parameterIndex, value, sqlType);         
+         checkState();
+         try 
+         {
+            ps.setObject(parameterIndex, value, sqlType);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setObject(int parameterIndex, Object value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setObject(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setObject(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setCharacterStream(parameterIndex, reader, length);         
+         checkState();
+         try 
+         {
+            ps.setCharacterStream(parameterIndex, reader, length);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setRef(int parameterIndex, Ref value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setRef(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setRef(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setBlob(int parameterIndex, Blob value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setBlob(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setBlob(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setClob(int parameterIndex, Clob value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setClob(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setClob(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setArray(int parameterIndex, Array value) throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         ps.setArray(parameterIndex, value);         
+         checkState();
+         try 
+         {
+            ps.setArray(parameterIndex, value);         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public ParameterMetaData getParameterMetaData() throws SQLException
    {
-      checkState();
-      try 
+      lock();
+      try
       {
-         return ps.getParameterMetaData();         
+         checkState();
+         try 
+         {
+            return ps.getParameterMetaData();         
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    protected PreparedStatement getWrappedObject() throws SQLException
    {
-      return ps;
+      return (PreparedStatement) super.getWrappedObject();
    }
 }

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedResultSet.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedResultSet.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedResultSet.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -101,8 +101,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
@@ -184,14 +192,22 @@
 
    public void deleteRow() throws SQLException
    {
-      checkState();
+      statement.lock();
       try
       {
-         resultSet.deleteRow();
+         checkTransaction();
+         try
+         {
+            resultSet.deleteRow();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         statement.unlock();
       }
    }
 
@@ -1066,14 +1082,22 @@
 
    public void insertRow() throws SQLException
    {
-      checkState();
+      statement.lock();
       try
       {
-         resultSet.insertRow();
+         checkTransaction();
+         try
+         {
+            resultSet.insertRow();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         statement.unlock();
       }
    }
 
@@ -1781,14 +1805,22 @@
 
    public void updateRow() throws SQLException
    {
-      checkState();
+      statement.lock();
       try
       {
-         resultSet.updateRow();
+         checkTransaction();
+         try
+         {
+            resultSet.updateRow();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         statement.unlock();
       }
    }
 
@@ -1911,7 +1943,7 @@
 
    protected ResultSet getWrappedObject() throws SQLException
    {
-      return resultSet;
+      return getUnderlyingResultSet();
    }
 
    protected SQLException checkException(Throwable t) throws SQLException
@@ -1936,4 +1968,10 @@
             throw new SQLException("The result set is closed.");
       }
    }
+
+   protected void checkTransaction() throws SQLException
+   {
+      checkState();
+      statement.checkTransactionActive();
+   }
 }

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedStatement.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedStatement.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedStatement.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -61,6 +61,16 @@
       lc.registerStatement(this);
    }
 
+   protected void lock() throws SQLException
+   {
+      lc.lock();
+   }
+
+   protected void unlock()
+   {
+      lc.unlock();
+   }
+
    public void close() throws SQLException
    {
       synchronized (lock)
@@ -76,57 +86,89 @@
 
    public boolean execute(String sql) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.execute(sql);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.execute(sql);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.execute(sql, autoGeneratedKeys);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.execute(sql, autoGeneratedKeys);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public boolean execute(String sql, int[] columnIndexes) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.execute(sql, columnIndexes);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.execute(sql, columnIndexes);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public boolean execute(String sql, String[]columnNames ) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.execute(sql, columnNames);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.execute(sql, columnNames);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
@@ -137,189 +179,301 @@
 
    public SQLWarning getWarnings() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getWarnings();
+         checkState();
+         try
+         {
+            return s.getWarnings();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void clearWarnings() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.clearWarnings();
+         checkState();
+         try
+         {
+            s.clearWarnings();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public ResultSet executeQuery(String sql) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         ResultSet result = s.executeQuery(sql);
-         return registerResultSet(result);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            ResultSet result = s.executeQuery(sql);
+            return registerResultSet(result);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int executeUpdate(String sql) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.executeUpdate(sql);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.executeUpdate(sql);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.executeUpdate(sql, autoGeneratedKeys);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.executeUpdate(sql, autoGeneratedKeys);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.executeUpdate(sql, columnIndexes);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.executeUpdate(sql, columnIndexes);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int executeUpdate(String sql, String[] columnNames) throws SQLException
    {
-      checkTransaction();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.executeUpdate(sql, columnNames);
+         checkTransaction();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.executeUpdate(sql, columnNames);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getMaxFieldSize() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getMaxFieldSize();
+         checkState();
+         try
+         {
+            return s.getMaxFieldSize();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setMaxFieldSize(int max) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.setMaxFieldSize(max);
+         checkState();
+         try
+         {
+            s.setMaxFieldSize(max);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getMaxRows() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getMaxRows();
+         checkState();
+         try
+         {
+            return s.getMaxRows();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setMaxRows(int max) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.setMaxRows(max);
+         checkState();
+         try
+         {
+            s.setMaxRows(max);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setEscapeProcessing(boolean enable) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.setEscapeProcessing(enable);
+         checkState();
+         try
+         {
+            s.setEscapeProcessing(enable);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getQueryTimeout() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getQueryTimeout();
+         checkState();
+         try
+         {
+            return s.getQueryTimeout();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setQueryTimeout(int timeout) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.setQueryTimeout(timeout);
+         checkState();
+         try
+         {
+            s.setQueryTimeout(timeout);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
@@ -338,227 +492,363 @@
 
    public void setCursorName(String name) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.setCursorName(name);
+         checkState();
+         try
+         {
+            s.setCursorName(name);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public ResultSet getResultSet() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         ResultSet result = s.getResultSet();
-         if (result == null)
-            return null;
-         else
-            return registerResultSet(result);
+         checkState();
+         try
+         {
+            ResultSet result = s.getResultSet();
+            if (result == null)
+               return null;
+            else
+               return registerResultSet(result);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getUpdateCount() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getUpdateCount();
+         checkState();
+         try
+         {
+            return s.getUpdateCount();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public boolean getMoreResults() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getMoreResults();
+         checkState();
+         try
+         {
+            return s.getMoreResults();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public boolean getMoreResults(int current) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getMoreResults(current);
+         checkState();
+         try
+         {
+            return s.getMoreResults(current);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setFetchDirection(int direction) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.setFetchDirection(direction);
+         checkState();
+         try
+         {
+            s.setFetchDirection(direction);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getFetchDirection() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getFetchDirection();
+         checkState();
+         try
+         {
+            return s.getFetchDirection();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setFetchSize(int rows) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.setFetchSize(rows);
+         checkState();
+         try
+         {
+            s.setFetchSize(rows);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getFetchSize() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getFetchSize();
+         checkState();
+         try
+         {
+            return s.getFetchSize();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getResultSetConcurrency() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getResultSetConcurrency();
+         checkState();
+         try
+         {
+            return s.getResultSetConcurrency();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getResultSetType() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getResultSetType();
+         checkState();
+         try
+         {
+            return s.getResultSetType();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void addBatch(String sql) throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.addBatch(sql);
+         checkState();
+         try
+         {
+            s.addBatch(sql);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void clearBatch() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         s.clearBatch();
+         checkState();
+         try
+         {
+            s.clearBatch();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int[] executeBatch() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         checkConfiguredQueryTimeout();
-         return s.executeBatch();
+         checkState();
+         try
+         {
+            checkConfiguredQueryTimeout();
+            return s.executeBatch();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public ResultSet getGeneratedKeys() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         ResultSet resultSet = s.getGeneratedKeys();
-         return registerResultSet(resultSet);
+         checkState();
+         try
+         {
+            ResultSet resultSet = s.getGeneratedKeys();
+            return registerResultSet(resultSet);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public int getResultSetHoldability() throws SQLException
    {
-      checkState();
+      lock();
       try
       {
-         return s.getResultSetHoldability();
+         checkState();
+         try
+         {
+            return s.getResultSetHoldability();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Statement getUnderlyingStatement() throws SQLException
    {
-      checkState();
-      return s;
+      lock();
+      try
+      {
+         checkState();
+         return s;
+      }
+      finally
+      {
+         unlock();
+      }
    }
 
    protected Statement getWrappedObject() throws SQLException
    {
-      return s;
+      return getUnderlyingStatement();
    }
 
    protected SQLException checkException(Throwable t)
@@ -578,7 +868,12 @@
    {
       lc.checkConfiguredQueryTimeout(this);
    }
-   
+
+   protected void checkTransactionActive() throws SQLException
+   {
+      lc.checkTransactionActive();
+   }
+
    protected void internalClose() throws SQLException
    {
       synchronized (lock)

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/WrapperDataSource.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -34,6 +34,7 @@
 import javax.sql.DataSource;
 import javax.transaction.RollbackException;
 
+import org.jboss.resource.connectionmanager.JTATransactionChecker;
 import org.jboss.tm.TransactionTimeoutConfiguration;
 import org.jboss.util.NestedSQLException;
 
@@ -144,4 +145,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);
+      }
+   }
 }

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedConnectionJDK6.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedConnectionJDK6.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedConnectionJDK6.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -77,170 +77,258 @@
 
    public Array createArrayOf(String typeName, Object[] elements) throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.createArrayOf(typeName, elements);
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.createArrayOf(typeName, elements);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Blob createBlob() throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.createBlob();
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.createBlob();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Clob createClob() throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.createClob();
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.createClob();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public NClob createNClob() throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.createNClob();
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.createNClob();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public SQLXML createSQLXML() throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.createSQLXML();
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.createSQLXML();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Struct createStruct(String typeName, Object[] attributes) throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.createStruct(typeName, attributes);
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.createStruct(typeName, attributes);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public Properties getClientInfo() throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.getClientInfo();
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.getClientInfo();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public String getClientInfo(String name) throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.getClientInfo(name);
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.getClientInfo(name);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public boolean isValid(int timeout) throws SQLException
    {
-      Connection c = getUnderlyingConnection();
+      lock();
       try
       {
-         return c.isValid(timeout);
+         Connection c = getUnderlyingConnection();
+         try
+         {
+            return c.isValid(timeout);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setClientInfo(Properties properties) throws SQLClientInfoException
    {
+      lock();
       try
       {
-         Connection c = getUnderlyingConnection();
          try
          {
-            c.setClientInfo(properties);
+            Connection c = getUnderlyingConnection();
+            try
+            {
+               c.setClientInfo(properties);
+            }
+            catch (Throwable t)
+            {
+               throw checkException(t);
+            }
          }
-         catch (Throwable t)
+         catch (SQLClientInfoException e)
          {
-            throw checkException(t);
+            throw e;
          }
+         catch (SQLException e)
+         {
+            SQLClientInfoException t = new SQLClientInfoException();
+            t.initCause(e);
+            throw t;
+         }
       }
-      catch (SQLClientInfoException e)
+      finally
       {
-         throw e;
+         unlock();
       }
-      catch (SQLException e)
-      {
-         SQLClientInfoException t = new SQLClientInfoException();
-         t.initCause(e);
-         throw t;
-      }
    }
 
    public void setClientInfo(String name, String value) throws SQLClientInfoException
    {
+      lock();
       try
       {
-         Connection c = getUnderlyingConnection();
          try
          {
-            c.setClientInfo(name, value);
+            Connection c = getUnderlyingConnection();
+            try
+            {
+               c.setClientInfo(name, value);
+            }
+            catch (Throwable t)
+            {
+               throw checkException(t);
+            }
          }
-         catch (Throwable t)
+         catch (SQLClientInfoException e)
          {
-            throw checkException(t);
+            throw e;
          }
+         catch (SQLException e)
+         {
+            SQLClientInfoException t = new SQLClientInfoException();
+            t.initCause(e);
+            throw t;
+         }
       }
-      catch (SQLClientInfoException e)
+      finally
       {
-         throw e;
+         unlock();
       }
-      catch (SQLException e)
-      {
-         SQLClientInfoException t = new SQLClientInfoException();
-         t.initCause(e);
-         throw t;
-      }
    }
 }

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedPreparedStatementJDK6.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedPreparedStatementJDK6.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedPreparedStatementJDK6.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -53,6 +53,7 @@
 
    public boolean isClosed() throws SQLException
    {
+      lock();
       try
       {
          PreparedStatement wrapped = getWrappedObject();
@@ -64,265 +65,429 @@
       {
          throw checkException(t);
       }
+      finally
+      {
+         unlock();
+      }
    }
 
    public boolean isPoolable() throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         return statement.isPoolable();
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            return statement.isPoolable();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setPoolable(boolean poolable) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setPoolable(poolable);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setPoolable(poolable);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setAsciiStream(parameterIndex, x, length);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setAsciiStream(parameterIndex, x, length);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setAsciiStream(parameterIndex, x);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setAsciiStream(parameterIndex, x);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setBinaryStream(parameterIndex, x, length);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setBinaryStream(parameterIndex, x, length);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setBinaryStream(parameterIndex, x);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setBinaryStream(parameterIndex, x);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setBlob(parameterIndex, inputStream, length);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setBlob(parameterIndex, inputStream, length);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setBlob(parameterIndex, inputStream);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setBlob(parameterIndex, inputStream);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setCharacterStream(parameterIndex, reader, length);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setCharacterStream(parameterIndex, reader, length);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setCharacterStream(parameterIndex, reader);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setCharacterStream(parameterIndex, reader);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setClob(int parameterIndex, Reader reader, long length) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setClob(parameterIndex, reader, length);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setClob(parameterIndex, reader, length);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setClob(int parameterIndex, Reader reader) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setClob(parameterIndex, reader);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setClob(parameterIndex, reader);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setNCharacterStream(parameterIndex, value, length);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setNCharacterStream(parameterIndex, value, length);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setNCharacterStream(parameterIndex, value);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setNCharacterStream(parameterIndex, value);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setNClob(int parameterIndex, NClob value) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setNClob(parameterIndex, value);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setNClob(parameterIndex, value);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setNClob(parameterIndex, reader, length);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setNClob(parameterIndex, reader, length);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setNClob(int parameterIndex, Reader reader) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setNClob(parameterIndex, reader);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setNClob(parameterIndex, reader);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setNString(int parameterIndex, String value) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setNString(parameterIndex, value);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setNString(parameterIndex, value);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setRowId(int parameterIndex, RowId x) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setRowId(parameterIndex, x);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setRowId(parameterIndex, x);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException
    {
-      PreparedStatement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setSQLXML(parameterIndex, xmlObject);
+         PreparedStatement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setSQLXML(parameterIndex, xmlObject);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 }

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedStatementJDK6.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedStatementJDK6.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/jdk6/WrappedStatementJDK6.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -48,6 +48,7 @@
 
    public boolean isClosed() throws SQLException
    {
+      lock();
       try
       {
          Statement wrapped = getWrappedObject();
@@ -59,31 +60,51 @@
       {
          throw checkException(t);
       }
+      finally
+      {
+         unlock();
+      }
    }
 
    public boolean isPoolable() throws SQLException
    {
-      Statement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         return statement.isPoolable();
+         Statement statement = getUnderlyingStatement();
+         try
+         {
+            return statement.isPoolable();
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 
    public void setPoolable(boolean poolable) throws SQLException
    {
-      Statement statement = getUnderlyingStatement();
+      lock();
       try
       {
-         statement.setPoolable(poolable);
+         Statement statement = getUnderlyingStatement();
+         try
+         {
+            statement.setPoolable(poolable);
+         }
+         catch (Throwable t)
+         {
+            throw checkException(t);
+         }
       }
-      catch (Throwable t)
+      finally
       {
-         throw checkException(t);
+         unlock();
       }
    }
 }

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/local/LocalManagedConnection.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/local/LocalManagedConnection.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/local/LocalManagedConnection.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -59,68 +59,92 @@
 
    public void commit() throws ResourceException
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction)
-            inManagedTransaction = false;
-      }
+      lock();
       try
       {
-         con.commit();
+         synchronized (stateLock)
+         {
+            if (inManagedTransaction)
+               inManagedTransaction = false;
+         }
+         try
+         {
+            con.commit();
+         }
+         catch (SQLException e)
+         {
+            checkException(e);
+         }
       }
-      catch (SQLException e)
+      finally
       {
-         checkException(e);
+         unlock();
       }
    }
 
    public void rollback() throws ResourceException
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction)
-            inManagedTransaction = false;
-      }
+      lock();
       try
       {
-         con.rollback();
-      }
-      catch (SQLException e)
-      {
+         synchronized (stateLock)
+         {
+            if (inManagedTransaction)
+               inManagedTransaction = false;
+         }
          try
          {
-            checkException(e);
+            con.rollback();
          }
-         catch (Exception e2)
+         catch (SQLException e)
          {
+            try
+            {
+               checkException(e);
+            }
+            catch (Exception e2)
+            {
+            }
          }
       }
+      finally
+      {
+         unlock();
+      }
    }
 
    public void begin() throws ResourceException
    {
-      synchronized (stateLock)
+      lock();
+      try
       {
-         if (inManagedTransaction == false)
+         synchronized (stateLock)
          {
-            try
+            if (inManagedTransaction == false)
             {
-               if (underlyingAutoCommit)
+               try
                {
-                  underlyingAutoCommit = false;
-                  con.setAutoCommit(false);
+                  if (underlyingAutoCommit)
+                  {
+                     underlyingAutoCommit = false;
+                     con.setAutoCommit(false);
+                  }
+                  checkState();
+                  inManagedTransaction = true;
                }
-               checkState();
-               inManagedTransaction = true;
+               catch (SQLException e)
+               {
+                  checkException(e);
+               }
             }
-            catch (SQLException e)
-            {
-               checkException(e);
-            }
+            else
+               throw new JBossResourceException("Trying to begin a nested local tx");
          }
-         else
-            throw new JBossResourceException("Trying to begin a nested local tx");
       }
+      finally
+      {
+         unlock();
+      }
    }
 
 

Modified: trunk/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java	2008-04-08 13:17:51 UTC (rev 71787)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java	2008-04-08 13:31:34 UTC (rev 71788)
@@ -73,69 +73,91 @@
    
    public void begin() throws ResourceException 
    {	
-      synchronized (stateLock)
+      lock();
+      try
       {
-         if (inManagedTransaction == false)
+         synchronized (stateLock)
          {
-            try
+            if (inManagedTransaction == false)
             {
-               if (underlyingAutoCommit)
+               try
                {
-                  underlyingAutoCommit = false;
-                  con.setAutoCommit(false);
+                  if (underlyingAutoCommit)
+                  {
+                     underlyingAutoCommit = false;
+                     con.setAutoCommit(false);
+                  }
+                  checkState();
+                  inManagedTransaction = true;
                }
-               checkState();
-               inManagedTransaction = true;
+               catch (SQLException e)
+               {
+                  checkException(e);
+               }
             }
-            catch (SQLException e)
-            {
-               checkException(e);
-            }
+            else
+               throw new JBossResourceException("Trying to begin a nested local tx");
          }
-         else
-            throw new JBossResourceException("Trying to begin a nested local tx");
       }
-   
+      finally
+      {
+         unlock();
+      }
    }
    public void commit() throws ResourceException 
    {	
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction)
-            inManagedTransaction = false;
-      }
+      lock();
       try
       {
-         con.commit();
+         synchronized (stateLock)
+         {
+            if (inManagedTransaction)
+               inManagedTransaction = false;
+         }
+         try
+         {
+            con.commit();
+         }
+         catch (SQLException e)
+         {
+            checkException(e);
+         }
       }
-      catch (SQLException e)
+      finally
       {
-         checkException(e);
+         unlock();
       }
-   
    }   
    
    public void rollback() throws ResourceException
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction)
-            inManagedTransaction = false;
-      }
+      lock();
       try
       {
-         con.rollback();
-      }
-      catch (SQLException e)
-      {
+         synchronized (stateLock)
+         {
+            if (inManagedTransaction)
+               inManagedTransaction = false;
+         }
          try
          {
-            checkException(e);
+            con.rollback();
          }
-         catch (Exception e2)
+         catch (SQLException e)
          {
+            try
+            {
+               checkException(e);
+            }
+            catch (Exception e2)
+            {
+            }
          }
       }
+      finally
+      {
+         unlock();
+      }
    }
    
    protected void broadcastConnectionError(SQLException e)
@@ -174,77 +196,116 @@
 
    public void start(Xid xid, int flags) throws XAException
    {
+      lock();
       try
       {
-         checkState();
-      }
-      catch (SQLException e)
-      {
-         getLog().warn("Error setting state ", e);
-      }
-      
-      try
-      {
-         xaResource.start(xid, flags);
+         try
+         {
+            checkState();
+         }
+         catch (SQLException e)
+         {
+            getLog().warn("Error setting state ", e);
+         }
+
+         try
+         {
+            xaResource.start(xid, flags);
+         }
+         catch(XAException e)
+         {
+            //JBAS-3336 Connections that fail in enlistment should not be returned
+            //to the pool
+            if(isFailedXA(e.errorCode))
+            {
+               broadcastConnectionError(e);  
+            }
+            
+            throw e;
+         }
          
-      }catch(XAException e)
-      {
-         //JBAS-3336 Connections that fail in enlistment should not be returned
-         //to the pool
-         if(isFailedXA(e.errorCode))
+         synchronized (stateLock)
          {
-            broadcastConnectionError(e);  
+            currentXid = xid;
+            inManagedTransaction = true;
          }
-         
-         throw e;
       }
-      
-      synchronized (stateLock)
+      finally
       {
-         currentXid = xid;
-         inManagedTransaction = true;
+         unlock();
       }
    }
 
    public void end(Xid xid, int flags) throws XAException
    {
-      
+      lock();
       try
       {
-         xaResource.end(xid, flags);
+         try
+         {
+            xaResource.end(xid, flags);
+         }
+         catch(XAException e)
+         {
+            broadcastConnectionError(e);
+            throw e;
+         }
+
          
-      }catch(XAException e)
-      {
-         broadcastConnectionError(e);
-         throw e;
-      }
-
-      
-      //we want to allow ending transactions that are not the current
-      //one. When one does this, inManagedTransaction is still true.
-      synchronized (stateLock)
-      {
-         if (currentXid != null && currentXid.equals(xid))
+         //we want to allow ending transactions that are not the current
+         //one. When one does this, inManagedTransaction is still true.
+         synchronized (stateLock)
          {
-            inManagedTransaction = false;
-            currentXid = null;
+            if (currentXid != null && currentXid.equals(xid))
+            {
+               inManagedTransaction = false;
+               currentXid = null;
+            }
          }
       }
+      finally
+      {
+         unlock();
+      }
    }
 
    public int prepare(Xid xid) throws XAException
    {
-      return xaResource.prepare(xid);
+      lock();
+      try
+      {
+         return xaResource.prepare(xid);
+      }
+      finally
+      {
+         unlock();
+      }
    }
 
    public void commit(Xid xid, boolean onePhase) throws XAException
    {
-      xaResource.commit(xid, onePhase);
+      lock();
+      try
+      {
+         xaResource.commit(xid, onePhase);
+      }
+      finally
+      {
+         unlock();
+      }
    }
 
    public void rollback(Xid xid) throws XAException
    {
-      xaResource.rollback(xid);
+      lock();
+      try
+      {
+         xaResource.rollback(xid);
+      }
+      finally
+      {
+         unlock();
+      }
    }
 
    public void forget(Xid xid) throws XAException




More information about the jboss-cvs-commits mailing list