Search in sources :

Example 21 with ClassRepresentation

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);
}
Also used : ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 22 with ClassRepresentation

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);
}
Also used : ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation)

Example 23 with ClassRepresentation

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);
}
Also used : ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation) Test(org.junit.jupiter.api.Test)

Example 24 with ClassRepresentation

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);
}
Also used : Money(org.jnosql.artemis.model.Money) ClassRepresentation(org.jnosql.artemis.reflection.ClassRepresentation) Test(org.junit.jupiter.api.Test)

Example 25 with ClassRepresentation

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;
}
Also used : DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) 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