db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/otm PerformanceTest.java
Date Sat, 13 Sep 2003 23:50:40 GMT
olegnitz    2003/09/13 16:50:40

  Modified:    src/java/org/apache/ojb/otm OTMConnection.java
               src/java/org/apache/ojb/otm/core BaseConnection.java
               src/test/org/apache/ojb/broker OJBPerfTest.java
                        PerformanceTest2.java
               src/test/org/apache/ojb/otm PerformanceTest.java
  Log:
  OTM perf-test added
  
  Revision  Changes    Path
  1.14      +20 -12    db-ojb/src/java/org/apache/ojb/otm/OTMConnection.java
  
  Index: OTMConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/OTMConnection.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- OTMConnection.java	13 Sep 2003 17:08:54 -0000	1.13
  +++ OTMConnection.java	13 Sep 2003 23:50:40 -0000	1.14
  @@ -54,6 +54,7 @@
    * <http://www.apache.org/>.
    */
   
  +import java.util.Collection;
   import java.util.Iterator;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.cache.ObjectCache;
  @@ -179,7 +180,14 @@
        * @return an Iterator that iterates Objects of class c if calling the .next()
        * method. The returned objects are locked with the given lock value.
        */
  -    public Iterator getIteratorByOQLQuery(OQLQuery query, int lock);
  +    public Collection getCollectionByQuery(Query query, int lock);
  +
  +    /**
  +     * @param query The query to execute
  +     * @return an Iterator that iterates Objects of class c if calling the .next()
  +     * method. The returned objects are locked for read.
  +     */
  +    public Collection getCollectionByQuery(Query query);
   
       /**
        * Get the identity of the object
  @@ -253,15 +261,15 @@
        */
       void close();
   
  -	/**
  -	 * check if the OTMConnection is closed
  -	 */
  -
  -	boolean isClosed();
  -
  -	/**
  -	 * get the global cache
  -	 * @return
  -	 */
  -	ObjectCache serviceObjectCache();
  +    /**
  +     * check if the OTMConnection is closed
  +     */
  +
  +    boolean isClosed();
  +
  +    /**
  +     * get the global cache
  +     * @return
  +     */
  +    ObjectCache serviceObjectCache();
   }
  
  
  
  1.26      +31 -0     db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java
  
  Index: BaseConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- BaseConnection.java	13 Sep 2003 12:08:56 -0000	1.25
  +++ BaseConnection.java	13 Sep 2003 23:50:40 -0000	1.26
  @@ -273,6 +273,37 @@
           }
       }
   
  +    /**
  +     * @param query The query to execute
  +     * @param lock the lock that need to be acquired on the object
  +     * Possible values are:
  +     * LockType.NO_LOCK (aka read only) - changes to the object will not be written to
database;
  +     * LockType.READ_LOCK (aka optimistic lock) - changes to the object will be written
to the database,
  +     * in this case the lock will be automatically upgraded to the write lock on transaction
commit;
  +     * LockType.WRITE_LOCK (aka pessimistic lock) - changes to the object will be written
to the database.
  +     * @return an Iterator that iterates Objects of class c if calling the .next()
  +     * method. The returned objects are locked with the given lock value.
  +     */
  +    public Collection getCollectionByQuery(Query query, int lock)
  +    {
  +        Collection col = _pb.getCollectionByQuery(query);
  +
  +        for (Iterator it = col.iterator(); it.hasNext(); )
  +        {
  +            insertObject(it.next(), lock);
  +        }
  +        return col;
  +    }
  +
  +    /**
  +     * @param query The query to execute
  +     * @return an Iterator that iterates Objects of class c if calling the .next()
  +     * method. The returned objects are locked for read.
  +     */
  +    public Collection getCollectionByQuery(Query query)
  +    {
  +        return getCollectionByQuery(query, LockType.READ_LOCK);
  +    }
   
       /**
        * Get the identity of the object
  
  
  
  1.10      +178 -1    db-ojb/src/test/org/apache/ojb/broker/OJBPerfTest.java
  
  Index: OJBPerfTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/OJBPerfTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- OJBPerfTest.java	28 Jun 2003 15:53:57 -0000	1.9
  +++ OJBPerfTest.java	13 Sep 2003 23:50:40 -0000	1.10
  @@ -10,6 +10,10 @@
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
   import org.apache.ojb.odmg.OJB;
  +import org.apache.ojb.otm.OTMConnection;
  +import org.apache.ojb.otm.OTMKit;
  +import org.apache.ojb.otm.kit.SimpleKit;
  +import org.apache.ojb.otm.lock.LockType;
   import org.apache.ojb.performance.PerfArticle;
   import org.apache.ojb.performance.PerfArticleImpl;
   import org.apache.ojb.performance.PerfHandle;
  @@ -585,6 +589,7 @@
               for (int i = 0; i < arr.length; i++)
               {
                   m_tx.lock(arr[i], Transaction.WRITE);
  +                arr[i].setArticleName("" + System.currentTimeMillis());
               }
               m_tx.commit();
           }
  @@ -596,6 +601,7 @@
                   Transaction tx = odmg.newTransaction();
                   tx.begin();
                   tx.lock(arr[i], Transaction.WRITE);
  +                arr[i].setArticleName("" + System.currentTimeMillis());
                   tx.commit();
               }
           }
  @@ -627,6 +633,177 @@
                   db.deletePersistent(arr[i]);
                   tx.commit();
               }
  +        }
  +    }
  +    
  +    // =====================================================================================
  +    // Inner class, test base class using OTM-api
  +    // =====================================================================================
  +    public static class OTMPerfTest extends PerfTest
  +    {
  +
  +        public OTMPerfTest()
  +        {
  +        }
  +
  +        public String testName()
  +        {
  +            return "OTM";
  +        }
  +
  +        public PerfHandle newPerfHandle(PerfTest test)
  +        {
  +            return new OTMPerfHandle(test);
  +        }
  +
  +        public int articleCount()
  +        {
  +            Criteria c = new Criteria();
  +            Query q = new QueryByCriteria(PerfArticleImpl.class, c);
  +            int count = 0;
  +            try
  +            {
  +                PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                count = broker.getCount(q);
  +                broker.close();
  +            }
  +            catch (Exception e)
  +            {
  +                e.printStackTrace();
  +            }
  +            return count;
  +        }
  +    }
  +
  +    // =====================================================================================
  +    // Inner class, test handle using PB-api
  +    // =====================================================================================
  +    public static class OTMPerfHandle extends PerfHandle
  +    {
  +        private OTMKit _kit;
  +
  +        private OTMConnection _conn;
  +
  +        private org.apache.ojb.otm.core.Transaction _tx;
  +
  +        public OTMPerfHandle(PerfTest test)
  +        {
  +            super(test);
  +        }
  +
  +        public void init()
  +        {
  +            _kit = SimpleKit.getInstance();
  +            _conn = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
  +        }
  +
  +        public void tearDown() throws Exception
  +        {
  +            if ((_tx != null) && _tx.isInProgress())
  +            {
  +                _tx.rollback();
  +            }
  +            _conn.close();
  +        }
  +
  +
  +        /**
  +         * A resource cumbering insert-method implementation,
  +         * this was used to test implementation.
  +         */
  +        public void insertNewArticlesStress(PerfArticle[] arr) throws Exception
  +        {
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                _tx = _kit.getTransaction(_conn);
  +                _tx.begin();
  +                _conn.makePersistent(arr[i]);
  +                _tx.commit();
  +            }
  +        }
  +
  +        /**
  +         * A performance optimized insert-method implementation,
  +         * used to test performance.
  +         */
  +        public void insertNewArticles(PerfArticle[] arr) throws Exception
  +        {
  +            _tx = _kit.getTransaction(_conn);
  +            _tx.begin();
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                _conn.makePersistent(arr[i]);
  +            }
  +            _tx.commit();
  +        }
  +
  +        public Collection readArticlesByCursor(String articleName) throws Exception
  +        {
  +            Criteria c = new Criteria();
  +            c.addLike("articleName", articleName);
  +            Query q = new QueryByCriteria(PerfArticleImpl.class, c);
  +
  +            _tx = _kit.getTransaction(_conn);
  +            _tx.begin();
  +            Collection col = _conn.getCollectionByQuery(q, LockType.NO_LOCK);
  +            _tx.commit();
  +            return col;
  +        }
  +
  +        public void updateArticles(PerfArticle[] arr) throws Exception
  +        {
  +            _tx = _kit.getTransaction(_conn);
  +            _tx.begin();
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                Identity oid = _conn.getIdentity(arr[i]);
  +                PerfArticle a = (PerfArticle) _conn.getObjectByIdentity(oid, LockType.WRITE_LOCK);
  +                a.setArticleName("" + System.currentTimeMillis());
  +            }
  +            _tx.commit();
  +        }
  +
  +        public void updateArticlesStress(PerfArticle[] arr) throws Exception
  +        {
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                _tx = _kit.getTransaction(_conn);
  +                _tx.begin();
  +                Identity oid = _conn.getIdentity(arr[i]);
  +                PerfArticle a = (PerfArticle) _conn.getObjectByIdentity(oid, LockType.WRITE_LOCK);
  +                a.setArticleName("" + System.currentTimeMillis());
  +                _tx.commit();
  +            }
  +        }
  +
  +        /**
  +         * A resource cumbering delete-method implementation,
  +         * used to test implementation
  +         */
  +        public void deleteArticlesStress(PerfArticle[] arr) throws Exception
  +        {
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                _tx = _kit.getTransaction(_conn);
  +                _tx.begin();
  +                _conn.deletePersistent(arr[i]);
  +                _tx.commit();
  +            }
  +        }
  +
  +        /**
  +         * A performance optimized delete-method implementation,
  +         * used to test performance
  +         */
  +        public void deleteArticles(PerfArticle[] arr) throws Exception
  +        {
  +            _tx = _kit.getTransaction(_conn);
  +            _tx.begin();
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                _conn.deletePersistent(arr[i]);
  +            }
  +            _tx.commit();
           }
       }
   }
  
  
  
  1.21      +5 -7      db-ojb/src/test/org/apache/ojb/broker/PerformanceTest2.java
  
  Index: PerformanceTest2.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PerformanceTest2.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- PerformanceTest2.java	13 Sep 2003 12:04:37 -0000	1.20
  +++ PerformanceTest2.java	13 Sep 2003 23:50:40 -0000	1.21
  @@ -510,7 +510,6 @@
        */
       class PerfomanceTestClientOTM extends TestClient
       {
  -        private static final String PRE_NAME = "B_";
           private PerformanceArticle[] arr;
           private String threadName;
           private PerformanceTest2 test;
  @@ -554,7 +553,7 @@
           {
               PerformanceArticle a = new PerformanceArticle();
               if (clientKeyGeneration) a.setArticleId(getId());
  -            a.setArticleName(PRE_NAME + name);
  +            a.setArticleName("New Performance Article " + id);
               a.setMinimumStock(100);
               a.setOrderedUnits(17);
               a.setPrice(0.45);
  @@ -598,11 +597,10 @@
               long start = System.currentTimeMillis();
               int artId = arr[0].articleId;
               org.apache.ojb.otm.core.Transaction tx = _kit.getTransaction(conn);
  -            OQLQuery query = conn.newOQLQuery(LockType.NO_LOCK);
  -            String sql = "select allArticles from " + PerformanceArticle.class.getName()
+
  -                    " where articleName = \"" + PRE_NAME + threadName + "\"";
  -            query.create(sql);
  -            Iterator iter = conn.getIteratorByOQLQuery(query);
  +            Criteria c = new Criteria();
  +            c.addBetween("articleId", new Integer(artId), new Integer(artId + iterationsPerThread));
  +            Query q = new QueryByCriteria(PerformanceArticle.class, c);
  +            Iterator iter = conn.getIteratorByQuery(q, LockType.NO_LOCK);
               int fetchCount = 0;
               while (iter.hasNext())
               {
  
  
  
  1.2       +7 -5      db-ojb/src/test/org/apache/ojb/otm/PerformanceTest.java
  
  Index: PerformanceTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/PerformanceTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PerformanceTest.java	13 Sep 2003 12:04:37 -0000	1.1
  +++ PerformanceTest.java	13 Sep 2003 23:50:40 -0000	1.2
  @@ -10,9 +10,11 @@
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PerformanceArticle;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.query.Criteria;
  +import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.odmg.OQLQuery;
   
   /**
    * This TestCase contains the OJB performance benchmarks for the
  @@ -176,11 +178,11 @@
           _conn.invalidateAll();
   
           Transaction tx = _kit.getTransaction(_conn);
  -        OQLQuery query = _conn.newOQLQuery(LockType.NO_LOCK);
  -        String sql = "select allArticles from " + PerformanceArticle.class.getName() +
" where articleId between " + new Integer(offsetId) + " and " + new Integer(offsetId + articleCount);
  -        query.create(sql);
  +        Criteria c = new Criteria();
  +        c.addBetween("articleId", new Integer(offsetId), new Integer(offsetId + articleCount));
  +        Query q = new QueryByCriteria(PerformanceArticle.class, c);
           long start = System.currentTimeMillis();
  -        Iterator iter = _conn.getIteratorByOQLQuery(query);
  +        Iterator iter = _conn.getIteratorByQuery(q, LockType.NO_LOCK);
           int fetchCount = 0;
           while (iter.hasNext())
           {
  
  
  

---------------------------------------------------------------------
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