Exemplo n.º 1
0
  protected void delete(boolean useMasterKey) throws ParseException {

    if (objectId == null) return;

    ParseCommand command = new ParseDeleteCommand(getEndPoint(), getObjectId(), useMasterKey);
    ParseResponse response = command.perform();
    if (response.isFailed()) {
      throw response.getException();
    }

    this.updatedAt = null;
    this.createdAt = null;
    this.objectId = null;
    this.isDirty = false;
    this.operations.clear();
    this.dirtyKeys.clear();
  }
Exemplo n.º 2
0
  private void save(boolean useMasterKey) throws ParseException {

    if (!isDirty) return;

    ParseCommand command;
    if (objectId == null) {
      command = new ParsePostCommand(getEndPoint(), useMasterKey);
    } else {
      command = new ParsePutCommand(getEndPoint(), getObjectId(), useMasterKey);
    }

    command.setData(getParseData());
    ParseResponse response = command.perform();
    if (!response.isFailed()) {
      JSONObject jsonResponse = response.getJsonObject();
      if (jsonResponse == null) {
        LOGGER.error("Empty response");
        throw response.getException();
      }
      try {
        if (getObjectId() == null) {
          setObjectId(jsonResponse.getString(ParseConstants.FIELD_OBJECT_ID));
          String createdAt = jsonResponse.getString(ParseConstants.FIELD_CREATED_AT);
          setCreatedAt(Parse.parseDate(createdAt));
          setUpdatedAt(Parse.parseDate(createdAt));
        } else {
          String updatedAt = jsonResponse.getString(ParseConstants.FIELD_UPDATED_AT);
          setUpdatedAt(Parse.parseDate(updatedAt));
        }

        this.isDirty = false;
        this.operations.clear();
        this.dirtyKeys.clear();
      } catch (JSONException e) {
        LOGGER.error("Request failed.");
        throw new ParseException(
            ParseException.INVALID_JSON,
            "Although Parse reports object successfully saved, the response was invalid.",
            e);
      }
    } else {
      LOGGER.error("Request failed.");
      throw response.getException();
    }
  }