Package org.jooq

Examples of org.jooq.Query


        testGetSQL0(q, "select 1, 'A' from dual");
    }

    @Test
    public void testGetSQLWithParamTypeNAMED() {
        Query q =
        DSL.using(SQLDialect.MYSQL, new Settings().withParamType(NAMED))
           .select(param("var", 1), val("A"));

        testGetSQL0(q, "select :var, :2 from dual");
    }
View Full Code Here


        testGetSQL0(q, "select :var, :2 from dual");
    }

    @Test
    public void testGetSQLWithParamTypeNAMEDandStatementTypeSTATIC() {
        Query q =
        DSL.using(SQLDialect.MYSQL, new Settings().withParamType(NAMED)
                                                  .withStatementType(STATIC_STATEMENT))
           .select(param("var", 1), val("A"));

        testGetSQL0(q, "select 1, 'A' from dual");
View Full Code Here

        testGetSQL0(q, "select 1, 'A' from dual");
    }

    @Test
    public void testGetSQLWithParamTypeNAMED_OR_INLINED() {
        Query q =
        DSL.using(SQLDialect.MYSQL, new Settings().withParamType(NAMED_OR_INLINED))
           .select(param("var", 1), val("A"));

        testGetSQL0(q, "select :var, 'A' from dual");
    }
View Full Code Here

        testGetSQL0(q, "select :var, 'A' from dual");
    }

    @Test
    public void testGetSQLWithParamTypeNAMED_OR_INLINEDandStatementTypeSTATIC() {
        Query q =
        DSL.using(SQLDialect.MYSQL, new Settings().withParamType(NAMED_OR_INLINED)
                                                  .withStatementType(STATIC_STATEMENT))
           .select(param("var", 1), val("A"));

        testGetSQL0(q, "select 1, 'A' from dual");
View Full Code Here

        testGetSQL0(q, "select 1, 'A' from dual");
    }

    @Test
    public void testGetSQLWithParamTypeINLINED() {
        Query q =
        DSL.using(SQLDialect.MYSQL, new Settings().withParamType(INLINED))
           .select(param("var", 1), val("A"));

        testGetSQL0(q, "select 1, 'A' from dual");
    }
View Full Code Here

        testGetSQL0(q, "select 1, 'A' from dual");
    }

    @Test
    public void testGetSQLWithParamTypeINLINEDandStatementTypeSTATIC() {
        Query q =
        DSL.using(SQLDialect.MYSQL, new Settings().withParamType(INLINED)
                                                  .withStatementType(STATIC_STATEMENT))
           .select(param("var", 1), val("A"));

        testGetSQL0(q, "select 1, 'A' from dual");
View Full Code Here

                }
            } while ((moreResults = stmt.getMoreResults()) || stmt.getUpdateCount() != -1);
        }

        Tools.title("You always know whether a result set is produced with jOOQ, because of the type");
        Query q1 = DSL.using(connection).query("UPDATE AUTHOR SET LAST_NAME = LAST_NAME");
        System.out.println(
            q1.execute()
        );

        ResultQuery<Record> q2 = DSL.using(connection).resultQuery("SELECT * FROM AUTHOR");
        System.out.println(
            q2.fetch()
View Full Code Here

            try {
                records[i].attach(local);
                executeAction(i);
            }
            catch (QueryCollectorSignal e) {
                Query query = e.getQuery();
                String sql = e.getSQL();

                // Aggregate executable queries by identical SQL
                if (query.isExecutable()) {
                    List<Query> list = queries.get(sql);

                    if (list == null) {
                        list = new ArrayList<Query>();
                        queries.put(sql, list);
                    }

                    list.add(query);
                }
            }
            finally {
                records[i].attach(previous);
            }
        }

        // Execute one batch statement for each identical SQL statement. Every
        // SQL statement may have several queries with different bind values.
        // The order is preserved as much as possible
        List<Integer> result = new ArrayList<Integer>();
        for (Entry<String, List<Query>> entry : queries.entrySet()) {
            BatchBindStep batch = create.batch(entry.getValue().get(0));

            for (Query query : entry.getValue()) {
                batch.bind(query.getBindValues().toArray());
            }

            int[] array = batch.execute();
            for (int i : array) {
                result.add(i);
View Full Code Here

            try {
                records[i].attach(local);
                executeAction(i);
            }
            catch (QueryCollectorSignal e) {
                Query query = e.getQuery();

                if (query.isExecutable()) {
                    queries.add(query);
                }
            }
            finally {
                records[i].attach(previous);
View Full Code Here

        assertEquals("select \"TABLE1\".\"ID1\", \"TABLE1\".\"NAME1\", \"TABLE1\".\"DATE1\" from \"TABLE1\" where exists (select \"TABLE2\".\"ID2\" from \"TABLE2\")", r_ref().render(q1));
    }

    @Test
    public void testNamedParams() throws Exception {
        Query q1 = create.select(val(1)).from(TABLE1).where(FIELD_ID1.equal(val(2)));
        Query q2 = create.select(param("p1", 1)).from(TABLE1).where(FIELD_ID1.equal(param("p2", 2)));
        Query q3 = create.select(param("p1", 1)).from(TABLE1).where(FIELD_ID1.equal(2));
        Query q4 = create.select(val(1)).from(TABLE1).where(FIELD_ID1.equal(param("p2", 2)));

        assertEquals("select 1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = 2", r_refI().render(q1));
        assertEquals("select :1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = :2", r_refP().render(q1));
        assertEquals("select ? from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?", r_ref().render(q1));

        assertEquals("select 1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = 2", r_refI().render(q2));
        assertEquals("select :p1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = :p2", r_refP().render(q2));
        assertEquals("select ? from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?", r_ref().render(q2));

        assertEquals("select 1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = 2", r_refI().render(q3));
        assertEquals("select :p1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = :2", r_refP().render(q3));
        assertEquals("select ? from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?", r_ref().render(q3));

        assertEquals("select 1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = 2", r_refI().render(q4));
        assertEquals("select :1 from \"TABLE1\" where \"TABLE1\".\"ID1\" = :p2", r_refP().render(q4));
        assertEquals("select ? from \"TABLE1\" where \"TABLE1\".\"ID1\" = ?", r_ref().render(q4));

        // Param / Val queries should be equal as toString() doesn't consider params
        assertEquals(q1, q2);
        assertEquals(q1, q3);
        assertEquals(q1, q4);

        // Params
        Param<?> p11 = q1.getParam("1");
        Param<?> p21 = q2.getParam("p1");
        Param<?> p31 = q3.getParam("p1");
        Param<?> p41 = q4.getParam("1");

        Param<?> p12 = q1.getParam("2");
        Param<?> p22 = q2.getParam("p2");
        Param<?> p32 = q3.getParam("2");
        Param<?> p42 = q4.getParam("p2");

        assertEquals(Arrays.asList("1", "2"), new ArrayList<String>(q1.getParams().keySet()));
        assertEquals(Arrays.asList("p1", "p2"), new ArrayList<String>(q2.getParams().keySet()));
        assertEquals(Arrays.asList("p1", "2"), new ArrayList<String>(q3.getParams().keySet()));
        assertEquals(Arrays.asList("1", "p2"), new ArrayList<String>(q4.getParams().keySet()));

        // Types
        assertEquals(Integer.class, p11.getType());
        assertEquals(Integer.class, p21.getType());
        assertEquals(Integer.class, p31.getType());
View Full Code Here

TOP

Related Classes of org.jooq.Query

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.