Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn F. Cook2011-08-02 16:05:35 -0400
committerRyan D. Brooks2011-08-02 16:05:35 -0400
commitd760f7f97c3373160d59c7cf07dd5d25350f4932 (patch)
treeb559bc0da1e9d3edc0a454059951541ece343255 /plugins/org.eclipse.osee.framework.database
parent694def2db13d9e45fe118fd4b8f508471582ca5e (diff)
downloadorg.eclipse.osee-d760f7f97c3373160d59c7cf07dd5d25350f4932.tar.gz
org.eclipse.osee-d760f7f97c3373160d59c7cf07dd5d25350f4932.tar.xz
org.eclipse.osee-d760f7f97c3373160d59c7cf07dd5d25350f4932.zip
refinement[bgz_350331]: Migrate ConsolidateRelations (BLAM) to server side command line
Diffstat (limited to 'plugins/org.eclipse.osee.framework.database')
-rw-r--r--plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/ConsolidateRelationsTxOperation.java285
1 files changed, 285 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/ConsolidateRelationsTxOperation.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/ConsolidateRelationsTxOperation.java
new file mode 100644
index 0000000000..645e3c2abf
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/ConsolidateRelationsTxOperation.java
@@ -0,0 +1,285 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.database.operation;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.osee.framework.core.enums.ModificationType;
+import org.eclipse.osee.framework.core.enums.TxChange;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.core.exception.OseeStateException;
+import org.eclipse.osee.framework.core.operation.OperationLogger;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.AbstractDbTxOperation;
+import org.eclipse.osee.framework.database.core.ConnectionHandler;
+import org.eclipse.osee.framework.database.core.ExportImportJoinQuery;
+import org.eclipse.osee.framework.database.core.IOseeStatement;
+import org.eclipse.osee.framework.database.core.JoinUtility;
+import org.eclipse.osee.framework.database.core.OseeConnection;
+import org.eclipse.osee.framework.database.internal.Activator;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class ConsolidateRelationsTxOperation extends AbstractDbTxOperation {
+ private static final String SELECT_RELATIONS =
+ "select * from osee_relation_link order by rel_link_type_id, a_art_id, b_art_id, gamma_id";
+
+ private static final String SELECT_RELATION_ADDRESSING =
+ "select txs.*, idj.id1 as net_gamma_id from osee_join_export_import idj, osee_txs txs where idj.query_id = ? and idj.id2 = txs.gamma_id order by net_gamma_id, transaction_id, id2";
+
+ private static final String UPDATE_TXS_GAMMAS =
+ "update osee_txs set gamma_id = ?, mod_type = ?, tx_current = ? where transaction_id = ? and gamma_id = ?";
+
+ private static final String DELETE_TXS = "delete from osee_txs where transaction_id = ? and gamma_id = ?";
+
+ private static final String DELETE_RELATIONS = "delete from osee_relation_link where gamma_id = ?";
+
+ private final List<Long[]> relationDeleteData = new ArrayList<Long[]>(14000);
+ private final List<Long> obsoleteGammas = new ArrayList<Long>();
+ private final StringBuilder addressingBackup = new StringBuilder(100000);
+ private final List<Object[]> addressingToDelete = new ArrayList<Object[]>(13000);
+ private final List<Object[]> updateAddressingData = new ArrayList<Object[]>(5000);
+ private ExportImportJoinQuery gammaJoin;
+ private OseeConnection connection;
+ private int previousRelationTypeId;
+ private int previousArtifactAId;
+ private int previousArtiafctBId;
+ private long netGamma;
+ private String netRationale;
+ boolean materiallyDifferent;
+ boolean updateAddressing;
+ private int counter;
+ private IOseeStatement chStmt;
+
+ long previousNetGammaId;
+ long previousObsoleteGammaId;
+ int previousTransactionId;
+ ModificationType netModType;
+ TxChange netTxCurrent;
+
+ public ConsolidateRelationsTxOperation(IOseeDatabaseService databaseService, OperationLogger logger) {
+ super(databaseService, "Consolidate Relations", Activator.PLUGIN_ID, logger);
+ }
+
+ private void init() throws OseeCoreException, IOException {
+ previousRelationTypeId = -1;
+ previousArtifactAId = -1;
+ previousArtiafctBId = -1;
+ materiallyDifferent = true;
+ relationDeleteData.clear();
+ obsoleteGammas.clear();
+ updateAddressingData.clear();
+ addressingToDelete.clear();
+ addressingBackup.delete(0, 999999999);
+ updateAddressing = false;
+
+ previousNetGammaId = -1;
+ previousTransactionId = -1;
+ chStmt = ConnectionHandler.getStatement();
+ gammaJoin = JoinUtility.createExportImportJoinQuery();
+
+ counter = 0;
+ }
+
+ @Override
+ protected void doTxWork(IProgressMonitor monitor, OseeConnection connection) throws OseeCoreException {
+ this.connection = connection;
+ try {
+ log("Consolidating relations:");
+ init();
+
+ findObsoleteRelations();
+
+ log("gamma join size: " + gammaJoin.size());
+
+ determineAffectedAddressing();
+
+ updateGammas();
+ log("...done.");
+ } catch (IOException ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ }
+
+ private void findObsoleteRelations() throws OseeCoreException {
+ try {
+ chStmt.runPreparedQuery(10000, SELECT_RELATIONS);
+ while (chStmt.next()) {
+ int relationTypeId = chStmt.getInt("rel_link_type_id");
+ int artifactAId = chStmt.getInt("a_art_id");
+ int artiafctBId = chStmt.getInt("b_art_id");
+
+ if (isNextConceptualRelation(relationTypeId, artifactAId, artiafctBId)) {
+ consolidate();
+ initNextConceptualRelation(relationTypeId, artifactAId, artiafctBId);
+ } else {
+ obsoleteGammas.add(chStmt.getLong("gamma_id"));
+ relationMateriallyDiffers(chStmt);
+ }
+ }
+ } finally {
+ if (chStmt != null) {
+ chStmt.close();
+ }
+ }
+ }
+
+ private void consolidate() {
+ if (!materiallyDifferent && obsoleteGammas.size() > 0) {
+ gammaJoin.add(netGamma, netGamma);
+ for (Long obsoleteGamma : obsoleteGammas) {
+ gammaJoin.add(netGamma, obsoleteGamma);
+ relationDeleteData.add(new Long[] {obsoleteGamma});
+ }
+ }
+ if (materiallyDifferent) {
+ counter++;
+ log("rel type: " + previousRelationTypeId + " A art id: " + previousArtifactAId + " B art id: " + previousArtiafctBId);
+ }
+ }
+
+ private void determineAffectedAddressing() throws OseeCoreException, IOException {
+ gammaJoin.store();
+
+ try {
+ log("counter: " + counter);
+ log("query id: " + gammaJoin.getQueryId());
+ chStmt.runPreparedQuery(10000, SELECT_RELATION_ADDRESSING, gammaJoin.getQueryId());
+
+ while (chStmt.next()) {
+ long obsoleteGammaId = chStmt.getLong("gamma_id");
+ int transactionId = chStmt.getInt("transaction_id");
+ long netGammaId = chStmt.getLong("net_gamma_id");
+ int modType = chStmt.getInt("mod_type");
+ TxChange txCurrent = TxChange.getChangeType(chStmt.getInt("tx_current"));
+
+ if (isNextAddressing(netGammaId, transactionId)) {
+ if (updateAddressing) {
+ updateAddressingData.add(new Object[] {
+ previousNetGammaId,
+ netModType.getValue(),
+ netTxCurrent.getValue(),
+ previousTransactionId,
+ previousObsoleteGammaId});
+ }
+ updateAddressing = obsoleteGammaId != netGammaId;
+ previousNetGammaId = netGammaId;
+ previousObsoleteGammaId = obsoleteGammaId;
+ previousTransactionId = transactionId;
+ netModType = ModificationType.getMod(modType);
+ netTxCurrent = txCurrent;
+ } else {
+ addressingToDelete.add(new Object[] {transactionId, obsoleteGammaId});
+ computeNetAddressing(ModificationType.getMod(modType), txCurrent);
+ }
+
+ writeAddressingBackup(obsoleteGammaId, transactionId, netGammaId, modType, txCurrent);
+ }
+ } finally {
+ if (chStmt != null) {
+ chStmt.close();
+ }
+ }
+ gammaJoin.delete();
+ }
+
+ private boolean isNextAddressing(long netGammaId, int transactionId) {
+ return previousNetGammaId != netGammaId || previousTransactionId != transactionId;
+ }
+
+ private void computeNetAddressing(ModificationType modificationType, TxChange txCurrent) throws OseeStateException {
+ if (netTxCurrentNeedsUpdate(txCurrent)) {
+ netTxCurrent = txCurrent;
+ updateAddressing = true;
+ }
+
+ if (netModTypeNeedsUpdate(modificationType)) {
+ netModType = modificationType;
+ updateAddressing = true;
+ } else if (!ignoreNetModType(modificationType)) {
+ throw new OseeStateException(" modType [%s] != [%s]", modificationType, netModType);
+ }
+ }
+
+ private boolean netTxCurrentNeedsUpdate(TxChange txCurrent) {
+ if (txCurrent == netTxCurrent) {
+ return false;
+ }
+ boolean needsUpdate = txCurrent == TxChange.NOT_CURRENT;
+ needsUpdate |= txCurrent == TxChange.CURRENT && netTxCurrent.isDeleted();
+ return needsUpdate || netTxCurrent == TxChange.DELETED && txCurrent == TxChange.ARTIFACT_DELETED;
+ }
+
+ private boolean netModTypeNeedsUpdate(ModificationType modificationType) {
+ boolean needsUpdate = !modificationType.isDeleted() && netModType.isDeleted();
+ needsUpdate |= netModType == ModificationType.NEW && modificationType == ModificationType.MODIFIED;
+ return needsUpdate || netModType == ModificationType.DELETED && modificationType == ModificationType.ARTIFACT_DELETED;
+ }
+
+ private boolean ignoreNetModType(ModificationType modificationType) {
+ boolean ignore = !netModType.isDeleted() && modificationType.isDeleted();
+ ignore |= netModType == modificationType;
+ ignore |= netModType == ModificationType.MODIFIED && modificationType == ModificationType.NEW;
+ return ignore || netModType == ModificationType.ARTIFACT_DELETED && modificationType == ModificationType.DELETED;
+ }
+
+ private void updateGammas() throws OseeCoreException, IOException {
+ log("Number of txs rows deleted: " + ConnectionHandler.runBatchUpdate(connection, DELETE_TXS, addressingToDelete));
+
+ log("Number of relation rows deleted: " + ConnectionHandler.runBatchUpdate(connection, DELETE_RELATIONS,
+ relationDeleteData));
+
+ log("Number of txs rows updated: " + ConnectionHandler.runBatchUpdate(connection, UPDATE_TXS_GAMMAS,
+ updateAddressingData));
+ }
+
+ private void writeAddressingBackup(long obsoleteGammaId, int transactionId, long netGammaId, int modType, TxChange txCurrent) throws IOException {
+ StringBuilder strB = new StringBuilder(30);
+
+ strB.append(obsoleteGammaId);
+ strB.append(",");
+ strB.append(transactionId);
+ strB.append(",");
+ strB.append(netGammaId);
+ strB.append(",");
+ strB.append(modType);
+ strB.append(",");
+ strB.append(txCurrent.getValue());
+ strB.append("\n");
+ log(strB.toString());
+ }
+
+ private boolean isNextConceptualRelation(int relationTypeId, int artifactAId, int artiafctBId) {
+ return previousRelationTypeId != relationTypeId || previousArtifactAId != artifactAId || previousArtiafctBId != artiafctBId;
+ }
+
+ private void relationMateriallyDiffers(IOseeStatement chStmt) throws OseeCoreException {
+ if (!materiallyDifferent) {
+ String currentRationale = chStmt.getString("rationale");
+ materiallyDifferent |= Strings.isValid(currentRationale) && !currentRationale.equals(netRationale);
+ }
+ }
+
+ private void initNextConceptualRelation(int relationTypeId, int artifactAId, int artiafctBId) throws OseeCoreException {
+ obsoleteGammas.clear();
+ previousRelationTypeId = relationTypeId;
+ previousArtifactAId = artifactAId;
+ previousArtiafctBId = artiafctBId;
+ netGamma = chStmt.getInt("gamma_id");
+ netRationale = chStmt.getString("rationale");
+ materiallyDifferent = false;
+ }
+} \ No newline at end of file

Back to the top