Package org.jooq.impl

Examples of org.jooq.impl.Factory


    private static final JooqLogger log = JooqLogger.getLogger(SybaseDatabase.class);

    @Override
    public Factory create() {
        return new Factory(getConnection(), SQLDialect.SYBASE);
    }
View Full Code Here


    protected DataType<?>[] getCastableDataTypes() {
        return delegate.getCastableDataTypes();
    }

    protected Factory create(Settings settings) {
        Factory create = delegate.create(settings);
        create.getSettings().getExecuteListeners().add(TestStatisticsListener.class.getName());
        create.getSettings().getExecuteListeners().add(DebugListener.class.getName());
        return create;
    }
View Full Code Here

        super(delegate);
    }

    @Test
    public void testExecuteListenerOnResultQuery() throws Exception {
        Factory create = create(new Settings()
            .withExecuteListeners(ResultQueryListener.class.getName()));

        create.setData("Foo", "Bar");
        create.setData("Bar", "Baz");

        Result<?> result =
        create.select(TBook_ID(), val("Hello"))
              .from(TBook())
              .where(TBook_ID().in(1, 2))
              .fetch();

        // [#1145] When inlining variables, no bind events are triggered
        int plus = (SettingsTools.executePreparedStatements(create.getSettings()) ? 2 : 0);

        // Check correct order of listener method invocation
        assertEquals(1, ResultQueryListener.start);
        assertEquals(2, ResultQueryListener.renderStart);
        assertEquals(3, ResultQueryListener.renderEnd);
View Full Code Here

            return;
        }

        jOOQAbstractTest.reset = false;

        Factory create = create(new Settings()
            .withExecuteListeners(BatchSingleListener.class.getName()));

        create.setData("Foo", "Bar");
        create.setData("Bar", "Baz");

        int[] result = create.batch(create().insertInto(TAuthor())
                                            .set(TAuthor_ID(), param("id", Integer.class))
                                            .set(TAuthor_LAST_NAME(), param("name", String.class)))
                             .bind(8, "Gamma")
                             .bind(9, "Helm")
                             .bind(10, "Johnson")
View Full Code Here

    @Test
    public void testExecuteListenerOnBatchMultiple() {
        jOOQAbstractTest.reset = false;

        Factory create = create(new Settings()
            .withExecuteListeners(BatchMultipleListener.class.getName()));

        create.setData("Foo", "Bar");
        create.setData("Bar", "Baz");

        int[] result = create.batch(
            create().insertInto(TAuthor())
                    .set(TAuthor_ID(), 8)
                    .set(TAuthor_LAST_NAME(), "Gamma"),

            create().insertInto(TAuthor())
View Full Code Here

            }
        };

        // [#1169] Some additional checks to see if custom data is correctly
        // passed on to custom QueryParts
        Factory create = create();
        create.setData("Foo-Field", "Bar");
        create.setData("Foo-Condition", "Bar");

        Result<Record> result = create
            .select(TBook_ID(), IDx2)
            .from(TBook())
            .where(c)
            .orderBy(IDx2)
            .fetch();

        assertEquals(3, result.size());
        assertEquals(Integer.valueOf(2), result.getValue(0, TBook_ID()));
        assertEquals(Integer.valueOf(3), result.getValue(1, TBook_ID()));
        assertEquals(Integer.valueOf(4), result.getValue(2, TBook_ID()));

        assertEquals(Integer.valueOf(4), result.getValue(0, IDx2));
        assertEquals(Integer.valueOf(6), result.getValue(1, IDx2));
        assertEquals(Integer.valueOf(8), result.getValue(2, IDx2));

        // [#1169] Check again
        assertEquals("Baz", create.getData("Foo-Field"));
        assertEquals("Baz", create.getData("Foo-Condition"));
    }
