Пример #1
0
  @Override
  public void visit(In obj) {
    visitNode(obj.getLeftExpression());
    Column column = (Column) this.onGoingExpression.pop();

    visitNodes(obj.getRightExpressions());

    if (isPartOfPrimaryKey(column)) {
      Object prevExpr = null;
      // NOTE: we are popping in reverse order to IN stmt
      for (int i = 0; i < obj.getRightExpressions().size(); i++) {
        Object rightExpr = this.onGoingExpression.pop();
        Range range = Range.exact(rightExpr.toString());
        if (obj.isNegated()) {
          if (prevExpr == null) {
            this.ranges.add(new Range(rightExpr.toString(), false, null, true));
            this.ranges.add(new Range(null, true, rightExpr.toString(), false));
          } else {
            this.ranges.remove(this.ranges.size() - 1);
            this.ranges.add(new Range(rightExpr.toString(), false, prevExpr.toString(), false));
            this.ranges.add(new Range(null, true, rightExpr.toString(), false));
          }
          prevExpr = rightExpr;
        } else {
          this.ranges.add(range);
        }
      }
    } else {
      this.doScanEvaluation = true;
    }
  }
Пример #2
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public static FilterConditionContext visit(
      In obj, QueryBuilder queryBuilder, FilterConditionBeginContext fcbc)
      throws TranslatorException {
    LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria."); // $NON-NLS-1$

    Expression lhs = obj.getLeftExpression();

    List<Expression> rhsList = obj.getRightExpressions();

    List v = new ArrayList(rhsList.size());
    // = Arrays.asList(1
    boolean createdQuery = false;
    for (Expression expr : rhsList) {

      if (expr instanceof Literal) {
        Literal literal = (Literal) expr;

        Object value = escapeReservedChars(literal.getValue());
        v.add(value);
        createdQuery = true;
      } else {
        throw new TranslatorException(
            InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25052, new Object[] {expr, "IN"}));
      }
    }

    if (createdQuery) {
      Column col = ((ColumnReference) lhs).getMetadataObject();

      if (fcbc == null) {
        if (obj.isNegated()) {
          return queryBuilder.not().having(col.getSourceName()).in(v);
        }
        return queryBuilder.having(col.getSourceName()).in(v);
      }
      if (obj.isNegated()) {
        return fcbc.not().having(col.getSourceName()).in(v);
      }
      return fcbc.having(col.getSourceName()).in(v);
    }
    return null;
  }