private Query limitIfPageable(SelectLimitStep<? extends Record> limitStep, Pageable pageable, Sort sort) { if (pageable == null || isCountQuery()) { return limitStep; } else if (sort == null) { return limitStep.limit(pageable.getPageSize()); } else { return limitStep.limit(pageable.getPageSize()).offset(pageable.getOffset()); } }
private Query limitIfPageable(SelectLimitStep<? extends Record> limitStep, Pageable pageable, Sort sort) { if (pageable == null || isCountQuery()) { return limitStep; } else if (sort == null) { return limitStep.limit(pageable.getPageSize()); } return limitStep.limit(pageable.getPageSize()).offset(pageable.getOffset()); }
/** * Creates the query for the given {@link org.springframework.data.domain.Sort}. * * @param pageable the pageable * @return the query */ private OSQLQuery<T> getQuery(Pageable pageable) { DSLContext context = DSL.using(SQLDialect.MYSQL); SelectJoinStep<? extends Record> joinStep = context.select().from(domainClass.getSimpleName()); Sort sort = pageable.getSort(); SelectLimitStep<? extends Record> limitStep = sort == null ? joinStep : joinStep.orderBy(QueryUtils.toOrders(sort)); Query query = pageable == null ? limitStep : limitStep.limit(pageable.getPageSize()).offset(pageable.getOffset()); return new OSQLSynchQuery<>(query.getSQL(ParamType.INLINED)); } }
/** * Creates the query for the given {@link org.springframework.data.domain.Sort}. * * @param pageable the pageable * @return the query */ private OSQLQuery<T> getQuery(Pageable pageable) { DSLContext context = DSL.using(SQLDialect.MYSQL); SelectJoinStep<? extends Record> joinStep = context.select().from(domainClass.getSimpleName()); Sort sort = pageable.getSort(); SelectLimitStep<? extends Record> limitStep = sort == null ? joinStep : joinStep.orderBy(QueryUtils.toOrders(sort)); Query query = pageable == null ? limitStep : limitStep.limit(pageable.getPageSize()).offset(pageable.getOffset()); return new OSQLSynchQuery<T>(query.getSQL(ParamType.INLINED)); } }
/** * Helper function returns a range query based on the bounds passed<br> */ protected String buildRangeQuery(Object lowerBoundKey, int offset, int limit) { Condition condition = DSL.trueCondition(); if (getWhereCondition() != null) { condition = condition.and(getWhereCondition()); } if (isPollerPartition && lowerBoundKey != null) { condition = andLowerBoundKeyCondition(condition, lowerBoundKey); } String sqlQuery; if (getColumnsExpression() != null) { Collection<Field<?>> columns = new ArrayList<>(); for (String column : getColumnsExpression().split(",")) { columns.add(field(column)); } sqlQuery = dslContext.select(columns).from(getTableName()).where(condition) .orderBy(field(getKey())).limit(limit).offset(offset).getSQL(ParamType.INLINED); } else { sqlQuery = dslContext.select().from(getTableName()).where(condition).orderBy(field(getKey())).limit(limit) .offset(offset).getSQL(ParamType.INLINED); } LOG.info("DSL Query: " + sqlQuery); return sqlQuery; }