Package org.apache.torque.util

Examples of org.apache.torque.util.Criteria


            throw new EntityExistsException("The account '" +
                    user.getName() + "' already exists");
        }
        user.setPassword(TurbineSecurity.encryptPassword(initialPassword));

        Criteria criteria = TurbineUserPeer.buildCriteria(user);
        try
        {
            // perform the insert to the database
            ObjectKey pk = TurbineUserPeer.doInsert(criteria);
View Full Code Here


        if (!accountExists(user))
        {
            throw new UnknownEntityException("The account '" +
                    user.getName() + "' does not exist");
        }
        Criteria criteria = new Criteria();
        criteria.add(TurbineUserPeer.USERNAME, user.getName());
        try
        {
            TurbineUserPeer.doDelete(criteria);
        }
        catch (Exception e)
View Full Code Here

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

        // clean the books database
        Criteria criteria = new Criteria();
        criteria.add(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.clear();
        criteria.add(
                AuthorPeer.AUTHOR_ID,
                (Long) null, Criteria.NOT_EQUAL);
        try
        {
            AuthorPeer.doDelete(criteria);
View Full Code Here

    public void testCriteriaOrderBy()
    {
        List 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 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 = (Author) bookAuthors.get(0);
            List 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 result = null;
        try
        {
            result = BasePeer.executeQuery(
                    "SELECT book.* FROM book "
                    + "INNER JOIN author "
                    + "ON book.AUTHOR_ID=author.AUTHOR_ID");
        }
        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.executeQuery(
                    "SELECT book.* FROM book,author "
                    + "WHERE book.AUTHOR_ID=author.AUTHOR_ID");
        }
        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 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 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

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

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

        criteria = new Criteria();
        criteria.add(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 authorList = AuthorPeer.doSelect(new Criteria());
        Author readAuthor = (Author) 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 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

                book.setIsbn("unknown");
                book.save();
            }
        }
        // clean booleancheck table (because insert uses fixed keys)
        Criteria criteria = new Criteria();
        criteria.add(BooleanCheckPeer.TEST_KEY, (Object) null, Criteria.NOT_EQUAL);
        BooleanCheckPeer.doDelete(criteria);

        BooleanCheck bc = new BooleanCheck();
        bc.setTestKey("t1");
        bc.setBintValue(true);
View Full Code Here

     * @throws Exception if the test fails
     */
    public void testMultiplePk() throws Exception
    {
        // clean table
        Criteria criteria = new Criteria();
        criteria.add(MultiPkPeer.PK1, (Object) null, Criteria.NOT_EQUAL);
        MultiPkPeer.doDelete(criteria);

        // do test
        MultiPk mpk = new MultiPk();
        mpk.setPrimaryKey("Svarchar:N5:Schar:");
View Full Code Here

TOP

Related Classes of org.apache.torque.util.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.