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));
}
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();
}
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"));
}
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"));
}
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"));
}
Aggregations