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 OJBPerfTest.java
Date Tue, 24 Jun 2003 16:30:42 GMT
arminw      2003/06/24 09:30:42

  Modified:    .        build.xml
               src/test/org/apache/ojb/performance PerfTest.java
                        PerfMain.java PerfHandle.java
               src/test/org/apache/ojb/broker OJBPerfTest.java
  Log:
  - add 'update' performance test
  - add native JDBC test
  
  Revision  Changes    Path
  1.94      +5 -4      db-ojb/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/build.xml,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- build.xml	20 Jun 2003 19:48:16 -0000	1.93
  +++ build.xml	24 Jun 2003 16:30:41 -0000	1.94
  @@ -41,7 +41,7 @@
       </path>
   
       <property name="runtime.classpath" refid="runtime-classpath"/>
  -    
  +
       <target name="splash" description="show splash screen">
   		<property name="splash.dir" location="./xdocs/images"/>
   		<splash imageurl="file://${splash.dir}/splash.png" showduration="0"/>
  @@ -866,9 +866,10 @@
           <java fork="yes" classname="org.apache.ojb.performance.PerfMain"
                 dir="${build.test}/ojb" taskname="ojb" failonerror="true" >
               <classpath refid="runtime-classpath"/>
  +            <!-- comma separated list of the PerfTest implementations -->
               <arg value=
  -            "org.apache.ojb.broker.OJBPerfTest$PBPerfTest,org.apache.ojb.broker.OJBPerfTest$ODMGPerfTest"
  -            /> <!-- comma separated list of the PerfTest implementations -->
  +            "org.apache.ojb.broker.OJBPerfTest$JdbcPerfTest,org.apache.ojb.broker.OJBPerfTest$PBPerfTest,org.apache.ojb.broker.OJBPerfTest$ODMGPerfTest"
  +            />
               <arg value="3"/> <!-- test loops, default was 3 -->
               <arg value="10"/> <!-- performed threads, default was 10 -->
   			<arg value="2000"/> <!-- number of managed objects per thread, default was
