Java Code Examples for com.couchbase.lite.Document#getProperties()

The following examples show how to use com.couchbase.lite.Document#getProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From mini-hacks with MIT License 6 votes vote down vote up
/**
 * Handle click on item in list
 */
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {

    // Step 10 code goes here
    // This code handles checkbox touches.  Couchbase Lite documents are like versioned-maps.
    // To change a Document, add a new Revision.
    QueryRow row = (QueryRow) adapterView.getItemAtPosition(position);
    Document document = row.getDocument();
    Map<String, Object> newProperties = new HashMap<String, Object>(document.getProperties());

    boolean checked = ((Boolean) newProperties.get("check")).booleanValue();
    newProperties.put("check", !checked);

    try {
        document.putProperties(newProperties);
        kitchenSyncArrayAdapter.notifyDataSetChanged();
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), "Error updating database, see logs for details", Toast.LENGTH_LONG).show();
        Log.e(TAG, "Error updating database", e);
    }

}
 
Example 2
Source File: MainActivity.java    From couchbase-lite-android with Apache License 2.0 5 votes vote down vote up
void databaseOperation() {
    try {
        Manager mgr = new Manager(new AndroidContext(getBaseContext()), null);
        DatabaseOptions opt = new DatabaseOptions();
        opt.setCreate(true);
        Database db = mgr.openDatabase(DB_NAME, opt);

        Map<String, Object> props;
        Document doc = db.getExistingDocument(DOC_ID);
        if (doc == null) {
            // new doc
            doc = db.getDocument(DOC_ID);
            props = new HashMap<>();
            props.put("Database Version", "1.4.1");
            props.put("update", 1);
            doc.putProperties(props);
        } else {
            // update
            props = new HashMap<>(doc.getProperties());
            props.put("update", (Integer) props.get("update") + 1);
            doc.putProperties(props);
        }

        Log.i(TAG, "Num of docs: " + db.getDocumentCount());
        Log.i(TAG, "Doc content: " + db.getDocument(DOC_ID).getProperties());

        db.close();
    } catch (Exception e) {
        Log.e(TAG, "" + e.getMessage());
        e.printStackTrace();
    }
}
 
Example 3
Source File: MainActivity.java    From couchbase-lite-android with Apache License 2.0 5 votes vote down vote up
void databaseOperationSDCard() {
    try {
        Manager mgr = new Manager(new SDCardContext(getBaseContext()), null);
        DatabaseOptions opt = new DatabaseOptions();
        opt.setCreate(true);
        Database db = mgr.openDatabase(DB_NAME, opt);

        Map<String, Object> props;
        Document doc = db.getExistingDocument(DOC_ID);
        if (doc == null) {
            // new doc
            doc = db.getDocument(DOC_ID);
            props = new HashMap<>();
            props.put("Database Version", "1.4.1");
            props.put("update", 1);
            doc.putProperties(props);
        } else {
            // update
            props = new HashMap<>(doc.getProperties());
            props.put("update", (Integer) props.get("update") + 1);
            doc.putProperties(props);
        }

        Log.i(TAG, "Num of docs: " + db.getDocumentCount());
        Log.i(TAG, "Doc content: " + db.getDocument(DOC_ID).getProperties());

        db.close();
    } catch (Exception e) {
        Log.e(TAG, "" + e.getMessage());
        e.printStackTrace();
    }
}