1 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 43 public class Assignment extends InstanceEntityObject implements AssignmentPersistenceInterface { 44 45 public static final String module = Assignment.class.getName(); 46 47 protected GenericValue assignment = null; 48 protected boolean newValue = false; 49 50 protected Assignment(EntityPersistentMgr mgr, GenericDelegator delegator, String activityId, String 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 activityId, String 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 actId) { 99 assignment.set("activityId", actId); 100 Debug.log("Set activityId on assignment : " + actId, module); 101 112 } 113 114 public String getActivityId() { 115 return assignment.getString("activityId"); 116 } 117 118 public void setResourceUsername(String username) { 119 assignment.set("userName", username); 120 Debug.log("Set userName on assignment : " + username, module); 121 } 122 123 public String getResourceUsername() { 124 return assignment.getString("userName"); 125 } 126 127 public void setProcessId(String procId) { 128 assignment.set("processId", procId); 129 Debug.log("Set processId on assignment : " + procId, module); 130 } 131 132 public String 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 |