Package org.teiid.language

Examples of org.teiid.language.Comparison


    }   
   
    @Override
    public List<?> translate(LanguageObject obj, ExecutionContext context) {
      if (obj instanceof Comparison) {
        Comparison compare = (Comparison)obj;
        if (compare.getLeftExpression().getType() == TypeFacility.RUNTIME_TYPES.BOOLEAN
            && compare.getLeftExpression() instanceof Function
            && compare.getRightExpression() instanceof Literal) {
          boolean isTrue = Boolean.TRUE.equals(((Literal)compare.getRightExpression()).getValue());
          if ((isTrue && compare.getOperator() == Operator.EQ) || (!isTrue && compare.getOperator() == Operator.NE)) {
            return Arrays.asList(compare.getLeftExpression());
          }
          if ((!isTrue && compare.getOperator() == Operator.EQ) || (isTrue && compare.getOperator() == Operator.NE)) {
            return Arrays.asList("NOT ", compare.getLeftExpression()); //$NON-NLS-1$
          }
        }
      } else if (obj instanceof Not) {
        Not not = (Not)obj;
        return Arrays.asList("NOT ", not.getCriteria()); //$NON-NLS-1$
View Full Code Here


   
    public void test2() {
        NamedTable g1 = new NamedTable("g1", null, null); //$NON-NLS-1$
        ColumnReference e1 = new ColumnReference(g1, "e1", null, String.class); //$NON-NLS-1$
        ColumnReference e2 = new ColumnReference(g1, "e2", null, String.class); //$NON-NLS-1$
        Comparison cc = new Comparison(e1, e2, Operator.EQ);
       
        helpTestElementsUsedByGroups(cc, new String[] {"g1.e1", "g1.e2"}, new String[] {"g1"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
View Full Code Here

      Literal literal = (Literal)startIndex; 
      if (literal.getValue() instanceof Integer && ((Integer)literal.getValue() < 1)) {
        literal.setValue(1);
      }
    } else {
      Comparison whenExpr = langFactory.createCompareCriteria(
          Operator.LT,
          startIndex,
          langFactory.createLiteral(1, Integer.class)
        );
      Literal thenExpr = langFactory.createLiteral(1, Integer.class);
View Full Code Here

    public static Comparison example(int operator, int leftVal, int rightVal) throws Exception {
        return TstLanguageBridgeFactory.factory.translate(helpExample(operator, leftVal, rightVal));
    }

    public void testGetLeftExpression() throws Exception {
        Comparison impl = example(AbstractCompareCriteria.GE, 200, 100);
        assertNotNull(impl.getLeftExpression());
        assertTrue(impl.getLeftExpression() instanceof Literal);
        assertEquals(new Integer(200), ((Literal)impl.getLeftExpression()).getValue());
    }
View Full Code Here

        assertTrue(impl.getLeftExpression() instanceof Literal);
        assertEquals(new Integer(200), ((Literal)impl.getLeftExpression()).getValue());
    }

    public void testGetRightExpression() throws Exception {
        Comparison impl = example(AbstractCompareCriteria.GE, 200, 100);
        assertNotNull(impl.getRightExpression());
        assertTrue(impl.getRightExpression() instanceof Literal);
        assertEquals(new Integer(100), ((Literal)impl.getRightExpression()).getValue());
    }
View Full Code Here

    }
    if (!(criteria instanceof Comparison)) {
            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.criteriaNotSimpleError"); //$NON-NLS-1$
      throw new TranslatorException(msg);
    }
    Comparison compareCriteria = (Comparison)criteria; 
    if (compareCriteria.getOperator() != Operator.EQ) {
            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.criteriaNotEqualsError"); //$NON-NLS-1$
      throw new TranslatorException(msg);
    }
    Expression leftExpr = compareCriteria.getLeftExpression();
    if (!(leftExpr instanceof ColumnReference)) {
            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.criteriaLHSNotElementError"); //$NON-NLS-1$
      throw new TranslatorException(msg);
    }
    // call utility method to get NameInSource/Name for element
    String nameLeftExpr = getNameFromElement((ColumnReference)leftExpr);
    if (!(nameLeftExpr.toUpperCase().equals("DN"))) {   //$NON-NLS-1$
            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.criteriaSrcColumnError",nameLeftExpr); //$NON-NLS-1$
      throw new TranslatorException(msg);
    }
    Expression rightExpr = compareCriteria.getRightExpression();
    if (!(rightExpr instanceof Literal)) {
            final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.criteriaRHSNotLiteralError"); //$NON-NLS-1$
      throw new TranslatorException(msg);
    }
    Object valueRightExpr = ((Literal)rightExpr).getValue();
View Full Code Here

                Arrays.asList(
                    function.getParameters().get(1),
                    new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)),
                  TypeFacility.RUNTIME_TYPES.INTEGER)),
        TypeFacility.RUNTIME_TYPES.INTEGER);
    clauses.add(new SearchedWhenClause(new Comparison(length, maxLength, Operator.GT), maxLength));
    Expression defaultExpr = null;
    if (isNegative == null) {
      clauses.add(new SearchedWhenClause(new Comparison(length, new Literal(0, TypeFacility.RUNTIME_TYPES.INTEGER), Operator.GT), length));
    } else if (isNegative) {
      //TODO: could be done in the rewriter
      function.getParameters().set(2, null);
      return null;
    } else {
View Full Code Here

TOP

Related Classes of org.teiid.language.Comparison

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.