Package org.apache.cayenne.exp

Examples of org.apache.cayenne.exp.Expression


        assertTrue("Failed: " + between, between.match(match3));
        assertFalse("Failed: " + notBetween, notBetween.match(match3));
    }

    public void testEvaluateIN() throws Exception {
        Expression in = new ASTIn(new ASTObjPath("estimatedPrice"), new ASTList(
                new Object[] {
                        new BigDecimal("10"), new BigDecimal("20")
                }));

        Expression notIn = new ASTNotIn(new ASTObjPath("estimatedPrice"), new ASTList(
                new Object[] {
                        new BigDecimal("10"), new BigDecimal("20")
                }));

        Painting noMatch1 = new Painting();
        noMatch1.setEstimatedPrice(new BigDecimal("21"));
        assertFalse(in.match(noMatch1));
        assertTrue(notIn.match(noMatch1));

        Painting noMatch2 = new Painting();
        noMatch2.setEstimatedPrice(new BigDecimal("11"));
        assertFalse("Failed: " + in, in.match(noMatch2));
        assertTrue("Failed: " + notIn, notIn.match(noMatch2));

        Painting match1 = new Painting();
        match1.setEstimatedPrice(new BigDecimal("20"));
        assertTrue(in.match(match1));
        assertFalse(notIn.match(match1));

        Painting match2 = new Painting();
        match2.setEstimatedPrice(new BigDecimal("10"));
        assertTrue("Failed: " + in, in.match(match2));
        assertFalse("Failed: " + notIn, notIn.match(match2));
    }
View Full Code Here


        assertTrue("Failed: " + in, in.match(match2));
        assertFalse("Failed: " + notIn, notIn.match(match2));
    }

    public void testEvaluateLIKE1() throws Exception {
        Expression like = new ASTLike(new ASTObjPath("artistName"), "abc%d");
        Expression notLike = new ASTNotLike(new ASTObjPath("artistName"), "abc%d");

        Artist noMatch = new Artist();
        noMatch.setArtistName("dabc");
        assertFalse(like.match(noMatch));
        assertTrue(notLike.match(noMatch));

        Artist match1 = new Artist();
        match1.setArtistName("abc123d");
        assertTrue("Failed: " + like, like.match(match1));
        assertFalse("Failed: " + notLike, notLike.match(match1));

        Artist match2 = new Artist();
        match2.setArtistName("abcd");
        assertTrue("Failed: " + like, like.match(match2));
        assertFalse("Failed: " + notLike, notLike.match(match2));
    }
View Full Code Here

        assertTrue("Failed: " + like, like.match(match2));
        assertFalse("Failed: " + notLike, notLike.match(match2));
    }

    public void testEvaluateLIKE2() throws Exception {
        Expression like = new ASTLike(new ASTObjPath("artistName"), "abc?d");
        Expression notLike = new ASTNotLike(new ASTObjPath("artistName"), "abc?d");

        Artist noMatch1 = new Artist();
        noMatch1.setArtistName("dabc");
        assertFalse(like.match(noMatch1));
        assertTrue(notLike.match(noMatch1));

        Artist noMatch2 = new Artist();
        noMatch2.setArtistName("abc123d");
        assertFalse("Failed: " + like, like.match(noMatch2));
        assertTrue("Failed: " + notLike, notLike.match(noMatch2));

        Artist match = new Artist();
        match.setArtistName("abcXd");
        assertTrue("Failed: " + like, like.match(match));
        assertFalse("Failed: " + notLike, notLike.match(match));
    }
View Full Code Here

        assertFalse("Failed: " + notLike, notLike.match(match));
    }

    public void testEvaluateLIKE3() throws Exception {
        // test special chars
        Expression like = new ASTLike(new ASTObjPath("artistName"), "/./");

        Artist noMatch1 = new Artist();
        noMatch1.setArtistName("/a/");
        assertFalse(like.match(noMatch1));

        Artist match = new Artist();
        match.setArtistName("/./");
        assertTrue("Failed: " + like, like.match(match));
    }
View Full Code Here

        match.setArtistName("/./");
        assertTrue("Failed: " + like, like.match(match));
    }

    public void testEvaluateLIKE_IGNORE_CASE() throws Exception {
        Expression like = new ASTLikeIgnoreCase(new ASTObjPath("artistName"), "aBcD");
        Expression notLike = new ASTNotLikeIgnoreCase(
                new ASTObjPath("artistName"),
                "aBcD");

        Artist noMatch1 = new Artist();
        noMatch1.setArtistName("dabc");
        assertFalse(like.match(noMatch1));
        assertTrue(notLike.match(noMatch1));

        Artist match1 = new Artist();
        match1.setArtistName("abcd");
        assertTrue("Failed: " + like, like.match(match1));
        assertFalse("Failed: " + notLike, notLike.match(match1));

        Artist match2 = new Artist();
        match2.setArtistName("ABcD");
        assertTrue("Failed: " + like, like.match(match2));
        assertFalse("Failed: " + notLike, notLike.match(match2));
    }
View Full Code Here

        assertTrue("Failed: " + like, like.match(match2));
        assertFalse("Failed: " + notLike, notLike.match(match2));
    }

    public void testEvaluateADD() throws Exception {
        Expression add = new ASTAdd(new Object[] {
                new Integer(1), new Double(5.5)
        });
        assertEquals(6.5, ((Number) add.evaluate(null)).doubleValue(), 0.0001);
    }
View Full Code Here

        });
        assertEquals(6.5, ((Number) add.evaluate(null)).doubleValue(), 0.0001);
    }

    public void testEvaluateSubtract() throws Exception {
        Expression subtract = new ASTSubtract(new Object[] {
                new Integer(1), new Double(0.1), new Double(0.2)
        });
        assertEquals(0.7, ((Number) subtract.evaluate(null)).doubleValue(), 0.0001);
    }
View Full Code Here

        });
        assertEquals(0.7, ((Number) subtract.evaluate(null)).doubleValue(), 0.0001);
    }

    public void testEvaluateMultiply() throws Exception {
        Expression multiply = new ASTMultiply(new Object[] {
                new Integer(2), new Double(3.5)
        });
        assertEquals(7, ((Number) multiply.evaluate(null)).doubleValue(), 0.0001);
    }
View Full Code Here

        });
        assertEquals(7, ((Number) multiply.evaluate(null)).doubleValue(), 0.0001);
    }

    public void testEvaluateDivide() throws Exception {
        Expression divide = new ASTDivide(new Object[] {
                new BigDecimal("7.0"), new BigDecimal("2.0")
        });
        assertEquals(3.5, ((Number) divide.evaluate(null)).doubleValue(), 0.0001);
    }
View Full Code Here

    /**
     * Comparable interface implementation. Can compare two Java Beans based on the stored
     * expression.
     */
    public int compare(Object o1, Object o2) {
        Expression exp = getSortSpec();
        Object value1 = null;
        Object value2 = null;
        try {
            value1 = exp.evaluate(o1);
        }
        catch (ExpressionException e) {
            if (pathExceptionSuppressed
                    && e.getCause() instanceof org.apache.cayenne.reflect.UnresolvablePathException) {
                // do nothing, we expect this
            }
            else {
                // re-throw
                throw e;
            }
        }

        try {
            value2 = exp.evaluate(o2);
        }
        catch (ExpressionException e) {
            if (pathExceptionSuppressed
                    && e.getCause() instanceof org.apache.cayenne.reflect.UnresolvablePathException) {
                // do nothing, we expect this
View Full Code Here

TOP

Related Classes of org.apache.cayenne.exp.Expression

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.