use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class AbstractColumnEntityConverter method toEntity.
@SuppressWarnings("unchecked")
@Override
public <T> T toEntity(ColumnEntity entity) {
requireNonNull(entity, "entity is required");
ClassRepresentation representation = getClassRepresentations().findByName(entity.getName());
T instance = getReflections().newInstance(representation.getConstructor());
return convertEntity(entity.getColumns(), representation, instance);
}
use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class AbstractColumnEntityConverter method toEntity.
protected <T> T toEntity(Class<T> entityClass, List<Column> columns) {
ClassRepresentation representation = getClassRepresentations().get(entityClass);
T instance = getReflections().newInstance(representation.getConstructor());
return convertEntity(columns, representation, instance);
}
use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class ConverterUtilTest method shouldNotConvert.
@Test
public void shouldNotConvert() {
ClassRepresentation representation = representations.get(Person.class);
Object value = 10_000L;
Object id = ConverterUtil.getValue(value, representation, "id", converters);
assertEquals(id, value);
}
use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class ConverterUtilTest method shouldUseAttributeConvert.
@Test
public void shouldUseAttributeConvert() {
ClassRepresentation representation = representations.get(Worker.class);
Object value = new Money("BRL", BigDecimal.TEN);
Object converted = ConverterUtil.getValue(value, representation, "salary", converters);
assertEquals("BRL 10", converted);
}
use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class AbstractDocumentEntityConverter method toDocument.
@Override
public DocumentEntity toDocument(Object entityInstance) {
requireNonNull(entityInstance, "Object is required");
ClassRepresentation representation = getClassRepresentations().get(entityInstance.getClass());
DocumentEntity entity = DocumentEntity.of(representation.getName());
representation.getFields().stream().map(f -> to(f, entityInstance)).filter(FieldValue::isNotEmpty).map(f -> f.toDocument(this, getConverters())).flatMap(List::stream).forEach(entity::add);
return entity;
}
Aggregations