1 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 44 public class EntityParticipantMap implements ParticipantMap { 45 46 public static final String 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 packageId, String processDefId, String 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 packageId, String processDefId, String 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 participantId) { 97 participant.set("participantId", participantId); 98 } 99 100 public String getParticipantId() { 101 return participant.getString("participantId"); 102 } 103 104 public void setPackageId(String packageId) { 105 participant.set("packageId", packageId); 106 } 107 108 public String getPackageId() { 109 return participant.getString("participantId"); 110 } 111 112 public void setProcessDefinitionId(String processDefId) { 113 participant.set("processDefId", processDefId); 114 } 115 116 public String getProcessDefinitionId() { 117 return participant.getString("processDefId"); 118 } 119 120 public void setUsername(String userName) { 121 participant.set("userName", userName); 122 } 123 124 public String 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 (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 |