@Override public T call() { if (!file.exists()) { return null; } return getFromDisk(coder, file, ParseObject.State.newBuilder(className)); } }, ParseExecutors.io());
try { State.Init<?> builder = state.newBuilder(); if (completeData) { builder.clear();
@Override /* package */ void setState(ParseObject.State newState) { if (isCurrentUser()) { State.Builder newStateBuilder = newState.newBuilder(); // Avoid clearing sessionToken when updating the current user's State via ParseQuery result if (getSessionToken() != null && newState.get(KEY_SESSION_TOKEN) == null) { newStateBuilder.put(KEY_SESSION_TOKEN, getSessionToken()); } // Avoid clearing authData when updating the current user's State via ParseQuery result if (getAuthData().size() > 0 && newState.get(KEY_AUTH_DATA) == null) { newStateBuilder.put(KEY_AUTH_DATA, getAuthData()); } newState = newStateBuilder.build(); } super.setState(newState); }
/** * 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); }
/** * 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; } });
/** * 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); } }
@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); } }
@Override public ParseObject.State then(Task<JSONObject> task) { JSONObject result = task.getResult(); // Copy and clear to create an new empty instance of the same type as `state` ParseObject.State.Init<?> builder = state.newBuilder().clear(); return coder.decode(builder, result, decoder) .isComplete(false) .build(); } });
@Override public ParseObject.State then(Task<JSONObject> task) { JSONObject result = task.getResult(); // Copy and clear to create an new empty instance of the same type as `state` ParseObject.State.Init<?> builder = state.newBuilder().clear(); return coder.decode(builder, result, decoder) .isComplete(false) .build(); } }));
@Override public ParseObject.State then(Task<JSONObject> task) { JSONObject result = task.getResult(); // Copy and clear to create an new empty instance of the same type as `state` ParseObject.State.Init<?> builder = state.newBuilder().clear(); return coder.decode(builder, result, decoder) .isComplete(true) .build(); } });