use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class StudentGradeService method extractDocuments.
private List<JsonDocument> extractDocuments(ViewResult result) {
List<JsonDocument> docs = new ArrayList<>();
for (ViewRow row : result.allRows()) {
JsonDocument doc = row.document();
docs.add(doc);
}
return docs;
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class PersonCrudService method update.
@Override
public void update(Person person) {
JsonDocument document = converter.toDocument(person);
bucket.upsert(document);
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class PersonCrudService method create.
@Override
public void create(Person person) {
if (person.getId() == null) {
person.setId(UUID.randomUUID().toString());
}
JsonDocument document = converter.toDocument(person);
bucket.insert(document);
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class N1QLIntegrationTest method givenDocument_whenInsert_thenResult.
@Test
public void givenDocument_whenInsert_thenResult() {
Bucket bucket = bucketFactory.getTestBucket();
JsonObject personObj = JsonObject.create().put("name", "John").put("email", "john@doe.com").put("interests", JsonArray.from("Java", "Nigerian Jollof"));
String id = UUID.randomUUID().toString();
JsonDocument doc = JsonDocument.create(id, personObj);
bucket.insert(doc);
assertNotNull(bucket.get(id));
}
use of com.couchbase.client.java.document.JsonDocument in project tutorials by eugenp.
the class N1QLIntegrationTest method givenDocuments_whenBatchInsert_thenResult.
@Test
public void givenDocuments_whenBatchInsert_thenResult() {
Bucket bucket = bucketFactory.getTravelSampleBucket();
List<JsonDocument> documents = IntStream.rangeClosed(0, 10).mapToObj(i -> {
JsonObject content = JsonObject.create().put("id", i).put("type", "airline").put("name", "Sample Airline " + i);
return JsonDocument.create("cust_" + i, content);
}).collect(Collectors.toList());
List<JsonDocument> r5 = Observable.from(documents).flatMap(doc -> bucket.async().insert(doc)).toList().last().toBlocking().single();
r5.forEach(System.out::println);
}
Aggregations