Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [nosql-dev] Repository custom query pagination

Hello Dmitry how are you?

Yeap, it is a bug, I'll submit it as an issue.

What you can do is the Pagination instance.

@ApplicationScoped
public interface PersonRepository extends Repository<Person, Long> {

    List<Person> findAll(Pagination pagination);
}

public class App11 {

    public static void main(String[] args) {
        try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {
            PersonRepository repository = container.select(PersonRepository.class).get();
            DocumentTemplate template = container.select(DocumentTemplate.class).get();
            template.delete(DocumentDeleteQuery.delete().from("Person").build());
            Person otavio = Person.builder().withId(1L)
                    .withName("Otavio")
                    .build();

            Person poliana = Person.builder().withId(2L)
                    .withName("Poliana")
                    .build();

            Person elder = Person.builder().withId(3L)
                    .withName("elder")
                    .build();

            Person yanaga = Person.builder().withId(4L)
                    .withName("Yanaga")
                    .build();

            repository.save(Arrays.asList(otavio, poliana, elder, yanaga));

            List<Person> people = repository.findAll(Pagination.page(1).size(1));
            System.out.println("First pagination");
            people.forEach(System.out::println);
            people = repository.findAll(Pagination.page(2).size(1));
            System.out.println("second pagination");
            people.forEach(System.out::println);

        }
    }
}

You can use this demo as a reference:
https://github.com/JNOSQL/demos/tree/main/demo-java-se/mongodb

On Tue, Jun 21, 2022 at 11:18 AM Dmitry Repchevsky via nosql-dev <nosql-dev@xxxxxxxxxxx> wrote:
Hello,

I am trying to use Repository with the pagination.

Since I use @Query annotation, I suppose that just adding the Pagination
parameter wont work, so I try to use "skip" and "limit" in the query.

@Query("select * from Variants where caseLevelData.biosampleId =
@biosampleId skip @skip limit @limit")
List<VariantEntity> findByBiosampleId(@Param("biosampleId") String
biosampleId, @Param("skip") int skip, @Param("limit") int limit);

Unfortunately this doesn't work either. I got ANTLR exception:
QueryException: line 1:75 mismatched input '@skip' expecting INT

I suppose that I am doing something wrong...

Is it possible to use Repository for this, or should I go for the
DocumentTemplate?

Thank you in advance,

Dmitry

_______________________________________________
nosql-dev mailing list
nosql-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/nosql-dev


--
Otávio Santana

Back to the top