Search in sources :

Example 21 with ClassMapping

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

Example 22 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class AbstractGraphTemplate method getVertex.

private <T> Optional<Vertex> getVertex(T entity) {
    ClassMapping classMapping = getClassMappings().get(entity.getClass());
    FieldMapping field = classMapping.getId().get();
    Object id = field.read(entity);
    Iterator<Vertex> vertices = getVertices(id);
    if (vertices.hasNext()) {
        return Optional.of(vertices.next());
    }
    return Optional.empty();
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) FieldMapping(org.eclipse.jnosql.mapping.reflection.FieldMapping)

Example 23 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class SelectQueryConverterTest method shouldRunQuery11.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByAgeIn" })
public void shouldRunQuery11(String methodName) {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
    graph.addVertex(T.label, "Person", "name", "Otavio", "age", 30);
    graph.addVertex(T.label, "Person", "name", "Ada", "age", 40);
    graph.addVertex(T.label, "Person", "name", "Poliana", "age", 25);
    ClassMapping mapping = mappings.get(Person.class);
    GraphQueryMethod queryMethod = new GraphQueryMethod(mapping, graph.traversal().V(), converters, method, new Object[] { Arrays.asList(25, 40, 30) });
    List<Vertex> vertices = converter.apply(queryMethod, null).collect(Collectors.toList());
    List<Object> names = vertices.stream().map(v -> v.value("name")).sorted().collect(Collectors.toList());
    assertEquals(3, vertices.size());
    MatcherAssert.assertThat(names, Matchers.contains("Ada", "Otavio", "Poliana"));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Method(java.lang.reflect.Method) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class SelectQueryConverterTest method shouldRunQuery12.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByNameIn" })
public void shouldRunQuery12(String methodName) {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
    graph.addVertex(T.label, "Person", "name", "Otavio", "age", 30);
    graph.addVertex(T.label, "Person", "name", "Ada", "age", 40);
    graph.addVertex(T.label, "Person", "name", "Poliana", "age", 25);
    ClassMapping mapping = mappings.get(Person.class);
    GraphQueryMethod queryMethod = new GraphQueryMethod(mapping, graph.traversal().V(), converters, method, new Object[] { Arrays.asList("Otavio", "Ada", "Poliana") });
    List<Vertex> vertices = converter.apply(queryMethod, null).collect(Collectors.toList());
    List<Object> names = vertices.stream().map(v -> v.value("name")).sorted().collect(Collectors.toList());
    assertEquals(3, vertices.size());
    MatcherAssert.assertThat(names, Matchers.contains("Ada", "Otavio", "Poliana"));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Method(java.lang.reflect.Method) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with ClassMapping

use of org.eclipse.jnosql.mapping.reflection.ClassMapping in project jnosql-diana by eclipse.

the class SelectQueryConverterTest method shouldRunQuery2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByNameNotEquals" })
public void shouldRunQuery2(String methodName) {
    Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
    graph.addVertex("Person").property("name", "Otavio");
    graph.addVertex("Person").property("name", "Ada");
    graph.addVertex("Person").property("name", "Poliana");
    ClassMapping mapping = mappings.get(Person.class);
    GraphQueryMethod queryMethod = new GraphQueryMethod(mapping, graph.traversal().V(), converters, method, new Object[] { "Ada" });
    List<Vertex> vertices = converter.apply(queryMethod, null).collect(Collectors.toList());
    assertEquals(2, vertices.size());
    assertNotEquals("Ada", vertices.get(0).value("name"));
    assertNotEquals("Ada", vertices.get(1).value("name"));
}
Also used : ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Method(java.lang.reflect.Method) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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