Пример #1
0
  public static boolean visit(
      In obj, BooleanJunction<BooleanJunction> junction, QueryBuilder queryBuilder)
      throws TranslatorException {
    LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing IN criteria."); // $NON-NLS-1$

    Expression lhs = obj.getLeftExpression();

    Column mdIDElement = ((ColumnReference) lhs).getMetadataObject();

    List<Expression> rhsList = obj.getRightExpressions();
    boolean createdQuery = false;
    for (Expression expr : rhsList) {

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

        // add these as OR queries
        createEqualsQuery(
            mdIDElement,
            escapeReservedChars(literal.getValue()),
            false,
            false,
            junction,
            queryBuilder);
        createdQuery = true;
      } else {
        String msg =
            ObjectPlugin.Util.getString(
                "LuceneSearch.Unsupported_expression", //$NON-NLS-1$
                new Object[] {expr, "IN"}); // $NON-NLS-1$
        throw new TranslatorException(msg);
      }
    }
    return createdQuery;
  }
Пример #2
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;
    }
  }
Пример #3
0
  @Override
  public void visit(In obj) {
    visitNode(obj.getLeftExpression());
    Column c = (Column) this.onGoingExpression.pop();

    ArrayList<Object> values = new ArrayList<Object>();
    for (Expression expr : obj.getRightExpressions()) {
      visitNode(expr);
      values.add(this.onGoingExpression.pop().toString());
    }
    this.filterValues.put(c.getName(), values);
  }
Пример #4
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;
  }