Search in sources :

Example 56 with ClassMapping

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);
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping)

Example 57 with ClassMapping

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);
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping)

Example 58 with ClassMapping

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;
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) ColumnEntity(jakarta.nosql.column.ColumnEntity)

Example 59 with ClassMapping

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);
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping)

Example 60 with ClassMapping

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);
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) ColumnQuery(jakarta.nosql.column.ColumnQuery) FieldMapping(org.eclipse.jnosql.mapping.reflection.FieldMapping)

Aggregations

ClassMapping (org.eclipse.jnosql.mapping.reflection.ClassMapping)60 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)31 Method (java.lang.reflect.Method)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 ValueSource (org.junit.jupiter.params.provider.ValueSource)19 FieldMapping (org.eclipse.jnosql.mapping.reflection.FieldMapping)12 List (java.util.List)10 Converters (jakarta.nosql.mapping.Converters)8 Edge (org.apache.tinkerpop.gremlin.structure.Edge)8 Graph (org.apache.tinkerpop.gremlin.structure.Graph)8 ClassMappings (org.eclipse.jnosql.mapping.reflection.ClassMappings)8 Collectors (java.util.stream.Collectors)7 Test (org.junit.jupiter.api.Test)7 Value (jakarta.nosql.Value)6 Optional (java.util.Optional)6 EntityNotFoundException (jakarta.nosql.mapping.EntityNotFoundException)5 SelectQuery (jakarta.nosql.query.SelectQuery)5 Iterator (java.util.Iterator)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Function (java.util.function.Function)5