db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker QueryTest.java
Date Thu, 16 Sep 2004 12:44:50 GMT
arminw      2004/09/16 05:44:50

  Modified:    src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        QueryTest.java
  Log:
  merge with trunk,
  add new test, using query range (setStartAtIndex, ...)
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.61.2.5  +59 -1     db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
  
  Index: QueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
  retrieving revision 1.61.2.4
  retrieving revision 1.61.2.5
  diff -u -r1.61.2.4 -r1.61.2.5
  --- QueryTest.java	27 Aug 2004 19:25:12 -0000	1.61.2.4
  +++ QueryTest.java	16 Sep 2004 12:44:50 -0000	1.61.2.5
  @@ -6,17 +6,19 @@
   import java.util.Collection;
   import java.util.HashSet;
   import java.util.Iterator;
  +import java.util.List;
   import java.util.Set;
   import java.util.Vector;
   
  +import org.apache.commons.lang.time.StopWatch;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.LikeCriteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.QueryFactory;
   import org.apache.ojb.broker.query.ReportQueryByCriteria;
  -import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
   import org.apache.ojb.junit.PBTestCase;
   
   /**
  @@ -1584,6 +1586,62 @@
       public void testQueryRangeAllRecords()
       {
           this.runQueryRangeTest(0);
  +    }
  +
  +    /**
  +     * Run a query range test.
  +     */
  +    public void testQueryRangeMassTest()
  +    {
  +        String name = "testQueryRangeMassTest_" + System.currentTimeMillis();
  +        int objCount = 2000;
  +
  +        broker.beginTransaction();
  +        for(int i = 0; i < objCount; i++)
  +        {
  +            Gourmet a = new Gourmet();
  +            a.setName(name);
  +            broker.store(a);
  +        }
  +        broker.commitTransaction();
  +
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        QueryByCriteria q = QueryFactory.newQuery(Gourmet.class, crit);
  +        q.setStartAtIndex(100);
  +        q.setEndAtIndex(109);
  +
  +        StopWatch watch = new StopWatch();
  +        watch.start();
  +        Collection c = broker.getCollectionByQuery(q);
  +        watch.stop();
  +        System.out.println("# Query 10 of " + objCount + " objects take " + watch.getTime()
+ " ms");
  +        assertNotNull(c);
  +        List result = new ArrayList(c);
  +        assertEquals(10, result.size());
  +
  +        crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +        q = QueryFactory.newQuery(Gourmet.class, crit);
  +        watch.start();
  +        c = broker.getCollectionByQuery(q);
  +        watch.stop();
  +        System.out.println("# Query all " + objCount + " objects take " + watch.getTime()
+ " ms");
  +        assertNotNull(c);
  +        result = new ArrayList(c);
  +        assertEquals(objCount, result.size());
  +
  +        broker.beginTransaction();
  +        for(int i = 0; i < result.size(); i++)
  +        {
  +            broker.delete(result.get(i));
  +        }
  +        broker.commitTransaction();
  +
  +        c = broker.getCollectionByQuery(q);
  +        assertNotNull(c);
  +        result = new ArrayList(c);
  +        assertEquals(0, result.size());
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message