Last active
August 29, 2015 14:02
-
-
Save ToxicBakery/3a9025b75aeaa2f1b10f to your computer and use it in GitHub Desktop.
Couchbase (Java) vs Couchbase Mobile (Android)
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
// Comparison of data management | |
// Given a simple object | |
class MyObject { | |
String name; | |
int value; | |
} | |
// Create an instance with some values | |
MyObject myObjectInstance = new MyObject(); | |
myObjectInstance.name = "One"; | |
myObjectInstance.value = 1; | |
Couchbase: | |
////////////////////////////// | |
// Create Document | |
client.set("myObjectInstance", myObjectInstance).get(); | |
// Retrieve Document | |
MyObject myObjectInstance = (MyObject) client.getDocument("myObjectInstance"); | |
// Update Document | |
MyObject myObjectInstance = (MyObject) client.getDocument("myObjectInstance"); | |
myObjectInstance.name = "newName"; | |
client.set("myObjectInstance", myObjectInstance); | |
////////////////////////////// | |
Couchbase Mobile: | |
////////////////////////////// | |
// Define Document | |
Map<String, Object> map = new HashMap<String, Object>(); | |
map.put("name", myObjectInstance.name); | |
map.put("value", myObjectInstance.value); | |
// Create Document | |
Document document = database.getDocument("myObjectInstance"); | |
UnsavedRevision rev = document.createRevision(); | |
rev.setUserProperties(map); | |
rev.save(); | |
// Retrieve Document | |
Document document = database.getDocument("myObjectInstance"); | |
MyObject obj = new MyObject(); | |
obj.name = document.getProperty("name"); | |
obj.value = document.getProperty("value"); | |
// Update Document | |
Document document = database.getDocument("myObjectInstance"); | |
UnsavedRevision rev = document.createRevision(); | |
rev.getUserProperties().put("name", "newName"); | |
rev.save(); | |
////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment