This closes #558
This commit is contained in:
commit
14516af7c7
artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store
artemis-server/src/test/java/org/apache/activemq/artemis/tests/util
|
@ -65,12 +65,21 @@ public class JDBCUtils {
|
||||||
|
|
||||||
public static void createTableIfNotExists(Connection connection, String tableName, String sql) throws SQLException {
|
public static void createTableIfNotExists(Connection connection, String tableName, String sql) throws SQLException {
|
||||||
logger.tracef("Validating if table %s didn't exist before creating", tableName);
|
logger.tracef("Validating if table %s didn't exist before creating", tableName);
|
||||||
ResultSet rs = connection.getMetaData().getTables(null, null, tableName, null);
|
try {
|
||||||
if (!rs.next()) {
|
connection.setAutoCommit(false);
|
||||||
logger.tracef("Table %s did not exist, creating it with SQL=%s", tableName, sql);
|
try (ResultSet rs = connection.getMetaData().getTables(null, null, tableName, null)) {
|
||||||
Statement statement = connection.createStatement();
|
if (rs != null && !rs.next()) {
|
||||||
statement.executeUpdate(sql);
|
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) {
|
public static SQLProvider getSQLProvider(String driverClass, String tableName) {
|
||||||
|
|
|
@ -43,6 +43,7 @@ import java.net.ServerSocket;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.Driver;
|
import java.sql.Driver;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -467,10 +468,16 @@ public abstract class ActiveMQTestBase extends Assert {
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
try {
|
try {
|
||||||
for (String tableName : tableNames) {
|
for (String tableName : tableNames) {
|
||||||
|
connection.setAutoCommit(false);
|
||||||
SQLProvider sqlProvider = JDBCUtils.getSQLProvider(getJDBCClassName(), tableName);
|
SQLProvider sqlProvider = JDBCUtils.getSQLProvider(getJDBCClassName(), tableName);
|
||||||
ResultSet rs = connection.getMetaData().getTables(null, null, sqlProvider.getTableName(), null);
|
try (ResultSet rs = connection.getMetaData().getTables(null, null, sqlProvider.getTableName(), null)) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
statement.execute("DROP TABLE " + sqlProvider.getTableName());
|
statement.execute("DROP TABLE " + sqlProvider.getTableName());
|
||||||
|
}
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
connection.rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue