Search in sources :

Example 11 with Pagination

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

the class GraphPageTest method shouldRequestPageTwice.

@Test
public void shouldRequestPageTwice() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = template.getTraversalVertex().orderBy("name").desc().page(pagination);
    List<Person> people = page.getContent().collect(Collectors.toList());
    assertFalse(people.isEmpty());
    assertNotNull(page.getContent(ArrayList::new));
    assertNotNull(page.getContent(HashSet::new));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 12 with Pagination

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

the class GraphPageTest method shouldReturnCollectionFromCollectionFactory.

@Test
public void shouldReturnCollectionFromCollectionFactory() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = template.getTraversalVertex().orderBy("name").desc().page(pagination);
    assertNotNull(page);
    Set<Person> people = page.getContent(HashSet::new);
    Person first = template.getTraversalVertex().orderBy("name").desc().<Person>getResult().findFirst().get();
    assertEquals(pagination, page.getPagination());
    assertEquals(1, people.size());
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Person(org.eclipse.jnosql.mapping.graph.model.Person) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 13 with Pagination

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

the class GraphPageTest method shouldReturnErrorWhenCollectionFactoryIsNull.

@Test
public void shouldReturnErrorWhenCollectionFactoryIsNull() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = template.getTraversalVertex().orderBy("name").desc().page(pagination);
    assertNotNull(page);
    assertThrows(NullPointerException.class, () -> page.getContent(null));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 14 with Pagination

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

the class GraphPageTest method shouldNext.

@Test
public void shouldNext() {
    Pagination pagination = Pagination.page(1).size(1);
    Page<Person> page = template.getTraversalVertex().orderBy("name").asc().page(pagination);
    assertNotNull(page);
    Stream<Person> people = page.get();
    assertEquals(pagination, page.getPagination());
    assertEquals(otavio.getName(), people.map(Person::getName).collect(joining()));
    pagination = pagination.next();
    page = page.next();
    people = page.get();
    assertEquals(pagination, page.getPagination());
    assertEquals(paulo.getName(), people.map(Person::getName).collect(joining()));
    pagination = pagination.next();
    page = page.next();
    people = page.get();
    assertEquals(pagination, page.getPagination());
    assertEquals(poliana.getName(), people.map(Person::getName).collect(joining()));
}
Also used : Pagination(jakarta.nosql.mapping.Pagination) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 15 with Pagination

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

the class AbstractGraphRepositoryProxy method converter.

private Object converter(Method method, Class<?> typeClass, Supplier<Stream<?>> querySupplier, Object[] args) {
    Supplier<Optional<?>> singleSupplier = DynamicReturn.toSingleResult(method).apply(querySupplier);
    Function<Pagination, Page<?>> pageFunction = p -> {
        throw new DynamicQueryException("Graph database repository does not support Page as return Type");
    };
    DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(typeClass).withMethodSource(method).withResult(querySupplier).withSingleResult(singleSupplier).withPagination(DynamicReturn.findPagination(args)).withStreamPagination(p -> querySupplier.get()).withSingleResultPagination(p -> singleSupplier.get()).withPage(pageFunction).build();
    return dynamicReturn.execute();
}
Also used : RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) GraphConverter(org.eclipse.jnosql.mapping.graph.GraphConverter) ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) DynamicReturn(org.eclipse.jnosql.mapping.repository.DynamicReturn) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Converters(jakarta.nosql.mapping.Converters) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Repository(jakarta.nosql.mapping.Repository) List(java.util.List) Stream(java.util.stream.Stream) GraphTemplate(org.eclipse.jnosql.mapping.graph.GraphTemplate) Optional(java.util.Optional) DynamicQueryException(jakarta.nosql.mapping.DynamicQueryException) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) Pagination(jakarta.nosql.mapping.Pagination) Method(java.lang.reflect.Method) Page(jakarta.nosql.mapping.Page) Pagination(jakarta.nosql.mapping.Pagination) Optional(java.util.Optional) DynamicQueryException(jakarta.nosql.mapping.DynamicQueryException) Page(jakarta.nosql.mapping.Page)

Aggregations

Pagination (jakarta.nosql.mapping.Pagination)99 Test (org.junit.jupiter.api.Test)96 Person (jakarta.nosql.tck.entities.Person)46 ColumnQuery (jakarta.nosql.column.ColumnQuery)27 DocumentQuery (jakarta.nosql.document.DocumentQuery)27 ColumnQueryPagination (jakarta.nosql.mapping.column.ColumnQueryPagination)17 DocumentQueryPagination (jakarta.nosql.mapping.document.DocumentQueryPagination)17 Method (java.lang.reflect.Method)15 Optional (java.util.Optional)15 Stream (java.util.stream.Stream)15 ColumnCondition (jakarta.nosql.column.ColumnCondition)13 DocumentCondition (jakarta.nosql.document.DocumentCondition)13 List (java.util.List)7 Person (org.eclipse.jnosql.mapping.graph.model.Person)7 Vendor (jakarta.nosql.tck.entities.Vendor)4 ColumnTemplate (jakarta.nosql.mapping.column.ColumnTemplate)3 DocumentTemplate (jakarta.nosql.mapping.document.DocumentTemplate)3 Value (jakarta.nosql.Value)2 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2