KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ProcessMgr.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.GenericValue;
28 import org.ofbiz.entity.GenericDelegator;
29 import org.ofbiz.entity.GenericEntityException;
30 import org.ofbiz.base.util.UtilMisc;
31 import org.ofbiz.base.util.Debug;
32 import org.ofbiz.shark.container.SharkContainer;
33
34 import org.enhydra.shark.api.internal.instancepersistence.*;
35
36 /**
37  * Persistance Object
38  *
39  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
40  * @version $Rev: 5462 $
41  * @since 3.1
42  */

43 public class ProcessMgr extends InstanceEntityObject implements ProcessMgrPersistenceInterface {
44
45     public static final String JavaDoc module = ProcessMgr.class.getName();
46     
47     protected GenericValue processMgr = null;
48     protected boolean newValue = false;
49
50     protected ProcessMgr(EntityPersistentMgr mgr, GenericDelegator delegator, String JavaDoc name) throws PersistenceException {
51         super(mgr, delegator);
52         if (this.delegator != null) {
53             try {
54                 this.processMgr = delegator.findByPrimaryKey("WfProcessMgr", UtilMisc.toMap("mgrName", name));
55             } catch (GenericEntityException e) {
56                 throw new PersistenceException(e);
57             }
58         } else {
59             Debug.logError("Invalid delegator object passed", module);
60         }
61     }
62
63     protected ProcessMgr(EntityPersistentMgr mgr, GenericValue processMgr) {
64         super(mgr, processMgr.getDelegator());
65         this.processMgr = processMgr;
66     }
67
68     public ProcessMgr(EntityPersistentMgr mgr, GenericDelegator delegator) {
69         super(mgr, delegator);
70         this.newValue = true;
71         this.processMgr = delegator.makeValue("WfProcessMgr", UtilMisc.toMap("currentState", new Long JavaDoc(0)));
72     }
73
74     public static ProcessMgr getInstance(EntityPersistentMgr pmgr, GenericValue processMgr) {
75         ProcessMgr mgr = new ProcessMgr(pmgr, processMgr);
76         if (mgr.isLoaded()) {
77             return mgr;
78         }
79         return null;
80     }
81
82     public static ProcessMgr getInstance(EntityPersistentMgr pmgr, String JavaDoc name) throws PersistenceException {
83         ProcessMgr mgr = new ProcessMgr(pmgr, SharkContainer.getDelegator(), name);
84         if (mgr.isLoaded()) {
85             return mgr;
86         }
87         return null;
88     }
89
90     public boolean isLoaded() {
91         if (processMgr == null) {
92             return false;
93         }
94         return true;
95     }
96
97     public void setName(String JavaDoc name) {
98         processMgr.set("mgrName", name);
99     }
100
101     public String JavaDoc getName() {
102         return processMgr.getString("mgrName");
103     }
104
105     public void setPackageId(String JavaDoc pkgId) {
106         processMgr.set("packageId", pkgId);
107     }
108
109     public String JavaDoc getPackageId() {
110         return processMgr.getString("packageId");
111     }
112
113     public void setProcessDefinitionId(String JavaDoc pdId) {
114         processMgr.set("definitionId", pdId);
115     }
116
117     public String JavaDoc getProcessDefinitionId() {
118         return processMgr.getString("definitionId");
119     }
120
121     public void setState(int state) {
122         processMgr.set("currentState", new Long JavaDoc(state));
123     }
124
125     public int getState() {
126         return processMgr.getLong("currentState").intValue();
127     }
128
129     public String JavaDoc getVersion() {
130         return processMgr.getString("packageVer");
131     }
132
133     public void setVersion(String JavaDoc version) {
134         processMgr.set("packageVer", version);
135     }
136
137     public String JavaDoc getCreated() {
138         return processMgr.getString("created");
139     }
140
141     public void setCreated(String JavaDoc created) {
142         processMgr.set("created", created);
143     }
144
145     public void store() throws GenericEntityException {
146         if (newValue) {
147             delegator.createOrStore(processMgr);
148             newValue = false;
149         } else {
150             delegator.store(processMgr);
151         }
152     }
153
154     public void reload() throws GenericEntityException {
155         if (!newValue) {
156             processMgr.refresh();
157         }
158     }
159
160     public void remove() throws GenericEntityException {
161         if (!newValue) {
162             delegator.removeValue(processMgr);
163             Debug.log("**** REMOVED : " + this, module);
164         }
165     }
166 }
167
Popular Tags