Package org.apache.torque.criteria

Examples of org.apache.torque.criteria.Criteria


        }

        // Check authors are in the database
        for (int i = 0; i < authorNames.length; ++i)
        {
            Criteria criteria = new Criteria();
            criteria.where(AuthorPeer.NAME, authorNames[i]);
            List<Author> authorList = AuthorPeer.doSelect(criteria);
            assertEquals(
                    "AuthorList should contain one author"
                        + " when querying for " + authorNames[i],
                    1,
                    authorList.size());
            Author author = authorList.get(0);
            assertEquals("Name of author should be " + authorNames[i],
                    authorNames[i],
                    author.getName());
        }

        for (Map.Entry<String, String> likeResult : likeResults.entrySet())
        {
            Criteria criteria = new Criteria();
            criteria.where(
                    AuthorPeer.NAME,
                    likeResult.getKey(),
                    Criteria.LIKE);
            List<Author> authorList;
            try
            {
                authorList = AuthorPeer.doSelect(criteria);
            }
            catch (Exception e)
            {
                throw new Exception(
                        "error rxecuting select using like content "
                        + likeResult.getKey(),
                    e);
            }
            assertEquals(
                    "AuthorList should contain one author"
                        + " when querying for " + likeResult.getKey(),
                    1,
                    authorList.size());
            Author author = authorList.get(0);
            assertEquals("Name of author should be "
                        + likeResult.getValue()
                        + " when querying for "
                        + likeResult.getKey(),
                    likeResult.getValue(),
                    author.getName());
        }

        // check that case insensitivity is maintained if
        // a like is replaced with an equals (no wildcard present)
        // This might be a problem for databases which use ILIKE
        Criteria criteria = new Criteria();
        criteria.where(AuthorPeer.NAME, "AbC", Criteria.LIKE);
        criteria.setIgnoreCase(true);
        List<Author> authorList = AuthorPeer.doSelect(criteria);
        assertEquals(
                "AuthorList should contain one author",
                1,
                authorList.size());
        Author author = authorList.get(0);
        assertEquals("Name of author should be abc",
                "abc",
                author.getName());

        // check that the escape clause (where needed) also works
        // with limit, offset and order by
        criteria = new Criteria();
        Criterion criterion1 = new Criterion(
                AuthorPeer.NAME,
                "b%",
                Criteria.LIKE);
        Criterion criterion2 = new Criterion(
                AuthorPeer.NAME,
                "a\\%%",
                Criteria.LIKE);
        Criterion criterion3 = new Criterion(
                AuthorPeer.NAME,
                "cbc",
                Criteria.LIKE);
        criteria.where(criterion1.or(criterion2).or(criterion3));
        criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
        criteria.setOffset(1);
        criteria.setLimit(1);
        authorList = AuthorPeer.doSelect(criteria);
        assertEquals(
                "AuthorList should contain one author",
                1,
                authorList.size());
View Full Code Here


    }

    private List<T> fillDatabase() throws TorqueException
    {
        List<T> result = new ArrayList<T>();
        peer.doDelete(new Criteria());
        T optimisticLocking = newObject();
        optimisticLocking.setName("1");
        optimisticLocking.save();
        result.add(optimisticLocking);
        optimisticLocking = newObject();
View Full Code Here

    private void assertDatabase(List<T> expected)
            throws TorqueException
    {
        assertEquals(
                expected.size(),
                peer.doSelect(new Criteria()).size());
        for (T expectedElement : expected)
        {
            T actual = peer.retrieveByPK(expectedElement.getPrimaryKey());
            assertEquals(expectedElement.getName(), actual.getName());
            assertEquals(expectedElement.getVersion(), actual.getVersion());
View Full Code Here

     *
     * @throws TorqueException if the tables could not be cleaned
     */
    public static void clearTablesInDatabase() throws TorqueException
    {
        Criteria criteria = new Criteria();
        NopkPeer.doDelete(criteria);
    }
View Full Code Here

     *
     * @throws TorqueException if the bookstore could not be cleaned
     */
    protected void cleanBookstore() throws TorqueException
    {
        Criteria criteria = new Criteria();
        BookPeer.doDelete(criteria);

        criteria = new Criteria();
        AuthorPeer.doDelete(criteria);
    }
View Full Code Here

    {
        int numBooks = 0;

        for (Author author : toVerify)
        {
            Criteria criteria = new Criteria()
                .where(AuthorPeer.NAME, author.getName())
                .and(AuthorPeer.AUTHOR_ID, author.getAuthorId());
            criteria.setSingleRecord(true);
            List<Author> selectedAuthorList = AuthorPeer.doSelect(criteria);
            assertEquals("Could not find author with id "
                    + author.getAuthorId()
                    + " and name "
                    + author.getName(),
                1,
                selectedAuthorList.size());

            numBooks += author.getBooks().size();

            for (Book book : author.getBooks())
            {
                criteria = new Criteria()
                    .where(BookPeer.TITLE, book.getTitle())
                    .and(BookPeer.BOOK_ID, book.getBookId())
                    .and(BookPeer.AUTHOR_ID, book.getAuthorId())
                    .and(BookPeer.ISBN, book.getIsbn());
                criteria.setSingleRecord(true);
                List<Book> selectedBookList = BookPeer.doSelect(criteria);
                assertEquals("Could not find book with id "
                        + book.getBookId()
                        + " title "
                        + book.getTitle()
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    public void testSelectInteger() throws Exception
    {
        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());

        List<Author> result = AuthorPeer.doSelect(criteria);
        assertEquals("Expected result of size 1 but got " + result.size(),
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    public void testSelectIntegerAsLvalue() throws Exception
    {
        Criteria criteria = new Criteria().where(
                authorList.get(0).getAuthorId(),
                AuthorPeer.AUTHOR_ID);

        List<Author> result = AuthorPeer.doSelect(criteria);
        assertEquals("Expected result of size 1 but got " + result.size(),
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    public void testSelectSingleRecord() throws Exception
    {
        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());

        Author author = AuthorPeer.doSelectSingleRecord(criteria);
        assertEquals("Expected author with Id "
View Full Code Here

     *
     * @throws Exception if the test fails
     */
    public void testSelectSingleRecordWithConnection() throws Exception
    {
        Criteria criteria = new Criteria().where(
                AuthorPeer.AUTHOR_ID,
                authorList.get(0).getAuthorId());

        Connection connection = Torque.getConnection();
        Author author = AuthorPeer.doSelectSingleRecord(criteria, connection);
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.