Search in sources :

Example 1 with ClassMapping

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

Example 2 with ClassMapping

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

Example 3 with ClassMapping

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

Example 4 with ClassMapping

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

Example 5 with ClassMapping

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

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