コード例 #1
0
  protected Operation transform(DeleteOperation delA, InsertOperation insB) {

    int posA = delA.getPosition();
    int lenA = delA.getTextLength();
    int posB = insB.getPosition();
    int lenB = insB.getTextLength();

    if (posB >= (posA + lenA)) {
      /*
       * Operation B is completely after operation A.
       */
      return delA;
    } else if (posB <= posA) {
      /*
       * Operation B starts before or at the same position like operation
       * A
       */
      return new DeleteOperation(posA + lenB, delA.getText());
    } else {
      /*
       * Operation B (insert) is in the range of operation A (delete).
       * Operation A' must be split up into two delete operations. (A):
       * "123456" (A'): "1" "23456"
       */
      DeleteOperation del1 = new DeleteOperation(posA, delA.getText().substring(0, posB - posA));
      DeleteOperation del2 =
          new DeleteOperation(posA + lenB, delA.getText().substring(posB - posA, lenA));
      return new SplitOperation(del1, del2);
    }
  }
コード例 #2
0
  protected Operation transform(InsertOperation insA, DeleteOperation delB) {

    int posA = insA.getPosition();
    int posB = delB.getPosition();
    int lenB = delB.getTextLength();

    if (posA <= posB) {
      /*
       * Operation A starts before or at the same position like operation
       */
      return insA;
    } else if (posA > (posB + lenB)) {
      /*
       * Operation A starts after operation B. Index of operation A' must
       * be reduced by the length of the text of operation B.
       */
      return new InsertOperation(posA - lenB, insA.getText(), insA.getOrigin());
    } else {
      /*
       * Operation A starts in operation B. Index of A' must be the index
       * of operation B.
       */
      return new InsertOperation(posB, insA.getText(), insA.getOrigin());
    }
  }
コード例 #3
0
  @Override
  public JsonObject visit(InsertOperation operation) throws Throwable {
    MobileServiceJsonTable table = this.getRemoteTable(operation.getTableName());
    table.setSystemProperties(EnumSet.allOf(MobileServiceSystemProperty.class));

    JsonObject item = removeSystemProperties(this.mItem);

    ListenableFuture<JsonObject> future = table.insert(item);

    try {
      return future.get();
    } catch (ExecutionException ex) {
      throw ex.getCause();
    }
  }
コード例 #4
0
  protected Operation transform(
      InsertOperation insA, InsertOperation insB, boolean isTransformPrivileged) {

    int posA = insA.getPosition();
    int posB = insB.getPosition();
    int lenB = insB.getTextLength();
    if ((posA < posB)
        || ((posA == posB) && (insA.getOrigin() < insB.getOrigin()))
        || ((posA == posB) && (insA.getOrigin() == insB.getOrigin()) && isTransformPrivileged)) {
      /*
       * Operation A starts before operation B.
       */
      return insA;
    } else {
      /*
       * Operation A starts in or behind operation B. Index of operation
       * A' must be increased by the length of the text of operation B.
       */
      return new InsertOperation(posA + lenB, insA.getText(), insA.getOrigin());
    }
  }
コード例 #5
0
ファイル: SimpleWorkload.java プロジェクト: rpau/ldbc_driver
 @Override
 public String serializeOperation(Operation operation) throws SerializingMarshallingException {
   try {
     switch (operation.type()) {
       case InsertOperation.TYPE:
         {
           InsertOperation simpleOperation = (InsertOperation) operation;
           List<Object> operationAsList = new ArrayList<>();
           operationAsList.add(simpleOperation.getClass().getName());
           operationAsList.add(simpleOperation.table());
           operationAsList.add(simpleOperation.key());
           // TODO
           //                operationAsList.add( simpleOperation.fields() );
           return OBJECT_MAPPER.writeValueAsString(operationAsList);
         }
       case ReadOperation.TYPE:
         {
           ReadOperation simpleOperation = (ReadOperation) operation;
           List<Object> operationAsList = new ArrayList<>();
           operationAsList.add(simpleOperation.getClass().getName());
           operationAsList.add(simpleOperation.table());
           operationAsList.add(simpleOperation.key());
           operationAsList.add(simpleOperation.fields());
           return OBJECT_MAPPER.writeValueAsString(operationAsList);
         }
       case UpdateOperation.TYPE:
         {
           UpdateOperation simpleOperation = (UpdateOperation) operation;
           List<Object> operationAsList = new ArrayList<>();
           operationAsList.add(simpleOperation.getClass().getName());
           operationAsList.add(simpleOperation.table());
           operationAsList.add(simpleOperation.key());
           // TODO
           //                operationAsList.add( simpleOperation.fields() );
           return OBJECT_MAPPER.writeValueAsString(operationAsList);
         }
       case ScanOperation.TYPE:
         {
           ScanOperation simpleOperation = (ScanOperation) operation;
           List<Object> operationAsList = new ArrayList<>();
           operationAsList.add(simpleOperation.getClass().getName());
           operationAsList.add(simpleOperation.table());
           operationAsList.add(simpleOperation.startkey());
           operationAsList.add(simpleOperation.recordCount());
           operationAsList.add(simpleOperation.fields());
           return OBJECT_MAPPER.writeValueAsString(operationAsList);
         }
       case ReadModifyWriteOperation.TYPE:
         {
           ReadModifyWriteOperation simpleOperation = (ReadModifyWriteOperation) operation;
           List<Object> operationAsList = new ArrayList<>();
           operationAsList.add(simpleOperation.getClass().getName());
           operationAsList.add(simpleOperation.table());
           operationAsList.add(simpleOperation.key());
           operationAsList.add(simpleOperation.fields());
           // TODO
           //                operationAsList.add( simpleOperation.values() );
           return OBJECT_MAPPER.writeValueAsString(operationAsList);
         }
       default:
         {
           throw new SerializingMarshallingException(
               format(
                   "Workload does not know how to serialize operation\nWorkload: %s\nOperation Type: "
                       + "%s\nOperation: %s",
                   getClass().getName(), operation.getClass().getName(), operation));
         }
     }
   } catch (IOException e) {
     throw new SerializingMarshallingException(
         format("Error serializing operation\n%s", operation), e);
   }
 }