You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2012/05/30 22:17:35 UTC
svn commit: r1344442 - in /commons/proper/configuration/trunk/src:
changes/changes.xml
main/java/org/apache/commons/configuration/DatabaseConfiguration.java
Author: oheger
Date: Wed May 30 20:17:35 2012
New Revision: 1344442
URL: http://svn.apache.org/viewvc?rev=1344442&view=rev
Log:
[CONFIGURATION-483] DatabaseConfiguration now ensures that the result set is always closed.
Modified:
commons/proper/configuration/trunk/src/changes/changes.xml
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java
Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1344442&r1=1344441&r2=1344442&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Wed May 30 20:17:35 2012
@@ -35,6 +35,9 @@
DataConfiguration.get() now also works with String properties and if no
data type conversion is required.
</action>
+ <action dev="oheger" type="update" issue="CONFIGURATION-483">
+ DatabaseConfiguration now always closes the result set.
+ </action>
<action dev="oheger" type="update" issue="CONFIGURATION-482" due-to="Chris Seieroe">
The Import-Package section in the OSGi manifest now uses the
resolution:=optional directive for optional dependencies.
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java?rev=1344442&r1=1344441&r2=1344442&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DatabaseConfiguration.java Wed May 30 20:17:35 2012
@@ -219,6 +219,7 @@ public class DatabaseConfiguration exten
Connection conn = null;
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
@@ -232,7 +233,7 @@ public class DatabaseConfiguration exten
pstmt.setString(2, name);
}
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
List<Object> results = new ArrayList<Object>();
while (rs.next())
@@ -264,7 +265,7 @@ public class DatabaseConfiguration exten
}
finally
{
- close(conn, pstmt);
+ close(conn, pstmt, rs);
}
return result;
@@ -321,7 +322,7 @@ public class DatabaseConfiguration exten
finally
{
// clean up
- close(conn, pstmt);
+ close(conn, pstmt, null);
}
}
@@ -377,6 +378,7 @@ public class DatabaseConfiguration exten
Connection conn = null;
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
@@ -389,7 +391,7 @@ public class DatabaseConfiguration exten
pstmt.setString(1, name);
}
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
@@ -403,7 +405,7 @@ public class DatabaseConfiguration exten
finally
{
// clean up
- close(conn, pstmt);
+ close(conn, pstmt, rs);
}
return empty;
@@ -432,6 +434,7 @@ public class DatabaseConfiguration exten
Connection conn = null;
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
@@ -445,7 +448,7 @@ public class DatabaseConfiguration exten
pstmt.setString(2, name);
}
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
found = rs.next();
}
@@ -456,7 +459,7 @@ public class DatabaseConfiguration exten
finally
{
// clean up
- close(conn, pstmt);
+ close(conn, pstmt, rs);
}
return found;
@@ -506,7 +509,7 @@ public class DatabaseConfiguration exten
finally
{
// clean up
- close(conn, pstmt);
+ close(conn, pstmt, null);
}
}
@@ -552,7 +555,7 @@ public class DatabaseConfiguration exten
finally
{
// clean up
- close(conn, pstmt);
+ close(conn, pstmt, null);
}
fireEvent(EVENT_CLEAR, null, null, false);
}
@@ -580,6 +583,7 @@ public class DatabaseConfiguration exten
Connection conn = null;
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
@@ -592,7 +596,7 @@ public class DatabaseConfiguration exten
pstmt.setString(1, name);
}
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next())
{
@@ -606,7 +610,7 @@ public class DatabaseConfiguration exten
finally
{
// clean up
- close(conn, pstmt);
+ close(conn, pstmt, rs);
}
return keys.iterator();
@@ -641,16 +645,29 @@ public class DatabaseConfiguration exten
}
/**
- * Close a {@code Connection} and, {@code Statement}.
+ * Close the specified database objects.
* Avoid closing if null and hide any SQLExceptions that occur.
*
* @param conn The database connection to close
* @param stmt The statement to close
+ * @param rs the result set to close
*/
- private void close(Connection conn, Statement stmt)
+ private void close(Connection conn, Statement stmt, ResultSet rs)
{
try
{
+ if (rs != null)
+ {
+ rs.close();
+ }
+ }
+ catch (SQLException e)
+ {
+ getLogger().error("An error occurred on closing the result set", e);
+ }
+
+ try
+ {
if (stmt != null)
{
stmt.close();