2000 -->
  
  
  
  1.6       +8 -6      db-ojb/src/test/org/apache/ojb/performance/PerfTest.java
  
  Index: PerfTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PerfTest.java	9 Jun 2003 12:06:29 -0000	1.5
  +++ PerfTest.java	24 Jun 2003 16:30:41 -0000	1.6
  @@ -68,7 +68,8 @@
        * testTimes[0] startTime/test length
        * testTimes[1] inserting times
        * testTimes[2] fetching times
  -     * testTimes[3] deleting times
  +     * testTimes[3] updating times
  +     * testTimes[4] deleting times
        */
       private long[] testTimes;
       private int threadCount;
  @@ -107,12 +108,14 @@
   
       private void checkApi() throws Exception
       {
  +        String name = testName()+"_Pre_Test_Object";
           PerfHandle handle = newPerfHandle(this);
  -        PerfArticle article = handle.getPreparedPerfArticle(testName());
  +        PerfArticle article = handle.getPreparedPerfArticle(name);
           PerfArticle[] arr = new PerfArticle[]{article};
           handle.init();
           handle.insertNewArticles(arr);
  -        handle.readArticlesByCursor(testName());
  +        handle.readArticlesByCursor(name);
  +        handle.updateArticles(arr);
           handle.deleteArticles(arr);
           handle.tearDown();
           checked = true;
  @@ -178,9 +181,8 @@
   
               int objectCount = 0;
               int objectCountAfter = 0;
  -            int activeThreadsStart = threadGroup.activeCount();
   
  -            testTimes = new long[4];
  +            testTimes = new long[5];
               threadCount = PerfMain.getConcurrentThreads();
   
               objectCount = articleCount();
  
  
  
  1.5       +33 -54    db-ojb/src/test/org/apache/ojb/performance/PerfMain.java
  
  Index: PerfMain.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfMain.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PerfMain.java	9 Jun 2003 12:06:29 -0000	1.4
  +++ PerfMain.java	24 Jun 2003 16:30:41 -0000	1.5
  @@ -254,22 +254,15 @@
           }
   
           print.println(buildTestSummary(resultMap.values()));
  -
  -//        Iterator it = resultMap.values().iterator();
  -//        while (it.hasNext())
  -//        {
  -//            PerfResult result = (PerfResult) it.next();
  -//            print.println(buildTestSummary(result));
  -//        }
       }
   
       private String buildTestSummary(Collection results)
       {
  -        int column = 13;
  +        int column = 8;
           StringBuffer buf = new StringBuffer();
           // table header
           buf.append(EOL);
  -        for (int i = 0; i < 5; i++)
  +        for (int i = 0; i < 7; i++)
           {
               buf.append(getFilledUpToLength("", column, "="));
           }
  @@ -284,24 +277,28 @@
           buf.append(getFilledUpToLength("", column, " "));
           buf.append("- " + (isUseStressMode() == false ? "performance mode" : "stress mode
-"));
           buf.append(EOL);
  -        for (int i = 0; i < 5; i++)
  +        for (int i = 0; i < 7; i++)
           {
               buf.append(getFilledUpToLength("", column, "="));
           }
           buf.append(EOL);
           buf.append(getFilledUpToLength("API", column, " "));
  -        buf.append(getFilledUpToLength("Test Period", column, " "));
  +        buf.append(getFilledUpToLength("Period", column, " "));
  +        buf.append(getFilledUpToLength("Total", column, " "));
           buf.append(getFilledUpToLength("Insert", column, " "));
           buf.append(getFilledUpToLength("Fetch", column, " "));
  +        buf.append(getFilledUpToLength("Update", column, " "));
           buf.append(getFilledUpToLength("Delete", column, " "));
           buf.append(EOL);
           buf.append(getFilledUpToLength("", column, " "));
           buf.append(getFilledUpToLength("[sec]", column, " "));
  +        buf.append(getFilledUpToLength("[sec]", column, " "));
  +        buf.append(getFilledUpToLength("[msec]", column, " "));
           buf.append(getFilledUpToLength("[msec]", column, " "));
           buf.append(getFilledUpToLength("[msec]", column, " "));
           buf.append(getFilledUpToLength("[msec]", column, " "));
           buf.append(EOL);
  -        for (int i = 0; i < 5; i++)
  +        for (int i = 0; i < 7; i++)
           {
               buf.append(getFilledUpToLength("", column, "-"));
           }
  @@ -314,12 +311,14 @@
               PerfResult res = (PerfResult) it.next();
               buf.append(getFilledUpToLength(res.getTestName(), column, " "));
               buf.append(getFilledUpToLength(new Double((double) (((double) res.getTestPeriod())
/ 1000)).toString(), column, " "));
  +            buf.append(getFilledUpToLength(new Double((double) (((double) res.getTotalTime())
/ 1000)).toString(), column, " "));
               buf.append(getFilledUpToLength(new Long(res.getInsertPeriod()).toString(),
column, " "));
               buf.append(getFilledUpToLength(new Long(res.getFetchPeriod()).toString(), column,
" "));
  +            buf.append(getFilledUpToLength(new Long(res.getUpdatePeriod()).toString(),
column, " "));
               buf.append(getFilledUpToLength(new Long(res.getDeletePeriod()).toString(),
column, " "));
           }
           buf.append(EOL);
  -        for (int i = 0; i < 5; i++)
  +        for (int i = 0; i < 7; i++)
           {
               buf.append(getFilledUpToLength("", column, "="));
           }
  @@ -339,44 +338,6 @@
           return blanks + target;
       }
   
  -//    private String buildTestSummary(PerfResult result)
  -//    {
  -//        String EOL = System.getProperty("line.separator");
  -//        StringBuffer buf = new StringBuffer();
  -//        buf.append(EOL);
  -//        buf.append("----------------------------------------------------");
  -//        buf.append(EOL);
  -//        buf.append("TEST SUMMARY - " + result.getTestName());
  -//        buf.append(EOL);
  -//        buf.append("----------------------------------------------------");
  -//        buf.append(EOL);
  -//        buf.append(PerfMain.getConcurrentThreads() + " concurrent threads, handle " +
PerfMain.getIterationsPerThread() + " articles per thread");
  -//        buf.append(EOL);
  -//        buf.append("- " + (result.isStressMode()==false ? "performance mode" : "stress
