Java Code Examples for com.couchbase.lite.Manager

The following examples show how to use com.couchbase.lite.Manager. These examples are extracted from open source projects. 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 Project: mini-hacks   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    docCountLabel = (TextView) findViewById(docCount);

    try {
        manager = new Manager(new AndroidContext(getApplicationContext()), Manager.DEFAULT_OPTIONS);
    } catch (IOException e) {
        e.printStackTrace();
    }

    DatabaseDownloader databaseDownloader = new DatabaseDownloader(getApplicationContext());
    databaseDownloader.execute();
    databaseDownloader.setDownloaderListener(new DownloaderListener() {
        @Override
        public void onCompleted() {
            setupQuery();
        }
    });

}
 
Example 2
Source Project: react-native-couchbase-lite   Source File: ReactCBLite.java    License: MIT License 5 votes vote down vote up
private void initWithCredentials(Credentials credentials, Callback callback) {
    this.allowedCredentials = credentials;

    try {
        View.setCompiler(new JavaScriptViewCompiler());
        Database.setFilterCompiler(new JavaScriptReplicationFilterCompiler());

        AndroidContext context = new AndroidContext(this.context);

        manager = new Manager(context, Manager.DEFAULT_OPTIONS);

        this.startListener();

        String url;
        if (credentials != null) {
            url = String.format(
                    Locale.ENGLISH,
                    "http://%s:%[email protected]:%d/",
                    credentials.getLogin(),
                    credentials.getPassword(),
                    listener.getListenPort()
            );
        } else {
            url = String.format(
                    Locale.ENGLISH,
                    "http://localhost:%d/",
                    listener.getListenPort()
            );
        }

        callback.invoke(url, null);

    } catch (final Exception e) {
        Log.e(TAG, "Couchbase init failed", e);
        callback.invoke(null, e.getMessage());
    }
}
 
Example 3
Source Project: react-native-couchbase-lite   Source File: ReactCBLite.java    License: MIT License 5 votes vote down vote up
private static void setLogLevel(int level) {
    Log.i(TAG, "Setting log level to '" + level + "'");

    Manager.enableLogging(Log.TAG, level);
    Manager.enableLogging(Log.TAG_SYNC, level);
    Manager.enableLogging(Log.TAG_QUERY, level);
    Manager.enableLogging(Log.TAG_VIEW, level);
    Manager.enableLogging(Log.TAG_CHANGE_TRACKER, level);
    Manager.enableLogging(Log.TAG_BLOB_STORE, level);
    Manager.enableLogging(Log.TAG_DATABASE, level);
    Manager.enableLogging(Log.TAG_LISTENER, level);
    Manager.enableLogging(Log.TAG_MULTI_STREAM_WRITER, level);
    Manager.enableLogging(Log.TAG_REMOTE_REQUEST, level);
    Manager.enableLogging(Log.TAG_ROUTER, level);
}
 
Example 4
Source Project: mini-hacks   Source File: SyncManager.java    License: MIT License 5 votes vote down vote up
public SyncManager(Context context) {
    this.context = context;

    Manager.enableLogging("CityExplorer", Logger.LogLevel.VERBOSE);
    Manager.enableLogging("Sync", Logger.LogLevel.VERBOSE);

    openDatabase();
}
 
Example 5
Source Project: couchbase-lite-android   Source File: MainActivity.java    License: 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 6
Source Project: couchbase-lite-android   Source File: MainActivity.java    License: 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();
    }
}
 
Example 7
private void setupCouchbase() throws CouchbaseLiteException, IOException {
    Manager manager = new Manager(new AndroidContext(getTargetContext()),
            Manager.DEFAULT_OPTIONS);
    database = manager.getDatabase(DB_NAME);
}