@Override public LimitPath orderBy(Sort... orderings) { element(new OrderByElement(orderings)); return new DefaultLimitPath(this); }
@Override public OffsetPath limit(int limit) { element(new LimitElement(limit)); return new DefaultOffsetPath(this); }
@Override public Statement getStatement(ParameterAccessor accessor, Object[] runtimeParameters, ReturnedType returnedType) { EvaluationContext evaluationContext = evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(), runtimeParameters); String parsedStatement = this.queryParser.doParse(parser, evaluationContext, false); String orderByPart = ""; String limitByPart = ""; Sort sort = accessor.getSort(); if (sort.isSorted()) { com.couchbase.client.java.query.dsl.Sort[] cbSorts = N1qlUtils.createSort(sort, getCouchbaseOperations().getConverter()); orderByPart = " " + new DefaultOrderByPath(null).orderBy(cbSorts).toString(); } if (queryMethod.isPageQuery()) { Pageable pageable = accessor.getPageable(); Assert.notNull(pageable, "Pageable must not be null!"); limitByPart = " " + new DefaultLimitPath(null).limit(pageable.getPageSize()) .offset(Math.toIntExact(pageable.getOffset())).toString(); } else if (queryMethod.isSliceQuery()) { Pageable pageable = accessor.getPageable(); Assert.notNull(pageable, "Pageable must not be null!"); limitByPart = " " + new DefaultLimitPath(null).limit(pageable.getPageSize() + 1) .offset(Math.toIntExact(pageable.getOffset())).toString(); } return N1qlQuery.simple(parsedStatement + orderByPart + limitByPart).statement(); }
@Override public Statement getStatement(ParameterAccessor accessor, Object[] runtimeParameters, ReturnedType returnedType) { EvaluationContext evaluationContext = evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(), runtimeParameters); String parsedStatement = this.queryParser.doParse(parser, evaluationContext, false); String orderByPart = ""; String limitByPart = ""; Sort sort = accessor.getSort(); if (sort.isSorted()) { com.couchbase.client.java.query.dsl.Sort[] cbSorts = N1qlUtils.createSort(sort, getCouchbaseOperations().getConverter()); orderByPart = " " + new DefaultOrderByPath(null).orderBy(cbSorts).toString(); } if (queryMethod.isPageQuery()) { Pageable pageable = accessor.getPageable(); Assert.notNull(pageable, "Pageable must not be null!"); limitByPart = " " + new DefaultLimitPath(null).limit(pageable.getPageSize()) .offset(Math.toIntExact(pageable.getOffset())).toString(); } else if (queryMethod.isSliceQuery()) { Pageable pageable = accessor.getPageable(); Assert.notNull(pageable, "Pageable must not be null!"); limitByPart = " " + new DefaultLimitPath(null).limit(pageable.getPageSize() + 1) .offset(Math.toIntExact(pageable.getOffset())).toString(); } return N1qlQuery.simple(parsedStatement + orderByPart + limitByPart).statement(); }