This closes #558
This commit is contained in:
commit
14516af7c7
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue