1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.controller.ControllerRequest; 68 import com.jcorporate.expresso.core.db.DBConnection; 69 import com.jcorporate.expresso.core.db.DBException; 70 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 71 import com.jcorporate.expresso.core.dbobj.ValidValue; 72 import com.jcorporate.expresso.core.misc.ConfigManager; 73 import com.jcorporate.expresso.core.misc.DateTime; 74 import com.jcorporate.expresso.core.security.User; 75 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 76 77 import java.util.Hashtable ; 78 import java.util.Iterator ; 79 import java.util.Vector ; 80 81 82 94 public class JobQueue 95 extends SecuredDBObject { 96 private Hashtable valuesCoded = null; 97 private Vector myParams = null; 98 public static final String FLD_JOBOSNAME = "JobOSName"; 99 public static final String FLD_JOBCRON_PARAMS = "JobCronParams"; 100 public static final String FLD_UID = "ExpUid"; 101 public static final String FLD_JOBCODE = "JobCode"; 102 public static final String FLD_STATUS_CODE = "StatusCode"; 103 public static final String FLD_PRIORITY = "Priority"; 104 public static final String FLD_JOBNUMBER = "JobNumber"; 105 public static final String FLD_REQUEST_TIME = "RequestTime"; 106 public static final String FLD_SERVERID = "ServerID"; 107 public static final String FLD_JOB_PROGRESS_MSG = "JobProgressMsg"; 108 109 public static final String JOB_PRIORITY_HIGH = "1"; 111 public static final String JOB_PRIORITY_NORMAL = "2"; 112 public static final String JOB_PRIORITY_LOW = "3"; 113 public static final String JOB_ARCH_UNIX = "Unix"; 114 public static final String JOB_ARCH_MSWIN = "MSWIN"; 115 public static final String JOB_ARCH_ANY = "any"; 116 public static final String JOB_STATUS_NEW = "N"; 117 public static final String JOB_STATUS_AVAILABLE = "A"; 118 public static final String JOB_STATUS_COMPLETED = "C"; 119 public static final String JOB_STATUS_RUNNING = "R"; 120 public static final String JOB_STATUS_STOPPED = "S"; 121 public static final String JOB_STATUS_KILLED = "K"; 122 public static final String JOB_STATUS_SUSPENDED = "P"; 123 124 127 public JobQueue() 128 throws DBException { 129 super(); 130 } 131 132 138 public JobQueue(DBConnection newConnection) throws DBException { 139 super(newConnection); 140 } 141 142 148 public JobQueue(int uid) 149 throws DBException { 150 super(uid); 151 } 152 153 159 public JobQueue(ControllerRequest request) 160 throws DBException { 161 super(request); 162 } 163 164 171 public void add() 172 throws DBException { 173 174 if (getField(FLD_STATUS_CODE).equals("")) { 175 setField(FLD_STATUS_CODE, JOB_STATUS_NEW); 176 } 177 178 setField(FLD_REQUEST_TIME, DateTime.getDateTimeForDB(this.getDataContext())); 179 180 if (getField(FLD_PRIORITY).equals("")) { 181 setField(FLD_PRIORITY, JOB_PRIORITY_LOW); 182 } 183 184 setField(FLD_SERVERID, "0"); 185 186 if (getField(FLD_JOBOSNAME).equals("")) { 187 setField(FLD_JOBOSNAME, JOB_ARCH_ANY); 188 } 189 190 super.add(); 191 } 192 193 194 200 public boolean find() 201 throws DBException { 202 boolean res = super.find(); 203 readParams(); 204 205 return res; 206 } 207 208 209 215 public synchronized Vector getParams() 216 throws DBException { 217 if (myParams == null) { 218 throw new DBException("Parameters not available until job queue entry has " + 219 "been retrieved"); 220 } 221 222 return (Vector ) myParams.clone(); 223 } 224 225 226 233 public synchronized String getParamValue(String paramCode) 234 throws DBException { 235 if (valuesCoded == null) { 236 readParams(); 237 } 238 239 return (String ) valuesCoded.get(paramCode); 240 } 241 242 243 251 public Vector getValidValues(String fieldName) 252 throws DBException { 253 if (fieldName.equals(FLD_STATUS_CODE)) { 254 Vector myValues = new Vector (4); 255 myValues.addElement(new ValidValue(JOB_STATUS_NEW, "New")); 256 myValues.addElement(new ValidValue(JOB_STATUS_AVAILABLE, 257 "Available")); 258 myValues.addElement(new ValidValue(JOB_STATUS_RUNNING, "Running")); 259 myValues.addElement(new ValidValue(JOB_STATUS_COMPLETED, 260 "Completed")); 261 myValues.addElement(new ValidValue(JOB_STATUS_STOPPED, "Stopped")); 262 myValues.addElement(new ValidValue(JOB_STATUS_KILLED, "Killed")); 263 myValues.addElement(new ValidValue(JOB_STATUS_SUSPENDED, 264 "Suspended")); 265 266 return myValues; 267 } 268 269 return super.getValidValues(fieldName); 270 } 271 272 273 278 private void readParams() 279 throws DBException { 280 myParams = new Vector (3); 281 valuesCoded = new Hashtable (3); 282 283 JobQueueParam paramList = new JobQueueParam(SecuredDBObject.SYSTEM_ACCOUNT); 284 paramList.setDataContext(getDataContext()); 285 paramList.setField(FLD_JOBNUMBER, getField(FLD_JOBNUMBER)); 286 287 for (Iterator e = paramList.searchAndRetrieveList("ParamNumber").iterator(); 288 e.hasNext();) { 289 JobQueueParam oneParam = (JobQueueParam) e.next(); 290 myParams.addElement(oneParam); 291 valuesCoded.put(oneParam.getField("ParamCode"), 292 oneParam.getField("ParamValue")); 293 } 294 } 295 296 297 303 public void retrieve() 304 throws DBException { 305 super.retrieve(); 306 readParams(); 307 } 308 309 310 313 protected synchronized void setupFields() 314 throws DBException { 315 setTargetTable("JOBQUEUE"); 316 setDescription("DBjobQueue"); 317 setCharset("ISO-8859-1"); 318 addField(FLD_JOBNUMBER, "auto-inc", 0, false, "jobSerial"); 319 addField(FLD_UID, "int", 0, false, "requestedByUser"); 320 addVirtualField("LoginName", "char", 30, "loginName"); 321 setLookupObject(FLD_UID, ConfigManager.getClassHandler("userInfo")); 322 addField(FLD_REQUEST_TIME, "datetime", 0, true, "requestedAt"); 323 addField(FLD_JOBCODE, "varchar", 255, false, "jobCode"); 324 addField(FLD_STATUS_CODE, "char", 1, false, "statusCode"); 325 addField(FLD_PRIORITY, "int", 0, false, "jobPrio"); 326 addField(FLD_SERVERID, "int", 0, false, "handlingServer"); 327 328 addField(FLD_JOBOSNAME, "varchar", 255, false, "requiredOS"); 331 addField(FLD_JOBCRON_PARAMS, "varchar", 255, true, "cronParams"); 332 333 setStringFilter(FLD_JOBCODE, "rawFilter"); 335 addKey(FLD_JOBNUMBER); 336 setMultiValued(FLD_STATUS_CODE); 337 setReadOnly(FLD_JOBNUMBER); 338 setReadOnly(FLD_REQUEST_TIME); 339 addDetail("com.jcorporate.expresso.services.dbobj.JobQueueParam", 340 FLD_JOBNUMBER, FLD_JOBNUMBER); 341 setLookupObject("ExpUid", "com.jcorporate.expresso.core.security.User"); 342 } 343 344 345 public String getField(String fieldName) 346 throws DBException { 347 if (fieldName.equals("LoginName")) { 348 User u = new User(); 349 u.setUid(getFieldInt("ExpUid")); 350 u.setDataContext(this.getDataContext()); 351 352 if (u.find()) { 353 return u.getLoginName(); 354 } 355 356 return "No such user"; 357 } 358 359 return super.getField(fieldName); 360 } 361 362 public void setJobOSName(String os) 363 throws DBException { 364 setField(FLD_JOBOSNAME, os); 365 } 366 367 public void setUid(String userId) 368 throws DBException { 369 setField(FLD_UID, userId); 370 } 371 372 public void setJobCode(String jobCode) 373 throws DBException { 374 setField(FLD_JOBCODE, jobCode); 375 } 376 377 public void setJobStatus(String status) 378 throws DBException { 379 setField(FLD_STATUS_CODE, status); 380 } 381 382 public String getJobStatus() 383 throws DBException { 384 return getField(FLD_STATUS_CODE); 385 } 386 387 393 public boolean useCron() 394 throws DBException { 395 String result = getField(FLD_JOBCRON_PARAMS); 396 if (result == null || result.length() == 0) { 397 return false; 398 } else { 399 return true; 400 } 401 } 402 403 public String getCronEntry() 404 throws DBException { 405 return getField(FLD_JOBCRON_PARAMS); 406 } 407 408 433 public void setCronParams(int minute, int hour, int dayOfMonth, int month, 434 int dayOfWeek, int year) 435 throws DBException { 436 FastStringBuffer sb = new FastStringBuffer(48); 437 sb.append(minute).append(","); 438 sb.append(hour).append(","); 439 sb.append(dayOfMonth).append(","); 440 sb.append(month).append(","); 441 sb.append(dayOfWeek).append(","); 442 sb.append(year); 443 setField(FLD_JOBCRON_PARAMS, sb.toString()); 444 } 445 } 446 447 | Popular Tags |