Package org.apache.ojb.broker.accesslayer

Examples of org.apache.ojb.broker.accesslayer.OJBIterator


        // 1. set query start equals end
        query.setStartAtIndex(4);
        query.setEndAtIndex(4);

        // 2. check if only one item is found
        OJBIterator ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        assertEquals("size of iterator should be one", 1, ojbIter.size());
        InterfaceArticle test4 = (InterfaceArticle) ojbIter.next();
        assertEquals("should be same value - id number", 5004, test4.getArticleId());
        ojbIter.releaseDbResources();
    }
View Full Code Here


    /**
     * Size returned by Iterator must be same as size of Collection
     */
    public void testIteratorSize()
    {
        OJBIterator ojbIter;
        Criteria crit;
        QueryByCriteria query;
        int collSize;
        int iterSize;

        crit = new Criteria();
        query = QueryFactory.newQuery(Article.class, crit);

        collSize = broker.getCollectionByQuery(query).size();

        ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        iterSize = ojbIter.size();

        assertEquals("collSize == iterSize", collSize , iterSize);
        ojbIter.releaseDbResources();
    }
View Full Code Here

        ojbIter.releaseDbResources();
    }

    public void testPaging()
    {
        OJBIterator ojbIter;
        Criteria crit;
        QueryByCriteria query;

        // All Articles index in range
        crit = new Criteria();
        query = QueryFactory.newQuery(Article.class, crit);
        int fullSize = broker.getCollectionByQuery(query).size();

        query.setStartAtIndex(10);
        query.setEndAtIndex(14);
        ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        assertEquals("index 10 - 14 expecting 5 rows", 5,ojbIter.size());
        ojbIter.releaseDbResources();
    }
View Full Code Here

        ojbIter.releaseDbResources();
    }

    public void testPagingPosition()
    {
        OJBIterator ojbIter;
        Criteria crit;
        QueryByCriteria query;
        Collection fullColl, pagedColl;
        InterfaceArticle article;
       
        // All Articles index in range
        crit = new Criteria();
        query = QueryFactory.newQuery(Article.class, crit);
        query.addOrderByAscending("articleId");
        fullColl = broker.getCollectionByQuery(query);
       
        // limited query
        query.setStartAtIndex(10);
        query.setEndAtIndex(14);
        pagedColl = broker.getCollectionByQuery(query);
                     
        ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
       
        assertEquals("collection- and iterator-size must match", pagedColl.size(), ojbIter.size());
        assertEquals("index 10 - 14 expecting 5 rows", 5,ojbIter.size());
       
        ojbIter.absolute(2);
        article = (InterfaceArticle)ojbIter.next();
        assertEquals("Article id=12", article.getArticleId(), 12);
       
        ojbIter.relative(-1);
        article = (InterfaceArticle)ojbIter.next();
        assertEquals("Article id=12", article.getArticleId(), 12);

        ojbIter.relative(-1);
        article = (InterfaceArticle)ojbIter.next();
        assertEquals("Article id=12", article.getArticleId(), 12);
       
        // last
        ojbIter.absolute(12);
        article = (InterfaceArticle)ojbIter.next();
        assertEquals("Article id=15", article.getArticleId(), 15);

        // first
        ojbIter.absolute(-12);
        article = (InterfaceArticle)ojbIter.next();
        assertEquals("Article id=10", article.getArticleId(), 10);
       
        ojbIter.releaseDbResources();
    }
View Full Code Here

        ojbIter.releaseDbResources();
    }
   
    public void testPagingIndicesOutOfRange()
    {
        OJBIterator ojbIter;
        Criteria crit;
        QueryByCriteria query;
        int fullSize;

        // All Articles index out of  range
        crit = new Criteria();
        query = QueryFactory.newQuery(Article.class, crit);
        fullSize = broker.getCollectionByQuery(query).size();

        query.setStartAtIndex(fullSize + 5);
        query.setEndAtIndex(fullSize + 14);
        ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        assertEquals("indices out of range expecting 0 rows", 0,ojbIter.size());
        ojbIter.releaseDbResources();
    }
View Full Code Here

        ojbIter.releaseDbResources();
    }

    public void testPagingEndIndexOutOfRange()
    {
        OJBIterator ojbIter;
        Criteria crit;
        QueryByCriteria query;
        int fullSize;

        // All Articles index out of  range
        crit = new Criteria();
        query = QueryFactory.newQuery(Article.class, crit);
        fullSize = broker.getCollectionByQuery(query).size();

        query.setStartAtIndex(fullSize - 9);
        query.setEndAtIndex(fullSize + 9);
        ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        assertEquals("end index out of range expecting 10 rows", 10,ojbIter.size());
        ojbIter.releaseDbResources();
    }
View Full Code Here

        ojbIter.releaseDbResources();
    }

    public void testPagingEmptyIterator()
    {
        OJBIterator ojbIter;
        Criteria crit;
        QueryByCriteria query;

        // looking for inexistent Article
        crit = new Criteria();
        crit.addEqualTo("articleId",new Integer(-777));
        query = QueryFactory.newQuery(Article.class, crit);
        int fullSize = broker.getCollectionByQuery(query).size();

        query.setStartAtIndex(10);
        query.setEndAtIndex(14);
        ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        assertEquals("index 10 - 14 expecting 0 rows for empty iterator", 0,ojbIter.size());
        ojbIter.releaseDbResources();
    }
View Full Code Here

        // 1. set query start equals end
        query.setStartAtIndex(4);
        query.setEndAtIndex(4);

        // 2. check if only one item is found
        OJBIterator ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        assertEquals("size of iterator should be one", 1, ojbIter.size());
        InterfaceArticle test4 = (InterfaceArticle) ojbIter.next();
        ojbIter.releaseDbResources();
        assertTrue("Id should be a number of the generated articles", range.containsInteger(test4.getArticleId()));
    }
View Full Code Here

    /**
     * Size returned by Iterator must be same as size of Collection
     */
    public void testIteratorSize()
    {
        OJBIterator ojbIter;
        Criteria crit;
        QueryByCriteria query;
        int collSize;
        int iterSize;

        crit = new Criteria();
        query = QueryFactory.newQuery(Article.class, crit);

        collSize = broker.getCollectionByQuery(query).size();

        ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        iterSize = ojbIter.size();

        assertEquals("collSize == iterSize", collSize , iterSize);
        ojbIter.releaseDbResources();
    }
View Full Code Here

        ojbIter.releaseDbResources();
    }

    public void testPaging()
    {
        OJBIterator ojbIter;
        Criteria crit;
        QueryByCriteria query;

        // All Articles index in range
        crit = new Criteria();
        query = QueryFactory.newQuery(Article.class, crit);
        int fullSize = broker.getCollectionByQuery(query).size();

        query.setStartAtIndex(10);
        query.setEndAtIndex(14);
        ojbIter = (OJBIterator)broker.getIteratorByQuery(query);
        assertEquals("index 10 - 14 expecting 5 rows", 5,ojbIter.size());
        ojbIter.releaseDbResources();
    }
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.accesslayer.OJBIterator

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.