use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class PaginatedCriteriaBuilderImpl method copyCriteriaBuilder.
@Override
public <Y> CriteriaBuilderImpl<Y> copyCriteriaBuilder(Class<Y> resultClass, boolean copyOrderBy) {
CriteriaBuilderImpl<Y> criteriaBuilder = super.copyCriteriaBuilder(resultClass, copyOrderBy);
criteriaBuilder.setFirstResult(0);
criteriaBuilder.setMaxResults(Integer.MAX_VALUE);
ResolvedExpression[] identifierExpressions = getIdentifierExpressions();
ResolvedExpression[] resultUniqueExpressions = getUniqueIdentifierExpressions();
if (resultUniqueExpressions != null) {
identifierExpressions = resultUniqueExpressions;
}
SubqueryBuilderImpl<T> subqueryBuilder = new SubqueryBuilderImpl<T>(criteriaBuilder.mainQuery, new QueryContext(criteriaBuilder, ClauseType.WHERE), criteriaBuilder.aliasManager, criteriaBuilder.joinManager, criteriaBuilder.mainQuery.subqueryExpressionFactory, null, false, null);
// We always need synthetic aliases for subquery select items because Hibernate does not resolve aliases in the order by clause of subqueries
applyPageIdQueryInto(subqueryBuilder, keysetPage, firstResult, maxResults, identifierExpressions, true);
subqueryBuilder.collectParameters();
Expression expression = new SubqueryExpression(subqueryBuilder);
if (needsNewIdList) {
List<Expression> subArgs = new ArrayList<>(2);
subArgs.add(expression);
subArgs.add(new NumericLiteral(Integer.toString(identifierExpressions.length), NumericType.INTEGER));
expression = new FunctionExpression(ColumnTruncFunction.FUNCTION_NAME, subArgs);
}
Predicate p;
if (identifierExpressions.length == 1) {
p = new InPredicate(identifierExpressions[0].getExpression(), expression);
} else {
List<Expression> args = new ArrayList<>(identifierExpressions.length + 2);
args.add(new StringLiteral("IN"));
for (int j = 0; j < identifierExpressions.length; j++) {
args.add(identifierExpressions[j].getExpression());
}
args.add(expression);
expression = new FunctionExpression(RowValueSubqueryComparisonFunction.FUNCTION_NAME, args);
p = new EqPredicate(expression, new NumericLiteral("0", NumericType.INTEGER));
}
CompoundPredicate predicate = criteriaBuilder.whereManager.rootPredicate.getPredicate();
predicate.getChildren().clear();
predicate.getChildren().add(p);
return criteriaBuilder;
}
use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class PredicateManager method restrictSetExpression.
void restrictSetExpression(Predicate predicate) {
rootPredicate.verifyBuilderEnded();
parameterManager.collectParameterRegistrations(predicate, getClauseType(), subqueryInitFactory.getQueryBuilder());
List<Predicate> children = rootPredicate.getPredicate().getChildren();
children.clear();
if (predicate instanceof CompoundPredicate) {
CompoundPredicate compoundPredicate = (CompoundPredicate) predicate;
if (compoundPredicate.getOperator() == CompoundPredicate.BooleanOperator.AND ^ compoundPredicate.isNegated()) {
children.addAll(compoundPredicate.getChildren());
} else {
children.add(predicate);
}
} else {
children.add(predicate);
}
}
use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class PredicateManager method restrictExpression.
void restrictExpression(Predicate predicate) {
rootPredicate.verifyBuilderEnded();
parameterManager.collectParameterRegistrations(predicate, getClauseType(), subqueryInitFactory.getQueryBuilder());
List<Predicate> children = rootPredicate.getPredicate().getChildren();
if (predicate instanceof CompoundPredicate) {
CompoundPredicate compoundPredicate = (CompoundPredicate) predicate;
if (compoundPredicate.getOperator() == CompoundPredicate.BooleanOperator.AND ^ compoundPredicate.isNegated()) {
children.addAll(compoundPredicate.getChildren());
} else {
children.add(predicate);
}
} else {
children.add(predicate);
}
}
Aggregations