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