diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/AbstractJDBCDriver.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/AbstractJDBCDriver.java index 79cc1e52ef..7f8c58f1fa 100644 --- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/AbstractJDBCDriver.java +++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/AbstractJDBCDriver.java @@ -23,6 +23,7 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Arrays; import java.util.Properties; import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider; @@ -76,8 +77,8 @@ public abstract class AbstractJDBCDriver { protected abstract void createSchema() throws SQLException; - protected void createTable(String schemaSql) throws SQLException { - createTableIfNotExists(connection, sqlProvider.getTableName(), schemaSql); + protected void createTable(String... schemaSqls) throws SQLException { + createTableIfNotExists(connection, sqlProvider.getTableName(), schemaSqls); } protected void connect() throws Exception { @@ -107,15 +108,17 @@ public abstract class AbstractJDBCDriver { } } - private static void createTableIfNotExists(Connection connection, String tableName, String sql) throws SQLException { + private static void createTableIfNotExists(Connection connection, String tableName, String... sqls) throws SQLException { logger.tracef("Validating if table %s didn't exist before creating", tableName); 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); + logger.tracef("Table %s did not exist, creating it with SQL=%s", tableName, Arrays.toString(sqls)); try (Statement statement = connection.createStatement()) { - statement.executeUpdate(sql); + for (String sql : sqls) { + statement.executeUpdate(sql); + } } } } diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/mysql/MySQLSQLProvider.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/mysql/MySQLSQLProvider.java index 7b2ab1f163..9b0c4e64b4 100644 --- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/mysql/MySQLSQLProvider.java +++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/mysql/MySQLSQLProvider.java @@ -25,7 +25,7 @@ public class MySQLSQLProvider extends GenericSQLProvider { private final String createFileTableSQL; - private final String createJournalTableSQL; + private final String[] createJournalTableSQL; private final String copyFileRecordByIdSQL; @@ -36,8 +36,10 @@ public class MySQLSQLProvider extends GenericSQLProvider { "(ID INTEGER NOT NULL AUTO_INCREMENT," + "FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA LONGBLOB, PRIMARY KEY(ID)) ENGINE=InnoDB;"; - createJournalTableSQL = "CREATE TABLE " + tableName + - "(id BIGINT,recordType SMALLINT,compactCount SMALLINT,txId BIGINT,userRecordType SMALLINT,variableSize INTEGER,record LONGBLOB,txDataSize INTEGER,txData LONGBLOB,txCheckNoRecords INTEGER,seq BIGINT) ENGINE=InnoDB;"; + createJournalTableSQL = new String[] { + "CREATE TABLE " + tableName + "(id BIGINT,recordType SMALLINT,compactCount SMALLINT,txId BIGINT,userRecordType SMALLINT,variableSize INTEGER,record LONGBLOB,txDataSize INTEGER,txData LONGBLOB,txCheckNoRecords INTEGER,seq BIGINT) ENGINE=InnoDB;", + "CREATE INDEX " + tableName + "_IDX ON " + tableName + " (id)" + }; copyFileRecordByIdSQL = " UPDATE " + tableName + ", (SELECT DATA AS FROM_DATA FROM " + tableName + " WHERE id=?) SELECT_COPY SET DATA=FROM_DATA WHERE id=?;"; @@ -54,7 +56,7 @@ public class MySQLSQLProvider extends GenericSQLProvider { } @Override - public String getCreateJournalTableSQL() { + public String[] getCreateJournalTableSQL() { return createJournalTableSQL; } diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/postgres/PostgresSQLProvider.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/postgres/PostgresSQLProvider.java index 254fa86c7d..fb0d34af25 100644 --- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/postgres/PostgresSQLProvider.java +++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/postgres/PostgresSQLProvider.java @@ -26,14 +26,17 @@ public class PostgresSQLProvider extends GenericSQLProvider { private final String createFileTableSQL; - private final String createJournalTableSQL; + private final String[] createJournalTableSQL; private PostgresSQLProvider(String tName) { super(tName.toLowerCase()); createFileTableSQL = "CREATE TABLE " + tableName + "(ID SERIAL, FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA OID, PRIMARY KEY(ID))"; - createJournalTableSQL = "CREATE TABLE " + tableName + "(id BIGINT,recordType SMALLINT,compactCount SMALLINT,txId BIGINT,userRecordType SMALLINT,variableSize INTEGER,record BYTEA,txDataSize INTEGER,txData BYTEA,txCheckNoRecords INTEGER,seq BIGINT)"; + createJournalTableSQL = new String[] { + "CREATE TABLE " + tableName + "(id BIGINT,recordType SMALLINT,compactCount SMALLINT,txId BIGINT,userRecordType SMALLINT,variableSize INTEGER,record BYTEA,txDataSize INTEGER,txData BYTEA,txCheckNoRecords INTEGER,seq BIGINT)", + "CREATE INDEX " + tableName + "_IDX ON " + tableName + " (id)" + }; } @Override @@ -42,7 +45,7 @@ public class PostgresSQLProvider extends GenericSQLProvider { } @Override - public String getCreateJournalTableSQL() { + public String[] getCreateJournalTableSQL() { return createJournalTableSQL; } diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/GenericSQLProvider.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/GenericSQLProvider.java index f7b37f7163..a7a4b478ba 100644 --- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/GenericSQLProvider.java +++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/GenericSQLProvider.java @@ -45,7 +45,7 @@ public class GenericSQLProvider implements SQLProvider { private final String dropFileTableSQL; - private final String createJournalTableSQL; + private final String[] createJournalTableSQL; private final String insertJournalRecordsSQL; @@ -84,7 +84,10 @@ public class GenericSQLProvider implements SQLProvider { dropFileTableSQL = "DROP TABLE " + tableName; - createJournalTableSQL = "CREATE TABLE " + tableName + "(id BIGINT,recordType SMALLINT,compactCount SMALLINT,txId BIGINT,userRecordType SMALLINT,variableSize INTEGER,record BLOB,txDataSize INTEGER,txData BLOB,txCheckNoRecords INTEGER,seq BIGINT)"; + createJournalTableSQL = new String[] { + "CREATE TABLE " + tableName + "(id BIGINT,recordType SMALLINT,compactCount SMALLINT,txId BIGINT,userRecordType SMALLINT,variableSize INTEGER,record BLOB,txDataSize INTEGER,txData BLOB,txCheckNoRecords INTEGER,seq BIGINT NOT NULL, PRIMARY KEY(seq))", + "CREATE INDEX " + tableName + "_IDX ON " + tableName + " (id)" + }; insertJournalRecordsSQL = "INSERT INTO " + tableName + "(id,recordType,compactCount,txId,userRecordType,variableSize,record,txDataSize,txData,txCheckNoRecords,seq) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)"; @@ -109,7 +112,7 @@ public class GenericSQLProvider implements SQLProvider { // Journal SQL Statements @Override - public String getCreateJournalTableSQL() { + public String[] getCreateJournalTableSQL() { return createJournalTableSQL; } diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/SQLProvider.java b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/SQLProvider.java index 1fae83ac28..21561ffaa4 100644 --- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/SQLProvider.java +++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/SQLProvider.java @@ -20,7 +20,7 @@ public interface SQLProvider { int getMaxBlobSize(); - String getCreateJournalTableSQL(); + String[] getCreateJournalTableSQL(); String getInsertJournalRecordsSQL(); diff --git a/pom.xml b/pom.xml index ff1cb407ae..3e7e52518c 100644 --- a/pom.xml +++ b/pom.xml @@ -1266,6 +1266,7 @@ **/.checkstyle **/.factorypath **/org.apache.activemq.artemis.cfg + **/nb-configuration.xml **/*.data **/*.bin