Search in sources :

Example 1 with Converters

use of jakarta.nosql.mapping.Converters in project jnosql-diana by eclipse.

the class RepositoryGraphBean method create.

@Override
public Repository create(CreationalContext<Repository> creationalContext) {
    ClassMappings classMappings = getInstance(ClassMappings.class);
    GraphTemplate repository = provider.isEmpty() ? getInstance(GraphTemplate.class) : getInstance(GraphTemplate.class, DatabaseQualifier.ofGraph(provider));
    GraphConverter converter = getInstance(GraphConverter.class);
    Graph graph = provider.isEmpty() ? getInstance(Graph.class) : getInstance(Graph.class, DatabaseQualifier.ofGraph(provider));
    Converters converters = getInstance(Converters.class);
    GraphRepositoryProxy handler = new GraphRepositoryProxy(repository, classMappings, type, graph, converter, converters);
    return (Repository) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
Also used : Repository(jakarta.nosql.mapping.Repository) Graph(org.apache.tinkerpop.gremlin.structure.Graph) GraphTemplate(org.eclipse.jnosql.mapping.graph.GraphTemplate) Converters(jakarta.nosql.mapping.Converters) GraphConverter(org.eclipse.jnosql.mapping.graph.GraphConverter) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings)

Example 2 with Converters

use of jakarta.nosql.mapping.Converters in project jnosql-diana by eclipse.

the class SelectQueryConverterTest method shouldRunQuery9.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByAgeLessThanOrderByNameDesc" })
public void shouldRunQuery9(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[] { 100 });
    List<Vertex> vertices = converter.apply(queryMethod, null).collect(Collectors.toList());
    List<Object> names = vertices.stream().map(v -> v.value("name")).collect(Collectors.toList());
    assertEquals(3, vertices.size());
    MatcherAssert.assertThat(names, Matchers.contains("Poliana", "Otavio", "Ada"));
}
Also used : Person(org.eclipse.jnosql.mapping.graph.model.Person) ValueSource(org.junit.jupiter.params.provider.ValueSource) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Matchers(org.hamcrest.Matchers) Converters(jakarta.nosql.mapping.Converters) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) T(org.apache.tinkerpop.gremlin.structure.T) Collectors(java.util.stream.Collectors) Repository(jakarta.nosql.mapping.Repository) Inject(javax.inject.Inject) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) Stream(java.util.stream.Stream) CDIExtension(jakarta.nosql.tck.test.CDIExtension) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Method(java.lang.reflect.Method) Edge(org.apache.tinkerpop.gremlin.structure.Edge) 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 3 with Converters

use of jakarta.nosql.mapping.Converters in project jnosql-diana by eclipse.

the class RepositoryDocumentBean method create.

@Override
public Repository create(CreationalContext<Repository> context) {
    ClassMappings classMappings = getInstance(ClassMappings.class);
    DocumentTemplate template = provider.isEmpty() ? getInstance(DocumentTemplate.class) : getInstance(DocumentTemplate.class, DatabaseQualifier.ofDocument(provider));
    Converters converters = getInstance(Converters.class);
    DocumentRepositoryProxy handler = new DocumentRepositoryProxy(template, classMappings, type, converters);
    return (Repository) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
Also used : Repository(jakarta.nosql.mapping.Repository) Converters(jakarta.nosql.mapping.Converters) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings)

Example 4 with Converters

use of jakarta.nosql.mapping.Converters in project jnosql-diana by eclipse.

the class ReactiveRepositoryColumnBean method create.

@Override
public ReactiveRepository<?, ?> create(CreationalContext<ReactiveRepository<?, ?>> context) {
    ClassMappings classMappings = getInstance(ClassMappings.class);
    ColumnTemplate template = provider.isEmpty() ? getInstance(ColumnTemplate.class) : getInstance(ColumnTemplate.class, DatabaseQualifier.ofDocument(provider));
    ReactiveColumnTemplateProducer reactiveProducer = getInstance(ReactiveColumnTemplateProducer.class);
    final ReactiveColumnTemplate reactiveTemplate = reactiveProducer.get(template);
    Converters converters = getInstance(Converters.class);
    ReactiveColumnRepositoryProxy<?> handler = new ReactiveColumnRepositoryProxy<>(reactiveTemplate, template, converters, classMappings, type);
    return (ReactiveRepository<?, ?>) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
Also used : ReactiveRepository(org.eclipse.jnosql.mapping.reactive.ReactiveRepository) ReactiveColumnTemplate(org.eclipse.jnosql.mapping.column.reactive.ReactiveColumnTemplate) ColumnTemplate(jakarta.nosql.mapping.column.ColumnTemplate) ReactiveColumnTemplate(org.eclipse.jnosql.mapping.column.reactive.ReactiveColumnTemplate) ReactiveColumnTemplateProducer(org.eclipse.jnosql.mapping.column.reactive.ReactiveColumnTemplateProducer) Converters(jakarta.nosql.mapping.Converters) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings)

Example 5 with Converters

use of jakarta.nosql.mapping.Converters in project jnosql-diana by eclipse.

the class SelectQueryConverterTest method shouldRunQuery10.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "findByAgeLessThanOrderByNameDescAgeAsc" })
public void shouldRunQuery10(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[] { 100 });
    List<Vertex> vertices = converter.apply(queryMethod, null).collect(Collectors.toList());
    List<Object> names = vertices.stream().map(v -> v.value("name")).collect(Collectors.toList());
    assertEquals(3, vertices.size());
    MatcherAssert.assertThat(names, Matchers.contains("Poliana", "Otavio", "Ada"));
}
Also used : Person(org.eclipse.jnosql.mapping.graph.model.Person) ValueSource(org.junit.jupiter.params.provider.ValueSource) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Matchers(org.hamcrest.Matchers) Converters(jakarta.nosql.mapping.Converters) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) T(org.apache.tinkerpop.gremlin.structure.T) Collectors(java.util.stream.Collectors) Repository(jakarta.nosql.mapping.Repository) Inject(javax.inject.Inject) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) Stream(java.util.stream.Stream) CDIExtension(jakarta.nosql.tck.test.CDIExtension) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Method(java.lang.reflect.Method) Edge(org.apache.tinkerpop.gremlin.structure.Edge) 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

Converters (jakarta.nosql.mapping.Converters)8 ClassMappings (org.eclipse.jnosql.mapping.reflection.ClassMappings)8 Repository (jakarta.nosql.mapping.Repository)6 Graph (org.apache.tinkerpop.gremlin.structure.Graph)4 CDIExtension (jakarta.nosql.tck.test.CDIExtension)3 Method (java.lang.reflect.Method)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 Inject (javax.inject.Inject)3 Edge (org.apache.tinkerpop.gremlin.structure.Edge)3 T (org.apache.tinkerpop.gremlin.structure.T)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 Person (org.eclipse.jnosql.mapping.graph.model.Person)3 ClassMapping (org.eclipse.jnosql.mapping.reflection.ClassMapping)3 MatcherAssert (org.hamcrest.MatcherAssert)3 Matchers (org.hamcrest.Matchers)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNotEquals (org.junit.jupiter.api.Assertions.assertNotEquals)3