@Override protected void updateBookkeeping(Record record) throws NoGuidForIdException, NullCursorException, ParentNotFoundException { super.updateBookkeeping(record); BookmarkRecord bmk = (BookmarkRecord) record; // If record is folder, update maps and re-parent children if necessary. if (!bmk.isFolder()) { Logger.debug(LOG_TAG, "Not a folder. No bookkeeping."); return; } Logger.debug(LOG_TAG, "Updating bookkeeping for folder " + record.guid); // Mappings between ID and GUID. // TODO: update our persisted children arrays! // TODO: if our Android ID just changed, replace parents for all of our children. parentGuidToIDMap.put(bmk.guid, bmk.androidID); parentIDToGuidMap.put(bmk.androidID, bmk.guid); JSONArray childArray = bmk.children; if (Logger.logVerbose(LOG_TAG)) { Logger.trace(LOG_TAG, bmk.guid + " has children " + childArray.toJSONString()); } parentToChildArray.put(bmk.guid, childArray); // Re-parent. if (missingParentToChildren.containsKey(bmk.guid)) { for (String child : missingParentToChildren.get(bmk.guid)) { // This might return -1; that's OK, the bookmark will // be properly repositioned later. long position = childArray.indexOf(child); dataAccessor.updateParentAndPosition(child, bmk.androidID, position); needsReparenting--; } missingParentToChildren.remove(bmk.guid); } }
/** * Ensure that the local database row for the provided bookmark reflects this record's parent * information. * * @param bookmark */ private void relocateBookmark(BookmarkRecord bookmark) { dataAccessor.updateParentAndPosition( bookmark.guid, bookmark.androidParentID, bookmark.androidPosition); }