1 64 65 70 package com.jcorporate.expresso.core.utility; 71 72 import com.jcorporate.expresso.core.db.DBException; 73 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 74 import com.jcorporate.expresso.core.misc.ConfigManager; 75 import com.jcorporate.expresso.kernel.LogManager; 76 import com.jcorporate.expresso.services.dbobj.JobQueue; 77 import com.jcorporate.expresso.services.dbobj.JobQueueParam; 78 79 import java.util.Enumeration ; 80 import java.util.Hashtable ; 81 import java.util.StringTokenizer ; 82 83 84 90 public class QueueJob { 91 private static final String thisClass = QueueJob.class.getName() + "."; 92 93 98 public QueueJob(String [] args) { 99 Hashtable commandArgs = new Hashtable (10); 100 String paramCode = null; 101 String paramValue = null; 102 103 for (int i = 0; i < args.length; i++) { 104 StringTokenizer stk = new StringTokenizer (args[i], "="); 105 106 if (!stk.hasMoreTokens()) { 107 usage(); 108 } 109 110 paramCode = stk.nextToken(); 111 112 if (!stk.hasMoreTokens()) { 113 usage(); 114 } 115 116 paramValue = stk.nextToken(); 117 } 118 try { 119 120 String logDir = (String ) commandArgs.get("logDir"); 121 String logConfig = (String ) commandArgs.get("logConfig"); 122 if (logConfig == null) { 123 logConfig = (String ) commandArgs.get("configDir") + "/expressoLogging.xml"; 124 } 125 126 LogManager lm = new LogManager(logConfig, logDir); 127 ConfigManager.load((String ) commandArgs.get("configDir")); 129 130 ConfigManager.dbInitialize(); 132 133 queueJob(commandArgs); 135 System.out.println("Job queued successfully"); 136 } catch (Exception de) { 137 System.out.println("QueueJob Error:" + de.getMessage()); 138 de.printStackTrace(); 139 System.exit(1); 140 } 141 } 142 143 164 public static void main(String [] args) { 165 Hashtable commandArgs = new Hashtable (10); 166 String paramCode = null; 167 String paramValue = null; 168 169 for (int i = 0; i < args.length; i++) { 170 StringTokenizer stk = new StringTokenizer (args[i], "="); 171 172 if (!stk.hasMoreTokens()) { 173 usage(); 174 } 175 176 paramCode = stk.nextToken(); 177 178 if (!stk.hasMoreTokens()) { 179 usage(); 180 } 181 182 paramValue = stk.nextToken(); 183 commandArgs.put(paramCode, paramValue); 184 } 185 186 try { 187 188 ConfigManager.load((String ) commandArgs.get("configDir")); 190 191 ConfigManager.dbInitialize(); 193 194 } catch (Exception de) { 196 System.out.println("Server Error:" + de.getMessage()); 197 de.printStackTrace(); 198 System.exit(1); 199 } 200 201 new QueueJob(args); 202 } 203 204 210 public void queueJob(Hashtable args) 211 throws DBException { 212 JobQueue myQueue = new JobQueue(SecuredDBObject.SYSTEM_ACCOUNT); 213 myQueue.setDataContext((String ) args.get("db")); 214 myQueue.setField("ExpUid", (String ) args.get("uid")); 215 myQueue.setField("JobCode", (String ) args.get("job")); 216 myQueue.setField("StatusCode", "N"); 217 myQueue.add(); 218 219 220 JobQueueParam myParam = new JobQueueParam(SecuredDBObject.SYSTEM_ACCOUNT); 221 myParam.setDataContext((String ) args.get("db")); 222 myParam.setField("JobNumber", myQueue.getField("JobNumber")); 223 224 String currentParam = null; 225 String currentValue = null; 226 int paramNumber = 0; 227 228 for (Enumeration e = args.keys(); e.hasMoreElements();) { 229 currentParam = (String ) e.nextElement(); 230 currentValue = (String ) args.get(currentParam); 231 paramNumber++; 232 myParam.setField("ParamNumber", ("" + paramNumber)); 233 myParam.setField("ParamCode", currentParam); 234 myParam.setField("ParamValue", currentValue); 235 myParam.add(); 236 System.out.println("Parameter '" + currentParam + "' set to '" + 237 currentValue + "'"); 238 } 239 240 241 myQueue.setField("StatusCode", "A"); 242 myQueue.update(); 243 } 244 245 246 250 private static void usage() { 251 System.out.println("Usage: QueueJob arg=value ... "); 252 System.out.println("Where arguments are: dbDriver dbURL " + 253 "dbConnectFormat dbLogin dbPassword "); 254 System.exit(1); 255 } 256 257 } 258 | Popular Tags |