1 25 package org.ofbiz.shark.instance; 26 27 import org.ofbiz.entity.GenericDelegator; 28 import org.ofbiz.entity.GenericValue; 29 import org.ofbiz.entity.GenericEntityException; 30 import org.ofbiz.base.util.UtilMisc; 31 import org.ofbiz.base.util.Debug; 32 import org.ofbiz.base.util.UtilDateTime; 33 import org.ofbiz.base.util.UtilObject; 34 import org.ofbiz.shark.container.SharkContainer; 35 36 import org.enhydra.shark.api.internal.instancepersistence.*; 37 38 45 public class Process extends InstanceEntityObject implements ProcessPersistenceInterface { 46 47 public static final String module = Process .class.getName(); 48 49 protected GenericValue process = null; 50 protected boolean newValue = false; 51 52 protected Process(EntityPersistentMgr mgr, GenericDelegator delegator, String processId) throws PersistenceException { 53 super(mgr, delegator); 54 if (this.delegator != null) { 55 try { 56 this.process = delegator.findByPrimaryKey("WfProcess", UtilMisc.toMap("processId", processId)); 57 } catch (GenericEntityException e) { 58 throw new PersistenceException(e); 59 } 60 } else { 61 Debug.logError("Invalid delegator object passed", module); 62 } 63 } 64 65 protected Process(EntityPersistentMgr mgr, GenericValue process) { 66 super(mgr, process.getDelegator()); 67 this.process = process; 68 } 69 70 public Process(EntityPersistentMgr mgr, GenericDelegator delegator) { 71 super(mgr, delegator); 72 this.newValue = true; 73 this.process = delegator.makeValue("WfProcess", null); 74 } 75 76 public static Process getInstance(EntityPersistentMgr mgr, GenericValue process) { 77 Process proc = new Process (mgr, process); 78 if (proc.isLoaded()) { 79 return proc; 80 } 81 return null; 82 } 83 84 public static Process getInstance(EntityPersistentMgr mgr, String processId) throws PersistenceException { 85 Process proc = new Process (mgr, SharkContainer.getDelegator(), processId); 86 if (proc.isLoaded()) { 87 Debug.log("Returning loaded Process", module); 88 return proc; 89 } 90 Debug.log("Returning null Process ID : " + processId, module); 91 if (processId == null) Debug.log(new Exception (), module); 92 return null; 93 } 94 95 public boolean isLoaded() { 96 if (process == null) { 97 return false; 98 } 99 return true; 100 } 101 102 public void setId(String s) { 103 process.set("processId", s); 104 } 105 106 public String getId() { 107 return process.getString("processId"); 108 } 109 110 public void setProcessMgrName(String s) { 111 process.set("mgrName", s); 112 try { 113 ProcessMgrPersistenceInterface pm = mgr.restoreProcessMgr(s, null); 114 process.set("packageId", pm.getPackageId()); 115 process.set("packageVer", pm.getVersion()); 116 } catch (PersistenceException e) { 117 Debug.logError(e, "Unable to set package information", module); 118 } 119 } 120 121 public String getProcessMgrName() { 122 return process.getString("mgrName"); 123 } 124 125 public void setExternalRequester(Object o) { 126 byte[] value = UtilObject.getBytes(o); 127 process.setBytes("externalReq", (value != null ? value : null)); 128 } 129 130 public Object getExternalRequester() { 131 byte[] value = process.getBytes("externalReq"); 132 return UtilObject.getObject(value); 133 } 134 135 public void setActivityRequesterId(String s) { 136 process.set("activityReqId", s); 137 } 138 139 public String getActivityRequesterId() { 140 return process.getString("activityReqId"); 141 } 142 143 public void setActivityRequestersProcessId(String s) { 144 process.set("activityReqProcessId", s); 145 } 146 147 public String getActivityRequestersProcessId() { 148 return process.getString("activityReqProcessId"); 149 } 150 151 public void setResourceRequesterId(String s) { 152 process.set("resourceReqId", s); 153 } 154 155 public String getResourceRequesterId() { 156 return process.getString("resourceReqId"); 157 } 158 159 public void setState(String s) { 160 process.set("currentState", s); 161 } 162 163 public String getState() { 164 return process.getString("currentState"); 165 } 166 167 public String getName() { 168 return process.getString("processName"); 169 } 170 171 public void setName(String s) { 172 process.set("processName", s); 173 } 174 175 public String getDescription() { 176 return process.getString("description"); 177 } 178 179 public void setDescription(String s) { 180 process.set("description", s); 181 } 182 183 public int getPriority() { 184 return process.getLong("priority").intValue(); 185 } 186 187 public void setPriority(int i) { 188 process.set("priority", new Long (i)); 189 } 190 191 public long getLastStateTime() { 192 return process.get("lastStateTime") != null ? process.getTimestamp("lastStateTime").getTime() : 0; 193 } 194 195 public void setLastStateTime(long timestamp) { 196 process.set("lastStateTime", UtilDateTime.getTimestamp(timestamp)); 197 } 198 199 public long getCreatedTime() { 200 return process.get("createdTime") != null ? process.getTimestamp("createdTime").getTime() : 0; 201 } 202 203 public void setCreatedTime(long time) { 204 process.set("createdTime", UtilDateTime.getTimestamp(time)); 205 } 206 207 public long getStartedTime() { 208 return process.get("startedTime") != null ? process.getTimestamp("startedTime").getTime() : 0; 209 } 210 211 public void setStartedTime(long timestamp) { 212 process.set("startedTime", UtilDateTime.getTimestamp(timestamp)); 213 } 214 215 public void store() throws GenericEntityException { 216 if (newValue) { 217 delegator.createOrStore(process); 218 newValue = false; 219 } else { 220 delegator.store(process); 221 } 222 } 223 224 public void reload() throws GenericEntityException { 225 if (!newValue) { 226 process.refresh(); 227 } 228 } 229 230 public void remove() throws GenericEntityException { 231 if (!newValue) { 232 delegator.removeValue(process); 233 Debug.log("**** REMOVED : " + this, module); 234 } 235 236 delegator.removeByAnd("WfRequester", UtilMisc.toMap("processId", this.getId())); 238 } 239 } 240 | Popular Tags |