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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations