builder.clear(); builder.isComplete(state.isComplete() || completeData); builder.objectId(newObjectId); continue; builder.createdAt(ParseDateFormat.getInstance().parse(json.getString(key))); continue; builder.updatedAt(ParseDateFormat.getInstance().parse(json.getString(key))); continue; builder.put(KEY_ACL, acl); continue; set.add(safeKey); builder.availableKeys(set); builder.put(key, decodedObject); return builder.build(); } catch (JSONException e) { throw new RuntimeException(e);
public T updatedAt(Date updatedAt) { this.updatedAt = updatedAt.getTime(); return self(); }
builder.objectId(newObjectId); json.getString(KEY_OLD_CREATED_AT); if (createdAtString != null) { builder.createdAt(ParseImpreciseDateFormat.getInstance().parse(createdAtString)); json.getString(KEY_OLD_UPDATED_AT); if (updatedAtString != null) { builder.updatedAt(ParseImpreciseDateFormat.getInstance().parse(updatedAtString)); String key = (String) keys.next(); JSONArray pointerArray = newPointers.getJSONArray(key); builder.put(key, ParseObject.createWithoutData(pointerArray.optString(0), pointerArray.optString(1))); builder.objectId(newObjectId); continue; builder.createdAt(ParseDateFormat.getInstance().parse(data.getString(key))); continue; builder.updatedAt(ParseDateFormat.getInstance().parse(data.getString(key))); continue; builder.put(key, decodedObject);
builder.isComplete(true); } else { if (!objectIdForPointer.equals(NEW_OFFLINE_OBJECT_ID_PLACEHOLDER)) { builder.objectId(objectIdForPointer); builder.isComplete(false); state = builder.build();
/** * Applies a {@code State} on top of this {@code Builder} instance. * * @param other The {@code State} to apply over this instance. * @return A new {@code Builder} instance. */ public T apply(State other) { if (other.objectId() != null) { objectId(other.objectId()); } if (other.createdAt() > 0) { createdAt(other.createdAt()); } if (other.updatedAt() > 0) { updatedAt(other.updatedAt()); } isComplete(isComplete || other.isComplete()); for (String key : other.keySet()) { put(key, other.get(key)); } availableKeys(other.availableKeys()); return self(); }
/** * Handles the result of {@code save}. * <p> * Should be called on success or failure. */ // TODO(grantland): Remove once we convert saveEventually and ParseUser.signUp/resolveLaziness // to controllers Task<Void> handleSaveResultAsync( final JSONObject result, final ParseOperationSet operationsBeforeSave) { ParseObject.State newState = null; if (result != null) { // Success synchronized (mutex) { final Map<String, ParseObject> fetchedObjects = collectFetchedObjects(); ParseDecoder decoder = new KnownParseObjectDecoder(fetchedObjects); newState = ParseObjectCoder.get().decode(getState().newBuilder().clear(), result, decoder) .isComplete(false) .build(); } } return handleSaveResultAsync(newState, operationsBeforeSave); }
/** * Retrieves a {@code ParseObject} from a file on disk in /2/ format. * * @param coder Current coder to decode the ParseObject. * @param file The file to retrieve the object from. * @param builder An empty builder which is used to generate a empty state and rebuild a ParseObject. * @return The {@code ParseObject} that was retrieved. If the file wasn't found, or the contents * of the file is an invalid {@code ParseObject}, returns {@code null}. * @see #saveToDisk(ParseObjectCurrentCoder, ParseObject, File) */ private static <T extends ParseObject> T getFromDisk( ParseObjectCurrentCoder coder, File file, ParseObject.State.Init builder) { JSONObject json; try { json = ParseFileUtils.readFileToJSONObject(file); } catch (IOException | JSONException e) { return null; } ParseObject.State newState = coder.decode(builder, json, ParseDecoder.get()) .isComplete(true) .build(); return ParseObject.from(newState); }
/** * Converts a {@code ParseObject.State} to a {@code ParseObject}. * * @param state The {@code ParseObject.State} to convert from. * @return A {@code ParseObject} instance. */ static <T extends ParseObject> T from(ParseObject.State state) { @SuppressWarnings("unchecked") T object = (T) ParseObject.createWithoutData(state.className(), state.objectId()); synchronized (object.mutex) { State newState; if (state.isComplete()) { newState = state; } else { newState = object.getState().newBuilder().apply(state).build(); } object.setState(newState); } return object; }
@Override public Void then(Task<Void> task) { synchronized (mutex) { State newState; if (result.isComplete()) { // Result is complete, so just replace newState = result; } else { // Result is incomplete, so we'll need to apply it to the current state newState = getState().newBuilder() .apply(operationsBeforeSave) .apply(result) .build(); } setState(newState); } return null; } });
@Override public Task<Void> then(Task<Void> task) { synchronized (mutex) { State newState; if (result.isComplete()) { // Result is complete, so just replace newState = result; } else { // Result is incomplete, so we'll need to apply it to the current state newState = getState().newBuilder().apply(result).build(); } setState(newState); } return null; } });
void mergeFromObject(ParseObject other) { synchronized (mutex) { // If they point to the same instance, we don't need to merge. if (this == other) { return; } State copy = other.getState().newBuilder().build(); // We don't want to notify if an objectId changed here since we utilize this method to merge // an anonymous current user with a new ParseUser instance that's calling signUp(). This // doesn't make any sense and we should probably remove that code in ParseUser. // Otherwise, there shouldn't be any objectId changes here since this method is only otherwise // used in fetchAll. setState(copy, false); } }
/** * Setter for the object id. In general you do not need to use this. However, in some cases this * can be convenient. For example, if you are serializing a {@code ParseObject} yourself and wish * to recreate it, you can use this to recreate the {@code ParseObject} exactly. */ public void setObjectId(String newObjectId) { synchronized (mutex) { String oldObjectId = state.objectId(); if (ParseTextUtils.equals(oldObjectId, newObjectId)) { return; } // We don't need to use setState since it doesn't affect our cached state. state = state.newBuilder().objectId(newObjectId).build(); notifyObjectIdChanged(oldObjectId, newObjectId); } }
public T apply(ParseOperationSet operations) { for (String key : operations.keySet()) { ParseFieldOperation operation = operations.get(key); Object oldValue = serverData.get(key); Object newValue = operation.apply(oldValue, key); if (newValue != null) { put(key, newValue); } else { remove(key); } } return self(); } }
public T objectId(String objectId) { this.objectId = objectId; return self(); }
public T remove(String key) { serverData.remove(key); return self(); }
public T createdAt(long createdAt) { this.createdAt = createdAt; return self(); }
public T updatedAt(long updatedAt) { this.updatedAt = updatedAt; return self(); }
public T createdAt(Date createdAt) { this.createdAt = createdAt.getTime(); return self(); }
@Override public Builder apply(ParseObject.State other) { isNew(((State) other).isNew()); return super.apply(other); }