KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > stress > QueryHelper


1 /**
2  * Copyright (C) 2001-2004 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.stress;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22
23 import org.objectweb.speedo.pobjects.basic.BasicA;
24 import org.objectweb.speedo.pobjects.collection.AMMB;
25 import org.objectweb.speedo.pobjects.collection.BMMB;
26 import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB;
27 import org.objectweb.speedo.pobjects.ref.Department;
28 import org.objectweb.speedo.pobjects.ref.Employee;
29 import org.objectweb.speedo.pobjects.userid.AutoIncFieldId;
30 import org.objectweb.speedo.pobjects.userid.Ref2AutoIncFieldId;
31 import org.objectweb.speedo.runtime.query.POBuilder;
32 import org.objectweb.speedo.runtime.query.PORemover;
33 import org.objectweb.util.monolog.api.BasicLevel;
34
35 /**
36  *
37  * @author M. Guillemin
38  */

39 public abstract class QueryHelper extends StressHelper {
40
41     /**
42      * is the lists of object identifier prepared before the transaction
43      * execution.
44      * if (oids == null) {
45      * db is not initialised
46      * } else if (oids != null && oids.length==0) {
47      * db initialised and keepOid = false
48      * } else {
49      * db initialised and keepOid == true
50      * }
51      */

52     protected static Object JavaDoc[] oids = null;
53     protected String JavaDoc DBSIZE = getLoggerName() + ".dbsize";
54     protected String JavaDoc NO_DB_INIT = getLoggerName() + ".nodbinit";
55
56
57     public QueryHelper(String JavaDoc s) {
58         super(s);
59     }
60
61     protected String JavaDoc[] getClassNamesToInit() {
62         return new String JavaDoc[]{Employee.class.getName(),
63                 Department.class.getName(),
64                 AMMB.class.getName(),
65                 BMMB.class.getName(),
66                 Ref2Ref2AMMB.class.getName(),
67                 Ref2AutoIncFieldId.class.getName(),
68                 AutoIncFieldId.class.getName(),
69                 BasicA.class.getName()};
70     };
71     
72     protected boolean keepOid() {
73         return false;
74     }
75 /*
76     public void setUp() throws Exception {
77         logger.log(BasicLevel.DEBUG, "setUp.");
78         cleanup();
79         initDataStructure(true);
80         debug = logger.isLoggable(BasicLevel.DEBUG);
81     }
82 */

83     protected void prepareTest(TaskManager tm, Object JavaDoc ctx) {
84         super.prepareTest(tm, ctx);
85         if (oids!=null) {
86             oids=null; // force initialization of the database in PrepareTask
87
// delete previous data
88
new PORemover(getName()).testRemovingOfPersistentObject();
89         }
90     }
91
92     /**
93      * Creates the persistent object if it is not already done.
94      * @param task the task to prepare
95      * @param _ctx the context of the test.
96      */

97     protected void prepareTask(Task task, Object JavaDoc _ctx) {
98         super.prepareTask(task, _ctx);
99         QueryCtx ctx = (QueryCtx) _ctx;
100         if (oids==null) {
101             synchronized (getClass()) {
102                 if (oids == null && !Boolean.getBoolean(NO_DB_INIT)) {
103                     //Initialisation the database
104
logger.log(BasicLevel.INFO, "\tPreparing test...");
105                     new POBuilder(getName()).testCreationOfPersistentObject();
106
107                     //db initialized without oids
108
oids = new Object JavaDoc[0];
109
110                     logger.log(BasicLevel.INFO, "\tTest Prepared.");
111                 }
112             }
113         }
114     }
115
116     /**
117      * The context to use for the object
118      */

119     public class QueryCtx {
120
121         public int queries[];
122
123         public QueryCtx(String JavaDoc v) {
124             logger.log(BasicLevel.DEBUG, "querysubset="+v);
125             ArrayList JavaDoc al = new ArrayList JavaDoc(35);
126             if (v != null) { // get the subset of the queries
127
v = v.trim();
128                 if (!v.startsWith("$")) {
129                     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(v, ", ", false);
130                     while(st.hasMoreTokens()) {
131                         try {
132                             al.add(new Integer JavaDoc(st.nextToken()));
133                         } catch (NumberFormatException JavaDoc e) {
134                         }
135                     }
136                 }
137             }
138             
139             if (al.size() == 0) { // All the queries could be executed
140
for(int i=0;i<35; i++) {
141                     al.add(new Integer JavaDoc(i));
142                 }
143             }
144             queries = new int[al.size()];
145             for(int i=(al.size()-1); i>=0; i--) {
146                 queries[i] = ((Integer JavaDoc) al.get(i)).intValue();
147                 //logger.log(BasicLevel.DEBUG, "queries["+i+"]="+queries[i]);
148
}
149         }
150         
151         public String JavaDoc toString() {
152             return "queries = " + queries;
153         }
154         
155     }
156 }
157
Popular Tags