bug[TW18967]: Fix sql syntax error for PostgreSQL during db init Change-Id: I24eccd64b0f757ca4c9d525dd243fd5a8d2f1e0d
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/SqlTable.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/SqlTable.java index 46781b4..c9cb1e0 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/SqlTable.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/SqlTable.java
@@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.List; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.osee.framework.core.data.OseeCodeVersion; import org.eclipse.osee.framework.jdk.core.type.ChainingArrayList; import org.eclipse.osee.framework.jdk.core.type.NamedBase; import org.eclipse.osee.framework.jdk.core.util.Collections; @@ -136,21 +137,15 @@ public static final SqlColumn TX_DETAILS_TX_TYPE = TX_DETAILS_TABLE.addColumn("TX_TYPE", JDBCType.SMALLINT); public static final SqlColumn TX_DETAILS_TX_COMMIT_ART_ID = TX_DETAILS_TABLE.addColumn("COMMIT_ART_ID", JDBCType.BIGINT, true); + public static final SqlColumn TX_DETAILS_BUILD_ID = TX_DETAILS_TABLE.addColumn("BUILD_ID", JDBCType.BIGINT); static { TX_DETAILS_TABLE.setPrimaryKeyConstraint(TX_DETAILS_TRANSACTION_ID); TX_DETAILS_TABLE.setForeignKeyConstraint("BRANCH_ID_FK1", TX_DETAILS_TX_BRANCH_ID, BRANCH_TABLE, BRANCH_ID); TX_DETAILS_TABLE.createIndex("OSEE_TX_DETAILS_B_TX_IDX", true, TX_DETAILS_TX_BRANCH_ID.getName(), TX_DETAILS_TRANSACTION_ID.getName()); TX_DETAILS_TABLE.addStatement("INSERT INTO OSEE_TX_DETAILS (" + Collections.toString(",", - (TX_DETAILS_TABLE.columns)) + ") VALUES (1,1,-1,CURRENT_TIMESTAMP,'" + CoreBranches.SYSTEM_ROOT.getName() + " Creation',1,NULL)"); - - TX_DETAILS_TABLE.addStatement( - "ALTER TABLE " + BRANCH_TABLE.getName() + " ADD CONSTRAINT PARENT_TX_ID_FK1 FOREIGN KEY(" + BRANCH_PARENT_TRANSACTION_ID.getName() + ") REFERENCES " + TX_DETAILS_TABLE.getName() + "(" + TX_DETAILS_TRANSACTION_ID.getName() + ")"); - TX_DETAILS_TABLE.addStatement( - "ALTER TABLE " + BRANCH_TABLE.getName() + " ADD CONSTRAINT BASELINE_TX_ID_FK1 FOREIGN KEY(" + BRANCH_BASELINE_TRANSACTION_ID.getName() + ") REFERENCES " + TX_DETAILS_TABLE.getName() + "(" + TX_DETAILS_TRANSACTION_ID.getName() + ")"); - + (TX_DETAILS_TABLE.columns)) + ") VALUES (1,1,-1,CURRENT_TIMESTAMP,'" + CoreBranches.SYSTEM_ROOT.getName() + " Creation',1,NULL," + OseeCodeVersion.getVersionId() + ")"); } - public static final SqlColumn TX_DETAILS_BUILD_ID = TX_DETAILS_TABLE.addColumn("BUILD_ID", JDBCType.BIGINT); public static final SqlTable OSEE_PERMISSION_TABLE = new SqlTable("osee_permission", "per"); public static final SqlColumn OSEE_PERMISSION_PERMISSION_NAME = @@ -187,8 +182,8 @@ OSEE_BRANCH_ACL_TABLE.addColumn("PERMISSION_ID", JDBCType.INTEGER); static { OSEE_BRANCH_ACL_TABLE.setPrimaryKeyConstraint(OSEE_BRANCH_ACL_BRANCH_ID, OSEE_BRANCH_ACL_PRIVILEGE_ENTITY_ID); - OSEE_BRANCH_ACL_TABLE.setForeignKeyConstraint("BRANCH_ACL_FK", OSEE_BRANCH_ACL_BRANCH_ID, BRANCH_TABLE, BRANCH_ID, - "ON DELETE CASCADE"); + OSEE_BRANCH_ACL_TABLE.setForeignKeyConstraintCascadeDelete("BRANCH_ACL_FK", OSEE_BRANCH_ACL_BRANCH_ID, + BRANCH_TABLE, BRANCH_ID); OSEE_BRANCH_ACL_TABLE.setForeignKeyConstraint("BRANCH_ACL_PERM_FK", OSEE_BRANCH_ACL_PERMISSION_ID, OSEE_PERMISSION_TABLE, OSEE_PERMISSION_PERMISSION_ID); @@ -631,9 +626,9 @@ OSEE_OAUTH_AUTHORIZATION_TABLE.addVarCharColumn("CODE", 512, true); static { OSEE_OAUTH_AUTHORIZATION_TABLE.setPrimaryKeyConstraint(OSEE_OAUTH_AUTHORIZATION_ID); - OSEE_OAUTH_AUTHORIZATION_TABLE.setForeignKeyConstraint("OSEE_OAUTH_AUTH__CI_FK", - OSEE_OAUTH_AUTHORIZATION_CLIENT_ID, OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE, OSEE_OAUTH_CLIENT_CREDENTIAL_CLIENT_ID, - "ON DELETE CASCADE"); + OSEE_OAUTH_AUTHORIZATION_TABLE.setForeignKeyConstraintCascadeDelete("OSEE_OAUTH_AUTH__CI_FK", + OSEE_OAUTH_AUTHORIZATION_CLIENT_ID, OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE, + OSEE_OAUTH_CLIENT_CREDENTIAL_CLIENT_ID); OSEE_OAUTH_AUTHORIZATION_TABLE.createIndex("OSEE_OAUTH_AUTH__C_IDX", false, OSEE_OAUTH_AUTHORIZATION_CODE.getName()); } @@ -662,8 +657,8 @@ OSEE_OAUTH_TOKEN_TABLE.addVarCharColumn("TOKEN_TYPE", 255, true); static { OSEE_OAUTH_TOKEN_TABLE.setPrimaryKeyConstraint(OSEE_OAUTH_TOKEN_ID); - OSEE_OAUTH_TOKEN_TABLE.setForeignKeyConstraint("OSEE_OAUTH_TOKEN__CI_FK", OSEE_OAUTH_TOKEN_CLIENT_ID, - OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE, OSEE_OAUTH_CLIENT_CREDENTIAL_CLIENT_ID, "ON DELETE CASCADE"); + OSEE_OAUTH_TOKEN_TABLE.setForeignKeyConstraintCascadeDelete("OSEE_OAUTH_TOKEN__CI_FK", OSEE_OAUTH_TOKEN_CLIENT_ID, + OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE, OSEE_OAUTH_CLIENT_CREDENTIAL_CLIENT_ID); OSEE_OAUTH_TOKEN_TABLE.createIndex("OSEE_OAUTH_TOKEN__TK_IDX", false, OSEE_OAUTH_TOKEN_TOKEN_KEY.getName()); } @@ -673,7 +668,7 @@ private final ArrayList<String> constraints; private final ArrayList<String> statements; private final int indexLevel; - private boolean hasJoinTblSp = false; + private final boolean hasJoinTblSp; private String tableExtras; private SqlTable(String tableName, String aliasPrefix) { @@ -689,13 +684,7 @@ } private SqlTable(String tableName, String aliasPrefix, ObjectType objectType, int indexLevel) { - super(tableName); - this.aliasPrefix = aliasPrefix; - this.objectType = objectType; - columns = new ChainingArrayList<>(); - constraints = new ArrayList<>(); - statements = new ArrayList<>(); - this.indexLevel = indexLevel; + this(tableName, aliasPrefix, objectType, indexLevel, false); } private SqlTable(String tableName, String aliasPrefix, ObjectType objectType, int indexLevel, boolean hasJoinTblSp) { @@ -768,14 +757,9 @@ "CONSTRAINT " + constraintName + " FOREIGN KEY (" + column + ") REFERENCES " + refTable + " (" + refColumn + ")"); } - public void setForeignKeyConstraint(String constraintName, SqlColumn column, SqlTable refTable, SqlColumn refColumn, String extras) { + public void setForeignKeyConstraintCascadeDelete(String constraintName, SqlColumn column, SqlTable refTable, SqlColumn refColumn) { constraints.add( - "CONSTRAINT " + constraintName + " FOREIGN KEY (" + column + ") REFERENCES " + refTable + " (" + refColumn + ") " + extras); - } - - public void setForeignKeyConstraint(SqlColumn column, SqlTable refTable, SqlColumn refColumn) { - constraints.add( - "CONSTRAINT " + getName() + "FOREIGN KEY (" + column + ") REFERENCES " + refTable + " (" + refColumn + ")"); + "CONSTRAINT " + constraintName + " FOREIGN KEY (" + column + ") REFERENCES " + refTable + " (" + refColumn + ") ON DELETE CASCADE"); } public void setUniqueKeyConstraint(String constraintName, String columnName) { @@ -784,10 +768,10 @@ public void createIndex(String indexName, boolean hasIndexTablespace, String... columns) { if (hasIndexTablespace) { - statements.add("CREATE INDEX " + indexName + " ON " + getName() + " (" + Collections.toString(",", + addStatement("CREATE INDEX " + indexName + " ON " + getName() + " (" + Collections.toString(",", Arrays.asList(columns)) + ")"); } else { - statements.add("CREATE INDEX " + indexName + " ON " + getName() + " (" + Collections.toString(",", + addStatement("CREATE INDEX " + indexName + " ON " + getName() + " (" + Collections.toString(",", Arrays.asList(columns)) + ")"); } }
diff --git a/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/DatabaseCreation.java b/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/DatabaseCreation.java index 3be8869..08428f5 100644 --- a/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/DatabaseCreation.java +++ b/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/DatabaseCreation.java
@@ -13,9 +13,51 @@ package org.eclipse.osee.jdbc.internal; +import static org.eclipse.osee.framework.core.enums.SqlTable.ARTIFACT_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.ATTRIBUTE_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.BRANCH_BASELINE_TRANSACTION_ID; +import static org.eclipse.osee.framework.core.enums.SqlTable.BRANCH_PARENT_TRANSACTION_ID; +import static org.eclipse.osee.framework.core.enums.SqlTable.BRANCH_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.LDAP_DETAILS_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_ACTIVITY_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_ACTIVITY_TYPE_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_ARTIFACT_ACL_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_BRANCH_ACL_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_BRANCH_GROUP_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_CONFLICT_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_IMPORT_INDEX_MAP_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_IMPORT_MAP_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_IMPORT_SAVE_POINT_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_IMPORT_SOURCE_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_INFO_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_JOIN_ARTIFACT_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_JOIN_CHAR_ID_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_JOIN_CLEANUP_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_JOIN_EXPORT_IMPORT_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_JOIN_ID4_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_JOIN_ID_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_JOIN_TRANSACTION_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_KEY_VALUE_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_MERGE_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_OAUTH_AUTHORIZATION_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_OAUTH_TOKEN_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_PERMISSION_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_SEARCH_TAGS_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_SEQUENCE_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_SERVER_LOOKUP_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_SESSION_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.OSEE_TAG_GAMMA_QUEUE_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.RELATION_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.TUPLE2; +import static org.eclipse.osee.framework.core.enums.SqlTable.TUPLE3; +import static org.eclipse.osee.framework.core.enums.SqlTable.TUPLE4; +import static org.eclipse.osee.framework.core.enums.SqlTable.TXS_ARCHIVED_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.TXS_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.TX_DETAILS_TABLE; +import static org.eclipse.osee.framework.core.enums.SqlTable.TX_DETAILS_TRANSACTION_ID; import java.sql.JDBCType; import java.util.logging.Level; - import org.eclipse.osee.framework.core.enums.SqlColumn; import org.eclipse.osee.framework.core.enums.SqlTable; import org.eclipse.osee.framework.jdk.core.util.Collections; @@ -45,46 +87,52 @@ public void createDataStore() { dropTables(); - createTable(SqlTable.ARTIFACT_TABLE); - createTable(SqlTable.ATTRIBUTE_TABLE); - createTable(SqlTable.RELATION_TABLE); - createTable(SqlTable.BRANCH_TABLE); - createTable(SqlTable.TXS_TABLE); - createTable(SqlTable.TXS_ARCHIVED_TABLE); - createTable(SqlTable.TX_DETAILS_TABLE); - createTable(SqlTable.OSEE_PERMISSION_TABLE); - createTable(SqlTable.OSEE_ARTIFACT_ACL_TABLE); - createTable(SqlTable.OSEE_BRANCH_ACL_TABLE); - createTable(SqlTable.OSEE_SEARCH_TAGS_TABLE); - createTable(SqlTable.OSEE_TAG_GAMMA_QUEUE_TABLE); - createTable(SqlTable.OSEE_SEQUENCE_TABLE); - createTable(SqlTable.OSEE_INFO_TABLE); - createTable(SqlTable.OSEE_MERGE_TABLE); - createTable(SqlTable.OSEE_CONFLICT_TABLE); - createTable(SqlTable.OSEE_JOIN_EXPORT_IMPORT_TABLE); - createTable(SqlTable.OSEE_IMPORT_SOURCE_TABLE); - createTable(SqlTable.OSEE_IMPORT_SAVE_POINT_TABLE); - createTable(SqlTable.OSEE_IMPORT_MAP_TABLE); - createTable(SqlTable.OSEE_IMPORT_INDEX_MAP_TABLE); - createTable(SqlTable.OSEE_JOIN_ARTIFACT_TABLE); - createTable(SqlTable.OSEE_JOIN_ID_TABLE); - createTable(SqlTable.OSEE_JOIN_CLEANUP_TABLE); - createTable(SqlTable.OSEE_JOIN_CHAR_ID_TABLE); - createTable(SqlTable.OSEE_JOIN_TRANSACTION_TABLE); - createTable(SqlTable.OSEE_BRANCH_GROUP_TABLE); - createTable(SqlTable.LDAP_DETAILS_TABLE); - createTable(SqlTable.TUPLE2); - createTable(SqlTable.TUPLE3); - createTable(SqlTable.TUPLE4); - createTable(SqlTable.OSEE_KEY_VALUE_TABLE); - createTable(SqlTable.OSEE_JOIN_ID4_TABLE); - createTable(SqlTable.OSEE_SERVER_LOOKUP_TABLE); - createTable(SqlTable.OSEE_SESSION_TABLE); - createTable(SqlTable.OSEE_ACTIVITY_TYPE_TABLE); - createTable(SqlTable.OSEE_ACTIVITY_TABLE); - createTable(SqlTable.OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE); - createTable(SqlTable.OSEE_OAUTH_AUTHORIZATION_TABLE); - createTable(SqlTable.OSEE_OAUTH_TOKEN_TABLE); + createTable(ARTIFACT_TABLE); + createTable(ATTRIBUTE_TABLE); + createTable(RELATION_TABLE); + createTable(BRANCH_TABLE); + createTable(TXS_TABLE); + createTable(TXS_ARCHIVED_TABLE); + createTable(TX_DETAILS_TABLE); + + alterForeignKeyConstraint("PARENT_TX_ID_FK1", BRANCH_TABLE, BRANCH_PARENT_TRANSACTION_ID, TX_DETAILS_TABLE, + TX_DETAILS_TRANSACTION_ID, ""); + deferredForeignKeyConstraint("BASELINE_TX_ID_FK1", BRANCH_TABLE, BRANCH_BASELINE_TRANSACTION_ID, TX_DETAILS_TABLE, + TX_DETAILS_TRANSACTION_ID); + + createTable(OSEE_PERMISSION_TABLE); + createTable(OSEE_ARTIFACT_ACL_TABLE); + createTable(OSEE_BRANCH_ACL_TABLE); + createTable(OSEE_SEARCH_TAGS_TABLE); + createTable(OSEE_TAG_GAMMA_QUEUE_TABLE); + createTable(OSEE_SEQUENCE_TABLE); + createTable(OSEE_INFO_TABLE); + createTable(OSEE_MERGE_TABLE); + createTable(OSEE_CONFLICT_TABLE); + createTable(OSEE_JOIN_EXPORT_IMPORT_TABLE); + createTable(OSEE_IMPORT_SOURCE_TABLE); + createTable(OSEE_IMPORT_SAVE_POINT_TABLE); + createTable(OSEE_IMPORT_MAP_TABLE); + createTable(OSEE_IMPORT_INDEX_MAP_TABLE); + createTable(OSEE_JOIN_ARTIFACT_TABLE); + createTable(OSEE_JOIN_ID_TABLE); + createTable(OSEE_JOIN_CLEANUP_TABLE); + createTable(OSEE_JOIN_CHAR_ID_TABLE); + createTable(OSEE_JOIN_TRANSACTION_TABLE); + createTable(OSEE_BRANCH_GROUP_TABLE); + createTable(LDAP_DETAILS_TABLE); + createTable(TUPLE2); + createTable(TUPLE3); + createTable(TUPLE4); + createTable(OSEE_KEY_VALUE_TABLE); + createTable(OSEE_JOIN_ID4_TABLE); + createTable(OSEE_SERVER_LOOKUP_TABLE); + createTable(OSEE_SESSION_TABLE); + createTable(OSEE_ACTIVITY_TYPE_TABLE); + createTable(OSEE_ACTIVITY_TABLE); + createTable(OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE); + createTable(OSEE_OAUTH_AUTHORIZATION_TABLE); + createTable(OSEE_OAUTH_TOKEN_TABLE); } private void dropTable(SqlTable table) { @@ -96,61 +144,61 @@ } private void dropTables() { - dropConstraint(SqlTable.TX_DETAILS_TABLE, "BRANCH_ID_FK1"); - dropConstraint(SqlTable.OSEE_ARTIFACT_ACL_TABLE, "ARTIFACT_ACL_PERM_FK"); - dropConstraint(SqlTable.OSEE_BRANCH_ACL_TABLE, "BRANCH_ACL_PERM_FK"); - dropConstraint(SqlTable.OSEE_PERMISSION_TABLE, SqlTable.OSEE_PERMISSION_TABLE.getName() + "_PK"); - dropConstraint(SqlTable.OSEE_MERGE_TABLE, "OSEE_MERGE__MBI_FK"); - dropConstraint(SqlTable.OSEE_MERGE_TABLE, "OSEE_MERGE__DBI_FK"); - dropConstraint(SqlTable.OSEE_BRANCH_ACL_TABLE, "BRANCH_ACL_FK"); - dropConstraint(SqlTable.BRANCH_TABLE, SqlTable.BRANCH_TABLE.getName() + "_PK"); - dropConstraint(SqlTable.TUPLE2, SqlTable.TUPLE2.getName() + "_PK"); - dropConstraint(SqlTable.OSEE_IMPORT_SAVE_POINT_TABLE, "OSEE_IMP_SAVE_POINT_II_FK"); - dropConstraint(SqlTable.OSEE_IMPORT_MAP_TABLE, "OSEE_IMPORT_MAP_II_FK"); - dropConstraint(SqlTable.OSEE_IMPORT_INDEX_MAP_TABLE, "OSEE_IMPORT_INDEX_MAP_II_FK"); - dropConstraint(SqlTable.OSEE_OAUTH_AUTHORIZATION_TABLE, "OSEE_OAUTH_AUTH__CI_FK"); - dropConstraint(SqlTable.OSEE_OAUTH_TOKEN_TABLE, "OSEE_OAUTH_TOKEN__CI_FK"); + dropConstraint(TX_DETAILS_TABLE, "BRANCH_ID_FK1"); + dropConstraint(OSEE_ARTIFACT_ACL_TABLE, "ARTIFACT_ACL_PERM_FK"); + dropConstraint(OSEE_BRANCH_ACL_TABLE, "BRANCH_ACL_PERM_FK"); + dropConstraint(OSEE_PERMISSION_TABLE, OSEE_PERMISSION_TABLE.getName() + "_PK"); + dropConstraint(OSEE_MERGE_TABLE, "OSEE_MERGE__MBI_FK"); + dropConstraint(OSEE_MERGE_TABLE, "OSEE_MERGE__DBI_FK"); + dropConstraint(OSEE_BRANCH_ACL_TABLE, "BRANCH_ACL_FK"); + dropConstraint(BRANCH_TABLE, BRANCH_TABLE.getName() + "_PK"); + dropConstraint(TUPLE2, TUPLE2.getName() + "_PK"); + dropConstraint(OSEE_IMPORT_SAVE_POINT_TABLE, "OSEE_IMP_SAVE_POINT_II_FK"); + dropConstraint(OSEE_IMPORT_MAP_TABLE, "OSEE_IMPORT_MAP_II_FK"); + dropConstraint(OSEE_IMPORT_INDEX_MAP_TABLE, "OSEE_IMPORT_INDEX_MAP_II_FK"); + dropConstraint(OSEE_OAUTH_AUTHORIZATION_TABLE, "OSEE_OAUTH_AUTH__CI_FK"); + dropConstraint(OSEE_OAUTH_TOKEN_TABLE, "OSEE_OAUTH_TOKEN__CI_FK"); - dropTable(SqlTable.OSEE_ARTIFACT_ACL_TABLE); - dropTable(SqlTable.OSEE_BRANCH_ACL_TABLE); - dropTable(SqlTable.OSEE_CONFLICT_TABLE); - dropTable(SqlTable.OSEE_MERGE_TABLE); - dropTable(SqlTable.ARTIFACT_TABLE); - dropTable(SqlTable.ATTRIBUTE_TABLE); - dropTable(SqlTable.RELATION_TABLE); - dropTable(SqlTable.BRANCH_TABLE); - dropTable(SqlTable.TXS_TABLE); - dropTable(SqlTable.TXS_ARCHIVED_TABLE); - dropTable(SqlTable.TX_DETAILS_TABLE); - dropTable(SqlTable.OSEE_PERMISSION_TABLE); - dropTable(SqlTable.OSEE_SEARCH_TAGS_TABLE); - dropTable(SqlTable.OSEE_TAG_GAMMA_QUEUE_TABLE); - dropTable(SqlTable.OSEE_SEQUENCE_TABLE); - dropTable(SqlTable.OSEE_INFO_TABLE); - dropTable(SqlTable.OSEE_JOIN_EXPORT_IMPORT_TABLE); - dropTable(SqlTable.OSEE_IMPORT_SOURCE_TABLE); - dropTable(SqlTable.OSEE_IMPORT_SAVE_POINT_TABLE); - dropTable(SqlTable.OSEE_IMPORT_MAP_TABLE); - dropTable(SqlTable.OSEE_IMPORT_INDEX_MAP_TABLE); - dropTable(SqlTable.OSEE_JOIN_ARTIFACT_TABLE); - dropTable(SqlTable.OSEE_JOIN_ID_TABLE); - dropTable(SqlTable.OSEE_JOIN_CLEANUP_TABLE); - dropTable(SqlTable.OSEE_JOIN_CHAR_ID_TABLE); - dropTable(SqlTable.OSEE_JOIN_TRANSACTION_TABLE); - dropTable(SqlTable.OSEE_BRANCH_GROUP_TABLE); - dropTable(SqlTable.LDAP_DETAILS_TABLE); - dropTable(SqlTable.TUPLE2); - dropTable(SqlTable.TUPLE3); - dropTable(SqlTable.TUPLE4); - dropTable(SqlTable.OSEE_KEY_VALUE_TABLE); - dropTable(SqlTable.OSEE_JOIN_ID4_TABLE); - dropTable(SqlTable.OSEE_SERVER_LOOKUP_TABLE); - dropTable(SqlTable.OSEE_SESSION_TABLE); - dropTable(SqlTable.OSEE_ACTIVITY_TYPE_TABLE); - dropTable(SqlTable.OSEE_ACTIVITY_TABLE); - dropTable(SqlTable.OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE); - dropTable(SqlTable.OSEE_OAUTH_AUTHORIZATION_TABLE); - dropTable(SqlTable.OSEE_OAUTH_TOKEN_TABLE); + dropTable(OSEE_ARTIFACT_ACL_TABLE); + dropTable(OSEE_BRANCH_ACL_TABLE); + dropTable(OSEE_CONFLICT_TABLE); + dropTable(OSEE_MERGE_TABLE); + dropTable(ARTIFACT_TABLE); + dropTable(ATTRIBUTE_TABLE); + dropTable(RELATION_TABLE); + dropTable(BRANCH_TABLE); + dropTable(TXS_TABLE); + dropTable(TXS_ARCHIVED_TABLE); + dropTable(TX_DETAILS_TABLE); + dropTable(OSEE_PERMISSION_TABLE); + dropTable(OSEE_SEARCH_TAGS_TABLE); + dropTable(OSEE_TAG_GAMMA_QUEUE_TABLE); + dropTable(OSEE_SEQUENCE_TABLE); + dropTable(OSEE_INFO_TABLE); + dropTable(OSEE_JOIN_EXPORT_IMPORT_TABLE); + dropTable(OSEE_IMPORT_SOURCE_TABLE); + dropTable(OSEE_IMPORT_SAVE_POINT_TABLE); + dropTable(OSEE_IMPORT_MAP_TABLE); + dropTable(OSEE_IMPORT_INDEX_MAP_TABLE); + dropTable(OSEE_JOIN_ARTIFACT_TABLE); + dropTable(OSEE_JOIN_ID_TABLE); + dropTable(OSEE_JOIN_CLEANUP_TABLE); + dropTable(OSEE_JOIN_CHAR_ID_TABLE); + dropTable(OSEE_JOIN_TRANSACTION_TABLE); + dropTable(OSEE_BRANCH_GROUP_TABLE); + dropTable(LDAP_DETAILS_TABLE); + dropTable(TUPLE2); + dropTable(TUPLE3); + dropTable(TUPLE4); + dropTable(OSEE_KEY_VALUE_TABLE); + dropTable(OSEE_JOIN_ID4_TABLE); + dropTable(OSEE_SERVER_LOOKUP_TABLE); + dropTable(OSEE_SESSION_TABLE); + dropTable(OSEE_ACTIVITY_TYPE_TABLE); + dropTable(OSEE_ACTIVITY_TABLE); + dropTable(OSEE_OAUTH_CLIENT_CREDENTIAL_TABLE); + dropTable(OSEE_OAUTH_AUTHORIZATION_TABLE); + dropTable(OSEE_OAUTH_TOKEN_TABLE); } public String columnToSql(SqlColumn column) { @@ -192,6 +240,7 @@ } public void createTable(SqlTable table) { + StringBuilder sql = new StringBuilder(200); sql.append("CREATE TABLE "); sql.append(table.getName()); @@ -205,7 +254,9 @@ } sql.append(Collections.toString(",\n\t", table.getConstraints())); sql.append("\n)"); - if (jdbcClient.getDbType().equals(JdbcDbType.oracle)) { + + JdbcDbType dbType = jdbcClient.getDbType(); + if (dbType.equals(JdbcDbType.oracle)) { if (table.getIndexLevel() != -1) { sql.append("\tORGANIZATION INDEX "); if (table.getIndexLevel() > 0) { @@ -216,26 +267,25 @@ sql.append("\n\t" + table.getTableExtras()); } } - sql.append("\n\n"); - for (int i = 0; i < table.getStatements().size(); i++) { - if (table.getStatements().get(i).contains("BASELINE_TX_ID_FK1")) { - if (jdbcClient.getDbType().equals(JdbcDbType.oracle) || jdbcClient.getDbType().equals( - JdbcDbType.postgresql)) { - table.getStatements().set(i, table.getStatements().get(i) + "DEFERRABLE INITIALLY DEFERRED"); - } - } - } - - sql.append("\n"); jdbcClient.runPreparedUpdate(sql.toString()); + for (String statement : table.getStatements()) { - if (statement.contains("CREATE INDEX")) { - if (jdbcClient.getDbType().equals(JdbcDbType.oracle)) { - statement += " TABLESPACE osee_index"; - } + if (statement.contains("CREATE INDEX") && dbType.equals(JdbcDbType.oracle)) { + statement += " TABLESPACE osee_index"; } jdbcClient.runPreparedUpdate(statement); } - } -} + + private void deferredForeignKeyConstraint(String constraintName, SqlTable table, SqlColumn column, SqlTable refTable, SqlColumn refColumn) { + String defered = jdbcClient.getDbType().matches(JdbcDbType.oracle, + JdbcDbType.postgresql) ? " DEFERRABLE INITIALLY DEFERRED" : ""; + alterForeignKeyConstraint(constraintName, table, column, refTable, refColumn, defered); + } + + private void alterForeignKeyConstraint(String constraintName, SqlTable table, SqlColumn column, SqlTable refTable, SqlColumn refColumn, String defered) { + String statement = String.format("ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY(%s) REFERENCES %s(%s)%s", table, + constraintName, column, refTable, refColumn, defered); + jdbcClient.runPreparedUpdate(statement); + } +} \ No newline at end of file