docs: @Override
      public Void call(SQLDatabase db) throws DocumentStoreException {
  
           /*
           Pick winner and mark the appropriate revision with the 'current' flag set
           - There can only be one winner in a tree (or set of trees - if there is no common root)
             at any one time, so if there is a new winner, we only have to mark the old winner as
             no longer 'current'. This is the 'previousWinner' object
           - The new winner is determined by:
             * consider only non-deleted leafs
             * sort according to the CouchDB sorting algorithm: highest rev wins, if there is a tie
               then do a lexicographical compare of the revision ID strings
             * we do a reverse sort (highest first) and pick the 1st and mark it 'current'
             * special case: if all leafs are deleted, then apply sorting and selection criteria
               above to all leafs
           */
  
          // first get all non-deleted leafs
          SortedMap<String, Long> leafs = new TreeMap<String, Long>(Collections.reverseOrder(new
                  GenerationComparator()));
  
          Cursor cursor = null;
          try {
              cursor = db.rawQuery(GET_NON_DELETED_LEAFS, new String[]{Long.toString(docNumericId)});
              while (cursor.moveToNext()) {
                  leafs.put(cursor.getString(0), cursor.getLong(1));
              }
          } catch (SQLException sqe) {
              throw new DocumentStoreException("Exception thrown whilst trying to fetch non-deleted " +
                      "leaf nodes.", sqe);
          } finally {
              DatabaseUtils.closeCursorQuietly(cursor);
          }
  
          // this is a corner case - all leaf nodes are deleted
          // re-get with the same query but without the revs.delete clause
          if (leafs.size() == 0) {
              try {
                  cursor = db.rawQuery(GET_ALL_LEAFS, new String[]{Long.toString(docNumericId)});
                  while (cursor.moveToNext()) {
                      leafs.put(cursor.getString(0), cursor.getLong(1));
                  }
              } catch (SQLException sqe) {
                  throw new DocumentStoreException("Exception thrown whilst trying to fetch all leaf " +
                          "nodes.", sqe);
              } finally {
                  DatabaseUtils.closeCursorQuietly(cursor);
              }
          }
  
          // new winner will be at the top of the list
          long newWinnerSeq = leafs.get(leafs.firstKey());
          // set current=1 for winning sequence
          ContentValues currentTrue = new ContentValues();
          currentTrue.put("current", 1);
          db.update("revs", currentTrue,
                  "sequence=?", new String[]{Long.toString(newWinnerSeq)});
          // set current=0 for all other leaf sequences with this doc_id
          ContentValues currentFalse = new ContentValues();
          currentFalse.put("current", 0);
          db.update("revs", currentFalse,
                  "sequence!=? AND doc_id=? AND sequence NOT IN " +
                          "(SELECT DISTINCT parent FROM revs revs_inner WHERE parent NOT NULL AND revs_inner.doc_id=revs.doc_id)",
                  new String[]{Long.toString(newWinnerSeq), Long.toString(docNumericId)});
          return null;
      }