Package org.apache.torque.criteria

Examples of org.apache.torque.criteria.Criteria


        OIntegerPk oIntegerPk = new OIntegerPk();
        oIntegerPk.setName("shutdownName");
        oIntegerPk.save();
        List<OIntegerPk> oIntegerPkList
                = OIntegerPkPeer.doSelect(new Criteria());
        assertEquals(
                "List should contain one OIntegerPk",
                1,
                oIntegerPkList.size());
        oIntegerPk = oIntegerPkList.get(0);
View Full Code Here


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

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

     * @throws Exception if the test fails.
     */
    public void testSelectSimpleKeyNullValue() throws Exception
    {
        SimpleKey keyToSelect = SimpleKey.keyFor((Integer) null);
        Criteria criteria = new Criteria()
                .where(BookPeer.ISBN, keyToSelect);

        List<Book> books = BookPeer.doSelect(criteria);
        assertEquals(10, books.size());
    }
View Full Code Here

        ForeignKeySchemaData.clearTablesInDatabase();
        PIntegerPk pIntegerPk = new PIntegerPk();
        pIntegerPk.setName("shutdownName");
        pIntegerPk.save();
        List<PIntegerPk> pIntegerPkList
                = PIntegerPkPeer.doSelect(new Criteria());
        assertEquals(
                "List should contain one PIntegerPk",
                1,
                pIntegerPkList.size());
        pIntegerPk = pIntegerPkList.get(0);
View Full Code Here

    public void setUp() throws Exception
    {
        super.setUp();

        // clean the books database
        Criteria criteria = new Criteria();
        criteria.where(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL);
        try
        {
            BookPeer.doDelete(criteria);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            fail("cleaning books : Exception caught : "
                     + e.getClass().getName()
                     + " : " + e.getMessage());
        }
        criteria = new Criteria();
        criteria.where(
                AuthorPeer.AUTHOR_ID,
                (Long) null, Criteria.NOT_EQUAL);
        try
        {
            AuthorPeer.doDelete(criteria);
View Full Code Here

    public void testCriteriaOrderBy()
    {
        List<Book> books = null;
        try
        {
            Criteria criteria = new Criteria();
            criteria.addAscendingOrderByColumn(BookPeer.TITLE);
            criteria.addAscendingOrderByColumn(BookPeer.ISBN);

            books = BookPeer.doSelect(criteria);
        }
        catch (Exception e)
        {
View Full Code Here

    {
        // inner joins
        List<Author> bookAuthors = null;
        try
        {
            Criteria criteria = new Criteria();
            criteria.addJoin(
                    AuthorPeer.AUTHOR_ID,
                    BookPeer.AUTHOR_ID,
                    Criteria.INNER_JOIN);

            bookAuthors = AuthorPeer.doSelect(criteria);

            // from Details section
            Author author = bookAuthors.get(0);
            List<Book> books = author.getBooks();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            fail("inner join : Exception caught : "
                     + e.getClass().getName()
                     + " : " + e.getMessage());
        }

        assertTrue(
                "inner join : size of bookAuthors is not 3, but"
                + bookAuthors.size(),
                bookAuthors.size() == 3);

        // test explicit sql statements from details section
        List<List<Object>> result = null;
        try
        {
            result = BasePeer.doSelect(
                    "SELECT book.* FROM book "
                        + "INNER JOIN author "
                        + "ON book.AUTHOR_ID=author.AUTHOR_ID",
                    new ObjectListMapper(),
                    (String) null);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            fail("Explicit SQL query 1 : Exception caught : "
                     + e.getClass().getName()
                     + " : " + e.getMessage());
        }

        assertTrue(
            "Explicit SQL query 1 : size of result is not 3, but"
            + result.size(),
            result.size() == 3);

        result = null;
        try
        {
            result = BasePeer.doSelect(
                    "SELECT book.* FROM book,author "
                        + "WHERE book.AUTHOR_ID=author.AUTHOR_ID",
                    new ObjectListMapper(),
                    (String) null);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            fail("Explicit SQL query 2 : Exception caught : "
                     + e.getClass().getName()
                     + " : " + e.getMessage());
        }

        assertTrue(
            "Explicit SQL query 2 : size of result is not 3, but"
            + result.size(),
            result.size() == 3);

        // test left outer join
        bookAuthors = null;
        try
        {
              Criteria criteria = new Criteria();
              criteria.addJoin(
                      AuthorPeer.AUTHOR_ID,
                      BookPeer.AUTHOR_ID,
                      Criteria.LEFT_JOIN);
              bookAuthors = AuthorPeer.doSelect(criteria);
        }
View Full Code Here

    public void testDistinct()
    {
        List<Author> bookAuthors = null;
        try
        {
            Criteria criteria = new Criteria();
            criteria.addJoin(
                    AuthorPeer.AUTHOR_ID,
                    BookPeer.AUTHOR_ID,
                    Criteria.INNER_JOIN);
            criteria.setDistinct();

            bookAuthors = AuthorPeer.doSelect(criteria);
        }
        catch (Exception e)
        {
View Full Code Here

    public void testJoinOrderDistinct()
    {
        List<Author> bookAuthors = null;
        try
        {
            Criteria criteria = new Criteria();
            criteria.addJoin(
                    AuthorPeer.AUTHOR_ID,
                    BookPeer.AUTHOR_ID,
                    Criteria.INNER_JOIN);
            criteria.setDistinct();
            criteria.addAscendingOrderByColumn(AuthorPeer.NAME);

            bookAuthors = AuthorPeer.doSelect(criteria);
        }
        catch (Exception e)
        {
View Full Code Here

                log.error("testSubqueries(): "
                        + "Subselects are not supported by Mysql < 4.1");
                return;
            }
        }
        Criteria subquery = new Criteria();
        subquery.addSelectColumn(
                new ColumnImpl("MAX(" + AuthorPeer.AUTHOR_ID + ")"));

        Criteria criteria = new Criteria();
        criteria.where(AuthorPeer.AUTHOR_ID, subquery);

        List<Author> authors = AuthorPeer.doSelect(criteria);
        assertEquals("Expected list of size 1 but got " + authors.size(),
                1,
                authors.size());
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.