Search in sources :

Example 1 with DocumentQuery.select

use of jakarta.nosql.document.DocumentQuery.select in project jnosql-diana-driver by eclipse.

the class ElasticsearchDocumentCollectionManagerTest method shouldFindOrderByNameDesc.

@Test
public void shouldFindOrderByNameDesc() throws InterruptedException {
    final DocumentEntity poliana = DocumentEntityGerator.getEntity();
    final DocumentEntity otavio = DocumentEntityGerator.getEntity();
    poliana.add("name", "poliana");
    otavio.add("name", "otavio");
    otavio.add("_id", "id2");
    entityManager.insert(Arrays.asList(poliana, otavio));
    SECONDS.sleep(1L);
    DocumentQuery query = DocumentQuery.select().from("person").orderBy("name").desc().build();
    String[] names = entityManager.select(query).map(d -> d.find("name")).filter(Optional::isPresent).map(Optional::get).map(d -> d.get(String.class)).toArray(String[]::new);
    assertArrayEquals(names, new String[] { "poliana", "otavio" });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ArrayList(java.util.ArrayList) TypeReference(jakarta.nosql.TypeReference) DocumentQuery(jakarta.nosql.document.DocumentQuery) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Documents(org.eclipse.jnosql.communication.document.Documents) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) QueryBuilders.termQuery(org.elasticsearch.index.query.QueryBuilders.termQuery) DocumentDeleteQuery.delete(jakarta.nosql.document.DocumentDeleteQuery.delete) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SECONDS(java.util.concurrent.TimeUnit.SECONDS) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Optional(java.util.Optional) Test(org.junit.jupiter.api.Test)

Example 2 with DocumentQuery.select

use of jakarta.nosql.document.DocumentQuery.select in project jnosql-diana-driver by eclipse.

the class ElasticsearchDocumentCollectionManagerTest method shouldFindOrderByName.

@Test
public void shouldFindOrderByName() throws InterruptedException {
    final DocumentEntity poliana = DocumentEntityGerator.getEntity();
    final DocumentEntity otavio = DocumentEntityGerator.getEntity();
    poliana.add("name", "poliana");
    otavio.add("name", "otavio");
    otavio.add("_id", "id2");
    entityManager.insert(Arrays.asList(poliana, otavio));
    SECONDS.sleep(1L);
    DocumentQuery query = DocumentQuery.select().from("person").orderBy("name").asc().build();
    String[] names = entityManager.select(query).map(d -> d.find("name")).filter(Optional::isPresent).map(Optional::get).map(d -> d.get(String.class)).toArray(String[]::new);
    assertArrayEquals(names, new String[] { "otavio", "poliana" });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ArrayList(java.util.ArrayList) TypeReference(jakarta.nosql.TypeReference) DocumentQuery(jakarta.nosql.document.DocumentQuery) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Documents(org.eclipse.jnosql.communication.document.Documents) Document(jakarta.nosql.document.Document) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) QueryBuilders.termQuery(org.elasticsearch.index.query.QueryBuilders.termQuery) DocumentDeleteQuery.delete(jakarta.nosql.document.DocumentDeleteQuery.delete) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SECONDS(java.util.concurrent.TimeUnit.SECONDS) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentEntity(jakarta.nosql.document.DocumentEntity) Optional(java.util.Optional) Test(org.junit.jupiter.api.Test)

Aggregations

TypeReference (jakarta.nosql.TypeReference)2 Document (jakarta.nosql.document.Document)2 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)2 DocumentDeleteQuery.delete (jakarta.nosql.document.DocumentDeleteQuery.delete)2 DocumentEntity (jakarta.nosql.document.DocumentEntity)2 DocumentQuery (jakarta.nosql.document.DocumentQuery)2 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Optional (java.util.Optional)2 SECONDS (java.util.concurrent.TimeUnit.SECONDS)2 Collectors (java.util.stream.Collectors)2 Documents (org.eclipse.jnosql.communication.document.Documents)2 QueryBuilders.termQuery (org.elasticsearch.index.query.QueryBuilders.termQuery)2 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.contains (org.hamcrest.Matchers.contains)2