Package org.jooq.example.db.h2.tables

Examples of org.jooq.example.db.h2.tables.Author


    public void testJoin() throws Exception {
        // All of these tables were generated by jOOQ's Maven plugin
        Book b = BOOK.as("b");
        Author a = AUTHOR.as("a");
        BookStore s = BOOK_STORE.as("s");
        BookToBookStore t = BOOK_TO_BOOK_STORE.as("t");

        Result<Record3<String, String, Integer>> result =
        DSL.using(connection)
              .select(a.FIRST_NAME, a.LAST_NAME, countDistinct(s.NAME))
              .from(a)
View Full Code Here


  public void testJoin() throws Exception {
    // All of these tables were generated by jOOQ's Maven plugin
    Book b = BOOK.as("b");
    Author a = AUTHOR.as("a");
    BookStore s = BOOK_STORE.as("s");
    BookToBookStore t = BOOK_TO_BOOK_STORE.as("t");

    Result<Record3<String, String, Integer>> result = create.select(a.FIRST_NAME, a.LAST_NAME, countDistinct(s.NAME))
        .from(a).join(b).on(b.AUTHOR_ID.equal(a.ID)).join(t).on(t.BOOK_ID.equal(b.ID)).join(s)
        .on(t.BOOK_STORE_NAME.equal(s.NAME)).groupBy(a.FIRST_NAME, a.LAST_NAME).orderBy(countDistinct(s.NAME).desc())
        .fetch();
View Full Code Here

        this.configuration = new DefaultConfiguration()
            .set(new SpringConnectionProvider(ds))
            .set(SQLDialect.H2)
            .set(new DefaultExecuteListenerProvider(new ExceptionTranslator(ds)));

        this.authors = new AuthorDao(configuration);
        this.books = new BookDao(configuration);
    }
View Full Code Here

            .set(new SpringConnectionProvider(ds))
            .set(SQLDialect.H2)
            .set(new DefaultExecuteListenerProvider(new ExceptionTranslator(ds)));

        this.authors = new AuthorDao(configuration);
        this.books = new BookDao(configuration);
    }
View Full Code Here

        assertEquals(2, service.getAuthors().size());
    }

    @Test
    public void testName() {
        Author author = service.getAuthor(1);
        assertEquals("George", author.getFirstName());
        assertEquals("Orwell", author.getLastName());
    }
View Full Code Here

            service.transactional(new Runnable() {
                @Override
                public void run() {

                    // This should work normally
                    Author author = service.getAuthor(1);
                    author.setFirstName("John");
                    author.setLastName("Smith");
                    assertEquals(1, service.mergeNames(author));

                    author = service.getAuthor(1);
                    assertEquals("John", author.getFirstName());
                    assertEquals("Smith", author.getLastName());

                    // But this shouldn't work. Authors have books, and there is no cascade delete
                    service.deleteAuthor(1);
                    fail();
                }
View Full Code Here

    @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
View Full Code Here

        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");
            book2.store();
        }

        catch (DataChangedException expected) {
            expected.printStackTrace();
        }
View Full Code Here

TOP

Related Classes of org.jooq.example.db.h2.tables.Author

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.