Package org.jooq

Examples of org.jooq.Condition


        Field object = fieldByName("ANY");

        // Check if a correct type was coerced correctly
        // ---------------------------------------------
        {
            Condition int_int = integer.eq(1);
            assertEquals("`TABLE1`.`ID1` = 1", r_refI().render(int_int));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(int_int).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition string_string = string.eq("1");
            assertEquals("`TABLE1`.`NAME1` = '1'", r_refI().render(string_string));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(string_string).peekIndex());
            context.assertIsSatisfied();
        }

        // Check if a convertible type was coerced correctly
        // -------------------------------------------------
        {
            Condition int_string = integer.eq("1");
            assertEquals("`TABLE1`.`ID1` = 1", r_refI().render(int_string));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(int_string).peekIndex());
            context.assertIsSatisfied();

            Condition string_int = string.eq(1);
            assertEquals("`TABLE1`.`NAME1` = '1'", r_refI().render(string_int));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(string_int).peekIndex());
            context.assertIsSatisfied();
        }

        // Check if ...
        // ------------
        {
            Condition object_int = object.eq(1);
            assertEquals("`ANY` = 1", r_refI().render(object_int));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(object_int).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition object_string = object.eq("1");
            assertEquals("`ANY` = '1'", r_refI().render(object_string));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(object_string).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition object_date = object.eq(Timestamp.valueOf("2012-12-21 15:30:00.0"));
            assertEquals("`ANY` = {ts '2012-12-21 15:30:00.0'}", r_refI().render(object_date));
            context.checking(new Expectations() {{
                oneOf(statement).setTimestamp(1, Timestamp.valueOf("2012-12-21 15:30:00.0"));
            }});
View Full Code Here


        Field object = fieldByName("ANY");

        // Check if a correct type was coerced correctly
        // ---------------------------------------------
        {
            Condition int_int = integer.in(1);
            assertEquals("`TABLE1`.`ID1` in (1)", r_refI().render(int_int));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(int_int).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition string_string = string.in("1");
            assertEquals("`TABLE1`.`NAME1` in ('1')", r_refI().render(string_string));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(string_string).peekIndex());
            context.assertIsSatisfied();
        }

        // Check if a convertible type was coerced correctly
        // -------------------------------------------------
        {
            Condition int_string = integer.in("1");
            assertEquals("`TABLE1`.`ID1` in (1)", r_refI().render(int_string));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(int_string).peekIndex());
            context.assertIsSatisfied();

            Condition string_int = string.in(1);
            assertEquals("`TABLE1`.`NAME1` in ('1')", r_refI().render(string_int));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(string_int).peekIndex());
            context.assertIsSatisfied();
        }

        // Check if ...
        // ------------
        {
            Condition object_int = object.in(1);
            assertEquals("`ANY` in (1)", r_refI().render(object_int));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(object_int).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition object_string = object.in("1");
            assertEquals("`ANY` in ('1')", r_refI().render(object_string));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});
View Full Code Here

    @Test
    public void testInPredicateWithCollection() {
        Field<Object> a = DSL.field("a");
        List<String> values = Arrays.asList("a", "b");

        Condition c = a.in(new Object[] { values });

        assertEquals("a in (?, ?)", create.render(c));
        assertEquals("a in ('a', 'b')", create.renderInlined(c));
        assertEquals("a in (:1, :2)", create.renderNamedParams(c));
    }
View Full Code Here

    @Test
    public void testInPredicateWithSelect() {
        Field<Object> a = DSL.field("a");
        Select<?> values = DSL.select(val(1));

        Condition c = a.in(values);

        assertEquals("a in (select ? from dual)", create.render(c));
        assertEquals("a in (select 1 from dual)", create.renderInlined(c));
        assertEquals("a in (select :1 from dual)", create.renderNamedParams(c));
    }
View Full Code Here

        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

    }

    @Test
    public void testQueryPartByNameAndConditions() throws Exception {
        List<String> v1 = Arrays.asList("1", "2");
        Condition c1 = fieldByName(String.class, "A", "b").in(v1);

        assertEquals("`A`.`b` in (?, ?)", r_ref().render(c1));
        assertEquals("`A`.`b` in ('1', '2')", r_refI().render(c1));

        Set<String> v2 = new TreeSet<String>(Arrays.asList("1", "2"));
        Condition c2 = fieldByName(String.class, "A", "b").in(v2);

        assertEquals("`A`.`b` in (?, ?)", r_ref().render(c2));
        assertEquals("`A`.`b` in ('1', '2')", r_refI().render(c2));
    }
View Full Code Here

    }

    @Test
    public void testPlainSQLInPredicate() throws Exception {
        List<String> v1 = Arrays.asList("1", "2");
        Condition c1 = field("f").in(v1);

        assertEquals("f in (?, ?)", r_ref().render(c1));
        assertEquals("f in ('1', '2')", r_refI().render(c1));

        Set<String> v2 = new TreeSet<String>(Arrays.asList("1", "2"));
        Condition c2 = field("f").in(v2);

        assertEquals("f in (?, ?)", r_ref().render(c2));
        assertEquals("f in ('1', '2')", r_refI().render(c2));
    }
View Full Code Here

        assertEquals("f in ('1', '2')", r_refI().render(c2));
    }

    @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.paramType() == INLINED) {
View Full Code Here

*/
public class PlainSQLTest extends AbstractTest {

    @Test
    public void testBindVariables() {
        Condition q = condition("a = ? and b = ?", val(1), 2);

        assertEquals("(a = ? and b = ?)", create.render(q));
        assertEquals("(a = 1 and b = 2)", create.renderInlined(q));
        assertEquals("(a = :1 and b = :2)", create.renderNamedParams(q));

        assertEquals("((a = ? and b = ?) and (a = ? and b = ?))", create.render(q.and(q)));
        assertEquals("((a = 1 and b = 2) and (a = 1 and b = 2))", create.renderInlined(q.and(q)));
        assertEquals("((a = :1 and b = :2) and (a = :3 and b = :4))", create.renderNamedParams(q.and(q)));
    }
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.