use of org.eclipse.jnosql.mapping.reflection.FieldMapping in project jnosql-diana by eclipse.
the class AbstractDocumentTemplate method delete.
@Override
public <T, K> void delete(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());
DocumentDeleteQuery query = DocumentDeleteQuery.delete().from(classMapping.getName()).where(idField.getName()).eq(value).build();
delete(query);
}
use of org.eclipse.jnosql.mapping.reflection.FieldMapping in project jnosql-diana by eclipse.
the class AbstractColumnTemplate method delete.
@Override
public <T, K> void delete(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());
ColumnDeleteQuery query = ColumnDeleteQuery.delete().from(classMapping.getName()).where(idField.getName()).eq(value).build();
getManager().delete(query);
}
use of org.eclipse.jnosql.mapping.reflection.FieldMapping in project jnosql-diana by eclipse.
the class AbstractGraphConverter method feedId.
private <T> void feedId(Vertex vertex, T entity) {
ClassMapping mapping = getClassMappings().get(entity.getClass());
Optional<FieldMapping> id = mapping.getId();
Object vertexId = vertex.id();
if (Objects.nonNull(vertexId) && id.isPresent()) {
FieldMapping fieldMapping = id.get();
if (fieldMapping.getConverter().isPresent()) {
AttributeConverter attributeConverter = getConverters().get(fieldMapping.getConverter().get());
Object attributeConverted = attributeConverter.convertToEntityAttribute(vertexId);
fieldMapping.write(entity, fieldMapping.getValue(Value.of(attributeConverted)));
} else {
fieldMapping.write(entity, fieldMapping.getValue(Value.of(vertexId)));
}
}
}
use of org.eclipse.jnosql.mapping.reflection.FieldMapping in project jnosql-diana by eclipse.
the class AbstractGraphTemplate 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());
final Optional<Vertex> vertex = getTraversal().V(value).hasLabel(classMapping.getName()).tryNext();
return (Optional<T>) vertex.map(getConverter()::toEntity);
}
use of org.eclipse.jnosql.mapping.reflection.FieldMapping in project jnosql-diana by eclipse.
the class AbstractGraphTemplate method isIdNull.
private <T> boolean isIdNull(T entity) {
ClassMapping classMapping = getClassMappings().get(entity.getClass());
FieldMapping field = classMapping.getId().get();
return isNull(field.read(entity));
}
Aggregations