Пример #1
0
  static BasicDocumentRevision getFullRevisionFromCurrentCursor(Cursor cursor) {
    String docId = cursor.getString(0);
    long internalId = cursor.getLong(1);
    String revId = cursor.getString(2);
    long sequence = cursor.getLong(3);
    byte[] json = cursor.getBlob(4);
    boolean current = cursor.getInt(5) > 0;
    boolean deleted = cursor.getInt(6) > 0;

    long parent = -1L;
    if (cursor.columnType(7) == Cursor.FIELD_TYPE_INTEGER) {
      parent = cursor.getLong(7);
    } else if (cursor.columnType(7) == Cursor.FIELD_TYPE_NULL) {
    } else {
      throw new IllegalArgumentException("Unexpected type: " + cursor.columnType(7));
    }

    DocumentRevisionBuilder builder =
        new DocumentRevisionBuilder()
            .setDocId(docId)
            .setRevId(revId)
            .setBody(BasicDocumentBody.bodyWith(json))
            .setDeleted(deleted)
            .setSequence(sequence)
            .setInternalId(internalId)
            .setCurrnet(current)
            .setParent(parent);

    return builder.buildBasicDBObject();
  }
 @Override
 public int getDocumentCount() {
   Preconditions.checkState(this.isOpen(), "Database is closed");
   String sql = "SELECT COUNT(DISTINCT doc_id) FROM revs WHERE current=1 AND deleted=0";
   Cursor cursor = null;
   int result = 0;
   try {
     cursor = this.sqlDb.rawQuery(sql, null);
     if (cursor.moveToFirst()) {
       result = cursor.getInt(0);
     }
   } catch (SQLException e) {
     Log.e(LOG_TAG, "Error getting document count", e);
   } finally {
     DatabaseUtils.closeCursorQuietly(cursor);
   }
   return result;
 }