KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: Assignment.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.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 Assignment extends InstanceEntityObject implements AssignmentPersistenceInterface {
44
45     public static final String JavaDoc module = Assignment.class.getName();
46
47     protected GenericValue assignment = null;
48     protected boolean newValue = false;
49
50     protected Assignment(EntityPersistentMgr mgr, GenericDelegator delegator, String JavaDoc activityId, String JavaDoc userName) throws PersistenceException {
51         super(mgr, delegator);
52         if (this.delegator != null) {
53             try {
54                 this.assignment = delegator.findByPrimaryKey("WfAssignment", UtilMisc.toMap("activityId", activityId, "userName", userName));
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 Assignment(EntityPersistentMgr mgr, GenericValue assignment) {
64         super(mgr, assignment.getDelegator());
65         this.assignment = assignment;
66     }
67
68     public Assignment(EntityPersistentMgr mgr, GenericDelegator delegator) {
69         super(mgr, delegator);
70         this.newValue = true;
71         this.assignment = delegator.makeValue("WfAssignment", null);
72         Debug.log("******* New assignment created", module);
73     }
74
75     public static Assignment getInstance(EntityPersistentMgr mgr, GenericValue assignment) {
76         Assignment assign = new Assignment(mgr, assignment);
77         if (assign.isLoaded()) {
78             return assign;
79         }
80         return null;
81     }
82
83     public static Assignment getInstance(EntityPersistentMgr mgr, String JavaDoc activityId, String JavaDoc userName) throws PersistenceException {
84         Assignment assign = new Assignment(mgr, SharkContainer.getDelegator(), activityId, userName);
85         if (assign.isLoaded()) {
86             return assign;
87         }
88         return null;
89     }
90
91     public boolean isLoaded() {
92         if (assignment == null) {
93             return false;
94         }
95         return true;
96     }
97
98     public void setActivityId(String JavaDoc actId) {
99         assignment.set("activityId", actId);
100         Debug.log("Set activityId on assignment : " + actId, module);
101         // set the processId - kludge
102
/* should not be needed anymore
103         try {
104             Activity activity = Activity.getInstance(actId);
105             if (activity != null) {
106                 this.setProcessId(activity.getProcessId());
107             }
108         } catch (PersistenceException e) {
109             Debug.logError(e, module);
110         }
111         */

112     }
113
114     public String JavaDoc getActivityId() {
115         return assignment.getString("activityId");
116     }
117
118     public void setResourceUsername(String JavaDoc username) {
119         assignment.set("userName", username);
120         Debug.log("Set userName on assignment : " + username, module);
121     }
122
123     public String JavaDoc getResourceUsername() {
124         return assignment.getString("userName");
125     }
126
127     public void setProcessId(String JavaDoc procId) {
128         assignment.set("processId", procId);
129         Debug.log("Set processId on assignment : " + procId, module);
130     }
131
132     public String JavaDoc getProcessId() {
133         return assignment.getString("processId");
134     }
135
136     public void setValid(boolean valid) {
137         assignment.set("isValid", valid ? "Y" : "N");
138     }
139
140     public boolean isValid() {
141         return (assignment.get("isValid") == null ? false : "Y".equalsIgnoreCase(assignment.getString("isValid")));
142     }
143
144     public void store() throws GenericEntityException {
145         if (newValue) {
146             delegator.createOrStore(assignment);
147             newValue = false;
148         } else {
149             delegator.store(assignment);
150         }
151         Debug.log("Stored assignment : " + assignment, module);
152     }
153
154     public void reload() throws GenericEntityException {
155         if (!newValue) {
156             assignment.refresh();
157         }
158     }
159
160     public void remove() throws GenericEntityException {
161         if (!newValue) {
162             delegator.removeValue(assignment);
163             Debug.log("**** REMOVED : " + this, module);
164         }
165     }
166 }
167
Popular Tags