[jboss-cvs] JBoss Messaging SVN: r2726 - in trunk/src/main/org/jboss: messaging/core/plugin and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 24 15:25:06 EDT 2007


Author: timfox
Date: 2007-05-24 15:25:06 -0400 (Thu, 24 May 2007)
New Revision: 2726

Modified:
   trunk/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManager.java
   trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/plugin/JDBCSupport.java
   trunk/src/main/org/jboss/messaging/core/plugin/postoffice/DefaultPostOffice.java
Log:
http://jira.jboss.com/jira/browse/JBMESSAGING-511


Modified: trunk/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManager.java	2007-05-24 18:58:03 UTC (rev 2725)
+++ trunk/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManager.java	2007-05-24 19:25:06 UTC (rev 2726)
@@ -25,6 +25,7 @@
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -139,18 +140,9 @@
       }
       finally
       {
-         if (rs != null)
-         {
-            rs.close();
-         }
-         if (ps != null)
-         {
-            ps.close();
-         }
-         if (conn != null)
-         {
-            conn.close();
-         }
+      	closeResultSet(rs);
+      	closeStatement(ps);
+      	closeConnection(conn);
          wrap.end();
       }     
    }
@@ -185,29 +177,29 @@
             {
                String statement = (String)iter.next();
                
+               Statement st = null;
+               
                try
                {
                   if (log.isTraceEnabled()) { log.trace("Executing: " + statement); }
                   
-                  conn.createStatement().executeUpdate(statement);
+                  st = conn.createStatement();
+                  
+                  st.executeUpdate(statement);
                }
                catch (SQLException e) 
                {
                   log.debug("Failed to execute " + statement, e);
-               }  
+               }
+               finally
+               {
+               	closeStatement(st);
+               }
             }      
          }
          finally
          {
-            if (conn != null)
-            {
-               try
-               {
-                  conn.close();
-               }
-               catch (Throwable t)
-               {}
-            }
+         	closeConnection(conn);
             tx.end();
          }    
       }

