Examples of DSLContext


Examples of org.jooq.DSLContext

        assertEquals("\"T\"", create2.render(table));
    }

    @Test
    public void testRenderMapping() {
        DSLContext create1 = DSL.using(SQLDialect.POSTGRES, new Settings().withRenderMapping(mapping()));
        assertEquals("\"TABLEX\"", create1.render(TABLE1));

        DSLContext create2 = DSL.using(SQLDialect.POSTGRES);
        create2.configuration().settings().setRenderMapping(mapping());
        assertEquals("\"TABLEX\"", create2.render(TABLE1));
    }
View Full Code Here

Examples of org.jooq.DSLContext

    @Test
    public void testKeywords() {
        Keyword keyword = DSL.keyword("Abc");
        Field<?> f = DSL.field("{0} Untouched {Xx} Untouched {1}", keyword, keyword);

        DSLContext def = DSL.using(MYSQL);
        DSLContext lower = DSL.using(MYSQL, new Settings().withRenderKeywordStyle(LOWER));
        DSLContext upper = DSL.using(MYSQL, new Settings().withRenderKeywordStyle(UPPER));

        assertEquals("abc Untouched xx Untouched abc", def.render(f));
        assertEquals("abc Untouched xx Untouched abc", lower.render(f));
        assertEquals("ABC Untouched XX Untouched ABC", upper.render(f));
    }
View Full Code Here

