Author: tv
Date: Thu Aug  5 18:14:08 2010
New Revision: 982720

URL: http://svn.apache.org/viewvc?rev=982720&view=rev
Log:
Fix TORQUE-123: Statement is left open when Exception is thrown in the 
QueryDataSet constructor

Modified:
    db/torque/village/trunk/src/java/com/workingdogs/village/DataSet.java
    db/torque/village/trunk/src/java/com/workingdogs/village/QueryDataSet.java
    db/torque/village/trunk/xdocs/changes.xml

Modified: db/torque/village/trunk/src/java/com/workingdogs/village/DataSet.java
URL: 
http://svn.apache.org/viewvc/db/torque/village/trunk/src/java/com/workingdogs/village/DataSet.java?rev=982720&r1=982719&r2=982720&view=diff
==============================================================================
--- db/torque/village/trunk/src/java/com/workingdogs/village/DataSet.java 
(original)
+++ db/torque/village/trunk/src/java/com/workingdogs/village/DataSet.java Thu 
Aug  5 18:14:08 2010
@@ -21,12 +21,10 @@ package com.workingdogs.village;
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintWriter;
-
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-
 import java.util.Vector;
 
 /**
@@ -343,20 +341,41 @@ public abstract class DataSet
     {
         releaseRecords();
         this.schema = null;
+        
+        SQLException sqlEx = null;
 
-        if (this.resultSet != null)
+        try 
         {
-            resultSet().close();
-        }
+                       if (this.resultSet != null)
+                       {
+                           resultSet().close();
+                       }
+               }
+        catch (SQLException e)
+        {
+                       sqlEx = e;
+               }
 
-        this.resultSet = null;
+               this.resultSet = null;
 
-        if (this.stmt != null)
+        try 
         {
-            this.stmt.close();
-        }
+                       if (this.stmt != null)
+                       {
+                           this.stmt.close();
+                       }
+               } 
+        catch (SQLException e) 
+               {
+                       sqlEx = e;
+               }
 
         this.conn = null;
+        
+        if (sqlEx != null)
+        {
+               throw sqlEx;
+        }
     }
 
     /**

Modified: 
db/torque/village/trunk/src/java/com/workingdogs/village/QueryDataSet.java
URL: 
http://svn.apache.org/viewvc/db/torque/village/trunk/src/java/com/workingdogs/village/QueryDataSet.java?rev=982720&r1=982719&r2=982720&view=diff
==============================================================================
--- db/torque/village/trunk/src/java/com/workingdogs/village/QueryDataSet.java 
(original)
+++ db/torque/village/trunk/src/java/com/workingdogs/village/QueryDataSet.java 
Thu Aug  5 18:14:08 2010
@@ -76,10 +76,38 @@ public class QueryDataSet
         this.conn = conn;
 
         selectString = new StringBuffer(selectStmt);
-        stmt = conn.createStatement();
-        resultSet = stmt.executeQuery(selectStmt);
-        schema = new Schema();
-        schema.populate(resultSet.getMetaData(), null);
+        
+        try 
+        { 
+               stmt = conn.createStatement(); 
+               resultSet = stmt.executeQuery(selectStmt); 
+               schema = new Schema(); 
+               schema.populate(resultSet.getMetaData(), null); 
+        } 
+        catch (Exception e) 
+        { 
+               try 
+               {
+                       close();
+               } 
+               catch (SQLException ignored)
+               {
+                       // Do nothing
+               } 
+
+               if (e instanceof SQLException)
+               {
+                       throw (SQLException)e;
+               }
+               else if (e instanceof DataSetException)
+               {
+                       throw (DataSetException)e;
+               }
+               else
+               {
+                       throw new SQLException("QueryDataSet: exception 
caught.", e);
+               }
+        }         
     }
 
     /**

Modified: db/torque/village/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/db/torque/village/trunk/xdocs/changes.xml?rev=982720&r1=982719&r2=982720&view=diff
==============================================================================
--- db/torque/village/trunk/xdocs/changes.xml (original)
+++ db/torque/village/trunk/xdocs/changes.xml Thu Aug  5 18:14:08 2010
@@ -25,6 +25,9 @@
 
   <body>
   <release version="3.3.1-SNAPSHOT" date="in SVN">
+    <action type="fix" dev="tv" issue="TORQUE-123">
+      Fixed: Statement is left open when Exception is thrown in the 
QueryDataSet constructor.
+    </action>
     <action type="fix" dev="tv" issue="TORQUE-8">
       Fixed: Village does not close every resultSet it opens.
     </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to