1 18 package org.objectweb.speedo.stress; 19 20 import java.util.ArrayList ; 21 import java.util.StringTokenizer ; 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 39 public abstract class QueryHelper extends StressHelper { 40 41 52 protected static Object [] oids = null; 53 protected String DBSIZE = getLoggerName() + ".dbsize"; 54 protected String NO_DB_INIT = getLoggerName() + ".nodbinit"; 55 56 57 public QueryHelper(String s) { 58 super(s); 59 } 60 61 protected String [] getClassNamesToInit() { 62 return new String []{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 83 protected void prepareTest(TaskManager tm, Object ctx) { 84 super.prepareTest(tm, ctx); 85 if (oids!=null) { 86 oids=null; new PORemover(getName()).testRemovingOfPersistentObject(); 89 } 90 } 91 92 97 protected void prepareTask(Task task, Object _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 logger.log(BasicLevel.INFO, "\tPreparing test..."); 105 new POBuilder(getName()).testCreationOfPersistentObject(); 106 107 oids = new Object [0]; 109 110 logger.log(BasicLevel.INFO, "\tTest Prepared."); 111 } 112 } 113 } 114 } 115 116 119 public class QueryCtx { 120 121 public int queries[]; 122 123 public QueryCtx(String v) { 124 logger.log(BasicLevel.DEBUG, "querysubset="+v); 125 ArrayList al = new ArrayList (35); 126 if (v != null) { v = v.trim(); 128 if (!v.startsWith("$")) { 129 StringTokenizer st = new StringTokenizer (v, ", ", false); 130 while(st.hasMoreTokens()) { 131 try { 132 al.add(new Integer (st.nextToken())); 133 } catch (NumberFormatException e) { 134 } 135 } 136 } 137 } 138 139 if (al.size() == 0) { for(int i=0;i<35; i++) { 141 al.add(new Integer (i)); 142 } 143 } 144 queries = new int[al.size()]; 145 for(int i=(al.size()-1); i>=0; i--) { 146 queries[i] = ((Integer ) al.get(i)).intValue(); 147 } 149 } 150 151 public String toString() { 152 return "queries = " + queries; 153 } 154 155 } 156 } 157 | Popular Tags |