Package org.jooq

Examples of org.jooq.DSLContext


        MOCK = DSL.using(new MockConnection(new MockFileDatabase(s)), SQLDialect.POSTGRES);
    }

    @Test
    public void testEmptyResult() {
        DSLContext e = DSL.using(new MockConnection(new EmptyResult()), SQLDialect.H2);
        Result<Record> result = e.fetch("select ?, ? from dual", 1, 2);

        assertEquals(0, result.size());
        assertEquals(3, result.fields().length);
        for (int i = 0; i < 3; i++) {
            assertEquals(TABLE1.field(i).getName(), result.field(i).getName());
View Full Code Here


        }
    }

    @Test
    public void testSingleResult() {
        DSLContext e = DSL.using(new MockConnection(new SingleResult()), SQLDialect.H2);
        Result<Record> result = e.fetch("select ?, ? from dual", 1, 2);

        assertEquals(1, result.size());
        assertEquals(3, result.fields().length);

        for (int i = 0; i < 3; i++) {
View Full Code Here

        }
    }

    @Test
    public void testTripleResult() {
        DSLContext e = DSL.using(new MockConnection(new TripleResult()), SQLDialect.H2);
        List<Result<Record>> result = e.fetchMany("select ?, ? from dual", 1, 2);

        assertEquals(3, result.size());
        assertEquals(1, result.get(0).size());
        assertEquals(2, result.get(1).size());
        assertEquals(3, result.get(0).fields().length);
View Full Code Here

        }
    }

    @Test
    public void testBatchSingle() {
        DSLContext e = DSL.using(new MockConnection(new BatchSingle()), SQLDialect.H2);

        int[] result =
        e.batch(
            e.query("insert into x values(1)"),
            e.query("insert into x values(2)")
        ).execute();

        assertEquals(2, result.length);
        assertEquals(0, result[0]);
        assertEquals(1, result[1]);
View Full Code Here

        }
    }

    @Test
    public void testBatchMultiple() {
        DSLContext e = DSL.using(new MockConnection(new BatchMultiple()), SQLDialect.H2);

        Query query = e.query("insert into x values(?, ?)", null, null);

        int[] result =
        e.batch(query)
         .bind(1, 2)
         .bind(3, 4)
         .execute();

        assertEquals(2, result.length);
View Full Code Here

        }
    }

    @Test
    public void testException() {
        DSLContext e = DSL.using(new MockConnection(new Exceptional()), SQLDialect.H2);

        Query query = e.query("insert into x values(1)");

        try {
            query.execute();
            fail();
        }
View Full Code Here

    @Test
    public void testInsertReturning() {

        // Note: INSERT .. RETURNING is hard to mock for all dialects...
        DSLContext e = DSL.using(new MockConnection(new InsertReturning()), SQLDialect.POSTGRES);

        InsertResultStep<Table1Record> query = e
            .insertInto(TABLE1, FIELD_ID1)
            .values(1)
            .returning();

        assertEquals(1, query.execute());
View Full Code Here

        }
    }

    @Test
    public void testArrays() {
        DSLContext e = DSL.using(new MockConnection(new ArrayResult(3)), SQLDialect.POSTGRES);

        Result<Record2<String[], Integer[]>> r = e.select(strings, integers).fetch();
        assertEquals(4, r.size());
        assertEquals(2, r.fields().length);
        assertNull(r.getValue(0, "STRINGS"));
        assertNull(r.getValue(0, "INTEGERS"));
        assertArrayEquals(new String[0], (String[]) r.getValue(1, "STRINGS"));
View Full Code Here

        assertArrayEquals(new Integer[] { 2, 2 }, (Integer[]) r.getValue(3, "INTEGERS"));
    }

    @Test
    public void testJDBCArrays() throws SQLException {
        DSLContext e = DSL.using(new MockConnection(new ArrayResult(3)), SQLDialect.POSTGRES);

        ResultSet r = e.select(strings, integers).fetchResultSet();
        assertEquals(2, r.getMetaData().getColumnCount());

        assertTrue(r.next());
        assertNull(r.getArray("STRINGS"));
        assertNull(r.getArray("INTEGERS"));
View Full Code Here

    @Test
    public void testRenderSchema() {
        Schema schema = new SchemaImpl("S");
        Table<?> table = new TableImpl<Record>("T", schema);

        DSLContext create0 = DSL.using(SQLDialect.POSTGRES);
        assertEquals("\"S\".\"T\"", create0.render(table));

        DSLContext create1 = DSL.using(SQLDialect.POSTGRES, new Settings().withRenderSchema(false));
        assertEquals("\"T\"", create1.render(table));

        DSLContext create2 = DSL.using(SQLDialect.POSTGRES);
        create2.configuration().settings().setRenderSchema(false);
        assertEquals("\"T\"", create2.render(table));
    }
View Full Code Here

TOP

Related Classes of org.jooq.DSLContext

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.