Skip to main content
summaryrefslogtreecommitdiffstats
blob: e85f1d16b65f7e4f5133b4384923b5fa12df116d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
 * Copyright (c) 2012 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.orcs.db.internal.callable;

import java.util.List;
import java.util.concurrent.Callable;
import org.eclipse.osee.framework.core.enums.TransactionVersion;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.TransactionDelta;
import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.core.model.cache.BranchCache;
import org.eclipse.osee.framework.core.model.change.ChangeItem;
import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.db.internal.change.AddArtifactChangeDataCallable;
import org.eclipse.osee.orcs.db.internal.change.ComputeNetChangeCallable;
import org.eclipse.osee.orcs.db.internal.change.LoadDeltasBetweenBranches;
import org.eclipse.osee.orcs.db.internal.change.LoadDeltasBetweenTxsOnTheSameBranch;
import org.eclipse.osee.orcs.db.internal.change.MissingChangeItemFactory;

public class CompareDatabaseCallable extends AbstractDatastoreCallable<List<ChangeItem>> {

   private final BranchCache branchCache;
   private final TransactionRecord sourceTx;
   private final TransactionRecord destinationTx;
   private final MissingChangeItemFactory missingChangeItemFactory;

   private static final String SELECT_BASE_TRANSACTION =
      "select baseline_transaction_id from osee_branch where branch_id = ?";

   public CompareDatabaseCallable(Log logger, OrcsSession session, IOseeDatabaseService service, BranchCache branchCache, TransactionRecord sourceTx, TransactionRecord destinationTx, MissingChangeItemFactory missingChangeItemFactory) {
      super(logger, session, service);
      this.branchCache = branchCache;
      this.sourceTx = sourceTx;
      this.destinationTx = destinationTx;
      this.missingChangeItemFactory = missingChangeItemFactory;
   }

   private BranchCache getBranchCache() {
      return branchCache;
   }

   @Override
   public List<ChangeItem> call() throws Exception {
      TransactionDelta txDelta = new TransactionDelta(sourceTx, destinationTx);

      Callable<List<ChangeItem>> callable;
      if (txDelta.areOnTheSameBranch()) {
         callable = new LoadDeltasBetweenTxsOnTheSameBranch(getLogger(), getSession(), getDatabaseService(), txDelta);
      } else {
         TransactionRecord mergeTx = getMergeTransaction(sourceTx, destinationTx);
         Long mergeBranchId = null;
         Integer mergeTxId = null;
         if (mergeTx != null) {
            mergeBranchId = mergeTx.getBranchId();
            mergeTxId = mergeTx.getId();
         }
         callable =
            new LoadDeltasBetweenBranches(getLogger(), getSession(), getDatabaseService(), sourceTx.getBranchId(),
               destinationTx.getBranchId(), destinationTx.getId(), mergeBranchId, mergeTxId);
      }
      List<ChangeItem> changes = callAndCheckForCancel(callable);

      changes.addAll(missingChangeItemFactory.createMissingChanges(this, getSession(), changes, sourceTx, destinationTx));
      Callable<List<ChangeItem>> computeChanges = new ComputeNetChangeCallable(changes);
      changes = callAndCheckForCancel(computeChanges);

      Callable<List<ChangeItem>> addArtifactData = new AddArtifactChangeDataCallable(changes);
      return callAndCheckForCancel(addArtifactData);
   }

   private TransactionRecord getMergeTransaction(TransactionRecord sourceTx, TransactionRecord destinationTx) throws OseeCoreException {
      Branch mergeBranch = getBranchCache().findMergeBranch(sourceTx.getBranch(), destinationTx.getBranch());
      return mergeBranch != null ? getBranchCache().getTransaction(mergeBranch, TransactionVersion.HEAD) : null;
   }

}

Back to the top