Example #1
0
  protected void writeRevisionDelta(
      InternalCDORevisionDelta revisionDelta, CDOBranch branch, long created) {
    CDOID id = revisionDelta.getID();
    InternalCDORevision revision =
        DB4ORevision.getCDORevision(getStore(), DB4OStore.getRevision(getObjectContainer(), id));
    InternalCDORevision newRevision = revision.copy();
    newRevision.adjustForCommit(branch, created);

    revisionDelta.apply(newRevision);
    writeRevision(newRevision, new Monitor());
  }
  /** TODO See {@link CDOObjectMerger}!!! */
  public static void changeObject(CDOObject object, CDORevisionDelta revisionDelta) {
    readObject(object);

    InternalCDORevision revision = (InternalCDORevision) object.cdoRevision().copy();
    ((InternalCDORevisionDelta) revisionDelta).setVersion(revision.getVersion());

    CDORevisionMerger merger = new CDORevisionMerger();
    merger.merge(revision, revisionDelta);
    ((InternalCDOObject) object).cdoInternalSetRevision(revision);
    ((InternalCDOObject) object).cdoInternalSetState(CDOState.DIRTY);
    ((InternalCDOObject) object).cdoInternalPostLoad();
  }
    @Override
    protected void resolveConflict(
        CDOObject conflict, CDORevisionDelta localDelta, List<CDORevisionDelta> remoteDeltas) {
      if (hasFeatureConflicts(localDelta, remoteDeltas)) {
        // TODO localDelta may be corrupt already and the transaction will not be able to restore
        // it!!!
        throw new CDOException(
            Messages.getString("AbstractObjectConflictResolver.0")); // $NON-NLS-1$
      }

      rollbackObject(conflict);

      // Add remote deltas to local delta
      for (CDORevisionDelta remoteDelta : remoteDeltas) {
        for (CDOFeatureDelta remoteFeatureDelta : remoteDelta.getFeatureDeltas()) {
          // TODO Add public API for this:
          ((InternalCDORevisionDelta) localDelta).addFeatureDelta(remoteFeatureDelta);
        }
      }

      changeObject(conflict, localDelta);
    }
Example #4
0
    @Override
    protected Object changedInSourceAndTarget(
        CDORevisionDelta targetDelta, CDORevisionDelta sourceDelta) {
      InternalCDORevisionDelta result = new CDORevisionDeltaImpl(targetDelta, false);
      ChangedInSourceAndTargetConflict conflict = null;

      Map<EStructuralFeature, CDOFeatureDelta> targetMap =
          ((InternalCDORevisionDelta) targetDelta).getFeatureDeltaMap();
      Map<EStructuralFeature, CDOFeatureDelta> sourceMap =
          ((InternalCDORevisionDelta) sourceDelta).getFeatureDeltaMap();

      for (CDOFeatureDelta targetFeatureDelta : targetMap.values()) {
        EStructuralFeature feature = targetFeatureDelta.getFeature();
        CDOFeatureDelta sourceFeatureDelta = sourceMap.get(feature);

        if (sourceFeatureDelta == null) {
          CDOFeatureDelta featureDelta = changedInTarget(targetFeatureDelta);
          if (featureDelta != null) {
            result.addFeatureDelta(featureDelta, null);
          }
        } else {
          CDOFeatureDelta featureDelta =
              changedInSourceAndTarget(targetFeatureDelta, sourceFeatureDelta);
          if (featureDelta != null) {
            result.addFeatureDelta(featureDelta, null);
          } else {
            if (conflict == null) {
              ResolutionPreference resolutionPreference = getResolutionPreference();
              switch (resolutionPreference) {
                case SOURCE_OVER_TARGET:
                  // TODO: implement
                  // DefaultCDOMerger.PerFeature.changedInSourceAndTarget(targetDelta, sourceDelta)
                  throw new UnsupportedOperationException();

                case TARGET_OVER_SOURCE:
                  // TODO: implement
                  // DefaultCDOMerger.PerFeature.changedInSourceAndTarget(targetDelta, sourceDelta)
                  throw new UnsupportedOperationException();

                case NONE:
                  conflict =
                      new ChangedInSourceAndTargetConflict(
                          new CDORevisionDeltaImpl(targetDelta, false),
                          new CDORevisionDeltaImpl(sourceDelta, false));
                  break;

                default:
                  throw new IllegalStateException(
                      "Illegal resolution preference: " + resolutionPreference);
              }
            }

            ((InternalCDORevisionDelta) conflict.getTargetDelta())
                .addFeatureDelta(targetFeatureDelta, null);
            ((InternalCDORevisionDelta) conflict.getSourceDelta())
                .addFeatureDelta(sourceFeatureDelta, null);
          }
        }
      }

      for (CDOFeatureDelta sourceFeatureDelta : sourceMap.values()) {
        EStructuralFeature feature = sourceFeatureDelta.getFeature();
        CDOFeatureDelta targetFeatureDelta = targetMap.get(feature);

        if (targetFeatureDelta == null) {
          CDOFeatureDelta featureDelta = changedInSource(sourceFeatureDelta);
          if (featureDelta != null) {
            result.addFeatureDelta(featureDelta, null);
          }
        }
      }

      if (result.isEmpty()) {
        return conflict;
      }

      if (conflict != null) {
        return Pair.create(result, conflict);
      }

      return result;
    }