[jboss-cvs] JBossAS SVN: r57135 - trunk/connector/src/main/org/jboss/resource/adapter/jdbc/xa

Adrian Brock adrian_brock at jboss.org
Wed Sep 27 07:44:13 EDT 2006


Don't do this log and throw anti-pattern!

I've spent nearly three years trying to tidy this up in the 
connector source. It is still a mess with duplicate and
redundant (e.g. logging errors/warns during close)
logging all over the place. :-(

The connection manager will log this anyway:

      public void connectionErrorOccurred(ConnectionEvent ce)
      {
         if (state == NORMAL)
         {
            if (ce != null)
            {
               Throwable t = ce.getException();
               if (t == null)
                  t = new Exception("No exception was reported");
               log.warn("Connection error occured: " + this, t);
            }
            else
            {
               Throwable t = new Exception("No exception was reported");
               log.warn("Unknown Connection error occured: " + this, t);
            }
         }

As a general rule, if you don't deal with the exception,
i.e. you rethrow it, don't log it at anything above DEBUG.

On Mon, 2006-09-25 at 11:59 -0400, jboss-cvs-commits at lists.jboss.org
wrote:
> Author: weston.price at jboss.com
> Date: 2006-09-25 11:59:38 -0400 (Mon, 25 Sep 2006)
> New Revision: 57135
> 
> Modified:
>    trunk/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java
> Log:
> [JBAS-3693] Do not return managed connection to pool in the case of an exception
> on XAResource.end().
> 
> 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	2006-09-25 13:41:52 UTC (rev 57134)
> +++ trunk/connector/src/main/org/jboss/resource/adapter/jdbc/xa/XAManagedConnection.java	2006-09-25 15:59:38 UTC (rev 57135)
> @@ -142,7 +142,19 @@
>  
>     public void end(Xid xid, int flags) throws XAException
>     {
> -      xaResource.end(xid, flags);
> +      
> +      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)
> 
> _______________________________________________
> jboss-cvs-commits mailing list
> jboss-cvs-commits at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jboss-cvs-commits
-- 
xxxxxxxxxxxxxxxxxxxxxxxxxxx
Adrian Brock
Chief Scientist
JBoss a division of Red Hat
xxxxxxxxxxxxxxxxxxxxxxxxxxx




More information about the jboss-cvs-commits mailing list