Created
January 22, 2016 07:56
-
-
Save hideki/bdf9b4ca5a8736341fbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected void startCBLite() throws IOException, CouchbaseLiteException { | |
| manager = new Manager(new AndroidContext(this), Manager.DEFAULT_OPTIONS); | |
| // DatabaseOptions options = new DatabaseOptions(); | |
| // options.setCreate(true); | |
| // options.setStorageType(Manager.FORESTDB_STORAGE); | |
| // database = manager.openDatabase(DATABASE_NAME, options); | |
| database = manager.getDatabase(DATABASE_NAME); | |
| } | |
| protected void stopCBLite() { | |
| if (database != null) { | |
| database.close(); | |
| database = null; | |
| } | |
| if (manager != null) { | |
| manager.close(); | |
| manager = null; | |
| } | |
| } | |
| public void createDocs(View view) { | |
| Log.e(TAG, "createDocs()"); | |
| try { | |
| for(int i = 0; i < 100; i++) { | |
| Document doc = database.getDocument("doc-" + String.format("%05d", i)); | |
| Map<String, Object> props = new HashMap<>(); | |
| props.put("key", i); | |
| doc.putProperties(props); | |
| } | |
| }catch (CouchbaseLiteException e){ | |
| Toast.makeText(getApplicationContext(), "Error to create new document", Toast.LENGTH_LONG).show(); | |
| Log.e(TAG, "Error to create new document", e); | |
| } | |
| } | |
| public void printDocs(View view) { | |
| Log.e(TAG, "printDocs()"); | |
| try { | |
| Query query = database.createAllDocumentsQuery(); | |
| QueryEnumerator e = query.run(); | |
| for(QueryRow row : e){ | |
| Log.e(TAG, "docID=" + row.getDocumentId()); | |
| } | |
| }catch (CouchbaseLiteException e){ | |
| Toast.makeText(getApplicationContext(), "Error to iterate all documents", Toast.LENGTH_LONG).show(); | |
| Log.e(TAG, "Error to iterate all documents", e); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment