use of org.jnosql.diana.api.Value in project jnosql-artemis by eclipse.
the class AbstractKeyValueEntityConverter method toEntity.
@Override
public <T> T toEntity(Class<T> entityClass, KeyValueEntity<?> entity) {
Value value = entity.getValue();
T t = value.get(entityClass);
if (Objects.isNull(t)) {
return null;
}
FieldRepresentation key = getId(entityClass, getClassRepresentations().get(entityClass));
Object keyValue = getReflections().getValue(t, key.getNativeField());
if (Objects.isNull(keyValue) || !keyValue.equals(entity.getKey())) {
getReflections().setValue(t, key.getNativeField(), entity.getKey());
}
return t;
}
use of org.jnosql.diana.api.Value 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;
}
Aggregations