use of org.jnosql.artemis.reflection.FieldRepresentation in project jnosql-artemis by eclipse.
the class AbstractDocumentTemplate method find.
@Override
public <T, ID> Optional<T> find(Class<T> entityClass, ID id) {
requireNonNull(entityClass, "entityClass is required");
requireNonNull(id, "id 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();
return singleResult(query);
}
use of org.jnosql.artemis.reflection.FieldRepresentation in project jnosql-artemis by eclipse.
the class AbstractDocumentTemplateAsync method getDeleteQuery.
private <T, ID> DocumentDeleteQuery getDeleteQuery(Class<T> entityClass, ID id) {
ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
return DocumentQueryBuilder.delete().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
}
Aggregations