Ejemplo n.º 1
0
  @Override
  public void put(Entry entry) {
    ByteBuffer key = ByteBuffer.wrap(entry.getKey());

    boolean done = false;
    while (!done) {
      Entry old = map.putIfAbsent(key, entry);

      done = true;
      if (old != null) {
        entry = resolver.resolve(old, entry);

        if (entry != old) {
          done = map.replace(key, old, entry);
        }
      }
    }
  }
  @Override
  public void resolveConflictsForDocument(String docId, ConflictResolver resolver)
      throws ConflictException {
    this.sqlDb.beginTransaction();
    try {

      DocumentRevisionTree doc = this.getAllRevisionsOfDocument(docId);
      if (!doc.hasConflicts()) {
        return;
      }

      DocumentRevision newWinner = null;
      try {
        newWinner = resolver.resolve(docId, doc.leafRevisions());
      } catch (Exception e) {
        Log.e(LOG_TAG, "Exception when calling ConflictResolver", e);
      }
      if (newWinner == null) {
        return;
      }

      DocumentRevision winner = doc.getCurrentRevision();
      if (!newWinner.isDeleted()) {
        this.updateDocument(winner.getId(), winner.getRevision(), newWinner.getBody());
      } else {
        this.deleteDocument(winner.getId(), winner.getRevision());
      }

      for (DocumentRevision revision : doc.leafRevisions()) {
        if (!revision.isCurrent() && !revision.isDeleted()) {
          this.deleteDocument(revision.getId(), revision.getRevision());
        }
      }
      this.sqlDb.setTransactionSuccessful();
    } finally {
      this.sqlDb.endTransaction();
    }
  }
Ejemplo n.º 3
0
 public Conflict resolveConflict(final InspectorList otherCollection) {
   return conflictResolver.resolveConflict(otherCollection);
 }