1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.dbobj.RequestContext; 69 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 70 import com.jcorporate.expresso.core.dbobj.ValidValue; 71 import com.jcorporate.expresso.core.misc.ConfigManager; 72 import com.jcorporate.expresso.core.misc.DateTime; 73 74 import java.util.Vector ; 75 76 82 public class JobHandlerControl 83 extends SecuredDBObject { 84 public static final String FLD_REQUEST_TIME = "RequestTime"; 85 88 public static final String FLD_COMMAND = "Command"; 89 public static final String FLD_UID = "ExpUid"; 90 public static final String FLD_STATUS_CODE = "Status"; 91 public static final String FLD_SERVERID = "ServerID"; 92 public static final String FLD_COMMAND_ID = "CommandId"; 93 public static final String JOB_STATUS_NEW = "N"; 94 public static final String JOB_STATUS_AVAILABLE = "A"; 95 public static final String JOB_STATUS_COMPLETED = "C"; 96 public static final String JOB_STATUS_RUNNING = "R"; 97 98 public static final String RESTART_COMMAND = "restart"; 99 public static final String STOP_COMMAND = "stop"; 100 101 104 public JobHandlerControl() 105 throws DBException { 106 } 107 108 109 113 public JobHandlerControl(int uid) 114 throws DBException { 115 super(uid); 116 } 117 118 125 public JobHandlerControl(RequestContext request) 126 throws DBException { 127 super(request); 128 } 129 130 133 protected synchronized void setupFields() 134 throws DBException { 135 setTargetTable("JOBHANDLERCONTROL"); 136 setDescription("DBjobHandlerControl"); 137 addField(FLD_COMMAND_ID, "auto-inc", 0, false, "commandSerialId"); 138 addField(FLD_STATUS_CODE, "varchar", 255, false, "statusCode"); 139 addField(FLD_COMMAND, "varchar", 255, false, "jobHandlerCommand"); 140 addField(FLD_SERVERID, "int", 0, false, "handlingServer"); 141 addField(FLD_UID, "int", 0, false, "requestedByUser"); 142 setLookupObject(FLD_UID, ConfigManager.getClassHandler("userInfo")); 143 addField(FLD_REQUEST_TIME, "datetime", 0, false, "requestedAt"); 144 addKey("CommandId"); 145 } 146 147 148 public void add() 149 throws DBException { 150 151 if (getField(FLD_STATUS_CODE).equals("")) { 152 setField(FLD_STATUS_CODE, JOB_STATUS_NEW); 153 } 154 155 setField(FLD_REQUEST_TIME, DateTime.getDateTimeForDB(this.getDataContext())); 156 setField(FLD_SERVERID, "0"); 157 super.add(); 158 } 159 160 161 169 public Vector getValidValues(String fieldName) 170 throws DBException { 171 if (fieldName.equals(FLD_STATUS_CODE)) { 172 Vector myValues = new Vector (4); 173 myValues.addElement(new ValidValue(JOB_STATUS_NEW, "New")); 174 myValues.addElement(new ValidValue(JOB_STATUS_AVAILABLE, 175 "Available")); 176 myValues.addElement(new ValidValue(JOB_STATUS_RUNNING, "Running")); 177 myValues.addElement(new ValidValue(JOB_STATUS_COMPLETED, 178 "Completed")); 179 180 return myValues; 181 } 182 183 return super.getValidValues(fieldName); 184 } 185 186 187 public void setCmdStopJob(String jobID) 188 throws DBException { 189 String cmd = "stop " + jobID; 190 setField(FLD_COMMAND, cmd); 191 } 192 193 public void setCmdRestartJob(String jobID) 194 throws DBException { 195 String cmd = "restart " + jobID; 196 setField(FLD_COMMAND, cmd); 197 } 198 199 public void setKillCommand(String jobID) 200 throws DBException { 201 String cmd = "kill " + jobID; 202 setField(FLD_COMMAND, cmd); 203 } 204 } 205 | Popular Tags |