示例#1
0
  public static boolean visit(
      Like obj, BooleanJunction<BooleanJunction> junction, QueryBuilder queryBuilder)
      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());
      createLikeQuery(
          c, value.replaceAll("%", ""), junction, queryBuilder); // "*" //$NON-NLS-1$ //$NON-NLS-2$
    } else {
      final String msg =
          ObjectPlugin.Util.getString(
              "LuceneSearch.Unsupported_expression", //$NON-NLS-1$
              new Object[] {literalExp.toString(), "LIKE"}); // $NON-NLS-1$
      throw new TranslatorException(msg);
    }

    return true;
  }
示例#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"}));
  }
  public void helpTest(Expression srcExpression, String tgtType, String expectedExpression)
      throws Exception {
    Function func =
        LANG_FACTORY.createFunction(
            "convert", //$NON-NLS-1$
            Arrays.asList(srcExpression, LANG_FACTORY.createLiteral(tgtType, String.class)),
            TypeFacility.getDataTypeClass(tgtType));

    assertEquals(
        "Error converting from " + srcExpression.getType() + " to " + tgtType,
        expectedExpression,
        helpGetString(func));
  }