Search in sources :

Example 21 with JsonDocument

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;
}
Also used : ArrayList(java.util.ArrayList) JsonDocument(com.couchbase.client.java.document.JsonDocument) ViewRow(com.couchbase.client.java.view.ViewRow)

Example 22 with JsonDocument

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);
}
Also used : JsonDocument(com.couchbase.client.java.document.JsonDocument)

Example 23 with JsonDocument

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);
}
Also used : JsonDocument(com.couchbase.client.java.document.JsonDocument)

Example 24 with JsonDocument

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));
}
Also used : Bucket(com.couchbase.client.java.Bucket) JsonObject(com.couchbase.client.java.document.json.JsonObject) JsonDocument(com.couchbase.client.java.document.JsonDocument) Test(org.junit.Test)

Example 25 with JsonDocument

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);
}
Also used : IntStream(java.util.stream.IntStream) Statement(com.couchbase.client.java.query.Statement) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonObject(com.couchbase.client.java.document.json.JsonObject) Observable(rx.Observable) JsonDocument(com.couchbase.client.java.document.JsonDocument) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Select.select(com.couchbase.client.java.query.Select.select) JsonNode(com.fasterxml.jackson.databind.JsonNode) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult) N1qlQueryRow(com.couchbase.client.java.query.N1qlQueryRow) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Bucket(com.couchbase.client.java.Bucket) List(java.util.List) Stream(java.util.stream.Stream) Cluster(com.couchbase.client.java.Cluster) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Expression(com.couchbase.client.java.query.dsl.Expression) N1qlQuery(com.couchbase.client.java.query.N1qlQuery) CodeSnippets.extractJsonResult(com.baeldung.couchbase.n1ql.CodeSnippets.extractJsonResult) JsonArray(com.couchbase.client.java.document.json.JsonArray) Bucket(com.couchbase.client.java.Bucket) JsonObject(com.couchbase.client.java.document.json.JsonObject) JsonDocument(com.couchbase.client.java.document.JsonDocument) Test(org.junit.Test)

Aggregations

JsonDocument (com.couchbase.client.java.document.JsonDocument)26 JsonObject (com.couchbase.client.java.document.json.JsonObject)10 Bucket (com.couchbase.client.java.Bucket)6 AsyncBucket (com.couchbase.client.java.AsyncBucket)4 Test (org.junit.Test)4 Person (com.baeldung.couchbase.async.person.Person)3 ArrayList (java.util.ArrayList)3 Func1 (rx.functions.Func1)3 AsyncIntegrationTest (com.baeldung.couchbase.async.AsyncIntegrationTest)2 CouchbaseCluster (com.couchbase.client.java.CouchbaseCluster)2 CouchbaseEnvironment (com.couchbase.client.java.env.CouchbaseEnvironment)2 DefaultCouchbaseEnvironment (com.couchbase.client.java.env.DefaultCouchbaseEnvironment)2 ViewRow (com.couchbase.client.java.view.ViewRow)2 Observable (rx.Observable)2 CodeSnippets.extractJsonResult (com.baeldung.couchbase.n1ql.CodeSnippets.extractJsonResult)1 BackpressureException (com.couchbase.client.core.BackpressureException)1 Cluster (com.couchbase.client.java.Cluster)1 RawJsonDocument (com.couchbase.client.java.document.RawJsonDocument)1 JsonArray (com.couchbase.client.java.document.json.JsonArray)1 DocumentAlreadyExistsException (com.couchbase.client.java.error.DocumentAlreadyExistsException)1