You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/06/03 16:03:08 UTC
[2/2] activemq-artemis git commit: Ensure ResultSet is closed on
table operation
Ensure ResultSet is closed on table operation
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/2932a2a7
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/2932a2a7
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/2932a2a7
Branch: refs/heads/master
Commit: 2932a2a711f49a89aa1c6f61e2d28ffe003e92bf
Parents: 4d51f4d
Author: Martyn Taylor <mt...@redhat.com>
Authored: Fri Jun 3 16:30:14 2016 +0100
Committer: Clebert Suconic <cl...@apache.org>
Committed: Fri Jun 3 12:03:00 2016 -0400
----------------------------------------------------------------------
.../activemq/artemis/jdbc/store/JDBCUtils.java | 19 ++++++++++++++-----
.../artemis/tests/util/ActiveMQTestBase.java | 13 ++++++++++---
2 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2932a2a7/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java
----------------------------------------------------------------------
diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java
index c63e323..61293af 100644
--- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java
+++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/JDBCUtils.java
@@ -65,12 +65,21 @@ public class JDBCUtils {
public static void createTableIfNotExists(Connection connection, String tableName, String sql) throws SQLException {
logger.tracef("Validating if table %s didn't exist before creating", tableName);
- ResultSet rs = connection.getMetaData().getTables(null, null, tableName, null);
- if (!rs.next()) {
- logger.tracef("Table %s did not exist, creating it with SQL=%s", tableName, sql);
- Statement statement = connection.createStatement();
- statement.executeUpdate(sql);
+ try {
+ connection.setAutoCommit(false);
+ try (ResultSet rs = connection.getMetaData().getTables(null, null, tableName, null)) {
+ if (rs != null && !rs.next()) {
+ logger.tracef("Table %s did not exist, creating it with SQL=%s", tableName, sql);
+ Statement statement = connection.createStatement();
+ statement.executeUpdate(sql);
+ }
+ }
+ connection.commit();
}
+ catch (SQLException e) {
+ connection.rollback();
+ }
+
}
public static SQLProvider getSQLProvider(String driverClass, String tableName) {
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/2932a2a7/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
index 31ad1d6..064091d 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java
@@ -43,6 +43,7 @@ import java.net.ServerSocket;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.ResultSet;
+import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
@@ -467,10 +468,16 @@ public abstract class ActiveMQTestBase extends Assert {
Statement statement = connection.createStatement();
try {
for (String tableName : tableNames) {
+ connection.setAutoCommit(false);
SQLProvider sqlProvider = JDBCUtils.getSQLProvider(getJDBCClassName(), tableName);
- ResultSet rs = connection.getMetaData().getTables(null, null, sqlProvider.getTableName(), null);
- if (rs.next()) {
- statement.execute("DROP TABLE " + sqlProvider.getTableName());
+ try (ResultSet rs = connection.getMetaData().getTables(null, null, sqlProvider.getTableName(), null)) {
+ if (rs.next()) {
+ statement.execute("DROP TABLE " + sqlProvider.getTableName());
+ }
+ connection.commit();
+ }
+ catch (SQLException e) {
+ connection.rollback();
}
}
}