Package org.apache.torque.test.dbobject

Examples of org.apache.torque.test.dbobject.Book


    {
        // insert test data
        Author author = new Author();
        author.setName("Author with one book");
        author.save();
        Book book = new Book();
        book.setAuthor(author);
        book.setTitle("Book 1");
        book.setIsbn("unknown");
        book.save();

        author = new Author();
        author.setName("Author without book");
        author.save();

        author = new Author();
        author.setName("Author with three books");
        author.save();
        for (int bookNr = 2; bookNr <=4; bookNr++)
        {
            book = new Book();
            book.setAuthor(author);
            book.setTitle("Book " + bookNr);
            book.setIsbn("unknown");
            book.save();
        }

    }
View Full Code Here


    {
        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());
        Author author = AuthorPeer.doSelect(criteria).get(0);
        Book book = authorList.get(0).getBooks().get(2);

        // execute : load books
        criteria = new Criteria().where(BookPeer.BOOK_ID, book.getBookId());
        List<Book> books = author.getBooks(criteria);

        // verify
        assertEquals(1, books.size());
        assertEquals(book.getBookId(), books.get(0).getBookId());
    }
View Full Code Here

        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());
        Author author = AuthorPeer.doSelect(criteria).get(0);
        author.getBooks();
        Book book = authorList.get(0).getBooks().get(2);

        // execute : load books
        criteria = new Criteria().where(BookPeer.BOOK_ID, book.getBookId());
        List<Book> books = author.getBooks(criteria);

        // verify
        assertEquals(1, books.size());
        assertEquals(book.getBookId(), books.get(0).getBookId());
    }
View Full Code Here

        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());
        Author author = AuthorPeer.doSelect(criteria).get(0);
        author.initBooks();
        Book book = authorList.get(0).getBooks().get(2);

        // execute : load books
        criteria = new Criteria().where(BookPeer.BOOK_ID, book.getBookId());
        List<Book> books = author.getBooks(criteria);

        // verify
        assertEquals(1, books.size());
        assertEquals(book.getBookId(), books.get(0).getBookId());
    }
View Full Code Here

        author2b.setName("author2");
        author2b.save();
        author3 = new Author();
        author3.setName("author3");
        author3.save();
        book1 = new Book();
        book1.setTitle("Book from author 1");
        book1.setAuthor(author1);
        book1.save();
        book3 = new Book();
        book3.setTitle("Book from author 3");
        book3.setAuthor(author3);
        book3.save();
    }
View Full Code Here

     *
     * @throws Exception if the test fails.
     */
    public void testPartialSelectOnlyOwnColumns() throws Exception
    {
        Book bookToSelect = authorList.get(0).getBooks().get(0);
        Criteria criteria = new Criteria()
            .where(BookPeer.BOOK_ID, bookToSelect.getBookId())
            .addSelectColumn(BookPeer.BOOK_ID)
            .addSelectColumn(BookPeer.TITLE);

        List<Book> books = BookPeer.doSelect(criteria);
        assertEquals(1, books.size());
        Book selectedBook = books.get(0);
        assertEquals(bookToSelect.getBookId(), selectedBook.getBookId());
        assertEquals(bookToSelect.getTitle(), selectedBook.getTitle());
        assertEquals(null, selectedBook.getIsbn());
        assertEquals(0, selectedBook.getAuthorId());
    }
View Full Code Here

        Author myauthor = AuthorManager.getCachedInstance(author1.getPrimaryKey());
        assertNotNull("Primary key of Author1 should not be null", author1.getPrimaryKey());
        assertNotNull("MyAuthor should not be null", myauthor);
        assertTrue("Author1 and MyAuthor should point to the same cache instance", author1 == myauthor);

        Book book = new Book();
        book.setAuthor(author1);
        book.setTitle("Book 1");
        book.setIsbn("unknown");
        book.save();

        Book mybook = BookManager.getInstance(book.getPrimaryKey());
        assertTrue("Author1 and the author of MyBook should point to the same cache instance", author1 == mybook.getAuthor());
    }
View Full Code Here

     * @throws Exception if the test fails.
     */
    public void testPartialSelectOffset() throws Exception
    {
        Criteria criteria = new Criteria();
        Book bookToSelect = authorList.get(0).getBooks().get(0);
        criteria.where(BookPeer.BOOK_ID, bookToSelect.getBookId());
        criteria.addSelectColumn(BookPeer.BOOK_ID);
        criteria.addSelectColumn(BookPeer.TITLE);
        // use CompositeMapper to enforce offset
        CompositeMapper recordMapper = new CompositeMapper();
        recordMapper.addMapper(new BookRecordMapper(), 1);

        List<List<Object>> books = BookPeer.doSelect(criteria, recordMapper);
        assertEquals(1, books.size());
        Book selectedBook = (Book) books.get(0).get(0);
        assertEquals(0, selectedBook.getBookId());
        assertEquals(bookToSelect.getTitle(), selectedBook.getTitle());
        assertEquals(null, selectedBook.getIsbn());
        assertEquals(0, selectedBook.getAuthorId());
    }
View Full Code Here

     * @throws Exception if the test fails.
     */
    public void testPartialSelectForeignColumns() throws Exception
    {
        Criteria criteria = new Criteria();
        Book bookToSelect = authorList.get(0).getBooks().get(0);
        criteria.where(BookPeer.BOOK_ID, bookToSelect.getBookId());
        criteria.addSelectColumn(AuthorPeer.AUTHOR_ID);
        criteria.addSelectColumn(BookPeer.BOOK_ID);
        criteria.addSelectColumn(AuthorPeer.NAME);
        criteria.addSelectColumn(BookPeer.TITLE);
        criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);

        List<Book> books = BookPeer.doSelect(criteria);
        assertEquals(1, books.size());
        Book selectedBook = books.get(0);
        assertEquals(bookToSelect.getBookId(), selectedBook.getBookId());
        assertEquals(bookToSelect.getTitle(), selectedBook.getTitle());
        assertEquals(null, selectedBook.getIsbn());
        assertEquals(0, selectedBook.getAuthorId());
    }
View Full Code Here

     *
     * @throws Exception if the test fails.
     */
    public void testPartialSelectNoOwnColumns() throws Exception
    {
        Book bookToSelect = authorList.get(0).getBooks().get(0);
        Criteria criteria = new Criteria()
                .where(BookPeer.BOOK_ID, bookToSelect.getBookId())
                .addSelectColumn(BookPeer.BOOK_ID);

        List<Author> authors = BookPeer.doSelect(
                criteria, new AuthorRecordMapper());
        assertEquals(1, authors.size());
View Full Code Here

TOP

Related Classes of org.apache.torque.test.dbobject.Book

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.