Package org.jooq

Examples of org.jooq.Condition


        context.assertIsSatisfied();
    }

    @Test
    public void testMultipleCombinedCondition() throws Exception {
        Condition c1 = FIELD_ID1.equal(10);
        Condition c2 = FIELD_ID2.equal(20);
        Condition c3 = FIELD_ID1.equal(30);
        Condition c4 = FIELD_ID2.equal(40);

        Condition c = c1.and(c2).or(c3.and(c4));
        assertEquals("((\"TABLE1\".\"ID1\" = 10 and \"TABLE2\".\"ID2\" = 20) or (\"TABLE1\".\"ID1\" = 30 and \"TABLE2\".\"ID2\" = 40))", r_refI().render(c));
        assertEquals("((\"TABLE1\".\"ID1\" = ? and \"TABLE2\".\"ID2\" = ?) or (\"TABLE1\".\"ID1\" = ? and \"TABLE2\".\"ID2\" = ?))", r_ref().render(c));

        c = c1.and(c2).or(c3).and(c4);
        assertEquals("(((\"TABLE1\".\"ID1\" = 10 and \"TABLE2\".\"ID2\" = 20) or \"TABLE1\".\"ID1\" = 30) and \"TABLE2\".\"ID2\" = 40)", r_refI().render(c));
View Full Code Here


        context.assertIsSatisfied();
    }

    @Test
    public void testBetweenCondition() throws Exception {
        Condition c = FIELD_ID1.between(1, 10);
        assertEquals("\"TABLE1\".\"ID1\" between 1 and 10", r_refI().render(c));
        assertEquals("\"TABLE1\".\"ID1\" between ? and ?", r_ref().render(c));

        c = FIELD_ID1.notBetween(1, 10);
        assertEquals("\"TABLE1\".\"ID1\" not between 1 and 10", r_refI().render(c));
View Full Code Here

        context.assertIsSatisfied();
    }

    @Test
    public void testInCondition() throws Exception {
        Condition c = FIELD_ID1.in(new Integer[0]);
        assertEquals(falseCondition(), c);

        c = FIELD_ID1.notIn(new Integer[0]);
        assertEquals(trueCondition(), c);
View Full Code Here

        context.assertIsSatisfied();
    }

    @Test
    public void testInSelectCondition() throws Exception {
        Condition c = FIELD_ID1.in(create.selectFrom(TABLE1).where(FIELD_NAME1.equal("x")));
        assertEquals("\"TABLE1\".\"ID1\" in (select \"TABLE1\".\"ID1\", \"TABLE1\".\"NAME1\", \"TABLE1\".\"DATE1\" from \"TABLE1\" where \"TABLE1\".\"NAME1\" = 'x')", r_refI().render(c));
        assertEquals("\"TABLE1\".\"ID1\" in (select \"TABLE1\".\"ID1\", \"TABLE1\".\"NAME1\", \"TABLE1\".\"DATE1\" from \"TABLE1\" where \"TABLE1\".\"NAME1\" = ?)", r_ref().render(c));

        c = FIELD_ID1.notIn(create.selectFrom(TABLE1).where(FIELD_NAME1.equal("x")));
        assertEquals("\"TABLE1\".\"ID1\" not in (select \"TABLE1\".\"ID1\", \"TABLE1\".\"NAME1\", \"TABLE1\".\"DATE1\" from \"TABLE1\" where \"TABLE1\".\"NAME1\" = 'x')", r_refI().render(c));
View Full Code Here

        context.assertIsSatisfied();
    }

    @Test
    public void testCompareCondition() throws Exception {
        Condition c = FIELD_ID1.equal(10);
        assertEquals("\"TABLE1\".\"ID1\" = 10", r_refI().render(c));
        assertEquals("\"TABLE1\".\"ID1\" = ?", r_ref().render(c));

        context.checking(new Expectations() {{
            oneOf(statement).setInt(1, 10);
View Full Code Here

        context.assertIsSatisfied();
    }

    @Test
    public void testNotCondition() throws Exception {
        Condition c = FIELD_ID1.equal(10).not();
        assertEquals("not(\"TABLE1\".\"ID1\" = 10)", r_refI().render(c));
        assertEquals("not(\"TABLE1\".\"ID1\" = ?)", r_ref().render(c));

        assertEquals("not(not(\"TABLE1\".\"ID1\" = 10))", r_refI().render(c.not()));
        assertEquals("not(not(\"TABLE1\".\"ID1\" = ?))", r_ref().render(c.not()));

        context.checking(new Expectations() {{
            oneOf(statement).setInt(1, 10);
        }});
View Full Code Here

        context.assertIsSatisfied();
    }

    @Test
    public void testLikeCondition() throws Exception {
        Condition c1 = FIELD_NAME1.like("%a%");
        assertEquals("\"TABLE1\".\"NAME1\" like '%a%'", r_refI().render(c1));
        assertEquals("\"TABLE1\".\"NAME1\" like ?", r_ref().render(c1));

        Condition c2 = FIELD_NAME1.notLike("%a%");
        assertEquals("\"TABLE1\".\"NAME1\" not like '%a%'", r_refI().render(c2));
        assertEquals("\"TABLE1\".\"NAME1\" not like ?", r_ref().render(c2));

        Condition c3 = FIELD_NAME1.like("%a%", '!');
        assertEquals("\"TABLE1\".\"NAME1\" like '%a%' escape '!'", r_refI().render(c3));
        assertEquals("\"TABLE1\".\"NAME1\" like ? escape '!'", r_ref().render(c3));

        Condition c4 = FIELD_NAME1.notLike("%a%", '!');
        assertEquals("\"TABLE1\".\"NAME1\" not like '%a%' escape '!'", r_refI().render(c4));
        assertEquals("\"TABLE1\".\"NAME1\" not like ? escape '!'", r_ref().render(c4));
    }
View Full Code Here

        assertEquals("\"TABLE1\".\"NAME1\" not like ? escape '!'", r_ref().render(c4));
    }

    @Test
    public void testPlainSQLCondition() throws Exception {
        Condition c1 = condition("TABLE1.ID = 10");
        Condition c2 = condition("TABLE1.ID = ? and TABLE2.ID = ?", 10, "20");

        assertEquals("(TABLE1.ID = 10)", r_refI().render(c1));
        assertEquals("(TABLE1.ID = 10)", r_ref().render(c1));

        assertEquals("(TABLE1.ID = 10 and TABLE2.ID = '20')", r_refI().render(c2));
View Full Code Here

        assertEquals("Hello 'A' 'Hello ?' Is there anybody '' 'B' ' out there '' ? '", r_refI().render(f));
    }

    @Test
    public void testCustomCondition() throws Exception {
        Condition c = new CustomCondition() {
            private static final long serialVersionUID = 6302350477408137757L;

            @Override
            public void toSQL(RenderContext ctx) {
                if (ctx.inline()) {
View Full Code Here

        context.assertIsSatisfied();
    }

    @Test
    public void testIsNullCondition() throws Exception {
        Condition c1 = FIELD_ID1.isNull();
        assertEquals("\"TABLE1\".\"ID1\" is null", r_refI().render(c1));
        assertEquals("\"TABLE1\".\"ID1\" is null", r_ref().render(c1));

        Condition c2 = FIELD_ID1.isNotNull();
        assertEquals("\"TABLE1\".\"ID1\" is not null", r_refI().render(c2));
        assertEquals("\"TABLE1\".\"ID1\" is not null", r_ref().render(c2));

        int i = b_ref().bind(c1).peekIndex();
        assertEquals(1, i);
View Full Code Here

TOP

Related Classes of org.jooq.Condition

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.