View Full Code Here

        Boolean bool3 = (derby ? bool1 : null);

        // Inlining bind values globally, through the factory settings
        // -----------------------------------------------------------
        {
            Factory create = create(new Settings()
                .withStatementType(StatementType.STATIC_STATEMENT));

            Object[] array1 = create.select(vals(s1, s2, s3, s4)).fetchOneArray();
            Object[] array2 = create.select(vals(b1, b2, sh1, sh2, i1, i2, l1, l2, bi1, bi2, bd1, bd2, db1, db2, f1, f2)).fetchOneArray();
            Object[] array3 = create.select(vals(d1, d2, t1, t2, ts1, ts2)).fetchOneArray();
            Object[] array4 = create.select(vals(by1, by2, bool1, bool2, bool3)).fetchOneArray();

            assertEquals(4, array1.length);
            assertEquals(16, array2.length);
            assertEquals(6, array3.length);
            assertEquals(5, array4.length);

            assertEquals(asList(s1, s2, s3, s4), asList(array1));
            assertEquals(asList((Number) b1, b2, sh1, sh2, i1, i2, l1, l2, bi1, bi2, bd1, bd2, db1, db2, f1, f2), asList(array2));
            assertEquals(asList(d1, d2, t1, t2, ts1, ts2), asList(array3));

            array4[0] = new String((byte[]) array4[0]);
            array4[1] = (derby ? new String((byte[]) array4[1]) : array4[1]);

            assertEquals(asList(new String(by1), (derby ? new String(by2) : by2), bool1, bool2, bool3), asList(array4));
        }

        // Inlining bind values locally, through bind value parameters
        // -----------------------------------------------------------
        {
            Factory create = create();

            Object[] array1 = create.select(inline(s1), inline(s2), inline(s3), inline(s4)).fetchOneArray();
            Object[] array2 = create.select(inline(b1), inline(b2), inline(sh1), inline(sh2), inline(i1), inline(i2), inline(l1), inline(l2), inline(bi1), inline(bi2), inline(bd1), inline(bd2), inline(db1), inline(db2), inline(f1), inline(f2)).fetchOneArray();
            Object[] array3 = create.select(inline(d1), inline(d2), inline(t1), inline(t2), inline(ts1), inline(ts2)).fetchOneArray();
            Object[] array4 = create.select(inline(by1), inline(by2), inline(bool1), inline(bool2), inline(bool3)).fetchOneArray();

            assertEquals(4, array1.length);
            assertEquals(16, array2.length);
            assertEquals(6, array3.length);
            assertEquals(5, array4.length);
View Full Code Here

        Date d1 = Date.valueOf("1981-07-10");
        // Time t1 = Time.valueOf("12:01:15"); // [#1013] TODO: Fix this for Oracle
        Timestamp ts1 = Timestamp.valueOf("1981-07-10 12:01:15");

        Factory create = create(new Settings()
            .withStatementType(StatementType.STATIC_STATEMENT));

        DATE date = create.newRecord(TDates());
        date.setValue(TDates_ID(), 1);
        assertEquals(1, date.store());

        date.setValue(TDates_ID(), 2);
        date.setValue(TDates_D(), d1);
        // date.setValue(TDates_T(), t1);
        date.setValue(TDates_TS(), ts1);
        assertEquals(1, date.store());

        Result<Record> dates =
        create.select(TDates_ID(), TDates_D(), TDates_T(), TDates_TS())
              .from(TDates())
              .orderBy(TDates_ID())
              .fetch();

        assertEquals(2, dates.size());
View Full Code Here

            case SQLSERVER:
                log.info("SKIPPING", "USE test");
                return;
        }

        Factory factory = create();
        factory.use(schema().getName());

        Result<?> result =
        factory.select(TBook_AUTHOR_ID(), count())
               .from(TBook())
               .join(TAuthor())
               .on(TBook_AUTHOR_ID().equal(TAuthor_ID()))
               .where(TAuthor_YEAR_OF_BIRTH().greaterOrEqual(TAuthor_ID()))
               .groupBy(TBook_AUTHOR_ID())
               .having(count().greaterOrEqual(1))
               .orderBy(TBook_AUTHOR_ID().desc())
               .fetch();

        assertEquals(Arrays.asList(2, 1), result.getValues(TBook_AUTHOR_ID()));
        assertEquals(Arrays.asList(2, 2), result.getValues(count()));

        String sql = factory.select(TBook_AUTHOR_ID()).from(TAuthor()).getSQL();
        assertFalse(sql.toLowerCase().contains(TAuthor().getSchema().getName().toLowerCase()));
    }
View Full Code Here

    @Test
    public void testAttachable() throws Exception {
        jOOQAbstractTest.reset = false;

        Factory create = create();

        S store = create.newRecord(TBookStore());
        assertNotNull(store);

        store.setValue(TBookStore_NAME(), "Barnes and Noble");
        assertEquals(1, store.store());

        store = create.newRecord(TBookStore());
        store.setValue(TBookStore_NAME(), "Barnes and Noble");
        store.attach(null);

        try {
            store.store();
            fail();
        }
        catch (DetachedException expected) {}

        try {
            store.refresh();
            fail();
        }
        catch (DetachedException expected) {}

        try {
            store.delete();
            fail();
        }
        catch (DetachedException expected) {}

        store.attach(create);
        store.refresh();
        assertEquals(1, store.delete());
        assertNull(create.fetchOne(TBookStore(), TBookStore_NAME().equal("Barnes and Noble")));
    }
View Full Code Here

TOP

Related Classes of org.jooq.impl.Factory

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.