KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > shark > mapping > EntityParticipantMap


1 /*
2  * $Id: EntityParticipantMap.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.mapping;
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.partmappersistence.ParticipantMap;
35 import org.enhydra.shark.api.RootException;
36
37 /**
38  * Shark Participant Map Implementation
39  *
40  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
41  * @version $Rev: 5462 $
42  * @since 3.1
43  */

44 public class EntityParticipantMap implements ParticipantMap {
45
46     public static final String JavaDoc module = EntityParticipantMap.class.getName();
47     
48     protected GenericDelegator delegator = null;
49     protected GenericValue participant = null;
50     protected boolean newValue = false;
51
52     protected EntityParticipantMap(GenericDelegator delegator, String JavaDoc packageId, String JavaDoc processDefId, String JavaDoc participantId) throws RootException {
53         this.delegator = delegator;
54         try {
55             this.participant = delegator.findByPrimaryKey("WfParticipantMap", UtilMisc.toMap("packageId", packageId, "processDefId", processDefId, "participantId", participantId));
56         } catch (GenericEntityException e) {
57             throw new RootException(e);
58         }
59     }
60
61     protected EntityParticipantMap(GenericValue application) {
62         this.participant = application;
63         this.delegator = application.getDelegator();
64     }
65
66     public EntityParticipantMap(GenericDelegator delegator) {
67         this.newValue = true;
68         this.delegator = delegator;
69
70         this.participant = delegator.makeValue("WfParticipantMap", UtilMisc.toMap("participantMapId", delegator.getNextSeqId("WfParticipantMap")));
71     }
72
73     public static EntityParticipantMap getInstance(GenericValue participant) {
74         EntityParticipantMap part = new EntityParticipantMap(participant);
75         if (part.isLoaded()) {
76             return part;
77         }
78         return null;
79     }
80
81     public static EntityParticipantMap getInstance(String JavaDoc packageId, String JavaDoc processDefId, String JavaDoc participantId) throws RootException {
82         EntityParticipantMap part = new EntityParticipantMap(SharkContainer.getDelegator(), packageId, processDefId, participantId);
83         if (part.isLoaded()) {
84             return part;
85         }
86         return null;
87     }
88
89     public boolean isLoaded() {
90         if (participant == null) {
91             return false;
92         }
93         return true;
94     }
95
96     public void setParticipantId(String JavaDoc participantId) {
97         participant.set("participantId", participantId);
98     }
99
100     public String JavaDoc getParticipantId() {
101         return participant.getString("participantId");
102     }
103
104     public void setPackageId(String JavaDoc packageId) {
105         participant.set("packageId", packageId);
106     }
107
108     public String JavaDoc getPackageId() {
109         return participant.getString("participantId");
110     }
111
112     public void setProcessDefinitionId(String JavaDoc processDefId) {
113         participant.set("processDefId", processDefId);
114     }
115
116     public String JavaDoc getProcessDefinitionId() {
117         return participant.getString("processDefId");
118     }
119
120     public void setUsername(String JavaDoc userName) {
121         participant.set("userName", userName);
122     }
123
124     public String JavaDoc getUsername() {
125         return participant.getString("userName");
126     }
127
128     public boolean getIsGroupUser() {
129         return (participant.getBoolean("isGroupUser") != null ? participant.getBoolean("isGroupUser").booleanValue() : false);
130     }
131
132     public void setIsGroupUser(boolean isGroupUser) {
133         participant.set("isGroupUser", new Boolean JavaDoc(isGroupUser));
134     }
135
136     public void store() throws RootException {
137         if (newValue) {
138             try {
139                 delegator.create(participant);
140                 newValue = false;
141             } catch (GenericEntityException e) {
142                 throw new RootException(e);
143             }
144         } else {
145             try {
146                 delegator.store(participant);
147             } catch (GenericEntityException e) {
148                 throw new RootException(e);
149             }
150         }
151     }
152
153     public void reload() throws RootException {
154         if (!newValue) {
155             try {
156                 delegator.refresh(participant);
157             } catch (GenericEntityException e) {
158                 throw new RootException(e);
159             }
160         }
161     }
162
163     public void remove() throws RootException {
164         Debug.log("::Remove Participant Map::", module);
165         if (!newValue) {
166             try {
167                 delegator.removeValue(participant);
168             } catch (GenericEntityException e) {
169                 throw new RootException(e);
170             }
171         }
172     }
173 }
174
Popular Tags