Examples of org.jooq.DSLContext

        return result[0];
    }

    final int storeInsert0(Field<?>[] storeFields) {
        DSLContext create = create();
        InsertQuery<R> insert = create.insertQuery(getTable());
        addChangedValues(storeFields, insert);

        // Don't store records if no value was set by client code
        if (!insert.isExecutable()) {
            if (log.isDebugEnabled())
                log.debug("Query is not executable", insert);

            return 0;
        }

        // [#1596] Set timestamp and/or version columns to appropriate values
        BigInteger version = addRecordVersion(insert);
        Timestamp timestamp = addRecordTimestamp(insert);

        // [#814] Refresh identity and/or main unique key values
        // [#1002] Consider also identity columns of non-updatable records
        // [#1537] Avoid refreshing identity columns on batch inserts
        Collection<Field<?>> key = null;
        if (!TRUE.equals(create.configuration().data(Utils.DATA_OMIT_RETURNING_CLAUSE))) {
            key = getReturning();
            insert.setReturning(key);
        }

        int result = insert.execute();
View Full Code Here

Examples of org.jooq.DSLContext

public class Example_2_1_ActiveRecords {

    @Test
    public void run() throws SQLException {
        Connection connection = connection();
        DSLContext dsl = DSL.using(connection);

        AuthorRecord author;

        try {
            Tools.title("Loading and changing active records");
            author = dsl.selectFrom(AUTHOR).where(AUTHOR.ID.eq(1)).fetchOne();
            author.setDateOfBirth(Date.valueOf("2000-01-01"));
            author.store();
            Tools.print(author);


            Tools.title("Creating a new active record");
            author = dsl.newRecord(AUTHOR);
            author.setId(3);
            author.setFirstName("Alfred");
            author.setLastName("Hitchcock");
            author.store();
            Tools.print(author);


            Tools.title("Refreshing an active record");
            author = dsl.newRecord(AUTHOR);
            author.setId(3);
            author.refresh();
            Tools.print(author);


            Tools.title("Updating an active record");
            author.setDateOfBirth(Date.valueOf("1899-08-13"));
            author.store();
            Tools.print(author);


            Tools.title("Deleting an active record");
            author.delete();
            Tools.print(dsl.selectFrom(AUTHOR).fetch());

        }

        // Don't store the changes
        finally {
View Full Code Here

Examples of org.jooq.DSLContext

public class Example_2_2_OptimisticLocking {

    @Test
    public void run() throws SQLException {
        Connection connection = connection();
        DSLContext dsl = DSL.using(connection, new Settings().withExecuteWithOptimisticLocking(true));

        try {
            Tools.title("Applying optimistic locking");

            BookRecord book1 = dsl.selectFrom(BOOK).where(BOOK.ID.eq(1)).fetchOne();
            BookRecord book2 = dsl.selectFrom(BOOK).where(BOOK.ID.eq(1)).fetchOne();

            book1.setTitle("New Title");
            book1.store();

            book2.setTitle("Another Title");
View Full Code Here

Examples of org.jooq.DSLContext

      Connection c = null;
     
    try {
        Class.forName("org.postgresql.Driver");
        c = getConnection("jdbc:postgresql:postgres", "postgres", System.getProperty("pw", "test"));
        DSLContext ctx = DSL.using(new DefaultConfiguration()
            .set(new DefaultConnectionProvider(c))
            .set(SQLDialect.POSTGRES)
            .set(new Settings().withExecuteLogging(false)));
       
        return runnable.run(ctx);
View Full Code Here

Examples of org.jooq.DSLContext

                    listener.executeStart(ctx);
                    result = ctx.statement().executeUpdate();
                    ctx.rows(result);
                    listener.executeEnd(ctx);

                    DSLContext create = DSL.using(ctx.configuration());
                    returned =
                    create.select(returning)
                          .from(getInto())
                          .where(rowid().equal(rowid().getDataType().convert(create.lastID())))
                          .fetchInto(getInto());

                    return result;
                }
View Full Code Here

Examples of org.jooq.DSLContext

        return getResultSet(index, count);
    }

    @SuppressWarnings("unchecked")
    private ResultSet getResultSet0(T[] a) {
        DSLContext create = DSL.using(dialect);

        Field<Long> index = fieldByName(Long.class, "INDEX");
        Field<T> value = (Field<T>) fieldByName(type.getComponentType(), "VALUE");
        Result<Record2<Long, T>> result = create.newResult(index, value);

        for (int i = 0; i < a.length; i++) {
            Record2<Long, T> record = create.newRecord(index, value);
           
            record.setValue(index, i + 1L);
            record.setValue(value, a[i]);
           
            result.add(record);
View Full Code Here

Examples of org.jooq.DSLContext

public class Example_1_5_ColumnExpressions {

    @Test
    public void run() {
        DSLContext dsl = DSL.using(connection());

        Tools.title("CONCAT() function with prefix notation");
        Tools.print(
            dsl.select(concat(AUTHOR.FIRST_NAME, val(" "), AUTHOR.LAST_NAME))
               .from(AUTHOR)
               .orderBy(AUTHOR.ID)
               .fetch()
        );

        Tools.title("CONCAT() function with infix notation");
        Tools.print(
            dsl.select(AUTHOR.FIRST_NAME.concat(" ").concat(AUTHOR.LAST_NAME))
               .from(AUTHOR)
               .orderBy(AUTHOR.ID)
               .fetch()
        );
View Full Code Here

Examples of org.jooq.DSLContext

    @Test
    public void run() throws SQLException {
        Connection connection = connection();

        DSLContext dsl = DSL.using(connection);

        try {

            // Inserting is just as easy as selecting
            Tools.title("Inserting a new AUTHOR");
            Tools.print(
                dsl.insertInto(AUTHOR, AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
                   .values(3, "Alfred", "Hitchcock")
                   .execute()
            );

            // But the Java compiler will actively check your statements. The
            // following statements will not compile:
            /*
            Tools.title("Not enough arguments to the values() method!");
            Tools.print(
                DSL.using(connection())
                   .insertInto(AUTHOR, AUTHOR.ID, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
                   .values(4, "Alfred")
                   .execute()
            );
            */
            /*
            Tools.title("Wrong order of types of arguments to the values() method!");
            Tools.print(
                DSL.using(connection())
                   .insertInto(AUTHOR, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME, AUTHOR.ID)
                   .values(4, "Alfred", "Hitchcock")
                   .execute()
            );
            */
            Tools.title("Check if our latest record was really created");
            Tools.print(
                dsl.select()
                   .from(AUTHOR)
                   .where(AUTHOR.ID.eq(3))
                   .fetch()
            );

            Tools.title("Update the DATE_OF_BIRTH column");
            Tools.print(
                dsl.update(AUTHOR)
                   .set(AUTHOR.DATE_OF_BIRTH, Date.valueOf("1899-08-13"))
                   .where(AUTHOR.ID.eq(3))
                   .execute()
            );

            Tools.title("Check if our latest record was really updated");
            Tools.print(
                dsl.select()
                   .from(AUTHOR)
                   .where(AUTHOR.ID.eq(3))
                   .fetch()
            );

            Tools.title("Delete the new record again");
            Tools.print(
                dsl.delete(AUTHOR)
                   .where(AUTHOR.ID.eq(3))
                   .execute()
            );

            Tools.title("Check if the record was really deleted");
            Tools.print(
                dsl.select()
                   .from(AUTHOR)
                   .fetch()
            );
        }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.