ARTEMIS-852: Add PK and index to create journal table DDL script
This commit is contained in:
parent
530852b28d
commit
95e88dd22f
|
@ -23,6 +23,7 @@ import java.sql.DriverManager;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider;
|
import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider;
|
||||||
|
@ -76,8 +77,8 @@ public abstract class AbstractJDBCDriver {
|
||||||
|
|
||||||
protected abstract void createSchema() throws SQLException;
|
protected abstract void createSchema() throws SQLException;
|
||||||
|
|
||||||
protected void createTable(String schemaSql) throws SQLException {
|
protected void createTable(String... schemaSqls) throws SQLException {
|
||||||
createTableIfNotExists(connection, sqlProvider.getTableName(), schemaSql);
|
createTableIfNotExists(connection, sqlProvider.getTableName(), schemaSqls);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void connect() throws Exception {
|
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);
|
logger.tracef("Validating if table %s didn't exist before creating", tableName);
|
||||||
try {
|
try {
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
try (ResultSet rs = connection.getMetaData().getTables(null, null, tableName, null)) {
|
try (ResultSet rs = connection.getMetaData().getTables(null, null, tableName, null)) {
|
||||||
if (rs != null && !rs.next()) {
|
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()) {
|
try (Statement statement = connection.createStatement()) {
|
||||||
statement.executeUpdate(sql);
|
for (String sql : sqls) {
|
||||||
|
statement.executeUpdate(sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class MySQLSQLProvider extends GenericSQLProvider {
|
||||||
|
|
||||||
private final String createFileTableSQL;
|
private final String createFileTableSQL;
|
||||||
|
|
||||||
private final String createJournalTableSQL;
|
private final String[] createJournalTableSQL;
|
||||||
|
|
||||||
private final String copyFileRecordByIdSQL;
|
private final String copyFileRecordByIdSQL;
|
||||||
|
|
||||||
|
@ -36,8 +36,10 @@ public class MySQLSQLProvider extends GenericSQLProvider {
|
||||||
"(ID INTEGER NOT NULL AUTO_INCREMENT," +
|
"(ID INTEGER NOT NULL AUTO_INCREMENT," +
|
||||||
"FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA LONGBLOB, PRIMARY KEY(ID)) ENGINE=InnoDB;";
|
"FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA LONGBLOB, PRIMARY KEY(ID)) ENGINE=InnoDB;";
|
||||||
|
|
||||||
createJournalTableSQL = "CREATE TABLE " + tableName +
|
createJournalTableSQL = new String[] {
|
||||||
"(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 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 +
|
copyFileRecordByIdSQL = " UPDATE " + tableName + ", (SELECT DATA AS FROM_DATA FROM " + tableName +
|
||||||
" WHERE id=?) SELECT_COPY SET DATA=FROM_DATA WHERE id=?;";
|
" WHERE id=?) SELECT_COPY SET DATA=FROM_DATA WHERE id=?;";
|
||||||
|
@ -54,7 +56,7 @@ public class MySQLSQLProvider extends GenericSQLProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCreateJournalTableSQL() {
|
public String[] getCreateJournalTableSQL() {
|
||||||
return createJournalTableSQL;
|
return createJournalTableSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,17 @@ public class PostgresSQLProvider extends GenericSQLProvider {
|
||||||
|
|
||||||
private final String createFileTableSQL;
|
private final String createFileTableSQL;
|
||||||
|
|
||||||
private final String createJournalTableSQL;
|
private final String[] createJournalTableSQL;
|
||||||
|
|
||||||
private PostgresSQLProvider(String tName) {
|
private PostgresSQLProvider(String tName) {
|
||||||
super(tName.toLowerCase());
|
super(tName.toLowerCase());
|
||||||
createFileTableSQL = "CREATE TABLE " + tableName +
|
createFileTableSQL = "CREATE TABLE " + tableName +
|
||||||
"(ID SERIAL, FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA OID, PRIMARY KEY(ID))";
|
"(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
|
@Override
|
||||||
|
@ -42,7 +45,7 @@ public class PostgresSQLProvider extends GenericSQLProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCreateJournalTableSQL() {
|
public String[] getCreateJournalTableSQL() {
|
||||||
return createJournalTableSQL;
|
return createJournalTableSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class GenericSQLProvider implements SQLProvider {
|
||||||
|
|
||||||
private final String dropFileTableSQL;
|
private final String dropFileTableSQL;
|
||||||
|
|
||||||
private final String createJournalTableSQL;
|
private final String[] createJournalTableSQL;
|
||||||
|
|
||||||
private final String insertJournalRecordsSQL;
|
private final String insertJournalRecordsSQL;
|
||||||
|
|
||||||
|
@ -84,7 +84,10 @@ public class GenericSQLProvider implements SQLProvider {
|
||||||
|
|
||||||
dropFileTableSQL = "DROP TABLE " + tableName;
|
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 (?,?,?,?,?,?,?,?,?,?,?)";
|
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
|
// Journal SQL Statements
|
||||||
@Override
|
@Override
|
||||||
public String getCreateJournalTableSQL() {
|
public String[] getCreateJournalTableSQL() {
|
||||||
return createJournalTableSQL;
|
return createJournalTableSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public interface SQLProvider {
|
||||||
|
|
||||||
int getMaxBlobSize();
|
int getMaxBlobSize();
|
||||||
|
|
||||||
String getCreateJournalTableSQL();
|
String[] getCreateJournalTableSQL();
|
||||||
|
|
||||||
String getInsertJournalRecordsSQL();
|
String getInsertJournalRecordsSQL();
|
||||||
|
|
||||||
|
|
1
pom.xml
1
pom.xml
|
@ -1266,6 +1266,7 @@
|
||||||
<exclude>**/.checkstyle</exclude>
|
<exclude>**/.checkstyle</exclude>
|
||||||
<exclude>**/.factorypath</exclude>
|
<exclude>**/.factorypath</exclude>
|
||||||
<exclude>**/org.apache.activemq.artemis.cfg</exclude>
|
<exclude>**/org.apache.activemq.artemis.cfg</exclude>
|
||||||
|
<exclude>**/nb-configuration.xml</exclude>
|
||||||
<!-- activemq5 unit tests exclude -->
|
<!-- activemq5 unit tests exclude -->
|
||||||
<exclude>**/*.data</exclude>
|
<exclude>**/*.data</exclude>
|
||||||
<exclude>**/*.bin</exclude>
|
<exclude>**/*.bin</exclude>
|
||||||
|
|
Loading…
Reference in New Issue