use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.
the class AbstractColumnEntityConverter method toEntity.
@Override
public <T> T toEntity(ColumnEntity entity) {
requireNonNull(entity, "entity is required");
ClassMapping mapping = getClassMappings().findByName(entity.getName());
T instance = mapping.newInstance();
return convertEntity(entity.getColumns(), mapping, instance);
}
use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana 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");
ClassMapping mapping = getClassMappings().get(entityInstance.getClass());
return convertEntity(entity.getColumns(), mapping, entityInstance);
}
use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.
the class AbstractColumnEntityConverter method toColumn.
@Override
public ColumnEntity toColumn(Object entityInstance) {
requireNonNull(entityInstance, "Object is required");
ClassMapping mapping = getClassMappings().get(entityInstance.getClass());
ColumnEntity entity = ColumnEntity.of(mapping.getName());
mapping.getFields().stream().map(f -> to(f, entityInstance)).filter(FieldValue::isNotEmpty).map(f -> f.toColumn(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 AbstractColumnEntityConverter method toEntity.
protected <T> T toEntity(Class<T> entityClass, List<Column> columns) {
ClassMapping mapping = getClassMappings().get(entityClass);
T instance = mapping.newInstance();
return convertEntity(columns, mapping, instance);
}
use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.
the class AbstractColumnTemplate method find.
@Override
public <T, K> Optional<T> find(Class<T> entityClass, K id) {
requireNonNull(entityClass, "entityClass is required");
requireNonNull(id, "id is required");
ClassMapping classMapping = getClassMappings().get(entityClass);
FieldMapping idField = classMapping.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
Object value = ConverterUtil.getValue(id, classMapping, idField.getFieldName(), getConverters());
ColumnQuery query = ColumnQuery.select().from(classMapping.getName()).where(idField.getName()).eq(value).build();
return singleResult(query);
}
Aggregations