public static void loadFromCache(AbstractBranchCacheMessage message, Collection<Branch> types)
     throws OseeCoreException {
   for (Branch br : types) {
     Integer branchId = br.getId();
     message
         .getBranchRows()
         .add(
             new BranchRow(
                 br.getId(),
                 br.getGuid(),
                 br.getName(),
                 br.getBranchType(),
                 br.getBranchState(),
                 br.getArchiveState(),
                 br.getStorageState()));
     if (br.hasParentBranch()) {
       message.getChildToParent().put(branchId, br.getParentBranch().getId());
     }
     addTxRecord(message.getBranchToBaseTx(), branchId, br.getBaseTransaction());
     addTxRecord(message.getBranchToSourceTx(), branchId, br.getSourceTransaction());
     addAssocArtifact(message.getBranchToAssocArt(), branchId, br.getAssociatedArtifactId());
     if (br.getBranchType().isMergeBranch()) {
       addMergeBranches(message.getMergeBranches(), (MergeBranch) br);
     }
   }
 }
 private void preLoadTransactions(AbstractBranchCacheMessage cacheMessage)
     throws OseeCoreException {
   Set<Integer> txIdsToLoad = new HashSet<Integer>();
   addValidTxIds(cacheMessage.getBranchToBaseTx().values(), txIdsToLoad);
   addValidTxIds(cacheMessage.getBranchToSourceTx().values(), txIdsToLoad);
   txCache.loadTransactions(txIdsToLoad);
 }
 public static void loadMessage(AbstractBranchCacheMessage message, PropertyStore store) {
   List<BranchRow> rows = message.getBranchRows();
   int rowCount = store.getInt(Fields.BRANCH_COUNT.name());
   for (int index = 0; index < rowCount; index++) {
     String[] rowData = store.getArray(TranslationUtil.createKey(Fields.BRANCH_ROW, index));
     rows.add(BranchRow.fromArray(rowData));
   }
   TranslationUtil.loadMap(message.getChildToParent(), store, Fields.CHILD_TO_PARENT);
   TranslationUtil.loadMap(message.getBranchToBaseTx(), store, Fields.BRANCH_TO_BASE_TX);
   TranslationUtil.loadMap(message.getBranchToSourceTx(), store, Fields.BRANCH_TO_SRC_TX);
   TranslationUtil.loadMap(message.getBranchToAssocArt(), store, Fields.BRANCH_TO_ASSOC_ART);
   TranslationUtil.loadArrayMap(message.getBranchAliases(), store, Fields.BRANCH_TO_ALIASES);
   TranslationUtil.loadTripletList(message.getMergeBranches(), store, Fields.SRC_DEST_MERGE);
 }
  public static void loadStore(PropertyStore store, AbstractBranchCacheMessage message) {
    List<BranchRow> rows = message.getBranchRows();
    for (int index = 0; index < rows.size(); index++) {
      BranchRow row = rows.get(index);
      store.put(TranslationUtil.createKey(Fields.BRANCH_ROW, index), row.toArray());
    }
    store.put(Fields.BRANCH_COUNT.name(), rows.size());

    TranslationUtil.putMap(store, Fields.CHILD_TO_PARENT, message.getChildToParent());
    TranslationUtil.putMap(store, Fields.BRANCH_TO_BASE_TX, message.getBranchToBaseTx());
    TranslationUtil.putMap(store, Fields.BRANCH_TO_SRC_TX, message.getBranchToSourceTx());
    TranslationUtil.putMap(store, Fields.BRANCH_TO_ASSOC_ART, message.getBranchToAssocArt());
    TranslationUtil.putArrayMap(store, Fields.BRANCH_TO_ALIASES, message.getBranchAliases());
    TranslationUtil.putTripletList(store, Fields.SRC_DEST_MERGE, message.getMergeBranches());
  }
  public Collection<Branch> updateCache(
      AbstractBranchCacheMessage cacheMessage, IOseeCache<String, Branch> cache)
      throws OseeCoreException {
    List<Branch> updatedItems = new ArrayList<Branch>();

    Map<Integer, Integer> branchToAssocArt = cacheMessage.getBranchToAssocArt();

    preLoadTransactions(cacheMessage);

    for (BranchRow srcItem : cacheMessage.getBranchRows()) {
      int branchId = srcItem.getBranchId();
      Branch updated =
          factory.createOrUpdate(
              cache,
              srcItem.getBranchId(),
              srcItem.getStorageState(),
              srcItem.getBranchGuid(),
              srcItem.getBranchName(),
              srcItem.getBranchType(),
              srcItem.getBranchState(),
              srcItem.getBranchArchived().isArchived());
      updatedItems.add(updated);

      Integer artifactId = branchToAssocArt.get(branchId);
      if (artifactId != null) {
        updated.setAssociatedArtifactId(artifactId);
      }

      updated.setBaseTransaction(getTx(cacheMessage.getBranchToBaseTx(), branchId));
      updated.setSourceTransaction(getTx(cacheMessage.getBranchToSourceTx(), branchId));
    }

    for (Entry<Integer, Integer> entry : cacheMessage.getChildToParent().entrySet()) {
      Branch parent = cache.getById(entry.getValue());
      if (parent != null) {
        Branch child = cache.getById(entry.getKey());
        if (child != null) {
          child.setParentBranch(parent);
        }
      }
    }
    for (Triplet<String, String, String> entry : cacheMessage.getMergeBranches()) {
      IOseeBranch sourceBranch =
          Strings.isValid(entry.getFirst()) ? cache.getByGuid(entry.getFirst()) : null;
      IOseeBranch destinationBranch =
          Strings.isValid(entry.getSecond()) ? cache.getByGuid(entry.getSecond()) : null;

      Branch branch = cache.getByGuid(entry.getThird());
      MergeBranch mergeBranch = null;
      try {
        mergeBranch = (MergeBranch) branch;
        mergeBranch.setSourceBranch(sourceBranch);
        mergeBranch.setDestinationBranch(destinationBranch);
      } catch (ClassCastException ex) {
        throw new OseeCoreException(
            ex,
            "Problem casting branch [%s] to MergeBranch, source: [%s], dest: [%s]",
            branch,
            sourceBranch,
            destinationBranch);
      }
    }
    return updatedItems;
  }