Search in sources :

Example 26 with DocumentQuery

use of org.jnosql.diana.api.document.DocumentQuery 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 27 with DocumentQuery

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

the class QueryAQLConverterTest method shouldRunEqualsQueryAnd.

@Test
public void shouldRunEqualsQueryAnd() {
    DocumentQuery query = select().from("collection").where("name").eq("value").and("age").lte(10).build();
    AQLQueryResult convert = QueryAQLConverter.select(query);
    String aql = convert.getQuery();
    Map<String, Object> values = convert.getValues();
    assertEquals("value", values.get("name"));
    assertEquals("FOR c IN collection FILTER  c.name == @name AND  c.age <= @age RETURN c", aql);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 28 with DocumentQuery

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

the class QueryAQLConverterTest method shouldRunEqualsQueryOr.

@Test
public void shouldRunEqualsQueryOr() {
    DocumentQuery query = select().from("collection").where("name").eq("value").or("age").lte(10).build();
    AQLQueryResult convert = QueryAQLConverter.select(query);
    String aql = convert.getQuery();
    Map<String, Object> values = convert.getValues();
    assertEquals("value", values.get("name"));
    assertEquals("FOR c IN collection FILTER  c.name == @name OR  c.age <= @age RETURN c", aql);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 29 with DocumentQuery

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

the class QueryAQLConverterTest method shouldRunEqualsQueryNot.

@Test
public void shouldRunEqualsQueryNot() {
    DocumentQuery query = select().from("collection").where("name").not().eq("value").build();
    AQLQueryResult convert = QueryAQLConverter.select(query);
    String aql = convert.getQuery();
    Map<String, Object> values = convert.getValues();
    assertEquals("value", values.get("name"));
    assertEquals("FOR c IN collection FILTER  NOT  c.name == @name RETURN c", aql);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 30 with DocumentQuery

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

the class QueryAQLConverterTest method shouldRunEqualsQuerySort2.

@Test
public void shouldRunEqualsQuerySort2() {
    DocumentQuery query = select().from("collection").where("name").eq("value").orderBy("name").asc().orderBy("age").desc().build();
    AQLQueryResult convert = QueryAQLConverter.select(query);
    String aql = convert.getQuery();
    Map<String, Object> values = convert.getValues();
    assertEquals("value", values.get("name"));
    assertEquals("FOR c IN collection FILTER  c.name == @name SORT  c.name ASC , c.age DESC RETURN c", aql);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)201 Test (org.junit.jupiter.api.Test)186 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)95 Document (org.jnosql.diana.api.document.Document)84 List (java.util.List)50 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)46 Person (org.jnosql.artemis.model.Person)37 DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)35 Arrays.asList (java.util.Arrays.asList)27 ArrayList (java.util.ArrayList)21 Duration (java.time.Duration)20 DocumentQueryBuilder.select (org.jnosql.diana.api.document.query.DocumentQueryBuilder.select)20 Optional (java.util.Optional)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 DocumentQueryBuilder.delete (org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete)17 BeforeEach (org.junit.jupiter.api.BeforeEach)17 Consumer (java.util.function.Consumer)16 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)16