diff options
author | David W. Miller | 2016-05-25 16:30:52 +0000 |
---|---|---|
committer | Angel Avila | 2016-05-25 16:30:52 +0000 |
commit | 38612afd41d6ff6086134ccbd2e962b182017146 (patch) | |
tree | 12bddd57d37710eda90423b3bd7c5e18d84b23b7 /plugins/org.eclipse.osee.orcs.db/src/org | |
parent | b4c738dbed7da24717a687c2c29f7d87db80500d (diff) | |
download | org.eclipse.osee-38612afd41d6ff6086134ccbd2e962b182017146.tar.gz org.eclipse.osee-38612afd41d6ff6086134ccbd2e962b182017146.tar.xz org.eclipse.osee-38612afd41d6ff6086134ccbd2e962b182017146.zip |
feature[ats_ATS284235]: Update constraint handling
Change-Id: I7c7daffcccf69ea1229d9109a71070157e761869
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.db/src/org')
3 files changed, 24 insertions, 2 deletions
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java index 9e4c7900fea..fe99006ff5d 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java @@ -31,6 +31,7 @@ import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime; import org.eclipse.osee.jdbc.JdbcClient; import org.eclipse.osee.jdbc.JdbcConnection; import org.eclipse.osee.jdbc.JdbcConstants; +import org.eclipse.osee.jdbc.JdbcDbType; import org.eclipse.osee.jdbc.JdbcStatement; import org.eclipse.osee.jdbc.JdbcTransaction; import org.eclipse.osee.jdbc.OseePreparedStatement; @@ -45,6 +46,8 @@ public class CreateBranchDatabaseTxCallable extends JdbcTransaction { private static final String INSERT_TX_DETAILS = "INSERT INTO osee_tx_details (branch_id, transaction_id, osee_comment, time, author, tx_type) VALUES (?,?,?,?,?,?)"; + private static final String UPDATE_BASELINE_BRANCH_TX = + "UPDATE osee_branch SET baseline_transaction_id = ? WHERE branch_id = ? AND baseline_transaction_id = 1"; // @formatter:off private static final String SELECT_ADDRESSING = "with\n"+ "txs as (select transaction_id, gamma_id, mod_type, app_id from osee_txs where branch_id = ? and transaction_id <= ?),\n\n"+ @@ -154,10 +157,16 @@ public class CreateBranchDatabaseTxCallable extends JdbcTransaction { Timestamp timestamp = GlobalTime.GreenwichMeanTimestamp(); int nextTransactionId = idManager.getNextTransactionId(); + int tobeTransactionId = nextTransactionId; + boolean needsUpdate = + jdbcClient.getDbType().equals(JdbcDbType.hsql) || jdbcClient.getDbType().equals(JdbcDbType.mysql); + if (needsUpdate) { + nextTransactionId = 1; + } int sourceTx; if (newBranchData.getBranchType().isSystemRootBranch()) { - sourceTx = nextTransactionId; + sourceTx = tobeTransactionId; } else { sourceTx = RelationalConstants.TRANSACTION_SENTINEL; @@ -188,10 +197,15 @@ public class CreateBranchDatabaseTxCallable extends JdbcTransaction { copyAccessRules(newBranchData.getUserArtifactId(), parentBranch, uuid); } + nextTransactionId = tobeTransactionId; jdbcClient.runPreparedUpdate(connection, INSERT_TX_DETAILS, uuid, nextTransactionId, newBranchData.getCreationComment(), timestamp, newBranchData.getUserArtifactId(), TransactionDetailsType.Baselined.getId()); + if (needsUpdate) { + jdbcClient.runPreparedUpdate(connection, UPDATE_BASELINE_BRANCH_TX, nextTransactionId, uuid); + } + populateBaseTransaction(0.30, connection, nextTransactionId, sourceTx); addMergeBranchEntry(0.20, connection); diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java index 5b5bb033179..899cea16498 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java @@ -17,6 +17,7 @@ import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.Pair; import org.eclipse.osee.jdbc.JdbcClient; import org.eclipse.osee.jdbc.JdbcConnection; +import org.eclipse.osee.jdbc.JdbcDbType; import org.eclipse.osee.jdbc.JdbcStatement; import org.eclipse.osee.logger.Log; import org.eclipse.osee.orcs.OrcsSession; @@ -36,7 +37,8 @@ public class PurgeBranchDatabaseCallable extends AbstractDatastoreTxCallable<Voi private final String DELETE_ARTIFACT_ACL_FROM_BRANCH = "DELETE FROM OSEE_ARTIFACT_ACL WHERE branch_id =?"; private final String SELECT_MERGE_BRANCHES = "SELECT merge_branch_id, archived FROM osee_merge, osee_branch where merge_branch_id = branch_id and (source_branch_id = ? or dest_branch_id = ?)"; - + private static final String TEMPORARY_BRANCH_UPDATE = + "UPDATE osee_branch SET baseline_transaction_id = 1 WHERE branch_id = ?"; private final BranchReadable toDelete; public PurgeBranchDatabaseCallable(Log logger, OrcsSession session, JdbcClient jdbcClient, BranchReadable toDelete) { @@ -59,6 +61,11 @@ public class PurgeBranchDatabaseCallable extends AbstractDatastoreTxCallable<Voi String sql = String.format("DELETE FROM %s WHERE branch_id = ?", sourceTableName); purgeFromTable(connection, sql, 0.20, branchUuid); + if (getJdbcClient().getDbType().equals(JdbcDbType.hsql) || getJdbcClient().getDbType().equals(JdbcDbType.mysql)) { + // update the branch table so that the baseline transaction ID of the given branch is '1' + purgeFromTable(connection, TEMPORARY_BRANCH_UPDATE, 0.01, branchUuid); + } + purgeFromTable(connection, DELETE_FROM_TX_DETAILS, 0.09, branchUuid); purgeFromTable(connection, DELETE_FROM_CONFLICT, 0.01, branchUuid); purgeFromTable(connection, DELETE_FROM_MERGE, 0.01, branchUuid); diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/resource/migration/V0.21.0_2015_02_25_1244__Osee_Versioning_Schema.sql b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/resource/migration/V0.21.0_2015_02_25_1244__Osee_Versioning_Schema.sql index 3b9fcc35c50..981c18d0e2c 100644 --- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/resource/migration/V0.21.0_2015_02_25_1244__Osee_Versioning_Schema.sql +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/resource/migration/V0.21.0_2015_02_25_1244__Osee_Versioning_Schema.sql @@ -106,6 +106,7 @@ CREATE INDEX OSEE_TX_DETAILS_B_TX_IDX ON OSEE_TX_DETAILS (BRANCH_ID, TRANSACTION INSERT INTO OSEE_TX_DETAILS (AUTHOR, TIME, OSEE_COMMENT, TX_TYPE, COMMIT_ART_ID, BRANCH_ID, TRANSACTION_ID) VALUES (-1,CURRENT_TIMESTAMP,'${osee.sys_root_name} Creation',1,NULL,1,1); ALTER TABLE OSEE_BRANCH ADD CONSTRAINT PARENT_TX_ID_FK1 FOREIGN KEY(PARENT_TRANSACTION_ID) REFERENCES OSEE_TX_DETAILS (TRANSACTION_ID); +ALTER TABLE OSEE_BRANCH ADD CONSTRAINT BASELINE_TX_ID_FK1 FOREIGN KEY(BASELINE_TRANSACTION_ID) REFERENCES OSEE_TX_DETAILS (TRANSACTION_ID) ${db.deferrable}; -- OSEE_PERMISSION CREATE TABLE OSEE_PERMISSION ( |