final String TAG = "Hello-CouchBase"; Log.d(TAG, "Begin app"); // create a manager Manager manager; try{ manager = new Manager(new AndroidContext(this), Manager.DEFAULT_OPTIONS); Log.d(TAG, "Manager created"); }catch (IOException e){ Log.e(TAG, "Cannot create Manager object"); return; } // create a name for the database and make sure the name is legal String dbname = "hello"; if(!Manager.isValidDatabaseName(dbname)){ Log.e(TAG, "Bad database name"); return; } // create a new database Database database; try { database = manager.getDatabase(dbname); Log.d(TAG, "Database created"); }catch (CouchbaseLiteException e){ Log.e(TAG, "Cannot get database"); return; } // get the current date and time SimpleDateFormat dataFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Calendar calendar = GregorianCalendar.getInstance(); String currentTimeString = dataFormatter.format(calendar.getTime()); // create an object that contains data for a document Map docContent = new HashMap(); docContent.put("message", "Hello Couchbase Lite"); docContent.put("creationDate", currentTimeString); // display the data for the new document Log.d(TAG, "docContent =" + String.valueOf(docContent)); // create an empty document Document document = database.createDocument(); // add content to document and write the document to the database try { document.putProperties(docContent); Log.d(TAG, "Document written to database named " + dbname + " with ID = " + document.getId()); } catch (CouchbaseLiteException e){ Log.e(TAG, "Cannot write document to database", e); } // save the ID of the new document String docID = document.getId(); // retrieve the document from the database Document retrievedDocument = database.getDocument(docID); // display the retrieved document Log.d(TAG, "retrievedDocument=" + String.valueOf(retrievedDocument.getProperties())); // update the document Map updatedProperties = new HashMap(); updatedProperties.putAll(retrievedDocument.getProperties()); updatedProperties.put("message", "We're having a heat wave!"); updatedProperties.put("temperature", "95"); try { retrievedDocument.putProperties(updatedProperties); Log.d(TAG, "updated retrievedDocument=" + String.valueOf(retrievedDocument.getProperties())); }catch (CouchbaseLiteException e){ Log.e(TAG, "Cannot update document", e); } // delete the document try { retrievedDocument.delete(); Log.d(TAG, "Deleted document, deletion status = " + retrievedDocument.isDeleted()); }catch (CouchbaseLiteException e){ Log.e(TAG, "Cannot delete document", e); } Log.d(TAG, "End app");