Exemplo n.º 1
0
    @Override
    public List<IOseeBranch> call() throws Exception {
      Collection<BranchReadable> branchesToPurge = getBranchesToPurge();

      Conditions.checkNotNull(branchesToPurge, "branchesToPurge");
      if (branchesToPurge.isEmpty()) {
        console.writeln("no branches matched specified criteria");
      } else {
        List<BranchReadable> orderedBranches =
            BranchUtil.orderByParentReadable(queryFactory, branchesToPurge);

        for (IOseeBranch toPurge : orderedBranches) {
          console.writeln(
              "Branch [%s] guid [%s] will be purged!", toPurge.getName(), toPurge.getGuid());
        }

        List<IOseeBranch> purged = new LinkedList<IOseeBranch>();
        if (runPurge) {
          int size = orderedBranches.size();
          int count = 0;
          for (IOseeBranch aBranch : orderedBranches) {
            console.writeln("Purging Branch [%s of %s]: [%s]", ++count, size, aBranch);
            Callable<List<IOseeBranch>> callable = orcsBranch.purgeBranch(aBranch, false);
            purged.addAll(callable.call());
          }
        }
        return purged;
      }
      return null;
    }
Exemplo n.º 2
0
  @Override
  public Callable<?> createCallable(Console console, ConsoleParameters params) {
    List<Long> branchUuids = new ArrayList<Long>();
    for (String uuid : params.getArray("branchUuids")) {
      if (Strings.isNumeric(uuid)) {
        branchUuids.add(Long.parseLong(uuid));
      } else {
        console.writeln("UUID listed %s is not a valid UUID", uuid);
      }
    }

    if (branchUuids.isEmpty()) {
      console.writeln("No branch uuids where specified");
    }

    Collection<String> options = params.getOptions();
    boolean recurse = options.contains("R");
    boolean unArchived = options.contains("A");
    boolean unDeleted = options.contains("D");
    boolean baseline = options.contains("B");
    boolean runPurge = options.contains("P");

    OrcsBranch orcsBranch = getOrcsApi().getBranchOps(null);
    return new PurgeBranchCallable(
        console,
        orcsBranch,
        getOrcsApi().getQueryFactory(null),
        branchUuids,
        recurse,
        unArchived,
        unDeleted,
        baseline,
        runPurge);
  }
Exemplo n.º 3
0
 private boolean filterBranch(BranchReadable branch) {
   if (!includeBaseline && branch.getBranchType() == BranchType.BASELINE) {
     console.writeln(ERROR_STRING, branch, branch.getUuid(), branch.getBranchType());
     return true;
   } else if (!includeUnarchived && branch.getArchiveState() == BranchArchivedState.UNARCHIVED) {
     console.writeln(ERROR_STRING, branch, branch.getUuid(), branch.getArchiveState());
     return true;
   } else if (!includeUndeleted && branch.getBranchState() != BranchState.DELETED) {
     console.writeln(ERROR_STRING, branch, branch.getUuid(), branch.getBranchState());
     return true;
   }
   return false;
 }
  private void updateGammas() throws OseeCoreException {
    console.writeln(
        "Number of txs rows deleted: [%s]",
        ConnectionHandler.runBatchUpdate(connection, DELETE_TXS, addressingToDelete));

    console.writeln(
        "Number of relation rows deleted: [%s]",
        ConnectionHandler.runBatchUpdate(connection, DELETE_RELATIONS, relationDeleteData));

    console.writeln(
        "Number of txs rows updated: [%s]",
        ConnectionHandler.runBatchUpdate(connection, UPDATE_TXS_GAMMAS, updateAddressingData));
  }
Exemplo n.º 5
0
    private Collection<BranchReadable> getBranchesToPurge() throws OseeCoreException {
      Set<BranchReadable> specifiedBranches = new HashSet<BranchReadable>();
      for (Long uuid : branchUuids) {
        if (uuid <= 0) {
          console.writeln("UUID listed %s is not a valid UUID", uuid);
        } else {
          BranchReadable cached =
              queryFactory.branchQuery().andUuids(uuid).getResults().getExactlyOne();
          if (cached != null) {
            specifiedBranches.add(cached);
          }
        }
      }

      Collection<BranchReadable> branchesToPurge =
          recurse ? getChildBranchesToPurge(specifiedBranches) : specifiedBranches;

      Iterator<BranchReadable> iter = branchesToPurge.iterator();
      while (iter.hasNext()) {
        if (filterBranch(iter.next())) {
          iter.remove();
        }
      }
      return branchesToPurge;
    }
  @Override
  protected Object handleTxWork(OseeConnection connection) throws OseeCoreException {
    this.connection = connection;
    console.writeln("Consolidating relations:");
    init();

    findObsoleteRelations();

    console.writeln("gamma join size: [%s]", gammaJoin.size());

    determineAffectedAddressing();

    updateGammas();
    console.writeln("...done.");
    return null;
  }
  private void determineAffectedAddressing() throws OseeCoreException {
    gammaJoin.store();

    try {
      console.writeln("counter: [%s]", counter);
      console.writeln("query id: [%s]", 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[] {chStmt.getInt("branch_id"), transactionId, obsoleteGammaId});
          computeNetAddressing(ModificationType.getMod(modType), txCurrent);
        }

        writeAddressingBackup(obsoleteGammaId, transactionId, netGammaId, modType, txCurrent);
      }
    } finally {
      chStmt.close();
    }
    gammaJoin.delete();
  }
 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++;
     console.writeln(
         "rel_type:[%s] a_art_id:[%s]  b_art_id:[%s]",
         previousRelationTypeId, previousArtifactAId, previousArtiafctBId);
   }
 }
Exemplo n.º 9
0
 private void writeStatistics(QueryStatistics stats) {
   console.writeln("\n----------------------------------------------");
   console.writeln("                  Search Stats");
   console.writeln("----------------------------------------------");
   console.writeln("Total Searches - [%d]", stats.getTotalSearches());
   console.writeln(
       "Search Time    - avg: [%s] ms - longest: [%s] ms",
       stats.getAverageSearchTime(), stats.getLongestSearchTime());
   console.writeln("Longest Search  - %s", stats.getLongestSearch());
 }
  private void writeAddressingBackup(
      long obsoleteGammaId, int transactionId, long netGammaId, int modType, TxChange txCurrent) {
    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");
    console.writeln(strB.toString());
  }