use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.
the class AbstractDocumentEntityConverter method toEntity.
protected <T> T toEntity(Class<T> entityClass, List<Document> documents) {
ClassMapping mapping = getClassMappings().get(entityClass);
T instance = mapping.newInstance();
return convertEntity(documents, mapping, instance);
}
use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.
the class AbstractDocumentEntityConverter method toEntity.
@SuppressWarnings("unchecked")
@Override
public <T> T toEntity(DocumentEntity entity) {
requireNonNull(entity, "entity is required");
ClassMapping mapping = getClassMappings().findByName(entity.getName());
T instance = mapping.newInstance();
return convertEntity(entity.getDocuments(), mapping, instance);
}
use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.
the class AbstractDocumentEntityConverter method toEntity.
@Override
public <T> T toEntity(T entityInstance, DocumentEntity entity) {
requireNonNull(entity, "entity is required");
requireNonNull(entityInstance, "entityInstance is required");
ClassMapping mapping = getClassMappings().get(entityInstance.getClass());
return convertEntity(entity.getDocuments(), mapping, entityInstance);
}
use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.
the class AbstractDocumentEntityConverter method toDocument.
@Override
public DocumentEntity toDocument(Object entityInstance) {
requireNonNull(entityInstance, "Object is required");
ClassMapping mapping = getClassMappings().get(entityInstance.getClass());
DocumentEntity entity = DocumentEntity.of(mapping.getName());
mapping.getFields().stream().map(f -> to(f, entityInstance)).filter(FieldValue::isNotEmpty).map(f -> f.toDocument(this, getConverters())).flatMap(List::stream).forEach(entity::add);
return entity;
}
use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.
the class ConverterUtilTest method shouldConvert.
@Test
public void shouldConvert() {
ClassMapping mapping = mappings.get(Person.class);
String value = "100";
Object id = ConverterUtil.getValue(value, mapping, "id", converters);
assertEquals(100L, id);
}
Aggregations