svn commit: r469548 - in /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare: OJBPerfTest.java PerformanceODMGTest.java

[email protected]
Newsgroups gmane.comp.jakarta.ojb.devel
Message-ID <[email protected]>
Author: arminw
Date: Tue Oct 31 08:49:35 2006
New Revision: 469548

URL: http://svn.apache.org/viewvc?view=rev&rev=469548
Log:
fix, improve tests

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/OJBPerfTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/PerformanceODMGTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/OJBPerfTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/OJBPerfTest.java?view=diff&rev=469548&r1=469547&r2=469548
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/OJBPerfTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/OJBPerfTest.java Tue Oct 31 08:49:35 2006
@@ -32,6 +32,7 @@
 import org.odmg.ODMGException;
 import org.odmg.OQLQuery;
 import org.odmg.Transaction;
+import org.odmg.QueryException;
 
 /**
  * Multi-threaded performance test implementation classes for testing
@@ -506,16 +507,15 @@
 
         public int articleCount()
         {
-            Criteria c = new Criteria();
-            Query q = new QueryByCriteria(PerfArticleImpl.class, c);
             int count = 0;
+            String select = "select all from " +PerfArticleImpl.class.getName();
+            OQLQuery query = odmg.newOQLQuery();
             try
             {
-                PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
-                count = broker.getCount(q);
-                broker.close();
+                query.create(select);
+                count = ((Collection) query.execute()).size();
             }
-            catch (Exception e)
+            catch(QueryException e)
             {
                 e.printStackTrace();
             }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/PerformanceODMGTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/PerformanceODMGTest.java?view=diff&rev=469548&r1=469547&r2=469548
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/PerformanceODMGTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/compare/PerformanceODMGTest.java Tue Oct 31 08:49:35 2006
@@ -1,9 +1,12 @@
 package org.apache.ojb.compare;
 
 import java.util.Iterator;
+import java.util.Collection;
 
 import org.apache.ojb.broker.ManageableCollection;
 import org.apache.ojb.broker.TestHelper;
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.odmg.OJB;
 import org.apache.ojb.odmg.TransactionExt;
 import org.odmg.Database;
@@ -117,16 +120,15 @@
         tx.setImplicitLocking(false);
         // the odmg-api hasn't specific methods to lookup objects
         // by primary key. It's recommended to use use PB-api instead for
-        // best performance. But here we use an oql-query for each object.
-        String sql = "select allArticles from " + PerformanceArticle.class.getName() + " where articleId=$1";
+        // best performance.
         long start = System.currentTimeMillis();
         tx.begin();
+        PersistenceBroker pb = tx.getBroker();
         for(int i = 0; i < articleCount; i++)
         {
-            OQLQuery query = odmg.newOQLQuery();
-            query.create(sql);
-            query.bind(arr[i].getArticleId());
-            query.execute();
+            Identity oid = pb.serviceIdentity().
+                    buildIdentity(PerformanceArticle.class, arr[i].getArticleId());
+            pb.getObjectByIdentity(oid);
         }
         tx.commit();
         long stop = System.currentTimeMillis();
@@ -155,14 +157,15 @@
                 + " where articleId between " + new Integer(offsetId) + " and "
                 + new Integer(offsetId + articleCount);
         query.create(sql);
-        ManageableCollection collection = (ManageableCollection) query.execute();
-        Iterator iter = collection.ojbIterator();
+        Collection collection = (Collection) query.execute();
+        Iterator iter = collection.iterator();
         int fetchCount = 0;
         while(iter.hasNext())
         {
             fetchCount++;
             iter.next();
         }
+        tx.commit();
         long stop = System.currentTimeMillis();
         logger.info("fetching " + fetchCount + " Objects: " + (stop - start) + " msec");
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.