KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > query > TestBillionQueries


1 /**
2  * Copyright (C) 2001-2005 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.runtime.query;
19
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import javax.jdo.Extent;
24 import javax.jdo.PersistenceManager;
25 import javax.jdo.Query;
26
27 import org.objectweb.speedo.SpeedoTestHelper;
28 import org.objectweb.speedo.pobjects.basic.BasicA;
29 import org.objectweb.util.monolog.api.BasicLevel;
30
31
32 /**
33  *
34  *
35  * @author S.Chassande-Barrioz
36  */

37 public class TestBillionQueries extends SpeedoTestHelper {
38
39     public TestBillionQueries() {
40         super("TestBillonQueries");
41     }
42     
43     public TestBillionQueries(String JavaDoc n) {
44         super(n);
45     }
46     
47     protected String JavaDoc getLoggerName() {
48         return SpeedoTestHelper.LOG_NAME + ".TestBillionQueries";
49     }
50
51     public void testLotOfQueryWithClose100_100() {
52         testLotOfQuery(true, 100, 100);
53     }
54     public void testLotOfQueryWithoutClose100_100() {
55         testLotOfQuery(false, 100, 100);
56     }
57     
58     public void testLotOfQueryWithClose10_10() {
59         testLotOfQuery(true, 10, 10);
60     }
61     
62     public void testLotOfQuery(boolean withclose, final int NB_PM, final int NB_QUERY) {
63         logger.log(BasicLevel.INFO, "testLotOfQuery(" + withclose
64                 + ", pm:" + NB_PM + ", query: "+ NB_QUERY +") is running ...");
65         PersistenceManager pm = pmf.getPersistenceManager();
66         pm.currentTransaction().begin();
67         for(int i=0; i<20; i++) {
68             BasicA ba = new BasicA();
69             ba.writeF1("testBillionQuery_" + i);
70             pm.makePersistent(ba);
71         }
72         pm.currentTransaction().commit();
73         pm.close();
74         for(int i=0; i<NB_PM; i++) {
75             logger.log(BasicLevel.DEBUG, "PM: " + i);
76             pm = pmf.getPersistenceManager();
77             for(int j=0; j<NB_QUERY; j++) {
78                 Query q = pm.newQuery(BasicA.class);
79                 q.setFilter("f1.startsWith(p1)");
80                 q.declareParameters("String p1");
81                 Collection JavaDoc c = (Collection JavaDoc) q.execute("dep");
82                 for (Iterator JavaDoc it = c.iterator(); it.hasNext();) {
83                     it.next();
84                 }
85                 q.closeAll();
86             }
87             pm.close();
88         }
89         pm = pmf.getPersistenceManager();
90         pm.currentTransaction().begin();
91         Extent e = pm.getExtent(BasicA.class);
92         for(Iterator JavaDoc it = e.iterator(); it.hasNext();) {
93             pm.deletePersistent(it.next());
94         }
95         pm.currentTransaction().commit();
96         pm.close();
97     }
98 }
99
Popular Tags