public OrderByInfo(Expression expression, boolean ascending, boolean nullFirst) { super(expression); this.expressionString = expression.toString(); this.ascending = ascending; this.nullFirst = nullFirst; }
private String getLiteralString(Expression expr) { String str = expr.toString(); return str.substring(1, str.length() - 1); }
private String getLiteralString(Expression expr) { String str = expr.toString(); return str.substring(1, str.length() - 1); }
@Override public void setExpression(Expression expression) { super.setExpression(expression); this.expressionString = expression.toString(); }
@Override public void set(Expression expression) { super.set(expression); this.expressionString = expression.toString(); }
JoinNode getRootNode(Expression expression) { String alias; if (expression instanceof PropertyExpression) { alias = expression.toString(); } else { return null; } List<JoinNode> nodes = rootNodes; int size = nodes.size(); for (int i = 0; i < size; i++) { JoinNode node = nodes.get(i); if (alias.equals(node.getAliasInfo().getAlias())) { return node; } } return null; }
@Override public void initialize(List<OrderByExpression> orderByExpressions) { Serializable[] tuple = new Serializable[orderByExpressions.size()]; for (int i = 0; i < tuple.length; i++) { String expressionString = orderByExpressions.get(0).getExpression().toString(); Object value = keysetValues.get(expressionString); if (value == null) { if (!keysetValues.containsKey(expressionString)) { throw new IllegalArgumentException("The keyset provided [" + keysetValues + "] does not contain an entry for the order by expression: " + expressionString); } tuple[i] = null; } else { if (!(value instanceof Serializable)) { throw new IllegalArgumentException("The keyset value [" + value + "] provided for the order by expression [" + expressionString + "] is not an instance of java.io.Serializable!"); } tuple[i] = (Serializable) value; } } keyset = new KeysetImpl(tuple); validate(keyset, orderByExpressions); }
private String getJoinAlias(ArrayExpression expr) { StringBuilder sb = new StringBuilder(expr.getBase().toString()); Expression indexExpr = expr.getIndex(); if (indexExpr instanceof ParameterExpression) { ParameterExpression indexParamExpr = (ParameterExpression) indexExpr; sb.append('_'); sb.append(indexParamExpr.getName()); } else if (indexExpr instanceof PathExpression) { PathExpression indexPathExpr = (PathExpression) indexExpr; sb.append('_'); sb.append(((JoinNode) indexPathExpr.getBaseNode()).getAliasInfo().getAlias()); if (indexPathExpr.getField() != null) { sb.append('_'); sb.append(indexPathExpr.getField().replaceAll("\\.", "_")); } } else if (indexExpr instanceof NumericLiteral) { sb.append('_'); sb.append(((NumericLiteral) indexExpr).getValue()); } else if (indexExpr instanceof StringLiteral) { sb.append('_'); sb.append(((StringLiteral) indexExpr).getValue()); } else { throw new IllegalStateException("Invalid array index expression " + indexExpr.toString()); } return sb.toString(); }
String right; if (booleanExpression instanceof EqPredicate) { left = ((EqPredicate) booleanExpression).getLeft().toString(); right = ((EqPredicate) booleanExpression).getRight().toString(); } else if (booleanExpression instanceof InPredicate) { left = ((InPredicate) booleanExpression).getLeft().toString(); List<Expression> list = ((InPredicate) booleanExpression).getRight(); if (list.size() > 1) { return false; right = list.get(0).toString(); } else { return false;
@Override public Expression visitLike_expression(JPQLSelectExpressionParser.Like_expressionContext ctx) { // @formatter:off return new LikePredicate( ctx.string_expression().accept(this), ctx.pattern_value().accept(this), true, ctx.escape_character() != null ? ctx.escape_character().accept(this).toString().charAt(1) : null, ctx.not != null); // @formatter:on }
@Override public Expression visitLike_expression(JPQLSelectExpressionParser.Like_expressionContext ctx) { // @formatter:off return new LikePredicate( ctx.string_expression().accept(this), ctx.pattern_value().accept(this), true, ctx.escape_character() != null ? ctx.escape_character().accept(this).toString().charAt(1) : null, ctx.not != null); // @formatter:on }
@Override public void visit(FunctionExpression expression) { // A type constraint of a treat expression from within an aggregate may not "escape" the aggregate Map<JoinNode, Boolean> oldTreatedJoinNodesForConstraints = treatedJoinNodesForConstraints; if (expression instanceof AggregateExpression) { treatedJoinNodesForConstraints = null; } if (com.blazebit.persistence.parser.util.ExpressionUtils.isOuterFunction(expression)) { // Outer can only have paths, no need to set expression context for parameters expression.getExpressions().get(0).accept(this); } else if (ExpressionUtils.isFunctionFunctionExpression(expression)) { final List<Expression> arguments = expression.getExpressions(); final String literalFunctionName = ExpressionUtils.unwrapStringLiteral(arguments.get(0).toString()); String resolvedFunctionName = resolveRenderedFunctionName(literalFunctionName); final List<Expression> argumentsWithoutFunctionName; if (arguments.size() > 1) { argumentsWithoutFunctionName = arguments.subList(1, arguments.size()); } else { argumentsWithoutFunctionName = Collections.emptyList(); } renderFunctionFunction(resolvedFunctionName, argumentsWithoutFunctionName); } else if (isCountStarFunction(expression)) { renderCountStar(); } else { super.visit(expression); } treatedJoinNodesForConstraints = oldTreatedJoinNodesForConstraints; }
String potentialSelectAlias = orderByExpressions.get(i).getExpression().toString(); AliasInfo aliasInfo = aliasManager.getAliasInfo(potentialSelectAlias); if (aliasInfo instanceof SelectInfo) { index = identifierExpressionStringMap.get(((SelectInfo) aliasInfo).getExpression().toString()); if (index == null) { keysetToSelectIndexMapping[i] = -1; for (int i = 0; i < selectInfos.size(); i++) { SelectInfo selectInfo = selectInfos.get(i); selectExpressionStringMap.put(selectInfo.getExpression().toString(), i); if (selectInfo.getAlias() != null) { selectExpressionStringMap.put(selectInfo.getAlias(), i); index = selectExpressionStringMap.get(orderByExpressions.get(i).getExpression().toString()); keysetToSelectIndexMapping[i] = index == null ? -1 : index;
throw new IllegalArgumentException("Illegal expression '" + selectExpression.toString() + "' for binding relation '" + attributeName + "'!");
correlationParent = parent.getRootNodeOrFail("Could not join correlation path [", correlationPath == null ? expr.toString() : correlationPath, "] because it did not use an absolute path but multiple root nodes are available!"); createOrUpdateNode(result.baseNode, result.addToList(Collections.singletonList(elementExpr.toString())), treatEntityType, rootAlias, null, false, true, true);
public void collect(ResolvedExpression expression, ClauseType clauseType, boolean hasGroupBy, JoinVisitor joinVisitor) { List<Expression> expressions = embeddableSplittingVisitor.splitOff(expression.getExpression()); if (expressions != null) { if (expressions.isEmpty()) { collect0(expression, clauseType, hasGroupBy); } else { if (jpaProvider.supportsSingleValuedAssociationIdExpressions() || joinVisitor == null) { for (Expression splitOffExpression : expressions) { ResolvedExpression subExpression = new ResolvedExpression(splitOffExpression.toString(), splitOffExpression); collect0(subExpression, clauseType, hasGroupBy); } } else { // When we don't support single valued id access, we need to do an implicit join as the embeddable might contain an association ClauseType fromClause = joinVisitor.getFromClause(); try { joinVisitor.setFromClause(clauseType); for (Expression splitOffExpression : expressions) { if (hasGroupBy) { splitOffExpression.accept(joinVisitor); } ResolvedExpression subExpression = new ResolvedExpression(splitOffExpression.toString(), splitOffExpression); collect0(subExpression, clauseType, hasGroupBy); } } finally { joinVisitor.setFromClause(fromClause); } } } } }
String groupByExprString = groupByExpr.toString(); ResolvedExpression resolvedExpression = new ResolvedExpression(groupByExprString, groupByExpr); Set<ClauseType> clauseTypes = requiredGroupBys.get(resolvedExpression);
throw new RuntimeException("The select expression '" + selectExpr.toString() + "' is not a simple path expression! No idea how to implicit join that.");