Package org.apache.torque.criteria

Examples of org.apache.torque.criteria.Criteria


    public void testSelect() throws Exception
    {
        // prepare
        cleanBookstore();
        List<Author> bookstoreContent = insertBookstoreData();
        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(BookAuthorsPeer.AUTHOR_ID);
        criteria.addAscendingOrderByColumn(BookAuthorsPeer.BOOK_ID);

        // execute
        List<BookAuthors> result = BookAuthorsPeer.doSelect(criteria);

        // verify
View Full Code Here


        oIntegerPk.save();

        // verify
        assertEquals(new Integer(3001), oIntegerPk.getId());

        Criteria criteria = new Criteria().where(OIntegerPkPeer.ID, 3001);
        List<OIntegerPk> integerObjectPkList
                = OIntegerPkPeer.doSelect(criteria);
        assertEquals(1, integerObjectPkList.size());

        assertEquals(
View Full Code Here

     * Tests that an insert works for objects without primary key.
     */
    public void testInsertWithoutPk() throws TorqueException
    {
        // prepare
        Criteria criteria = new Criteria();
        NopkPeer.doDelete(criteria);

        Nopk nopk = new Nopk();
        nopk.setName("name");
        nopk.save();

        // execute
        nopk.save();

        // verify
        assertEquals("name", nopk.getName());

        criteria = new Criteria().where(NopkPeer.NAME, "name");
        List<Nopk> nopkList = NopkPeer.doSelect(criteria);
        assertEquals(1, nopkList.size());

        assertEquals(1, new CountHelper().count(NopkPeer.getTableMap()));
    }
View Full Code Here

     * nothing is modified.
     */
    public void testSaveWithoutPkNoModification() throws TorqueException
    {
        // prepare
        Criteria criteria = new Criteria();
        NopkPeer.doDelete(criteria);

        Nopk nopk = new Nopk();
        nopk.setName("name");
        nopk.save();

        // execute
        nopk.save();

        // verify
        assertEquals("name", nopk.getName());

        criteria = new Criteria().where(NopkPeer.NAME, "name");
        List<Nopk> nopkList = NopkPeer.doSelect(criteria);
        assertEquals(1, nopkList.size());

        assertEquals(1, new CountHelper().count(NopkPeer.getTableMap()));
    }
View Full Code Here

                differentAuthor.getBooks().get(0) != book);
    }

    public void testSaves() throws Exception
    {
        Criteria criteria = new Criteria();
        criteria.where(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL);
        BookPeer.doDelete(criteria);

        criteria = new Criteria();
        criteria.where(AuthorPeer.AUTHOR_ID, (Long) null, Criteria.NOT_EQUAL);
        AuthorPeer.doDelete(criteria);

        Author author = new Author();
        author.setName(AUTHOR_1_NAME);
        author.save();

        assertFalse("isModified() should return false after save",
                author.isModified());
        assertFalse("isNew() should return false after save",
                author.isNew());

        AuthorBean authorBean = author.getBean();

        assertFalse("bean.isModified() should return false after save "
                + "and bean creation",
                authorBean.isModified());
        assertFalse("bean.isNew() should return false after save "
                + "and bean creation",
                authorBean.isNew());

        author = Author.createAuthor(authorBean);

        assertFalse("isModified() should return false after save "
                + "and bean roundtrip",
                author.isModified());
        assertFalse("isNew() should return false after save "
                + "and bean rounddtrip",
                author.isNew());

        authorBean.setName(AUTHOR_2_NAME);
        assertTrue("bean.isModified() should return true after it was modified",
                authorBean.isModified());
        assertFalse("bean.isNew() should still return false "
                + "after bean creation and modification",
                authorBean.isNew());

        author = Author.createAuthor(authorBean);
        assertTrue("isModified() should return true after creation of object "
                + "from modified bean",
                author.isModified());

        author.save();

        List<Author> authorList = AuthorPeer.doSelect(new Criteria());
        Author readAuthor = authorList.get(0);
        assertEquals("name from read Author is " + readAuthor.getName()
                +" but should be " + authorBean.getName(),
                readAuthor.getName(),
                authorBean.getName());

        BookBean bookBean = new BookBean();
        bookBean.setTitle(BOOK_1_TITLE);
        bookBean.setIsbn(BOOK_1_ISBN);

        Book book = Book.createBook(bookBean);
        assertTrue("isModified() should return true after creation of object "
                + " from new bean",
                book.isModified());
        assertTrue("isNew() should return true after creation of object "
                + " from new bean",
                book.isNew());
        book.setAuthor(author);
        book.save();

        List<Book> bookList = BookPeer.doSelect(new Criteria());
        assertTrue("Ther should be one book in DB but there are "
                + bookList.size(),
                bookList.size() == 1);
    }
View Full Code Here

     * which is already saved.
     */
    public void testSaveWithoutPkModification() throws TorqueException
    {
        // prepare
        Criteria criteria = new Criteria();
        NopkPeer.doDelete(criteria);

        Nopk nopk = new Nopk();
        nopk.setName("name");
        nopk.save();
View Full Code Here

        // verify
        // propagation would have been possible, reference is there
        assertNotNull(book.getAuthor());

        // Author in db should still have old name
        Criteria criteria = new Criteria().where(AuthorPeer.NAME, "Author");
        List<Author> authorList = AuthorPeer.doSelect(criteria);
        assertEquals(1, authorList.size());
    }
View Full Code Here

        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(
                RequiredPIntegerFkPeer.ID);
        List<RequiredPIntegerFk> fkList
                = RequiredPIntegerFkPeer.doSelect(criteria);
        assertEquals(3, fkList.size());
        assertEquals(
View Full Code Here

        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(
                NullableOIntegerFkPeer.ID);
        List<NullableOIntegerFk> fkList
                = NullableOIntegerFkPeer.doSelect(criteria);
        assertEquals(4, fkList.size());
        assertEquals(
View Full Code Here

        ForeignKeySchemaData.clearTablesInDatabase();
        ForeignKeySchemaData testData
                = ForeignKeySchemaData.getDefaultTestData();
        testData.save();

        Criteria criteria = new Criteria();
        criteria.addAscendingOrderByColumn(
                NonPkOIntegerFkPeer.ID);
        List<NonPkOIntegerFk> fkList
                = NonPkOIntegerFkPeer.doSelect(criteria);
        assertEquals(4, fkList.size());
        assertEquals(
View Full Code Here

TOP

Related Classes of org.apache.torque.criteria.Criteria

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.