use of com.blazebit.persistence.impl.keyset.KeysetMode in project blaze-persistence by Blazebit.
the class PaginatedCriteriaBuilderImpl method updateKeysetMode.
private void updateKeysetMode() {
KeysetMode oldMode = this.keysetMode;
this.keysetMode = KeysetPaginationHelper.getKeysetMode(keysetPage, entityId, firstResult, maxResults);
if (keysetMode == KeysetMode.NONE) {
this.keysetManager.setKeysetLink(null);
} else if (keysetMode == KeysetMode.NEXT) {
this.keysetManager.setKeysetLink(new SimpleKeysetLink(keysetPage.getHighest(), keysetMode));
} else {
this.keysetManager.setKeysetLink(new SimpleKeysetLink(keysetPage.getLowest(), keysetMode));
}
if (keysetMode != oldMode) {
prepareForModification(ClauseType.WHERE);
}
}
use of com.blazebit.persistence.impl.keyset.KeysetMode in project blaze-persistence by Blazebit.
the class AbstractFullQueryBuilder method applyPageIdQueryInto.
protected void applyPageIdQueryInto(AbstractCommonQueryBuilder<?, ?, ?, ?, ?> newBuilder, KeysetPage keysetPage, int firstResult, int maxResults, ResolvedExpression[] identifierExpressionsToUse, boolean withAlias) {
ExpressionCopyContext expressionCopyContext = newBuilder.applyFrom(this, true, false, false, false, ID_QUERY_GROUP_BY_CLAUSE_EXCLUSIONS, getIdentifierExpressionsToUseNonRootJoinNodes(identifierExpressionsToUse), new IdentityHashMap<JoinManager, JoinManager>(), ExpressionCopyContext.EMPTY);
newBuilder.setFirstResult(firstResult);
newBuilder.setMaxResults(maxResults);
// Paginated criteria builders always need the last order by expression to be unique
List<OrderByExpression> orderByExpressions = orderByManager.getOrderByExpressions(false, whereManager.rootPredicate.getPredicate(), hasGroupBy ? Arrays.asList(getIdentifierExpressions()) : Collections.<ResolvedExpression>emptyList(), null);
if (!orderByExpressions.get(orderByExpressions.size() - 1).isResultUnique()) {
throw new IllegalStateException("The order by items of the query builder are not guaranteed to produce unique tuples! Consider also ordering by the entity identifier!");
}
if (keysetPage != null) {
KeysetMode keysetMode = KeysetPaginationHelper.getKeysetMode(keysetPage, null, firstResult, maxResults);
if (keysetMode == KeysetMode.NONE) {
newBuilder.keysetManager.setKeysetLink(null);
} else if (keysetMode == KeysetMode.NEXT) {
newBuilder.keysetManager.setKeysetLink(new SimpleKeysetLink(keysetPage.getHighest(), keysetMode));
} else {
newBuilder.keysetManager.setKeysetLink(new SimpleKeysetLink(keysetPage.getLowest(), keysetMode));
}
newBuilder.keysetManager.initialize(orderByExpressions);
}
// Applying order by items needs special care for page id queries because we have to re-alias the items to avoid collisions
Map<String, Integer> identifierExpressionStringMap = new HashMap<>(identifierExpressionsToUse.length);
for (int i = 0; i < identifierExpressionsToUse.length; i++) {
identifierExpressionStringMap.put(identifierExpressionsToUse[i].getExpressionString(), i);
}
String[] identifierToUseSelectAliases = newBuilder.orderByManager.applyFrom(orderByManager, identifierExpressionStringMap);
if (withAlias) {
for (int i = 0; i < identifierExpressionsToUse.length; i++) {
List<Expression> args = new ArrayList<>(2);
args.add(identifierExpressionsToUse[i].getExpression().copy(expressionCopyContext));
args.add(new StringLiteral(ColumnTruncFunction.SYNTHETIC_COLUMN_PREFIX + i));
newBuilder.selectManager.select(new FunctionExpression(AliasFunction.FUNCTION_NAME, args), identifierToUseSelectAliases[i]);
}
} else {
for (int i = 0; i < identifierExpressionsToUse.length; i++) {
newBuilder.selectManager.select(identifierExpressionsToUse[i].getExpression().copy(expressionCopyContext), identifierToUseSelectAliases[i]);
}
}
}
Aggregations