jpauserset now working.
[utils] / test / enterprise / src / main / java / org / wamblee / support / persistence / DatabaseUtils.java
index 2beb9f1133124bbc518bf5f003728bd70316f17b..1b300433d8bc49ca268dc964d5db902b28e1231f 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.wamblee.support.persistence;
 
 import java.sql.Connection;
@@ -75,7 +90,7 @@ public class DatabaseUtils {
         final String[] tables = getTableNames(aTables);
         executeInTransaction(new JdbcUnitOfWork<Void>() {
             public Void execute(Connection aConnection) throws Exception {
-                for (int i = tables.length - 1; i >= 0; i--) {
+                for (int i = tables.length-1; i >= 0; i--) {
                     aOperation.execute(tables[i]);
                 }
                 return null;
@@ -131,15 +146,20 @@ public class DatabaseUtils {
         LOG.fine("Getting database table names to clean (schema: '" +
             SCHEMA_PATTERN + "'");
 
-        ResultSet tables = dataSource.getConnection().getMetaData().getTables(
-            null, SCHEMA_PATTERN, "%", new String[] { "TABLE" });
-        while (tables.next()) {
-            String table = tables.getString("TABLE_NAME");
-            if (aSelection.accept(table)) {
-                result.add(table);
+        Connection connection = dataSource.getConnection();
+        try {
+            ResultSet tables = connection.getMetaData().getTables(null,
+                SCHEMA_PATTERN, "%", new String[] { "TABLE" });
+            while (tables.next()) {
+                String table = tables.getString("TABLE_NAME");
+                if (aSelection.accept(table)) {
+                    result.add(table);
+                }
             }
+            return (String[]) result.toArray(new String[0]);
+        } finally {
+            connection.close();
         }
-        return (String[]) result.toArray(new String[0]);
     }
 
     public void emptyTables() throws Exception {
@@ -348,7 +368,7 @@ public class DatabaseUtils {
         if (aObject instanceof Integer) {
             aStatement.setInt(aIndex, ((Integer) aObject).intValue());
         } else if (aObject instanceof Long) {
-            aStatement.setLong(aIndex, ((Integer) aObject).longValue());
+            aStatement.setLong(aIndex, ((Long) aObject).longValue());
         } else if (aObject instanceof String) {
             aStatement.setString(aIndex, (String) aObject);
         } else {