Package org.teiid.query.sql.symbol

Examples of org.teiid.query.sql.symbol.CaseExpression


        return list;
    }

    public static CaseExpression example(int whens) {
        ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
        CaseExpression caseExpr = new CaseExpression(x, getWhenExpressions(whens), getThenExpressions(whens));
        caseExpr.setElseExpression(new Constant(new Integer(9999)));
        return caseExpr;
    }
View Full Code Here


    }
   
    public static CaseExpression example(int whens, int nullIndex, boolean includeNull) {
        ArgCheck.isTrue(nullIndex < whens, "Null Index must be less than the number of When expressions"); //$NON-NLS-1$
        ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$
        CaseExpression caseExpr = new CaseExpression(x, getWhenExpressions(whens, nullIndex, includeNull), getThenExpressions(whens));
        caseExpr.setElseExpression(new Constant(new Integer(9999)));
        return caseExpr;
    }
View Full Code Here

        assertNotNull(example(1).getExpression());
        assertEquals(new ElementSymbol("x"), example(1).getExpression()); //$NON-NLS-1$
    }

    public void testSetExpression() {
        CaseExpression caseExpr = example(1);
        ElementSymbol y = new ElementSymbol("y"); //$NON-NLS-1$
        caseExpr.setExpression(y);
        assertEquals(y, caseExpr.getExpression());
       
        try {
            caseExpr.setExpression(null);
            fail("Setting the expression to null should fail."); //$NON-NLS-1$
        } catch (IllegalArgumentException e) {
            // There should be no side-effects of an illegal argument
            assertEquals(y, caseExpr.getExpression());           
        }
    }
View Full Code Here

        Constant const2 = new Constant("b"); //$NON-NLS-1$
        ArrayList thens = new ArrayList();
        thens.add(const1);
        thens.add(const2);
        Expression elseExpression = new Constant("c"); //$NON-NLS-1$
        CaseExpression expr = new CaseExpression(x, whens, thens);
        expr.setElseExpression(elseExpression);
        expr.setType(DataTypeManager.DefaultDataClasses.STRING);
       
        CaseExpression clone = (CaseExpression)expr.clone();
       
        assertTrue(expr != clone);
       
        helpTestStrictEquivalence(x, clone.getExpression());
        helpTestStrictEquivalence(expr.getExpression(), clone.getExpression());
       
        assertEquals(2, clone.getWhenCount());
       
        helpTestStrictEquivalence(e1, clone.getWhenExpression(0));
        helpTestStrictEquivalence(expr.getWhenExpression(0), clone.getWhenExpression(0));
        helpTestStrictEquivalence(e2, clone.getWhenExpression(1));
        helpTestStrictEquivalence(expr.getWhenExpression(1), clone.getWhenExpression(1));
       
        helpTestStrictEquivalence(const1, clone.getThenExpression(0));
        helpTestStrictEquivalence(expr.getThenExpression(0), clone.getThenExpression(0));
        helpTestStrictEquivalence(const2, clone.getThenExpression(1));
        helpTestStrictEquivalence(expr.getThenExpression(1), clone.getThenExpression(1));
       
        helpTestStrictEquivalence(expr.getElseExpression(), clone.getElseExpression());
        assertEquals(expr.getType(), clone.getType());
        assertEquals(expr.isResolved(), clone.isResolved());
    }
View Full Code Here

        thens.add(new Constant(new Integer(0)));
        whens.add(new Constant(String.valueOf('b')));
        thens.add(new Constant(new Integer(1)));
        whens.add(new Constant(String.valueOf('c')));
        thens.add(new Constant(new Integer(2)));
        CaseExpression mapped = new CaseExpression(y, whens, thens);
        mapped.setElseExpression(new Constant(new Integer(9999)));
       
        helpTest(TestCaseExpression.example(3), map, mapped);
    }
View Full Code Here

                 "SELECT c1, c2 INTO #temp FROM m.g", //$NON-NLS-1$
                 q)
    }
   
    @Test public void testCaseExpression1() {
        CaseExpression expr = TestCaseExpression.example(4);
        Select select = new Select();
        select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$
        select.addSymbol(new ElementSymbol("z")); //$NON-NLS-1$
        // The parser hard-codes the name "expr"
        select.addSymbol(new ExpressionSymbol("expr", expr)); //$NON-NLS-1$
View Full Code Here

       
        helpTest(query, query, q);
    }
   
    @Test public void testCaseExpression2() {
        CaseExpression expr = TestCaseExpression.example(4);
        expr.setElseExpression(null);
        Select select = new Select();
        select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$
        select.addSymbol(new ElementSymbol("z")); //$NON-NLS-1$
        // The parser hard-codes the name "expr"
        select.addSymbol(new ExpressionSymbol("expr", expr)); //$NON-NLS-1$
View Full Code Here

        helpTest(TestCaseExpression.example(2),
                 "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1 ELSE 9999 END"); //$NON-NLS-1$
    }
   
    public void testCaseExpression2() {
        CaseExpression example = TestCaseExpression.example(2);
        example.setElseExpression(null);
        helpTest(example, "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1 END"); //$NON-NLS-1$
    }
View Full Code Here

        example.setElseExpression(null);
        helpTest(example, "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1 END"); //$NON-NLS-1$
    }
   
    public void testCaseExpression3() {
        CaseExpression example = TestCaseExpression.example(3, 0, true);
        helpTest(example, "CASE x WHEN null THEN 0 WHEN 'b' THEN 1 WHEN 'c' THEN 2 ELSE 9999 END"); //$NON-NLS-1$
    }
View Full Code Here

        CaseExpression example = TestCaseExpression.example(3, 0, true);
        helpTest(example, "CASE x WHEN null THEN 0 WHEN 'b' THEN 1 WHEN 'c' THEN 2 ELSE 9999 END"); //$NON-NLS-1$
    }
   
    public void testCaseExpression4() {
        CaseExpression example = TestCaseExpression.example(3, 2, true);
        example.setElseExpression(null);
        helpTest(example, "CASE x WHEN 'a' THEN 0 WHEN 'b' THEN 1 WHEN null THEN 2 END"); //$NON-NLS-1$
    }
View Full Code Here

TOP

Related Classes of org.teiid.query.sql.symbol.CaseExpression

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.