mode -"));
  -//        buf.append(EOL);
  -//        buf.append("Test period: " + (double) (((double) result.getTestPeriod()) / 1000)
+ " [sec]");
  -//        buf.append(EOL);
  -//        buf.append("Inserting period: " + result.getInsertPeriod() + " [msec]");
  -//        buf.append(EOL);
  -//        buf.append("Fetching period: " + result.getFetchPeriod() + " [msec]");
  -//        buf.append(EOL);
  -//        buf.append("Deleting period: " + result.getDeletePeriod() + " [msec]");
  -//        buf.append(EOL);
  -//
  -//        if (result.isValid())
  -//        {
  -//            buf.append(EOL + "Test was successful" + EOL);
  -//        }
  -//        else
  -//        {
  -//            buf.append(EOL + buildObjectBeforeAfterList(result.consistentList) + EOL);
  -//        }
  -//
  -//        buf.append("----------------------------------------------------");
  -//
  -//        return buf.toString();
  -//    }
  -
       private String buildObjectBeforeAfterList(List consistentList)
       {
           StringBuffer buf = new StringBuffer();
  @@ -395,7 +356,8 @@
        * resultArr[0] startTime/test length
        * resultArr[1] inserting times
        * resultArr[2] fetching times
  -     * resultArr[3] deleting times
  +     * resultArr[3] updating times
  +     * resultArr[4] deleting times
        */
       public void addPeriodResult(String testName, long[] resultArr)
       {
  @@ -414,7 +376,8 @@
           result.addTestPeriod(resultArr[0]);
           result.addInsertPeriod(resultArr[1]);
           result.addFetchPeriod(resultArr[2]);
  -        result.addDeletePeriod(resultArr[3]);
  +        result.addUpdatePeriod(resultArr[3]);
  +        result.addDeletePeriod(resultArr[4]);
       }
   
       public void addConsistentResult(String testName, int objectsBefore, int objectsAfter)
  @@ -474,6 +437,7 @@
   
           private long insertPeriod;
           private long fetchPeriod;
  +        private long updatePeriod;
           private long deletePeriod;
   
           private boolean valid;
  @@ -580,6 +544,11 @@
               this.iterationsPerThread = numberOfObjects;
           }
   
  +        public long getTotalTime()
  +        {
  +            return ((insertPeriod + fetchPeriod + updatePeriod + deletePeriod)/ getTestLoops())
/ getNumberOfThreads();
  +        }
  +
           public long getInsertPeriod()
           {
               return (insertPeriod / getTestLoops()) / getNumberOfThreads();
  @@ -598,6 +567,16 @@
           public void addFetchPeriod(long aFetchPeriod)
           {
               this.fetchPeriod += aFetchPeriod;
  +        }
  +
  +        public long getUpdatePeriod()
  +        {
  +            return (updatePeriod / getTestLoops()) / getNumberOfThreads();
  +        }
  +
  +        public void addUpdatePeriod(long aUpdatePeriod)
  +        {
  +            this.updatePeriod += aUpdatePeriod;
           }
   
           public long getDeletePeriod()
  
  
  
  1.7       +68 -13    db-ojb/src/test/org/apache/ojb/performance/PerfHandle.java
  
  Index: PerfHandle.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfHandle.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PerfHandle.java	9 Jun 2003 12:06:29 -0000	1.6
  +++ PerfHandle.java	24 Jun 2003 16:30:42 -0000	1.7
  @@ -67,7 +67,7 @@
   public abstract class PerfHandle implements Runnable
   {
       private String PREFIX_LOG = "[" + this.getClass().getName() + "] ";
  -    private PerfArticle[] m_arr;
  +    // private PerfArticle[] m_arr;
       private String threadName;
       private PerfTest test;
       private String objectName;
  @@ -121,6 +121,18 @@
       public abstract void deleteArticlesStress(PerfArticle[] arr) throws Exception;
   
       /**
  +     * Update the given articles. Do optimize
  +     * performance.
  +     */
  +    public abstract void updateArticles(PerfArticle[] arr) throws Exception;
  +
  +    /**
  +     * Update the given articles. Implement a really
  +     * resource stressing way.
  +     */
  +    public abstract void updateArticlesStress(PerfArticle[] arr) throws Exception;
  +
  +    /**
        * Called to get a new instance class of the {@link org.apache.ojb.performance.PerfArticle}
        * interface, override this method if you need your own implementation
        * (with default constructor) of the PerfArticle-Interface.
  @@ -176,7 +188,7 @@
        */
       public void run()
       {
  -        m_arr = new PerfArticle[PerfMain.getIterationsPerThread()];
  +        PerfArticle[] m_arr = new PerfArticle[PerfMain.getIterationsPerThread()];
           for (int i = 0; i < PerfMain.getIterationsPerThread(); i++)
           {
               PerfArticle a = getPreparedPerfArticle(getTestObjectName());
  @@ -187,6 +199,8 @@
           {
               long period = 0;
               init();
  +
  +            // insert objects
               if (!PerfMain.isUseStressMode())
               {
                   period = System.currentTimeMillis();
  @@ -202,15 +216,26 @@
                   test.addTime(1, period);
               }
   
  +            // read objects
               period = System.currentTimeMillis();
               Collection col = readArticlesByCursor(objectName);
               period = System.currentTimeMillis() - period;
  +            try
  +            {
  +                checkQueryResult(col, m_arr);
  +            }
  +            catch (Exception e)
  +            {
  +                test.registerException("Something wrong with query result", e);
  +            }
               test.addTime(2, period);
   
  +            // update objects
  +            modifyPerfArticle(m_arr);
               if (!PerfMain.isUseStressMode())
               {
                   period = System.currentTimeMillis();
  -                deleteArticles(m_arr);
  +                updateArticles(m_arr);
                   period = System.currentTimeMillis() - period;
                   test.addTime(3, period);
               }
  @@ -222,6 +247,22 @@
                   test.addTime(3, period);
               }
   
  +            // delete objects
  +            if (!PerfMain.isUseStressMode())
  +            {
  +                period = System.currentTimeMillis();
  +                deleteArticles(m_arr);
  +                period = System.currentTimeMillis() - period;
  +                test.addTime(4, period);
  +            }
  +            else
  +            {
  +                period = System.currentTimeMillis();
  +                deleteArticlesStress(m_arr);
  +                period = System.currentTimeMillis() - period;
  +                test.addTime(4, period);
  +            }
  +            m_arr = null;
               tearDown();
           }
           catch (Exception e)
  @@ -232,20 +273,34 @@
           }
       }
   
  -    private boolean checkQueryResult(Collection col)
  +    private void modifyPerfArticle(PerfArticle[] m_arr)
  +    {
  +        PerfArticle article;
  +        String prefix = "updated_";
  +        for (int i = 0; i < m_arr.length; i++)
  +        {
  +            article = m_arr[i];
  +            article.setArticleName(prefix + article.getArticleName());
  +        }
  +    }
  +
  +    private void checkQueryResult(Collection col, PerfArticle[] m_arr) throws Exception
       {
           Iterator iter = col.iterator();
  -        int fetchCount = 0;
  -        while (iter.hasNext())
  +        if(col.size() > 0)
           {
  -            fetchCount++;
  -            iter.next();
  +            Iterator it = col.iterator();
  +            Object obj = it.next();
  +            if(!(obj instanceof PerfArticle))
  +            {
  +                throw new Exception("Read objects: Wrong object type found. Expected instance
of"+
  +                    PerfArticle.class.getName() + ", found " + obj.getClass().getName());
  +            }
           }
  -        if (fetchCount != m_arr.length)
  +        if (col.size() != m_arr.length)
           {
  -            System.out.println("## Read objects: Could not found number of created objects,
expected " +
  -                    (m_arr.length) + " found " + fetchCount + " ##");
  +            throw new Exception("Read objects: Wrong number of objects found. Expected
" +
  +                    (m_arr.length) + ", found " + col.size());
           }
  -        return true;
       }
   }
  
  
  
  1.5       +292 -17   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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- OJBPerfTest.java	7 Jun 2003 10:15:29 -0000	1.4
  +++ OJBPerfTest.java	24 Jun 2003 16:30:42 -0000	1.5
  @@ -1,8 +1,10 @@
   package org.apache.ojb.broker;
   
  -import java.util.Collection;
  -import java.util.List;
  -
  +import org.apache.ojb.broker.accesslayer.ConnectionFactory;
  +import org.apache.ojb.broker.accesslayer.ConnectionFactoryFactory;
  +import org.apache.ojb.broker.accesslayer.LookupException;
  +import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  +import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
  @@ -18,19 +20,230 @@
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  +import java.sql.Connection;
  +import java.sql.PreparedStatement;
  +import java.sql.ResultSet;
  +import java.sql.Statement;
  +import java.util.Collection;
  +import java.util.List;
  +import java.util.ArrayList;
  +
   /**
    * Performance test implementation classes for testing
  - * the PB-api and ODMG-api of OJB using the performance-package
  - * test classes.
  + * the PB-api, ODMG-api of OJB against native JDBC using
  + * the performance-package test classes.
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
   public class OJBPerfTest
   {
  +    // =====================================================================================
  +    // Inner class, test base class using native JDBC
  +    // =====================================================================================
  +    public static class JdbcPerfTest extends PerfTest
  +    {
  +        private static final String TABLE_NAME = "PERF_ARTICLE";
  +        private static ConnectionFactory conFac = ConnectionFactoryFactory.getInstance().createConnectionFactory();
  +        private static JdbcConnectionDescriptor defJcd = MetadataManager.getInstance().
  +                connectionRepository().getDescriptor(TestHelper.DEF_KEY);
  +
  +        public JdbcPerfTest()
  +        {
  +        }
  +
  +        public String testName()
  +        {
  +            return "JDBC";
  +        }
  +
  +        public PerfHandle newPerfHandle(PerfTest test)
  +        {
  +            return new JdbcPerfHandle(test);
  +        }
  +
  +        public int articleCount()
  +        {
  +            int result = 0;
  +            try
  +            {
  +                String sql = "SELECT COUNT(*) FROM " + TABLE_NAME;
  +                Connection con = getConnection();
  +                Statement stmt = con.createStatement();
  +                ResultSet rs = stmt.executeQuery(sql);
  +                rs.next();
  +                result = rs.getInt(1);
  +                rs.close();
  +                stmt.close();
  +                releaseConnection(con);
  +            }
  +            catch (Exception e)
  +            {
  +                e.printStackTrace();
  +            }
  +            return result;
  +        }
  +
  +        private Connection getConnection() throws LookupException
  +        {
  +            return conFac.lookupConnection(defJcd);
  +        }
  +
  +        private void releaseConnection(Connection con)
  +        {
  +            conFac.releaseConnection(defJcd, con);
  +        }
  +    }
  +
  +    // =====================================================================================
  +    // Inner class, test handle using native JDBC
  +    // =====================================================================================
  +    public static class JdbcPerfHandle extends PerfHandle
  +    {
  +        private static final String TABLE_NAME = "PERF_ARTICLE";
  +        private PersistenceBroker broker;
  +
  +
  +        public JdbcPerfHandle(PerfTest test)
  +        {
  +            super(test);
  +        }
  +
  +        public void init() throws Exception
  +        {
  +            if (broker == null)
  +            {
  +                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +            }
  +        }
  +
  +        public void tearDown() throws Exception
  +        {
  +            if (broker != null)
  +            {
  +                broker.close();
  +            }
  +        }
  +
  +        public void insertNewArticles(PerfArticle[] arr) throws Exception
  +        {
  +            StringBuffer buf = new StringBuffer();
  +            buf.append("INSERT INTO ").append(TABLE_NAME);
  +            buf.append(" (ARTICLE_ID, ARTICLE_NAME, MINIMUM_STOCK, PRICE, UNIT, STOCK,
SUPPLIER_ID)");
  +            buf.append(" VALUES (?,?,?,?,?,?,?)");
  +            Connection con = getConnection();
  +            PreparedStatement stmt = con.prepareStatement(buf.toString());
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                PerfArticle article = arr[i];
  +                // use Identity to set pk field value
  +                Identity oid = new Identity(article, broker);
  +                stmt.setLong(1, article.getArticleId().longValue());
  +                stmt.setString(2, article.getArticleName());
  +                stmt.setInt(3, article.getMinimumStock());
  +                stmt.setBigDecimal(4, article.getPrice());
  +                stmt.setString(5, article.getUnit());
  +                stmt.setInt(6, article.getStock());
  +                stmt.setInt(7, article.getSupplierId());
  +                stmt.executeUpdate();
  +            }
  +            stmt.close();
  +            releaseConnection();
  +        }
  +
  +        public void insertNewArticlesStress(PerfArticle[] arr) throws Exception
  +        {
  +            System.out.println("Stress-Mode is NOT supported");
  +        }
  +
  +        public Collection readArticlesByCursor(String articleName) throws Exception
  +        {
  +            String sql = "SELECT * FROM " + TABLE_NAME + " WHERE ARTICLE_NAME LIKE '"+articleName+"'";
  +            Connection con = getConnection();
  +            Statement stmt = con.createStatement();
  +            ResultSet rs = stmt.executeQuery(sql);
  +            ArrayList list = new ArrayList();
  +            while(rs.next())
  +            {
  +                PerfArticle article = new PerfArticleImpl();
  +                article.setArticleId(new Long(rs.getLong("ARTICLE_ID")));
  +                article.setArticleName(rs.getString("ARTICLE_NAME"));
  +                article.setMinimumStock(rs.getInt("MINIMUM_STOCK"));
  +                article.setPrice(rs.getBigDecimal("PRICE"));
  +                article.setUnit(rs.getString("UNIT"));
  +                article.setStock(rs.getInt("STOCK"));
  +                article.setSupplierId(rs.getInt("SUPPLIER_ID"));
  +                list.add(article);
  +            }
  +            rs.close();
  +            stmt.close();
  +            releaseConnection();
  +            return list;
  +        }
  +
  +        public void updateArticles(PerfArticle[] arr) throws Exception
  +        {
  +            // we don't know which field is to update, thus do do all
  +            StringBuffer buf = new StringBuffer();
  +            buf.append("UPDATE ").append(TABLE_NAME);
  +            buf.append(" SET ARTICLE_NAME = ?, MINIMUM_STOCK = ?, PRICE = ?, UNIT = ?,
STOCK = ?, SUPPLIER_ID = ?");
  +            buf.append(" WHERE ARTICLE_ID = ?");
  +            Connection con = getConnection();
  +            PreparedStatement stmt = con.prepareStatement(buf.toString());
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                PerfArticle article = arr[i];
  +                stmt.setString(1, article.getArticleName());
  +                stmt.setInt(2, article.getMinimumStock());
  +                stmt.setBigDecimal(3, article.getPrice());
  +                stmt.setString(4, article.getUnit());
  +                stmt.setInt(5, article.getStock());
  +                stmt.setInt(6, article.getSupplierId());
  +                stmt.setLong(7, article.getArticleId().longValue());
  +                stmt.executeUpdate();
  +            }
  +            stmt.close();
  +            releaseConnection();
  +        }
  +
  +        public void updateArticlesStress(PerfArticle[] arr) throws Exception
  +        {
  +            System.out.println("Stress-Mode is NOT supported");
  +        }
  +
  +        public void deleteArticles(PerfArticle[] arr) throws Exception
  +        {
  +            String sql = "DELETE FROM "+TABLE_NAME + " WHERE ARTICLE_ID = ?";
  +            Connection con = getConnection();
  +            PreparedStatement stmt = con.prepareStatement(sql);
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                PerfArticle article = arr[i];
  +                stmt.setLong(1, article.getArticleId().longValue());
  +                stmt.execute();
  +            }
  +            stmt.close();
  +            releaseConnection();
  +        }
  +
  +        public void deleteArticlesStress(PerfArticle[] arr) throws Exception
  +        {
  +            System.out.println("Stress-Mode is NOT supported");
  +        }
  +
  +        private Connection getConnection() throws LookupException
  +        {
  +            return broker.serviceConnectionManager().getConnection();
  +        }
  +
  +        private void releaseConnection()
  +        {
  +            broker.serviceConnectionManager().releaseConnection();
  +        }
  +    }
   
       // =====================================================================================
  -    // Inner class
  +    // Inner class, test base class using PB-api
       // =====================================================================================
       public static class PBPerfTest extends PerfTest
       {
  @@ -68,7 +281,7 @@
       }
   
       // =====================================================================================
  -    // Inner class
  +    // Inner class, test handle using PB-api
       // =====================================================================================
       public static class PBPerfHandle extends PerfHandle
       {
  @@ -81,6 +294,10 @@
           {
           }
   
  +        public void tearDown() throws Exception
  +        {
  +        }
  +
           /**
            * A resource cumbering insert-method implementation,
            * this was used to test implementation.
  @@ -101,7 +318,6 @@
                   {
                       if (broker != null) broker.close();
                   }
  -
               }
           }
   
  @@ -117,7 +333,7 @@
               try
               {
                   broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                broker.serviceConnectionManager().setBatchMode(true);
  +                // broker.serviceConnectionManager().setBatchMode(true);
                   broker.beginTransaction();
                   for (int i = 0; i < arr.length; i++)
                   {
  @@ -151,6 +367,48 @@
               return col;
           }
   
  +        public void updateArticles(PerfArticle[] arr) throws Exception
  +        {
  +            ObjectModificationDefaultImpl needsInsert = new ObjectModificationDefaultImpl();
  +            needsInsert.setNeedsUpdate(true);
  +            PersistenceBroker broker = null;
  +            try
  +            {
  +                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                // broker.serviceConnectionManager().setBatchMode(true);
  +                broker.beginTransaction();
  +                for (int i = 0; i < arr.length; i++)
  +                {
  +                    // broker.store(arr[i], needsInsert);
  +                    broker.store(arr[i]);
  +                }
  +                broker.commitTransaction();
  +            }
  +            finally
  +            {
  +                if (broker != null) broker.close();
  +            }
  +        }
  +
  +        public void updateArticlesStress(PerfArticle[] arr) throws Exception
  +        {
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                PersistenceBroker broker = null;
  +                try
  +                {
  +                    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                    broker.beginTransaction();
  +                    broker.store(arr[i]);
  +                    broker.commitTransaction();
  +                }
  +                finally
  +                {
  +                    if (broker != null) broker.close();
  +                }
  +            }
  +        }
  +
           /**
            * A resource cumbering delete-method implementation,
            * used to test implementation
  @@ -196,14 +454,10 @@
                   if (broker != null) broker.close();
               }
           }
  -
  -        public void tearDown() throws Exception
  -        {
  -        }
       }
   
       // =====================================================================================
  -    // Inner class
  +    // Inner class, test base class using ODMG-api
       // =====================================================================================
       public static class ODMGPerfTest extends PerfTest
       {
  @@ -241,7 +495,7 @@
       }
   
       // =====================================================================================
  -    // Inner class
  +    // Inner class, test handle using ODMG-api
       // =====================================================================================
       public static class ODMGPerfHandle extends PerfHandle
       {
  @@ -271,7 +525,7 @@
   
           public void tearDown() throws Exception
           {
  -            if(m_tx.isOpen()) m_tx.abort();
  +            if (m_tx.isOpen()) m_tx.abort();
               db.close();
           }
   
  @@ -314,6 +568,27 @@
               List allProducts = (List) query.execute();
               m_tx.commit();
               return allProducts;
  +        }
  +
  +        public void updateArticles(PerfArticle[] arr) throws Exception
  +        {
  +            m_tx.begin();
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                m_tx.lock(arr[i], Transaction.WRITE);
  +            }
  +            m_tx.commit();
  +        }
  +
  +        public void updateArticlesStress(PerfArticle[] arr) throws Exception
  +        {
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                Transaction tx = odmg.newTransaction();
  +                tx.begin();
  +                tx.lock(arr[i], Transaction.WRITE);
  +                tx.commit();
  +            }
           }
   
           /**
  
  
  

Mime
View raw message