Search in sources :

Example 16 with ClassRepresentation

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

the class DefaultDocumentQueryMapperBuilder method deleteFrom.

@Override
public <T> DocumentDeleteFrom deleteFrom(Class<T> entityClass) {
    requireNonNull(entityClass, "entity is required");
    ClassRepresentation representation = classRepresentations.get().get(entityClass);
    return new DefaultDocumentMapperDeleteBuilder(representation, converters.get());
}
Also used : ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 17 with ClassRepresentation

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

the class DefaultDocumentQueryMapperBuilder method selectFrom.

@Override
public <T> DocumentFrom selectFrom(Class<T> entityClass) {
    requireNonNull(entityClass, "entity is required");
    ClassRepresentation representation = classRepresentations.get().get(entityClass);
    return new DefaultDocumentMapperSelectBuilder(representation, converters.get());
}
Also used : ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 18 with ClassRepresentation

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

the class ConverterUtil method getValue.

public static Object getValue(Object value, ClassRepresentation representation, String name, Converters converters) {
    Optional<FieldRepresentation> fieldOptional = representation.getFieldRepresentation(name);
    if (fieldOptional.isPresent()) {
        FieldRepresentation field = fieldOptional.get();
        Field nativeField = field.getNativeField();
        if (!nativeField.getType().equals(value.getClass())) {
            return field.getConverter().map(converters::get).map(a -> a.convertToDatabaseColumn(value)).orElseGet(() -> Value.of(value).get(nativeField.getType()));
        }
        return field.getConverter().map(converters::get).map(a -> a.convertToDatabaseColumn(value)).orElse(value);
    }
    return value;
}
Also used : FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) Converters(org.jnosql.artemis.Converters) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation) FieldRepresentation(org.jnosql.artemis.reflection.FieldRepresentation) Value(org.jnosql.diana.api.Value) Optional(java.util.Optional) Field(java.lang.reflect.Field) Field(java.lang.reflect.Field)

Example 19 with ClassRepresentation

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

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

Example 20 with ClassRepresentation

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

the class AbstractColumnEntityConverter method toEntity.

@Override
public <T> T toEntity(T entityInstance, ColumnEntity entity) {
    requireNonNull(entity, "entity is required");
    requireNonNull(entityInstance, "entityInstance is required");
    ClassRepresentation representation = getClassRepresentations().get(entityInstance.getClass());
    return convertEntity(entity.getColumns(), representation, entityInstance);
}
Also used : ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Aggregations

ClassRepresentation (org.jnosql.artemis.reflection.ClassRepresentation)29 FieldRepresentation (org.jnosql.artemis.reflection.FieldRepresentation)11 Test (org.junit.jupiter.api.Test)6 Field (java.lang.reflect.Field)2 Optional (java.util.Optional)2 Converters (org.jnosql.artemis.Converters)2 Money (org.jnosql.artemis.model.Money)2 Value (org.jnosql.diana.api.Value)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 ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)1 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)1 DocumentEntity (org.jnosql.diana.api.document.DocumentEntity)1