/** * Populate IN query filter. * * @param inExpression * the in expression * @param metadata * the metadata * @return the filter builder */ private QueryBuilder populateInQuery(InExpression inExpression, EntityMetadata metadata) { String property = getField(inExpression.getExpression().toParsedText()); Expression inItemsParameter = inExpression.getInItems(); log.debug("IN query parameters for field " + property + " is: " + inItemsParameter); Iterable inItemsIterable = getInValuesCollection(inItemsParameter); return getFilter(kunderaQuery.new FilterClause(property, Expression.IN, inItemsIterable, property), metadata); }
/** * Returns the {@link Expression} that represents the list if items. * * @return The expression that was parsed representing the list of items */ public Expression getInItems() { if (inItems == null) { inItems = buildNullExpression(); } return inItems; }
/** * On in expression. * * @param expression * the expression * @param m * the m * @param idColumn * the id column * @param isIdColumn * the is id column * @return * @return the filter */ public static Map<String, Object> onInExpression(Expression expression, EntityMetadata m, KunderaMetadata kunderaMetadata, KunderaQuery kunderaQuery) { InExpression inExp = (InExpression) expression; Expression sfpExp = inExp.getExpression(); Map<String, Object> map = KunderaQueryUtils.setFieldClazzAndColumnFamily(sfpExp, m, kunderaMetadata); kunderaQuery.addFilterClause( (String) map.get(Constants.COL_NAME), inExp.getIdentifier(), inExp.getInItems(), (String) map.get(Constants.FIELD_NAME), (Boolean) map.get(Constants.IGNORE_CASE)); return map; }
if (!expression.hasExpression()) { int startPosition = position(expression); addProblem(expression, startPosition, InExpression_MissingExpression); Expression leftExpression = expression.getExpression(); JPQLQueryBNF queryBNF = getQueryBNF(expression.getExpressionExpressionQueryBNFId()); expression.isSingleInputParameter(); if (!expression.hasLeftParenthesis() && !singleInputParameter) { length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 /* NOT + whitespace */ : 0) + 2 /* IN */; else if (!expression.hasInItems()) { length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 /* NOT + whitespace */ : 0) + 2 /* IN */ + (expression.hasSpaceAfterIn() ? 1 : 0) + (expression.hasLeftParenthesis() ? 1 : 0); Expression inItems = expression.getInItems(); CollectionExpression collectionExpression = getCollectionExpression(inItems); JPQLQueryBNF queryBNF = getQueryBNF(expression.getExpressionItemQueryBNFId());
/** * {@inheritDoc} */ @Override public void visit(InExpression expression) { // Visit the left expression InExpressionExpressionBuilder visitor1 = new InExpressionExpressionBuilder(); expression.getExpression().accept(visitor1); // Visit the IN items InExpressionBuilder visitor2 = new InExpressionBuilder(); visitor2.hasNot = expression.hasNot(); visitor2.singleInputParameter = expression.isSingleInputParameter(); visitor2.leftExpression = queryExpression; expression.getInItems().accept(visitor2); // Set the expression type type[0] = Boolean.class; }
/** * {@inheritDoc} */ @Override public void visit(InExpression expression) { if (expression.getInItems().isAncestor(inputParameter)) { // BNF: ... IN collection_valued_input_parameter if (expression.isSingleInputParameter()) { type = Collection.class; } else if (visitedExpressions.add(expression)) { expression.getExpression().accept(this); visitedExpressions.remove(expression); } } }
/** * Validates the given {@link InExpression}. The test to perform is: * <ul> * <li>If the expression is a path expression, validation makes sure it is an association mapping, * a basic field is not allowed.</li> * </ul> * * @param expression The {@link InExpression} to validate */ protected void validateInExpression(InExpression expression) { // Validate the left expression if (expression.hasExpression()) { Expression stringExpression = expression.getExpression(); // Special case for state field path expression StateFieldPathExpression pathExpression = getStateFieldPathExpression(stringExpression); if (pathExpression != null) { validateStateFieldPathExpression(pathExpression, validPathExpressionTypeForInExpression()); } else { stringExpression.accept(this); } } // Validate the items expression.getInItems().accept(getInItemsVisitor()); }
/** * {@inheritDoc} */ public void visit(InExpression expression) { if (badExpression) { if (!expression.hasExpression() && positionWithinInvalidExpression <= 2 /* IN */) { queryPosition.setExpression(expression); queryPosition.addPosition(expression, positionWithinInvalidExpression); } } else { if (expression.hasInItems() && !expression.hasRightParenthesis()) { expression.getInItems(); } if (queryPosition.getExpression() == null) { queryPosition.setExpression(expression); } queryPosition.addPosition(expression, expression.getLength() - correction); } }
expression.accept(getVisitParentVisitor()); int position = queryPosition.getPosition(expression) - corrections.peek(); int length = 0; if (expression.hasExpression()) { length = expression.getExpression().getLength() + SPACE_LENGTH; if (isPositionWithin(position, length, expression.getIdentifier())) { addFunctionIdentifiers(expression.getParent().findQueryBNF(expression)); else if (expression.hasLeftParenthesis()) { length += expression.getIdentifier().length() + SPACE_LENGTH;
/** * {@inheritDoc} */ @Override public void visit(InExpression expression) { int position = visitor.queryPosition.getPosition(expression) - visitor.corrections.peek(); int length = 0; if (expression.hasExpression()) { length += expression.getExpression().getLength() + SPACE_LENGTH; } // Within "IN" if (visitor.isPositionWithin(position, length, expression.getIdentifier())) { boolean hasOnlyIdentifier = !expression.hasExpression() && !expression.hasInItems(); if (hasOnlyIdentifier) { visitor.corrections.add(visitor.queryPosition.getPosition(expression)); } super.visit(expression); if (hasOnlyIdentifier) { visitor.corrections.pop(); } } else { super.visit(expression); } } }
Iterable listIterable = null; boolean isParameter = false; if (CollectionExpression.class.isAssignableFrom(inExp.getInItems().getClass())) listIterable = ((CollectionExpression) inExp.getInItems()).children(); String param = ((InputParameter) inExp.getInItems()).getParameter(); Object items = getKunderaQuery().getParametersMap().get(param);
/** * {@inheritDoc} */ @Override public void visit(InExpression expression) { valid = (pathExpression != expression.getExpression()); }
if (hasExpression()) { children.add(expression); children.add(buildStringExpression(SPACE)); children.add(buildStringExpression(NOT)); children.add(buildStringExpression(SPACE)); children.add(buildStringExpression(IN)); children.add(buildStringExpression(LEFT_PARENTHESIS)); children.add(buildStringExpression(SPACE)); if (hasInItems()) { children.add(inItems); children.add(buildStringExpression(RIGHT_PARENTHESIS));
inItems = parse(wordParser, InExpressionItemBNF.ID, tolerant); if (hasLeftParenthesis || !isSingleInputParameter()) { hasRightParenthesis = true; wordParser.moveForward(1);
/** * {@inheritDoc} */ @Override protected AbstractExpression buildExpression(AbstractExpression parent, WordParser wordParser, String word, JPQLQueryBNF queryBNF, AbstractExpression expression, boolean tolerant) { expression = new InExpression(parent, expression); expression.parse(wordParser, tolerant); return expression; } }
if (!expression.hasExpression()) { int startPosition = position(expression); addProblem(expression, startPosition, InExpression_MissingExpression); Expression leftExpression = expression.getExpression(); JPQLQueryBNF queryBNF = getQueryBNF(expression.getExpressionExpressionQueryBNFId()); expression.isSingleInputParameter(); if (!expression.hasLeftParenthesis() && !singleInputParameter) { length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 /* NOT + whitespace */ : 0) + 2 /* IN */; else if (!expression.hasInItems()) { length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 /* NOT + whitespace */ : 0) + 2 /* IN */ + (expression.hasSpaceAfterIn() ? 1 : 0) + (expression.hasLeftParenthesis() ? 1 : 0); Expression inItems = expression.getInItems(); CollectionExpression collectionExpression = getCollectionExpression(inItems); JPQLQueryBNF queryBNF = getQueryBNF(expression.getExpressionItemQueryBNFId());
/** * {@inheritDoc} */ @Override public void visit(InExpression expression) { // Visit the left expression InExpressionExpressionBuilder visitor1 = new InExpressionExpressionBuilder(); expression.getExpression().accept(visitor1); // Visit the IN items InExpressionBuilder visitor2 = new InExpressionBuilder(); visitor2.hasNot = expression.hasNot(); visitor2.singleInputParameter = expression.isSingleInputParameter(); visitor2.leftExpression = queryExpression; expression.getInItems().accept(visitor2); // Set the expression type type[0] = Boolean.class; }
/** * {@inheritDoc} */ @Override public void visit(InExpression expression) { if (expression.getInItems().isAncestor(inputParameter)) { // BNF: ... IN collection_valued_input_parameter if (expression.isSingleInputParameter()) { type = Collection.class; } else if (visitedExpressions.add(expression)) { expression.getExpression().accept(this); visitedExpressions.remove(expression); } } }
/** * Validates the given {@link InExpression}. The test to perform is: * <ul> * <li>If the expression is a path expression, validation makes sure it is an association mapping, * a basic field is not allowed.</li> * </ul> * * @param expression The {@link InExpression} to validate */ protected void validateInExpression(InExpression expression) { // Validate the left expression if (expression.hasExpression()) { Expression stringExpression = expression.getExpression(); // Special case for state field path expression StateFieldPathExpression pathExpression = getStateFieldPathExpression(stringExpression); if (pathExpression != null) { validateStateFieldPathExpression(pathExpression, validPathExpressionTypeForInExpression()); } else { stringExpression.accept(this); } } // Validate the items expression.getInItems().accept(getInItemsVisitor()); }
/** * Determines whether what was parsed after the <code>IN</code> identifier is a single input * parameter: * <div><b>BNF:</b> <code>in_expression ::= {state_field_path_expression | type_discriminator} [NOT] IN collection_valued_input_parameter</code><p></div> * * @return <code>true</code> if what is following the <code>IN</code> identifier is a single * input parameter (without the left or right parenthesis); <code>false</code> otherwise * @since 2.4 */ public boolean isSingleInputParameter() { if (singleInputParameter == null) { if (hasLeftParenthesis || hasRightParenthesis) { singleInputParameter = Boolean.FALSE; } else { WordParser wordParser = new WordParser(getInItems().toActualText()); String word = wordParser.word(); wordParser.moveForward(word); singleInputParameter = (word.length() > 0) && ExpressionTools.isParameter(word.charAt(0)) && wordParser.isTail(); } } return singleInputParameter; }