use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class StudentGradeServiceIntegrationTest method printDocuments.
private void printDocuments(List<JsonDocument> docs) {
for (JsonDocument doc : docs) {
String key = doc.id();
logger.info(key + " = " + doc.content().toString());
}
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class StudentGradeService method insert.
public String insert(StudentGrade studentGrade) throws DuplicateKeyException {
String id = keyGenerator.generateKey(studentGrade);
if (bucket.exists(id)) {
throw new DuplicateKeyException("document already exists with key " + id);
}
JsonObject content = JsonObject.empty().put("type", "StudentGrade").put("name", studentGrade.getName()).put("course", studentGrade.getCourse()).put("grade", studentGrade.getGrade()).put("hours", studentGrade.getHours());
JsonDocument doc = JsonDocument.create(id, content);
bucket.insert(doc);
return id;
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class CodeSnippets method retrieveAndUpsertExample.
static JsonDocument retrieveAndUpsertExample(Bucket bucket, String id) {
JsonDocument document = bucket.get(id);
JsonObject content = document.content();
content.put("homeTown", "Kansas City");
JsonDocument upserted = bucket.upsert(document);
return upserted;
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class CodeSnippets method replaceExample.
static JsonDocument replaceExample(Bucket bucket, String id) {
JsonDocument document = bucket.get(id);
JsonObject content = document.content();
content.put("homeTown", "Milwaukee");
JsonDocument replaced = bucket.replace(document);
return replaced;
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class CodeSnippets method insertExample.
static JsonDocument insertExample(Bucket bucket) {
JsonObject content = JsonObject.empty().put("name", "John Doe").put("type", "Person").put("email", "john.doe@mydomain.com").put("homeTown", "Chicago");
String id = UUID.randomUUID().toString();
JsonDocument document = JsonDocument.create(id, content);
JsonDocument inserted = bucket.insert(document);
return inserted;
}
Aggregations