[jboss-cvs] JBossAS SVN: r71463 - in branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc: xa and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 31 05:18:59 EDT 2008


Author: vicky.kak at jboss.com
Date: 2008-03-31 05:18:59 -0400 (Mon, 31 Mar 2008)
New Revision: 71463

Modified:
   branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/local/LocalManagedConnection.java
   branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java
Log:
[JBPAPP-662]Add a lock for the session to avoid racing between jms activity and asynchronous rollback

Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/local/LocalManagedConnection.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/local/LocalManagedConnection.java	2008-03-31 09:16:28 UTC (rev 71462)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/local/LocalManagedConnection.java	2008-03-31 09:18:59 UTC (rev 71463)
@@ -59,68 +59,92 @@
 
    public void commit() throws ResourceException
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction)
-            inManagedTransaction = false;
-      }
-      try
-      {
-         con.commit();
-      }
-      catch (SQLException e)
-      {
-         checkException(e);
-      }
+	  lock();
+	  try
+	  {
+	      synchronized (stateLock)
+	      {
+	         if (inManagedTransaction)
+	            inManagedTransaction = false;
+	      }
+	      try
+	      {
+	         con.commit();
+	      }
+	      catch (SQLException e)
+	      {
+	         checkException(e);
+	      }
+	  }
+	  finally
+	  {
+		  unlock();
+	  }
    }
 
    public void rollback() throws ResourceException
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction)
-            inManagedTransaction = false;
-      }
-      try
-      {
-         con.rollback();
-      }
-      catch (SQLException e)
-      {
-         try
-         {
-            checkException(e);
-         }
-         catch (Exception e2)
-         {
-         }
-      }
+	  lock(); 
+	  try
+	  {
+	      synchronized (stateLock)
+	      {
+	         if (inManagedTransaction)
+	            inManagedTransaction = false;
+	      }
+	      try
+	      {
+	         con.rollback();
+	      }
+	      catch (SQLException e)
+	      {
+	         try
+	         {
+	            checkException(e);
+	         }
+	         catch (Exception e2)
+	         {
+	         }
+	      }
+	  }
+	  finally
+	  {
+		  unlock();
+	  }
    }
 
    public void begin() throws ResourceException
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction == false)
-         {
-            try
-            {
-               if (underlyingAutoCommit)
-               {
-                  underlyingAutoCommit = false;
-                  con.setAutoCommit(false);
-               }
-               checkState();
-               inManagedTransaction = true;
-            }
-            catch (SQLException e)
-            {
-               checkException(e);
-            }
-         }
-         else
-            throw new JBossResourceException("Trying to begin a nested local tx");
-      }
+	  lock();
+	  try
+	  {
+	      synchronized (stateLock)
+	      {
+	         if (inManagedTransaction == false)
+	         {
+	            try
+	            {
+	               if (underlyingAutoCommit)
+	               {
+	                  underlyingAutoCommit = false;
+	                  con.setAutoCommit(false);
+	               }
+	               checkState();
+	               inManagedTransaction = true;
+	            }
+	            catch (SQLException e)
+	            {
+	               checkException(e);
+	            }
+	         }
+	         else
+	            throw new JBossResourceException("Trying to begin a nested local tx");
+	      }
+	  }
+	  finally
+	  {
+		  unlock();
+	  }
    }
 
    Properties getProps()

Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java	2008-03-31 09:16:28 UTC (rev 71462)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java	2008-03-31 09:18:59 UTC (rev 71463)
@@ -108,81 +108,129 @@
 
    public void start(Xid xid, int flags) throws XAException
    {
-      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))
-         {
-            getLog().error("Start transaction failed for " + this);
-            broadcastConnectionError(e);  
-         }
-         
-         throw e;
-      }
-      
-      synchronized (stateLock)
-      {
-         currentXid = xid;
-         inManagedTransaction = true;
-      }
+	  lock();
+	  try
+	  {
+	      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))
+	         {
+	            getLog().error("Start transaction failed for " + this);
+	            broadcastConnectionError(e);  
+	         }
+	         
+	         throw e;
+	      }
+	      
+	      synchronized (stateLock)
+	      {
+	         currentXid = xid;
+	         inManagedTransaction = true;
+	      }
+	  }
+	  finally
+	  {
+		  unlock();
+	  }
    }
 
    public void end(Xid xid, int flags) throws XAException
    {
-      try
-      {
-         xaResource.end(xid, flags);
-         
-      }catch(XAException e)
-      {
-         getLog().error("End transaction failed for XAResource", 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))
-         {
-            inManagedTransaction = false;
-            currentXid = null;
-         }
-      }
+	  lock();
+	  try
+	  {
+	      try
+	      {
+	         xaResource.end(xid, flags);
+	         
+	      }catch(XAException e)
+	      {
+	         getLog().error("End transaction failed for XAResource", 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))
+	         {
+	            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
    {
-      xaResource.forget(xid);
+	  lock();
+	  try
+	  {
+		  xaResource.forget(xid);
+	  }
+	  finally
+	  {
+		  unlock();
+	  }
    }
 
    public Xid[] recover(int flag) throws XAException
@@ -222,66 +270,90 @@
 
    public void begin() throws ResourceException 
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction == false)
-         {
-            try
-            {
-               if (underlyingAutoCommit)
-               {
-                  underlyingAutoCommit = false;
-                  con.setAutoCommit(false);
-               }
-               checkState();
-               inManagedTransaction = true;
-            }
-            catch (SQLException e)
-            {
-               checkException(e);
-            }
-         }
-         else
-            throw new JBossResourceException("Trying to begin a nested local tx");
-      }
+	  lock();
+	  try
+	  {
+	      synchronized (stateLock)
+	      {
+	         if (inManagedTransaction == false)
+	         {
+	            try
+	            {
+	               if (underlyingAutoCommit)
+	               {
+	                  underlyingAutoCommit = false;
+	                  con.setAutoCommit(false);
+	               }
+	               checkState();
+	               inManagedTransaction = true;
+	            }
+	            catch (SQLException e)
+	            {
+	               checkException(e);
+	            }
+	         }
+	         else
+	            throw new JBossResourceException("Trying to begin a nested local tx");
+	      }
+	  }
+	  finally
+	  {
+		  unlock();
+	  }
    }
    public void commit() throws ResourceException
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction)
-            inManagedTransaction = false;
-      }
-      try
-      {
-         con.commit();
-      }
-      catch (SQLException e)
-      {
-         checkException(e);
-      }
+	  lock();
+	  try
+	  {
+	      synchronized (stateLock)
+	      {
+	         if (inManagedTransaction)
+	            inManagedTransaction = false;
+	      }
+	      try
+	      {
+	         con.commit();
+	      }
+	      catch (SQLException e)
+	      {
+	         checkException(e);
+	      }
+	  }
+	  finally
+	  {
+		  unlock();
+	  }
    }
    public void rollback() throws ResourceException
    {
-      synchronized (stateLock)
-      {
-         if (inManagedTransaction)
-            inManagedTransaction = false;
-      }
-      try
-      {
-         con.rollback();
-      }
-      catch (SQLException e)
-      {
-         try
-         {
-            checkException(e);
-         }
-         catch (Exception e2)
-         {
-         }
-      }
+	  lock();
+	  try
+	  {
+	      synchronized (stateLock)
+	      {
+	         if (inManagedTransaction)
+	            inManagedTransaction = false;
+	      }
+	      try
+	      {
+	         con.rollback();
+	      }
+	      catch (SQLException e)
+	      {
+	         try
+	         {
+	            checkException(e);
+	         }
+	         catch (Exception e2)
+	         {
+	         }
+	      }
+	  }
+	  finally
+	  {
+		  unlock();
+	  }
    }
 
 }




More information about the jboss-cvs-commits mailing list