Modified: trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java	2007-05-24 18:58:03 UTC (rev 2725)
+++ trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java	2007-05-24 19:25:06 UTC (rev 2726)
@@ -234,40 +234,13 @@
       }
       finally
       {
-         if (rs != null)
-         {
-            try
-            {
-               rs.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (st != null)
-         {
-            try
-            {
-               st.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeResultSet(rs);
+      	closeStatement(st);
+      	closeConnection(conn);
          wrap.end();
       }
    }
-   
+         
                
    // Related to counters
    // ===================
@@ -354,26 +327,8 @@
       }
       finally
       {
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(ps);
+      	closeConnection(conn);
          wrap.end();
       }     
    }
@@ -496,36 +451,9 @@
       }
       finally
       {
-         if (rs != null)
-         {
-            try
-            {
-               rs.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeResultSet(rs);
+      	closeStatement(ps);
+      	closeConnection(conn);
          wrap.end();
       }
    }  
@@ -726,46 +654,10 @@
       }
       finally
       {
-         if (psInsertReference != null)
-         {
-            try
-            {
-               psInsertReference.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psInsertMessage != null)
-         {
-            try
-            {
-               psInsertMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psUpdateMessage != null)
-         {
-            try
-            {
-               psUpdateMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
+      	closeStatement(psInsertReference);
+      	closeStatement(psInsertMessage);
+      	closeStatement(psUpdateMessage);
+      	closeConnection(conn);         
          try
          {
             wrap.end();                       
@@ -902,46 +794,10 @@
       }
       finally
       {
-         if (psDeleteReference != null)
-         {
-            try
-            {
-               psDeleteReference.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psDeleteMessage != null)
-         {
-            try
-            {
-               psDeleteMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psUpdateMessage != null)
-         {
-            try
-            {
-               psUpdateMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
+      	closeStatement(psDeleteReference);
+      	closeStatement(psDeleteMessage);
+      	closeStatement(psUpdateMessage);
+      	closeConnection(conn);         
          try
          {
             wrap.end();
@@ -992,26 +848,8 @@
       }
       finally
       {
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(ps);
+      	closeConnection(conn);       
          wrap.end();
       }
    }
@@ -1171,36 +1009,9 @@
       }
       finally
       {
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (ps2 != null)
-         {
-            try
-            {
-               ps2.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(ps);
+      	closeStatement(ps2);
+      	closeConnection(conn);       
          wrap.end();
       }
    }
@@ -1271,26 +1082,8 @@
       }
       finally
       {
-         if (psUpdateReference != null)
-         {
-            try
-            {
-               psUpdateReference.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
+      	closeStatement(psUpdateReference);
+      	closeConnection(conn);       
          wrap.end();
       }    
    }
@@ -1357,36 +1150,9 @@
       }
       finally
       {
-         if (rs != null)
-         {
-            try
-            {
-               rs.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeResultSet(rs);
+      	closeStatement(ps);
+      	closeConnection(conn);       
          wrap.end();
       }      
    }   
@@ -1478,36 +1244,9 @@
       }
       finally
       {
-         if (rs != null)
-         {
-            try
-            {
-               rs.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeResultSet(rs);
+      	closeStatement(ps);      	
+      	closeConnection(conn);       
          wrap.end();
       }      
    }   
@@ -1583,36 +1322,9 @@
          }
          finally
          {
-            if (psReference != null)
-            {
-               try
-               {
-                  psReference.close();
-               }
-               catch (Throwable t)
-               {
-               }
-            }
-            if (psMessage != null)
-            {
-               try
-               {
-                  psMessage.close();
-               }
-               catch (Throwable t)
-               {
-               }
-            }
-            if (conn != null)
-            {
-               try
-               {
-                  conn.close();
-               }
-               catch (Throwable t)
-               {
-               }
-            }
+         	closeStatement(psReference);
+         	closeStatement(psMessage);
+         	closeConnection(conn);  
             try
             {
                wrap.end();
@@ -1655,26 +1367,8 @@
       }
       finally
       {
-         if (psReference != null)
-         {
-            try
-            {
-               psReference.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }         
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
+      	closeStatement(psReference);
+      	closeConnection(conn);
          wrap.end();                        
       }  
    }
@@ -1750,46 +1444,10 @@
          }
          finally
          {
-            if (psReference != null)
-            {
-               try
-               {
-                  psReference.close();
-               }
-               catch (Throwable t)
-               {
-               }
-            }
-            if (psUpdate != null)
-            {
-               try
-               {
-                  psUpdate.close();
-               }
-               catch (Throwable t)
-               {
-               }
-            }
-            if (psMessage != null)
-            {
-               try
-               {
-                  psMessage.close();
-               }
-               catch (Throwable t)
-               {
-               }
-            }
-            if (conn != null)
-            {
-               try
-               {
-                  conn.close();
-               }
-               catch (Throwable t)
-               {
-               }
-            }
+         	closeStatement(psReference);
+         	closeStatement(psUpdate);
+         	closeStatement(psMessage);
+         	closeConnection(conn);
             try
             {
                wrap.end();               
@@ -1837,36 +1495,9 @@
       }
       finally
       {
-         if (rs != null)
-         {
-            try
-            {
-               rs.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (st != null)
-         {
-            try
-            {
-               st.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeResultSet(rs);
+      	closeStatement(st);
+      	closeConnection(conn);
          wrap.end();
       }
    }
@@ -1903,36 +1534,9 @@
       }
       finally
       {
-         if (rs != null)
-         {
-            try
-            {
-               rs.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (st != null)
-         {
-            try
-            {
-               st.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeResultSet(rs);
+      	closeStatement(st);
+      	closeConnection(conn);
          wrap.end();
       }
    }
@@ -2244,67 +1848,12 @@
       }
       finally
       {
-         if (psReference != null)
-         {
-            try
-            {
-               psReference.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psInsertMessage != null)
-         {
-            try
-            {
-               psInsertMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psIncMessage != null)
-         {
-            try
-            {
-               psIncMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psDecMessage != null)
-         {
-            try
-            {
-               psDecMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psDeleteMessage != null)
-         {
-            try
-            {
-               psDeleteMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               if (trace) { log.trace("Closing connection"); }
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(psReference);
+      	closeStatement(psInsertMessage);
+      	closeStatement(psIncMessage);
+      	closeStatement(psDecMessage);
+      	closeStatement(psDeleteMessage);
+      	closeConnection(conn);        
          try
          {
             wrap.end();                        
@@ -2431,36 +1980,9 @@
       }
       finally
       {
-         if (psDeleteMessage != null)
-         {
-            try
-            {
-               psDeleteMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psUpdateMessage != null)
-         {
-            try
-            {
-               psUpdateMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(psDeleteMessage);
+      	closeStatement(psUpdateMessage);
+      	closeConnection(conn);        
          try
          {
             wrap.end();
@@ -2689,46 +2211,10 @@
       }
       finally
       {
-         if (psReference != null)
-         {
-            try
-            {
-               psReference.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psInsertMessage != null)
-         {
-            try
-            {
-               psInsertMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psUpdateMessage != null)
-         {
-            try
-            {
-               psUpdateMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(psReference);
+      	closeStatement(psInsertMessage);
+      	closeStatement(psUpdateMessage);
+      	closeConnection(conn);         
          try
          {
             wrap.end();            
@@ -2851,36 +2337,9 @@
       }
       finally
       {
-         if (psDeleteMessage != null)
-         {
-            try
-            {
-               psDeleteMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (psUpdateMessage != null)
-         {
-            try
-            {
-               psUpdateMessage.close();
-            }
-            catch (Throwable t)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(psDeleteMessage);
+      	closeStatement(psUpdateMessage);      	
+      	closeConnection(conn);                
          try
          {
             wrap.end();
@@ -2934,17 +2393,7 @@
                   new Integer(formatID), "<byte-array>");
             log.trace(s + (rows == -1 ? " failed!" : " inserted " + rows + " row(s)"));
          }
-         try
-         {
-            if (ps != null)
-            {
-               ps.close();
-            }
-         }
-         catch (Throwable e)
-         {
-            //Ignore
-         }
+         closeStatement(ps);      
       }
    }
    
@@ -2966,17 +2415,7 @@
       }
       finally
       {
-         try
-         {
-            if (ps != null)
-            {
-               ps.close();
-            }
-         }
-         catch (Throwable e)
-         {
-            //Ignore
-         }
+      	closeStatement(ps);    
       }
    }  
    
@@ -3075,16 +2514,7 @@
       }
       finally
       {
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(ps);
       }
    }
    
@@ -3122,16 +2552,7 @@
       }
       finally
       {
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeStatement(ps);
       }
    }
    
@@ -3649,36 +3070,9 @@
       }
       finally
       {
-         if (rs != null)
-         {
-            try
-            {
-               rs.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (ps != null)
-         {
-            try
-            {
-               ps.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Throwable e)
-            {
-            }
-         }
+      	closeResultSet(rs);
+      	closeStatement(ps);
+      	closeConnection(conn);
          wrap.end();
       }
    }

Modified: trunk/src/main/org/jboss/messaging/core/plugin/JDBCSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/JDBCSupport.java	2007-05-24 18:58:03 UTC (rev 2725)
+++ trunk/src/main/org/jboss/messaging/core/plugin/JDBCSupport.java	2007-05-24 19:25:06 UTC (rev 2726)
@@ -22,6 +22,7 @@
 package org.jboss.messaging.core.plugin;
 
 import java.sql.Connection;
+import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collections;
@@ -199,6 +200,60 @@
    {
       return false;
    }
+   
+   protected void closeResultSet(ResultSet rs)
+   {
+   	if (rs != null)
+      {
+         try
+         {
+            rs.close();
+         }
+         catch (Throwable e)
+         {
+         	if (trace)
+         	{
+         		log.trace("Failed to close result set", e);
+         	}
+         }
+      }
+   }
+   
+   protected void closeStatement(Statement st)
+   {
+   	if (st != null)
+      {
+         try
+         {
+         	st.close();
+         }
+         catch (Throwable e)
+         {
+         	if (trace)
+         	{
+         		log.trace("Failed to close statement", e);
+         	}
+         }
+      }
+   }
+   
+   protected void closeConnection(Connection conn)
+   {
+   	if (conn != null)
+      {
+         try
+         {
+         	conn.close();
+         }
+         catch (Throwable e)
+         {
+         	if (trace)
+         	{
+         		log.trace("Failed to close statement", e);
+         	}
+         }
+      }
+   }
    // Private ----------------------------------------------------------------
               
    private void createSchema() throws Exception

Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/DefaultPostOffice.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/DefaultPostOffice.java	2007-05-24 18:58:03 UTC (rev 2725)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/DefaultPostOffice.java	2007-05-24 19:25:06 UTC (rev 2726)
@@ -712,14 +712,8 @@
       }
       finally
       {
-         if (ps != null)
-         {
-            ps.close();
-         }
-         if (conn != null)
-         {
-            conn.close();
-         }
+      	closeStatement(ps);
+      	closeConnection(conn);
          wrap.end();
       }
    }
@@ -747,14 +741,8 @@
       }
       finally
       {
-         if (ps != null)
-         {
-            ps.close();
-         }
-         if (conn != null)
-         {
-            conn.close();
-         }
+      	closeStatement(ps);
+      	closeConnection(conn);
          wrap.end();
       }
    }




More information about the jboss-cvs-commits mailing list