Exemplo n.º 1
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;
  }
Exemplo n.º 2
0
  @SuppressWarnings("rawtypes")
  public static FilterConditionContext visit(
      Like obj, QueryBuilder queryBuilder, FilterConditionBeginContext fcbc)
      throws TranslatorException {
    LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing LIKE criteria."); // $NON-NLS-1$

    Expression lhs = obj.getLeftExpression();
    Expression rhs = obj.getRightExpression();

    Column c = null;
    Expression literalExp = null;
    if (lhs instanceof ColumnReference) {
      c = ((ColumnReference) lhs).getMetadataObject();
      literalExp = rhs;
    } else {
      c = ((ColumnReference) rhs).getMetadataObject();
      literalExp = lhs;
    }

    String value = null;
    if (literalExp instanceof Literal) {

      value = (String) escapeReservedChars(((Literal) literalExp).getValue());

      if (fcbc == null) {
        if (obj.isNegated()) {
          return queryBuilder.not().having(c.getSourceName()).like(value);
        }
        return queryBuilder.having(c.getSourceName()).like(value);
      }
      if (obj.isNegated()) {
        return fcbc.not().having(c.getSourceName()).like(value);
      }

      return fcbc.having(c.getSourceName()).like(value);
    }
    throw new TranslatorException(
        InfinispanPlugin.Util.gs(
            InfinispanPlugin.Event.TEIID25052, new Object[] {literalExp.toString(), "LIKE"}));
  }
Exemplo n.º 3
0
  @SuppressWarnings("rawtypes")
  public static FilterConditionContext visit(
      Comparison obj, QueryBuilder queryBuilder, FilterConditionBeginContext fcbc)
      throws TranslatorException {

    LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Parsing Comparison criteria."); // $NON-NLS-1$
    Comparison.Operator op = obj.getOperator();

    Expression lhs = obj.getLeftExpression();
    Expression rhs = obj.getRightExpression();

    // joins between the objects in the same cache is not usable
    if ((lhs instanceof ColumnReference && rhs instanceof ColumnReference)
        || (lhs instanceof Literal && rhs instanceof Literal)) {
      return null;
    }

    Object value = null;
    Column mdIDElement = null;
    Literal literal = null;
    if (lhs instanceof ColumnReference) {

      mdIDElement = ((ColumnReference) lhs).getMetadataObject();
      literal = (Literal) rhs;
      value = literal.getValue();

    } else if (rhs instanceof ColumnReference) {
      mdIDElement = ((ColumnReference) rhs).getMetadataObject();
      literal = (Literal) lhs;
      value = literal.getValue();
    }

    if (value == null) {
      throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25051));
    }

    value = escapeReservedChars(value);
    switch (op) {
      case NE:
        if (fcbc == null) {
          return queryBuilder.not().having(mdIDElement.getSourceName()).eq(value);
        }
        return fcbc.not().having(mdIDElement.getSourceName()).eq(value);

      case EQ:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).eq(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).eq(value);

      case GT:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).gt(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).gt(value);

      case GE:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).gte(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).gte(value);

      case LT:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).lt(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).lt(value);

      case LE:
        if (fcbc == null) {
          return queryBuilder.having(mdIDElement.getSourceName()).lte(value);
        }
        return fcbc.having(mdIDElement.getSourceName()).lte(value);

      default:
        throw new TranslatorException(
            InfinispanPlugin.Util.gs(
                InfinispanPlugin.Event.TEIID25050, new Object[] {op, "NE, EQ, GT, GE, LT, LE"}));
    }
  }
Exemplo n.º 4
0
  private static FilterConditionContext buildQueryFromWhereClause(
      Condition criteria,
      @SuppressWarnings("rawtypes") QueryBuilder queryBuilder,
      FilterConditionBeginContext fcbc)
      throws TranslatorException {

    if (criteria == null) return null;
    FilterConditionContext fcc = null;

    if (criteria instanceof AndOr) {
      LogManager.logTrace(
          LogConstants.CTX_CONNECTOR, "Infinispan DSL Parsing compound criteria."); // $NON-NLS-1$
      AndOr crit = (AndOr) criteria;
      AndOr.Operator op = crit.getOperator();

      switch (op) {
        case AND:
          FilterConditionContext f_and =
              buildQueryFromWhereClause(crit.getLeftCondition(), queryBuilder, fcbc);
          FilterConditionBeginContext fcbca = null;
          if (f_and != null) {
            fcbca = f_and.and();
          }
          fcc = buildQueryFromWhereClause(crit.getRightCondition(), queryBuilder, fcbca);

          break;

        case OR:
          FilterConditionContext f_or =
              buildQueryFromWhereClause(crit.getLeftCondition(), queryBuilder, fcbc);
          FilterConditionBeginContext fcbcb = null;
          if (f_or != null) {
            fcbcb = f_or.or();
          }
          fcc = buildQueryFromWhereClause(crit.getRightCondition(), queryBuilder, fcbcb);

          break;

        default:
          throw new TranslatorException(
              InfinispanPlugin.Util.gs(
                  InfinispanPlugin.Event.TEIID25050, new Object[] {op, "And, Or"}));
      }

    } else if (criteria instanceof Comparison) {
      fcc = visit((Comparison) criteria, queryBuilder, fcbc);

    } else if (criteria instanceof Like) {
      fcc = visit((Like) criteria, queryBuilder, fcbc);

    } else if (criteria instanceof In) {
      fcc = visit((In) criteria, queryBuilder, fcbc);

    } else if (criteria instanceof IsNull) {
      fcc = visit((IsNull) criteria, queryBuilder, fcbc);
    } else if (criteria instanceof Not) {
      Condition c = ((Not) criteria).getCriteria();
      if (fcbc == null) {
        fcc = queryBuilder.not(buildQueryFromWhereClause(c, queryBuilder, fcbc));
      } else {
        fcc = fcbc.not(buildQueryFromWhereClause(c, queryBuilder, fcbc));
      }
    } else {
      throw new TranslatorException(
          InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25054, criteria.toString()));
    }
    return fcc;
  }