ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boisv...@apache.org
Subject svn commit: r697176 - /ode/trunk/engine/src/main/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableModule.java
Date Fri, 19 Sep 2008 18:28:38 GMT
Author: boisvert
Date: Fri Sep 19 11:28:38 2008
New Revision: 697176

URL: http://svn.apache.org/viewvc?rev=697176&view=rev
Log:
Properly close all PrepareStatements, ResultSets

Modified:
    ode/trunk/engine/src/main/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableModule.java

Modified: ode/trunk/engine/src/main/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableModule.java
URL: http://svn.apache.org/viewvc/ode/trunk/engine/src/main/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableModule.java?rev=697176&r1=697175&r2=697176&view=diff
==============================================================================
--- ode/trunk/engine/src/main/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableModule.java
(original)
+++ ode/trunk/engine/src/main/java/org/apache/ode/bpel/extvar/jdbc/JdbcExternalVariableModule.java
Fri Sep 19 11:28:38 2008
@@ -193,15 +193,18 @@
 
                 Column c = dbev.new Column(name, colname, key.equalsIgnoreCase("yes"), gtype,
expression);
                 ResultSet cmd = metaData.getColumns(null, dbev.schema, dbev.table, colname);
+                try {
                 if (cmd.next()) {
                     c.dataType = cmd.getInt("DATA_TYPE");
                     c.nullok = cmd.getInt("NULLABLE") != 0;
                 } else
                     throw new ExternalVariableModuleException("External variable " + evarId
+ " referenced "
                             + "non-existant column \"" + colname + "\"!");
+                } finally {
+                    cmd.close();
+                }
 
                 dbev.addColumn(c);
-
             }
 
             if (dbev.numColumns() == 0)
@@ -310,12 +313,13 @@
 
     int execUpdate(DbExternalVariable dbev, RowKey key, RowVal values) throws SQLException
{
         Connection conn = dbev.dataSource.getConnection();
+        PreparedStatement stmt = null;
         try {
             if (__log.isDebugEnabled()) {
                 __log.debug("execUpdate: key=" + key + " values=" + values);
                 __log.debug("Prepare statement: " + dbev.update);
             }
-            PreparedStatement stmt = conn.prepareStatement(dbev.update);
+            stmt = conn.prepareStatement(dbev.update);
             int idx = 1;
             for (Column c : dbev._updcolumns) {
                 Object val = values.get(c.name);
@@ -338,6 +342,7 @@
             }
             return stmt.executeUpdate();
         } finally {
+            if (stmt != null) stmt.close();
             conn.close();
         }
     }
@@ -356,9 +361,10 @@
         
         RowVal ret = dbev.new RowVal();
         Connection conn = dbev.dataSource.getConnection();
+        PreparedStatement stmt = null;
         try {
             if (__log.isDebugEnabled()) __log.debug("Prepare statement: " + dbev.select);
-            PreparedStatement stmt = conn.prepareStatement(dbev.select);
+            stmt = conn.prepareStatement(dbev.select);
             int idx = 1;
             for (Object k : rowkey) {
                 if (__log.isDebugEnabled()) __log.debug("Set key parameter "+idx+": "+k);
@@ -387,6 +393,7 @@
                 rs.close();
             }
         } finally {
+            if (stmt != null) stmt.close();
             conn.close();
         }
 
@@ -395,6 +402,7 @@
 
     RowKey execInsert(DbExternalVariable dbev, Locator locator, RowKey keys, RowVal values)
throws SQLException {
         Connection conn = dbev.dataSource.getConnection();
+        PreparedStatement stmt = null; 
         try {
             if (__log.isDebugEnabled()) {
                 __log.debug("execInsert: keys=" + keys + " values=" + values);
@@ -403,7 +411,7 @@
                 __log.debug("_autoColNames: " + ObjectPrinter.stringifyNvList(dbev._autoColNames));
             }
 
-            PreparedStatement stmt = keys.missingDatabaseGeneratedValues() 
+            stmt = keys.missingDatabaseGeneratedValues() 
                 ? conn.prepareStatement(dbev.insert, dbev._autoColNames) 
                 : conn.prepareStatement(dbev.insert);
 
@@ -430,6 +438,7 @@
             if (keys.missingDatabaseGeneratedValues() ) {
                 // With JDBC 3, we can get the values of the key columns (if the db supports
it)
                 ResultSet keyRS = stmt.getGeneratedKeys();
+                try {
                 if (keyRS == null) 
                     throw new SQLException("Database did not return generated keys");
                 keyRS.next();
@@ -438,9 +447,13 @@
                     if (__log.isDebugEnabled()) __log.debug("Generated key "+ck.name+": "+value);
                     keys.put(ck.name, value);
                 }
+                } finally {
+                    keyRS.close();
+                }
             } 
             return keys;
         } finally {
+            if (stmt != null) stmt.close();
             conn.close();
         }
     }



Mime
View raw message