Search in sources :

Example 1 with Select

use of com.couchbase.client.java.query.Select in project jnosql-diana-driver by eclipse.

the class CouchbaseDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.

@Test
public void shouldRetrieveListSubdocumentList() {
    DocumentEntity entity = entityManager.insert(createSubdocumentList());
    Document key = entity.find("_id").get();
    DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
    DocumentEntity documentEntity = entityManager.singleResult(query).get();
    assertNotNull(documentEntity);
    List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
    assertEquals(3, contacts.size());
    assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
Also used : Expression.x(com.couchbase.client.java.query.dsl.Expression.x) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) Statement(com.couchbase.client.java.query.Statement) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) HashMap(java.util.HashMap) JsonObject(com.couchbase.client.java.document.json.JsonObject) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) Select(com.couchbase.client.java.query.Select) TypeReference(jakarta.nosql.TypeReference) CouchbaseDocumentTcConfiguration(org.eclipse.jnosql.communication.couchbase.configuration.CouchbaseDocumentTcConfiguration) DocumentQuery(jakarta.nosql.document.DocumentQuery) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) CouchbaseKeyValueConfiguration(org.eclipse.jnosql.communication.couchbase.keyvalue.CouchbaseKeyValueConfiguration) BucketManager(jakarta.nosql.keyvalue.BucketManager) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Documents(org.eclipse.jnosql.communication.document.Documents) BucketManagerFactory(jakarta.nosql.keyvalue.BucketManagerFactory) Set(java.util.Set) CouchbaseUtil(org.eclipse.jnosql.communication.couchbase.CouchbaseUtil) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CouchbaseKeyValueTcConfiguration(org.eclipse.jnosql.communication.couchbase.configuration.CouchbaseKeyValueTcConfiguration) List(java.util.List) DocumentDeleteQuery.delete(jakarta.nosql.document.DocumentDeleteQuery.delete) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(jakarta.nosql.document.Document) Test(org.junit.jupiter.api.Test)

Example 2 with Select

use of com.couchbase.client.java.query.Select in project jnosql-diana-driver by eclipse.

the class CouchbaseDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.

@Test
public void shouldRetrieveListSubdocumentList() {
    DocumentEntity entity = entityManager.insert(createSubdocumentList());
    Document key = entity.find("_id").get();
    DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
    DocumentEntity documentEntity = entityManager.singleResult(query).get();
    assertNotNull(documentEntity);
    List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
    assertEquals(3, contacts.size());
    assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
Also used : Expression.x(com.couchbase.client.java.query.dsl.Expression.x) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Statement(com.couchbase.client.java.query.Statement) TypeReference(org.jnosql.diana.api.TypeReference) HashMap(java.util.HashMap) JsonObject(com.couchbase.client.java.document.json.JsonObject) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) HashSet(java.util.HashSet) Select(com.couchbase.client.java.query.Select) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) CouchbaseUtil(org.jnosql.diana.couchbase.CouchbaseUtil) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) GroupByPath(com.couchbase.client.java.query.dsl.path.GroupByPath) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) CouchbaseKeyValueConfiguration(org.jnosql.diana.couchbase.key.CouchbaseKeyValueConfiguration) Set(java.util.Set) DocumentQueryBuilder(org.jnosql.diana.api.document.query.DocumentQueryBuilder) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test) List(java.util.List) Documents(org.jnosql.diana.api.document.Documents) Matchers.contains(org.hamcrest.Matchers.contains) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BucketManager(org.jnosql.diana.api.key.BucketManager) Expression(com.couchbase.client.java.query.dsl.Expression) Optional(java.util.Optional) BucketManagerFactory(org.jnosql.diana.api.key.BucketManagerFactory) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

JsonObject (com.couchbase.client.java.document.json.JsonObject)2 Select (com.couchbase.client.java.query.Select)2 Statement (com.couchbase.client.java.query.Statement)2 Expression.x (com.couchbase.client.java.query.dsl.Expression.x)2 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.contains (org.hamcrest.Matchers.contains)2 AfterAll (org.junit.jupiter.api.AfterAll)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Test (org.junit.jupiter.api.Test)2