001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.stress;
018:
019: import java.util.ArrayList;
020: import java.util.StringTokenizer;
021:
022: import org.objectweb.speedo.pobjects.basic.BasicA;
023: import org.objectweb.speedo.pobjects.collection.AMMB;
024: import org.objectweb.speedo.pobjects.collection.BMMB;
025: import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB;
026: import org.objectweb.speedo.pobjects.ref.Department;
027: import org.objectweb.speedo.pobjects.ref.Employee;
028: import org.objectweb.speedo.pobjects.userid.AutoIncFieldId;
029: import org.objectweb.speedo.pobjects.userid.Ref2AutoIncFieldId;
030: import org.objectweb.speedo.runtime.query.POBuilder;
031: import org.objectweb.speedo.runtime.query.PORemover;
032: import org.objectweb.util.monolog.api.BasicLevel;
033:
034: /**
035: *
036: * @author M. Guillemin
037: */
038: public abstract class QueryHelper extends StressHelper {
039:
040: /**
041: * is the lists of object identifier prepared before the transaction
042: * execution.
043: * if (oids == null) {
044: * db is not initialised
045: * } else if (oids != null && oids.length==0) {
046: * db initialised and keepOid = false
047: * } else {
048: * db initialised and keepOid == true
049: * }
050: */
051: protected static Object[] oids = null;
052: protected String DBSIZE = getLoggerName() + ".dbsize";
053: protected String NO_DB_INIT = getLoggerName() + ".nodbinit";
054:
055: public QueryHelper(String s) {
056: super (s);
057: }
058:
059: protected String[] getClassNamesToInit() {
060: return new String[] { Employee.class.getName(),
061: Department.class.getName(), AMMB.class.getName(),
062: BMMB.class.getName(), Ref2Ref2AMMB.class.getName(),
063: Ref2AutoIncFieldId.class.getName(),
064: AutoIncFieldId.class.getName(), BasicA.class.getName() };
065: };
066:
067: protected boolean keepOid() {
068: return false;
069: }
070:
071: /*
072: public void setUp() throws Exception {
073: logger.log(BasicLevel.DEBUG, "setUp.");
074: cleanup();
075: initDataStructure(true);
076: debug = logger.isLoggable(BasicLevel.DEBUG);
077: }
078: */
079: protected void prepareTest(TaskManager tm, Object ctx) {
080: super .prepareTest(tm, ctx);
081: if (oids != null) {
082: oids = null; // force initialization of the database in PrepareTask
083: // delete previous data
084: new PORemover(getName()).testRemovingOfPersistentObject();
085: }
086: }
087:
088: /**
089: * Creates the persistent object if it is not already done.
090: * @param task the task to prepare
091: * @param _ctx the context of the test.
092: */
093: protected void prepareTask(Task task, Object _ctx) {
094: super .prepareTask(task, _ctx);
095: QueryCtx ctx = (QueryCtx) _ctx;
096: if (oids == null) {
097: synchronized (getClass()) {
098: if (oids == null && !Boolean.getBoolean(NO_DB_INIT)) {
099: //Initialisation the database
100: logger.log(BasicLevel.INFO, "\tPreparing test...");
101: new POBuilder(getName())
102: .testCreationOfPersistentObject();
103:
104: //db initialized without oids
105: oids = new Object[0];
106:
107: logger.log(BasicLevel.INFO, "\tTest Prepared.");
108: }
109: }
110: }
111: }
112:
113: /**
114: * The context to use for the object
115: */
116: public class QueryCtx {
117:
118: public int queries[];
119:
120: public QueryCtx(String v) {
121: logger.log(BasicLevel.DEBUG, "querysubset=" + v);
122: ArrayList al = new ArrayList(35);
123: if (v != null) { // get the subset of the queries
124: v = v.trim();
125: if (!v.startsWith("$")) {
126: StringTokenizer st = new StringTokenizer(v, ", ",
127: false);
128: while (st.hasMoreTokens()) {
129: try {
130: al.add(new Integer(st.nextToken()));
131: } catch (NumberFormatException e) {
132: }
133: }
134: }
135: }
136:
137: if (al.size() == 0) { // All the queries could be executed
138: for (int i = 0; i < 35; i++) {
139: al.add(new Integer(i));
140: }
141: }
142: queries = new int[al.size()];
143: for (int i = (al.size() - 1); i >= 0; i--) {
144: queries[i] = ((Integer) al.get(i)).intValue();
145: //logger.log(BasicLevel.DEBUG, "queries["+i+"]="+queries[i]);
146: }
147: }
148:
149: public String toString() {
150: return "queries = " + queries;
151: }
152:
153: }
154: }
|