Search in sources :

Example 36 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.

the class CouchbaseDocumentCollectionManagerTest method shouldSaveSetDocument.

@Test
public void shouldSaveSetDocument() throws InterruptedException {
    Set<String> set = new HashSet<>();
    set.add("Acarajé");
    set.add("Munguzá");
    DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME);
    entity.add(Document.of("_id", "id"));
    entity.add(Document.of("foods", set));
    entityManager.insert(entity);
    Document id = entity.find("_id").get();
    Thread.sleep(1_000L);
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentEntity entityFound = entityManager.singleResult(query).get();
    Optional<Document> foods = entityFound.find("foods");
    Set<String> setFoods = foods.get().get(new TypeReference<Set<String>>() {
    });
    assertEquals(set, setFoods);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) HashSet(java.util.HashSet) Set(java.util.Set) Document(org.jnosql.diana.api.document.Document) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 37 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.

the class DocumentQueryTest method shouldShouldDefineLimit.

@Test
public void shouldShouldDefineLimit() {
    DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
    Document name = entity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).limit(2L).build();
    List<DocumentEntity> entities = entityManager.select(query);
    assertEquals(2, entities.size());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 38 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.

the class DocumentQueryTest method shouldFindDocumentByNameSortDesc.

@Test
public void shouldFindDocumentByNameSortDesc() {
    DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id4"), Document.of("name", "name3"), Document.of("_key", "person:id4")));
    Optional<Document> name = entity.find("name");
    DocumentQuery query = select().from(COLLECTION_NAME).orderBy("name").desc().build();
    List<DocumentEntity> entities = entityManager.select(query);
    List<String> result = entities.stream().flatMap(e -> e.getDocuments().stream()).filter(d -> "name".equals(d.getName())).map(d -> d.get(String.class)).collect(Collectors.toList());
    assertFalse(result.isEmpty());
    assertThat(result, contains("name3", "name", "name", "name"));
}
Also used : Document(org.jnosql.diana.api.document.Document) Arrays(java.util.Arrays) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) CouchbaseKeyValueConfiguration(org.jnosql.diana.couchbase.key.CouchbaseKeyValueConfiguration) Collectors(java.util.stream.Collectors) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) Matchers.contains(org.hamcrest.Matchers.contains) Arrays.asList(java.util.Arrays.asList) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) BucketManager(org.jnosql.diana.api.key.BucketManager) CouchbaseUtil(org.jnosql.diana.couchbase.CouchbaseUtil) Optional(java.util.Optional) BucketManagerFactory(org.jnosql.diana.api.key.BucketManagerFactory) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 39 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.

the class DocumentQueryTest method shouldShouldDefineLimitAndStart.

@Test
public void shouldShouldDefineLimitAndStart() {
    DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
    Document name = entity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).start(2L).limit(2L).build();
    List<DocumentEntity> entities = entityManager.select(query);
    assertEquals(1, entities.size());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Example 40 with Document

use of org.jnosql.diana.api.document.Document in project jnosql-diana-driver by eclipse.

the class DocumentQueryTest method shouldShouldDefineStart.

@Test
public void shouldShouldDefineStart() {
    DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
    Document name = entity.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).start(1L).build();
    List<DocumentEntity> entities = entityManager.select(query);
    assertEquals(2, entities.size());
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Document (org.jnosql.diana.api.document.Document)126 Test (org.junit.jupiter.api.Test)102 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)94 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)71 List (java.util.List)41 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)37 ArrayList (java.util.ArrayList)25 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)25 Arrays.asList (java.util.Arrays.asList)23 HashMap (java.util.HashMap)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 Map (java.util.Map)11 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 TypeReference (org.jnosql.diana.api.TypeReference)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Matchers.contains (org.hamcrest.Matchers.contains)10 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)10 Arrays (java.util.Arrays)8 Optional (java.util.Optional)8 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)8