Search in sources :

Example 1 with Slice

use of io.micronaut.data.model.Slice in project micronaut-data by micronaut-projects.

the class DefaultFindSliceReactiveInterceptor method intercept.

@Override
public Object intercept(RepositoryMethodKey methodKey, MethodInvocationContext<Object, Object> context) {
    if (context.hasAnnotation(Query.class)) {
        PreparedQuery<Object, Object> preparedQuery = (PreparedQuery<Object, Object>) prepareQuery(methodKey, context);
        Pageable pageable = preparedQuery.getPageable();
        Mono<Slice<Object>> publisher = Flux.from(reactiveOperations.findAll(preparedQuery)).collectList().map(objects -> Slice.of(objects, pageable));
        return Publishers.convertPublisher(publisher, context.getReturnType().getType());
    } else {
        PagedQuery<Object> pagedQuery = getPagedQuery(context);
        Mono<? extends Slice<?>> result = Flux.from(reactiveOperations.findAll(pagedQuery)).collectList().map(objects -> Slice.of(objects, pagedQuery.getPageable()));
        return Publishers.convertPublisher(result, context.getReturnType().getType());
    }
}
Also used : Pageable(io.micronaut.data.model.Pageable) Slice(io.micronaut.data.model.Slice) PreparedQuery(io.micronaut.data.model.runtime.PreparedQuery)

Aggregations

Pageable (io.micronaut.data.model.Pageable)1 Slice (io.micronaut.data.model.Slice)1 PreparedQuery (io.micronaut.data.model.runtime.PreparedQuery)1