Search in sources :

Example 81 with DocumentQuery

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

the class AbstractDocumentTemplateAsync method find.

@Override
public <T, ID> void find(Class<T> entityClass, ID id, Consumer<Optional<T>> callBack) {
    requireNonNull(entityClass, "entityClass is required");
    requireNonNull(id, "id is required");
    requireNonNull(callBack, "callBack is required");
    ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
    FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
    Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
    DocumentQuery query = DocumentQueryBuilder.select().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
    singleResult(query, callBack);
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 82 with DocumentQuery

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

the class DefaultDocumentMapperSelectBuilderTest method shouldSelectWhereNameAnd.

@Test
public void shouldSelectWhereNameAnd() {
    DocumentQuery query = mapperBuilder.selectFrom(Person.class).where("age").between(10, 20).and("name").eq("Ada").build();
    DocumentQuery queryExpected = select().from("Person").where("age").between(10, 20).and("name").eq("Ada").build();
    assertEquals(queryExpected, query);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 83 with DocumentQuery

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

the class DefaultDocumentMapperSelectBuilderTest method shouldSelectWhereNameGt.

@Test
public void shouldSelectWhereNameGt() {
    DocumentQuery query = mapperBuilder.selectFrom(Person.class).where("id").gt(10).build();
    DocumentQuery queryExpected = select().from("Person").where("_id").gt(10L).build();
    assertEquals(queryExpected, query);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Person(org.jnosql.artemis.model.Person) Test(org.junit.jupiter.api.Test)

Example 84 with DocumentQuery

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

the class DefaultDocumentMapperSelectBuilderTest method shouldSelectLimit.

@Test
public void shouldSelectLimit() {
    DocumentQuery query = mapperBuilder.selectFrom(Worker.class).limit(10).build();
    DocumentQuery queryExpected = select().from("Worker").limit(10L).build();
    assertEquals(queryExpected, query);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 85 with DocumentQuery

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

the class DefaultDocumentMapperSelectBuilderTest method shouldQueryBySubEntity.

@Test
public void shouldQueryBySubEntity() {
    DocumentQuery query = mapperBuilder.selectFrom(Address.class).where("zipcode.zip").eq("01312321").build();
    DocumentQuery queryExpected = select().from("Address").where("zip").eq("01312321").build();
    assertEquals(queryExpected, query);
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Address(org.jnosql.artemis.model.Address) 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