Example #1
0
  public JSONObject getParseData() {
    JSONObject parseData = new JSONObject();

    for (String key : operations.keySet()) {
      ParseFieldOperation operation = (ParseFieldOperation) operations.get(key);
      if (operation instanceof SetFieldOperation) {
        parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
      } else if (operation instanceof IncrementFieldOperation) {
        parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
      } else if (operation instanceof DeleteFieldOperation) {
        parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
      } else if (operation instanceof RelationOperation) {
        parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
      } else {
        // here we deal will sub objects like ParseObject;
        Object obj = data.get(key);
        if (obj instanceof ParseObject) {
          ParseObject pob = (ParseObject) obj;
          parseData.put(key, pob.getParseData());
        }
      }
    }

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("parseData-> " + parseData);
    }

    return parseData;
  }
Example #2
0
  public void performOperation(String key, ParseFieldOperation operation) {

    // if field already exist, remove field and any pending operation for that field
    if (has(key)) {
      operations.remove(key);
      data.remove(key);
    }

    Object value = operation.apply(null, this, key);
    if (value != null) {
      data.put(key, value);
    } else {
      data.remove(key);
    }
    operations.put(key, operation);
    dirtyKeys.add(key);
    isDirty = true;
  }