KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > shark > instance > Process


1 /*
2  * $Id: Process.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

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 /**
39  * Persistance Object
40  *
41  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
42  * @version $Rev: 5462 $
43  * @since 3.1
44  */

45 public class Process extends InstanceEntityObject implements ProcessPersistenceInterface {
46
47     public static final String JavaDoc module = Process JavaDoc.class.getName();
48
49     protected GenericValue process = null;
50     protected boolean newValue = false;
51
52     protected Process(EntityPersistentMgr mgr, GenericDelegator delegator, String JavaDoc 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 JavaDoc getInstance(EntityPersistentMgr mgr, GenericValue process) {
77         Process JavaDoc proc = new Process JavaDoc(mgr, process);
78         if (proc.isLoaded()) {
79             return proc;
80         }
81         return null;
82     }
83
84     public static Process JavaDoc getInstance(EntityPersistentMgr mgr, String JavaDoc processId) throws PersistenceException {
85         Process JavaDoc proc = new Process JavaDoc(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 JavaDoc(), 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 JavaDoc s) {
103         process.set("processId", s);
104     }
105
106     public String JavaDoc getId() {
107         return process.getString("processId");
108     }
109
110     public void setProcessMgrName(String JavaDoc 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 JavaDoc getProcessMgrName() {
122         return process.getString("mgrName");
123     }
124
125     public void setExternalRequester(Object JavaDoc o) {
126         byte[] value = UtilObject.getBytes(o);
127         process.setBytes("externalReq", (value != null ? value : null));
128     }
129
130     public Object JavaDoc getExternalRequester() {
131         byte[] value = process.getBytes("externalReq");
132         return UtilObject.getObject(value);
133     }
134
135     public void setActivityRequesterId(String JavaDoc s) {
136         process.set("activityReqId", s);
137     }
138
139     public String JavaDoc getActivityRequesterId() {
140         return process.getString("activityReqId");
141     }
142
143     public void setActivityRequestersProcessId(String JavaDoc s) {
144         process.set("activityReqProcessId", s);
145     }
146
147     public String JavaDoc getActivityRequestersProcessId() {
148         return process.getString("activityReqProcessId");
149     }
150
151     public void setResourceRequesterId(String JavaDoc s) {
152         process.set("resourceReqId", s);
153     }
154
155     public String JavaDoc getResourceRequesterId() {
156         return process.getString("resourceReqId");
157     }
158
159     public void setState(String JavaDoc s) {
160         process.set("currentState", s);
161     }
162
163     public String JavaDoc getState() {
164         return process.getString("currentState");
165     }
166
167     public String JavaDoc getName() {
168         return process.getString("processName");
169     }
170
171     public void setName(String JavaDoc s) {
172         process.set("processName", s);
173     }
174
175     public String JavaDoc getDescription() {
176         return process.getString("description");
177     }
178
179     public void setDescription(String JavaDoc 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 JavaDoc(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         // remove all requesters
237
delegator.removeByAnd("WfRequester", UtilMisc.toMap("processId", this.getId()));
238     }
239 }
240
Popular Tags