use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class AbstractColumnTemplate method delete.
@Override
public <T, ID> void delete(Class<T> entityClass, ID id) {
requireNonNull(entityClass, "entityClass is required");
requireNonNull(id, "id is required");
ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
ColumnDeleteQuery query = ColumnQueryBuilder.delete().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
getManager().delete(query);
}
use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class AbstractColumnTemplate method find.
@Override
public <T, ID> Optional<T> find(Class<T> entityClass, ID id) {
requireNonNull(entityClass, "entityClass is required");
requireNonNull(id, "id is required");
ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
ColumnQuery query = ColumnQueryBuilder.select().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
return singleResult(query);
}
use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class AbstractColumnTemplateAsync method getDeleteQuery.
private <T, ID> ColumnDeleteQuery getDeleteQuery(Class<T> entityClass, ID id) {
ClassRepresentation classRepresentation = getClassRepresentations().get(entityClass);
FieldRepresentation idField = classRepresentation.getId().orElseThrow(() -> IdNotFoundException.newInstance(entityClass));
Object value = ConverterUtil.getValue(id, classRepresentation, idField.getFieldName(), getConverters());
return ColumnQueryBuilder.delete().from(classRepresentation.getName()).where(idField.getName()).eq(value).build();
}
use of org.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class AbstractColumnEntityConverter method toColumn.
@Override
public ColumnEntity toColumn(Object entityInstance) {
requireNonNull(entityInstance, "Object is required");
ClassRepresentation representation = getClassRepresentations().get(entityInstance.getClass());
ColumnEntity entity = ColumnEntity.of(representation.getName());
representation.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.jnosql.artemis.reflection.ClassRepresentation in project jnosql-artemis by eclipse.
the class ConverterUtilTest method shouldConvert.
@Test
public void shouldConvert() {
ClassRepresentation representation = representations.get(Person.class);
String value = "100";
Object id = ConverterUtil.getValue(value, representation, "id", converters);
assertEquals(100L, id);
}
Aggregations