Search in sources :

Example 1 with FieldRepresentation

use of org.jnosql.artemis.reflection.FieldRepresentation in project jnosql-artemis by eclipse.

the class AbstractColumnTemplate method delete.

@Override
public <T, ID> void delete(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());
    ColumnDeleteQuery query = ColumnQueryBuilder.delete().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
    getManager().delete(query);
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery)

Example 2 with FieldRepresentation

use of org.jnosql.artemis.reflection.FieldRepresentation in project jnosql-artemis by eclipse.

the class AbstractColumnTemplate 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());
    ColumnQuery query = ColumnQueryBuilder.select().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
    return singleResult(query);
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 3 with FieldRepresentation

use of org.jnosql.artemis.reflection.FieldRepresentation in project jnosql-artemis by eclipse.

the class AbstractColumnTemplateAsync method getDeleteQuery.

private <T, ID> ColumnDeleteQuery 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 ColumnQueryBuilder.delete().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 4 with FieldRepresentation

use of org.jnosql.artemis.reflection.FieldRepresentation in project jnosql-artemis by eclipse.

the class AbstractDocumentTemplate method delete.

@Override
public <T, ID> void delete(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());
    DocumentDeleteQuery query = DocumentQueryBuilder.delete().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
    delete(query);
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery)

Example 5 with FieldRepresentation

use of org.jnosql.artemis.reflection.FieldRepresentation 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)

Aggregations

FieldRepresentation (org.jnosql.artemis.reflection.FieldRepresentation)12 ClassRepresentation (org.jnosql.artemis.reflection.ClassRepresentation)11 Value (org.jnosql.diana.api.Value)3 Field (java.lang.reflect.Field)2 Optional (java.util.Optional)2 Converters (org.jnosql.artemis.Converters)2 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)2 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)2 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)1 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)1