/** * Finds all of the local ids in this command and decrements their retain counts in the on-disk * store. This should be called when removing a serialized command from the disk, when we know * that we will never need to resolve these local ids for this command again in the future. */ public void releaseLocalIds() { if (localId != null) { getLocalIdManager().releaseLocalIdOnDisk(localId); } try { ArrayList<JSONObject> localPointers = new ArrayList<>(); getLocalPointersIn(jsonParameters, localPointers); for (JSONObject pointer : localPointers) { String localId = (String) pointer.get("localId"); getLocalIdManager().releaseLocalIdOnDisk(localId); } } catch (JSONException e) { // Well, nothing to do here... } }
/** * Finds all of the local ids in this command and increments their retain counts in the on-disk * store. This should be called immediately before serializing the command to disk, so that we * know we might need to resolve these local ids at some point in the future. */ public void retainLocalIds() { if (localId != null) { getLocalIdManager().retainLocalIdOnDisk(localId); } try { ArrayList<JSONObject> localPointers = new ArrayList<>(); getLocalPointersIn(jsonParameters, localPointers); for (JSONObject pointer : localPointers) { String localId = (String) pointer.get("localId"); getLocalIdManager().retainLocalIdOnDisk(localId); } } catch (JSONException e) { // Well, nothing to do here... } }
/** * If this was the second save on a new object while offline, then its objectId wasn't yet set * when the command was created, so it would have been considered a "create". But if the first * save succeeded, then there is an objectId now, and it will be mapped to the localId for this * command's result. If so, change the "create" operation to an "update", and add the objectId to * the command. */ private void maybeChangeServerOperation() { if (localId != null) { String objectId = getLocalIdManager().getObjectId(localId); if (objectId != null) { localId = null; httpPath += String.format("/%s", objectId); url = createUrl(httpPath); if (httpPath.startsWith("classes") && method == ParseHttpRequest.Method.POST) { method = ParseHttpRequest.Method.PUT; } } } }
public void resolveLocalIds() { try { ArrayList<JSONObject> localPointers = new ArrayList<>(); getLocalPointersIn(jsonParameters, localPointers); for (JSONObject pointer : localPointers) { String localId = (String) pointer.get("localId"); String objectId = getLocalIdManager().getObjectId(localId); if (objectId == null) { throw new IllegalStateException( "Tried to serialize a command referencing a new, unsaved object."); } pointer.put("objectId", objectId); pointer.remove("localId"); } maybeChangeServerOperation(); } catch (JSONException e) { // Well, nothing to do here... } }