1 package org.apache.ojb.compare; 2 3 import java.util.Iterator ; 4 5 import org.apache.ojb.broker.Identity; 6 import org.apache.ojb.broker.PersistenceBrokerException; 7 import org.apache.ojb.broker.query.Criteria; 8 import org.apache.ojb.broker.query.Query; 9 import org.apache.ojb.broker.query.QueryByCriteria; 10 import org.apache.ojb.broker.util.ObjectModification; 11 12 18 public class PerformancePBTest extends PerformanceBaseTest 19 { 20 public PerformancePBTest(String name) 21 { 22 super(name); 23 setNameOfTest("Test for PB-api"); 24 } 25 26 33 public static void main(String [] args) 34 { 35 if(args.length > 0) 36 { 37 articleCount = Integer.parseInt(args[0]); 38 } 39 if(args.length > 1) 40 { 41 iterations = Integer.parseInt(args[1]); 42 } 43 44 String [] arr = {PerformancePBTest.class.getName()}; 45 junit.textui.TestRunner.main(arr); 46 } 47 48 public void testBenchmark() throws Exception 49 { 50 super.testBenchmark(); 51 } 52 53 56 protected void deleteArticles() throws PersistenceBrokerException 57 { 58 long start = System.currentTimeMillis(); 59 broker.beginTransaction(); 60 for(int i = 0; i < articleCount; i++) 61 { 62 broker.delete(arr[i]); 63 } 64 broker.commitTransaction(); 65 long stop = System.currentTimeMillis(); 66 logger.info("deleting " + articleCount + " Objects: " + (stop - start) + " msec"); 67 } 68 69 70 74 protected void insertNewArticles() throws PersistenceBrokerException 75 { 76 long start = System.currentTimeMillis(); 77 broker.beginTransaction(); 78 for(int i = 0; i < articleCount; i++) 79 { 80 broker.store(arr[i], ObjectModification.INSERT); 81 } 82 broker.commitTransaction(); 83 long stop = System.currentTimeMillis(); 84 logger.info("inserting " + articleCount + " Objects: " + (stop - start) + " msec"); 85 86 } 87 88 93 protected void readArticles() throws PersistenceBrokerException 94 { 95 long start = System.currentTimeMillis(); 96 broker.beginTransaction(); 97 for(int i = 0; i < articleCount; i++) 98 { 99 Identity oid = broker.serviceIdentity(). 100 buildIdentity(PerformanceArticle.class, arr[i].getArticleId()); 101 broker.getObjectByIdentity(oid); 102 } 103 broker.commitTransaction(); 104 long stop = System.currentTimeMillis(); 105 logger.info("querying " + articleCount + " Objects: " + (stop - start) + " msec"); 106 107 } 108 109 116 protected void readArticlesByCursor() throws PersistenceBrokerException 117 118 { 119 broker.clearCache(); 120 Criteria c = new Criteria(); 121 c.addBetween("articleId", new Integer (offsetId), new Integer (offsetId + articleCount)); 122 Query q = new QueryByCriteria(PerformanceArticle.class, c); 123 124 long start = System.currentTimeMillis(); 125 Iterator iter = broker.getIteratorByQuery(q); 126 int fetchCount = 0; 127 while(iter.hasNext()) 128 { 129 fetchCount++; 130 iter.next(); 131 } 132 long stop = System.currentTimeMillis(); 133 logger.info("fetching " + fetchCount + " Objects: " + (stop - start) + " msec"); 134 135 } 136 137 141 protected void updateExistingArticles() throws PersistenceBrokerException 142 { 143 for(int i = 0; i < articleCount; i++) 145 { 146 arr[i].setPrice(arr[i].getPrice() * 1.95583); 147 } 148 149 long start = System.currentTimeMillis(); 150 broker.beginTransaction(); 151 for(int i = 0; i < articleCount; i++) 152 { 153 broker.store(arr[i], ObjectModification.UPDATE); 154 } 155 broker.commitTransaction(); 156 long stop = System.currentTimeMillis(); 157 logger.info("updating " + articleCount + " Objects: " + (stop - start) + " msec"); 158 } 159 } 160 | Popular Tags |