1 package org.apache.ojb.compare; 2 3 import java.util.Iterator ; 4 5 import org.apache.ojb.broker.ManageableCollection; 6 import org.apache.ojb.broker.TestHelper; 7 import org.apache.ojb.odmg.OJB; 8 import org.apache.ojb.odmg.TransactionExt; 9 import org.odmg.Database; 10 import org.odmg.Implementation; 11 import org.odmg.OQLQuery; 12 import org.odmg.Transaction; 13 14 20 public class PerformanceODMGTest extends PerformanceBaseTest 21 { 22 private Implementation odmg; 23 private Database db; 24 25 public PerformanceODMGTest(String name) 26 { 27 super(name); 28 setNameOfTest("Test for ODMG-api"); 29 } 30 31 38 public static void main(String [] args) 39 { 40 if(args.length > 0) 41 { 42 articleCount = Integer.parseInt(args[0]); 43 } 44 if(args.length > 1) 45 { 46 iterations = Integer.parseInt(args[1]); 47 } 48 String [] arr = {PerformanceODMGTest.class.getName()}; 49 junit.textui.TestRunner.main(arr); 50 } 51 52 public void testBenchmark() throws Exception 53 { 54 super.testBenchmark(); 55 } 56 57 public void setUp() throws Exception 58 { 59 super.setUp(); 61 62 odmg = OJB.getInstance(); 63 db = odmg.newDatabase(); 64 db.open(TestHelper.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE); 65 } 66 67 public void tearDown() throws Exception 68 { 69 super.tearDown(); 70 } 71 72 75 protected void deleteArticles() throws Exception 76 { 77 Transaction tx = odmg.newTransaction(); 78 long start = System.currentTimeMillis(); 79 tx.begin(); 80 for(int i = 0; i < articleCount; i++) 81 { 82 db.deletePersistent(arr[i]); 83 } 84 tx.commit(); 85 long stop = System.currentTimeMillis(); 86 logger.info("deleting " + articleCount + " Objects: " + (stop - start) + " msec"); 87 } 88 89 94 protected void insertNewArticles() throws Exception 95 { 96 Transaction tx = odmg.newTransaction(); 97 long start = System.currentTimeMillis(); 98 tx.begin(); 99 for(int i = 0; i < articleCount; i++) 100 { 101 db.makePersistent(arr[i]); 102 } 103 tx.commit(); 104 long stop = System.currentTimeMillis(); 105 logger.info("inserting " + articleCount + " Objects: " + (stop - start) + " msec"); 106 } 107 108 113 protected void readArticles() throws Exception 114 { 115 TransactionExt tx = (TransactionExt) odmg.newTransaction(); 116 tx.setImplicitLocking(false); 118 String sql = "select allArticles from " + PerformanceArticle.class.getName() + " where articleId=$1"; 119 long start = System.currentTimeMillis(); 120 tx.begin(); 121 for(int i = 0; i < articleCount; i++) 122 { 123 OQLQuery query = odmg.newOQLQuery(); 124 query.create(sql); 125 query.bind(arr[i].getArticleId()); 126 query.execute(); 127 } 128 tx.commit(); 129 long stop = System.currentTimeMillis(); 130 logger.info("querying " + articleCount + " Objects: " + (stop - start) + " msec"); 131 } 132 133 140 protected void readArticlesByCursor() throws Exception 141 { 142 TransactionExt tx = (TransactionExt) odmg.newTransaction(); 143 tx.setImplicitLocking(false); 145 tx.begin(); 146 tx.getBroker().clearCache(); 148 149 long start = System.currentTimeMillis(); 150 OQLQuery query = odmg.newOQLQuery(); 151 String sql = "select allArticles from " + PerformanceArticle.class.getName() 152 + " where articleId between " + new Integer (offsetId) + " and " 153 + new Integer (offsetId + articleCount); 154 query.create(sql); 155 ManageableCollection collection = (ManageableCollection) query.execute(); 156 Iterator iter = collection.ojbIterator(); 157 int fetchCount = 0; 158 while(iter.hasNext()) 159 { 160 fetchCount++; 161 iter.next(); 162 } 163 long stop = System.currentTimeMillis(); 164 logger.info("fetching " + fetchCount + " Objects: " + (stop - start) + " msec"); 165 } 166 167 171 protected void updateExistingArticles() throws Exception 172 { 173 Transaction tx = odmg.newTransaction(); 174 long start = System.currentTimeMillis(); 175 tx.begin(); 176 for(int i = 0; i < articleCount; i++) 178 { 179 tx.lock(arr[i], Transaction.WRITE); 180 arr[i].setPrice(arr[i].getPrice() * 1.95583); 181 } 182 tx.commit(); 183 long stop = System.currentTimeMillis(); 184 logger.info("updating " + articleCount + " Objects: " + (stop - start) + " msec"); 185 } 186 } 187 188 | Popular Tags |