/** * 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; }
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);
/** * 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); }
ListIterator<Expression> inIter = ((InExpression) whereExp).getInItems().children().iterator(); Attribute attribute = entityType.getAttribute(((InExpression) whereExp).getExpression().toActualText() .split(DOT_REGEX)[1]);
/** * {@inheritDoc} */ @Override protected void addChildrenTo(Collection<Expression> children) { children.add(getExpression()); children.add(getInItems()); }
/** * {@inheritDoc} */ @Override protected void addChildrenTo(Collection<Expression> children) { children.add(getExpression()); children.add(getInItems()); }
/** * {@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); } } }
/** * {@inheritDoc} */ public void acceptChildren(ExpressionVisitor visitor) { getExpression().accept(visitor); getInItems().accept(visitor); }
/** * {@inheritDoc} */ public void acceptChildren(ExpressionVisitor visitor) { getExpression().accept(visitor); getInItems().accept(visitor); }
/** * {@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); } } }
/** * 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; }
/** * 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); }
/** * {@inheritDoc} */ @Override protected void validateInExpression(InExpression expression) { super.validateInExpression(expression); // Make sure the number of items matches if the left expression // is a nested array and the IN items expression is a subquery Expression inItems = expression.getInItems(); if (isSubquery(inItems)) { int nestedArraySize = nestedArraySize(expression.getExpression()); int subquerySelectItemsSize = subquerySelectItemCount(inItems); if ((nestedArraySize > -1) && (subquerySelectItemsSize != nestedArraySize) || (nestedArraySize == -1) && (subquerySelectItemsSize > 1)) { addProblem(expression, InExpression_InvalidItemCount); } } }
/** * {@inheritDoc} */ @Override protected void validateInExpression(InExpression expression) { super.validateInExpression(expression); // Make sure the number of items matches if the left expression // is a nested array and the IN items expression is a subquery Expression inItems = expression.getInItems(); if (isSubquery(inItems)) { int nestedArraySize = nestedArraySize(expression.getExpression()); int subquerySelectItemsSize = subquerySelectItemCount(inItems); if ((nestedArraySize > -1) && (subquerySelectItemsSize != nestedArraySize) || (nestedArraySize == -1) && (subquerySelectItemsSize > 1)) { addProblem(expression, InExpression_InvalidItemCount); } } }
/** * {@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) { // 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) { expression.getExpression().accept(this); InExpressionStateObject stateObject = new InExpressionStateObject( parent, this.stateObject, expression.hasNot(), buildChildren(expression.getInItems()) ); stateObject.setSingleInputParameter(expression.isSingleInputParameter()); stateObject.setExpression(expression); this.stateObject = stateObject; }
/** * 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()); }
/** * 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); } }