1 25 package org.ofbiz.shark.instance; 26 27 import org.ofbiz.base.util.Debug; 28 import org.ofbiz.base.util.UtilMisc; 29 import org.ofbiz.base.util.UtilObject; 30 import org.ofbiz.entity.GenericDelegator; 31 import org.ofbiz.entity.GenericEntityException; 32 import org.ofbiz.entity.GenericValue; 33 import org.ofbiz.shark.container.SharkContainer; 34 35 import org.enhydra.shark.api.internal.instancepersistence.ActivityVariablePersistenceInterface; 36 import org.enhydra.shark.api.internal.instancepersistence.PersistenceException; 37 38 45 public class ActivityVariable extends InstanceEntityObject implements ActivityVariablePersistenceInterface { 46 47 public static final String module = ActivityVariable.class.getName(); 48 49 protected GenericValue activityVariable = null; 50 protected boolean newValue = false; 51 52 protected ActivityVariable(EntityPersistentMgr mgr, GenericDelegator delegator, String activityVariableId) throws PersistenceException { 53 super(mgr, delegator); 54 this.delegator = delegator; 55 if (this.delegator != null) { 56 try { 57 this.activityVariable = delegator.findByPrimaryKey("WfActivityVariable", UtilMisc.toMap("activityVariableId", activityVariableId)); 58 } catch (GenericEntityException e) { 59 throw new PersistenceException(e); 60 } 61 } else { 62 Debug.logError("Invalid delegator object passed", module); 63 } 64 } 65 66 protected ActivityVariable(EntityPersistentMgr mgr, GenericValue activityVariable) { 67 super(mgr, activityVariable.getDelegator()); 68 this.activityVariable = activityVariable; 69 } 70 71 public ActivityVariable(EntityPersistentMgr mgr, GenericDelegator delegator) { 72 super(mgr, delegator); 73 this.newValue = true; 74 this.activityVariable = delegator.makeValue("WfActivityVariable", UtilMisc.toMap("activityVariableId", delegator.getNextSeqId("WfActivityVariable"))); 75 Debug.log("******* New activity variable created", module); 76 } 77 78 public static ActivityVariable getInstance(EntityPersistentMgr mgr, GenericValue activityVariable) { 79 ActivityVariable var = new ActivityVariable(mgr, activityVariable); 80 if (var.isLoaded()) { 81 return var; 82 } 83 return null; 84 } 85 86 public static ActivityVariable getInstance(EntityPersistentMgr mgr, String activityVariableId) throws PersistenceException { 87 ActivityVariable var = new ActivityVariable(mgr, SharkContainer.getDelegator(), activityVariableId); 88 if (var.isLoaded()) { 89 return var; 90 } 91 return null; 92 } 93 94 public boolean isLoaded() { 95 if (activityVariable == null) { 96 return false; 97 } 98 return true; 99 } 100 101 public void setActivityId(String aId) { 102 activityVariable.set("activityId", aId); 103 } 104 105 public String getActivityId() { 106 return activityVariable.getString("activityId"); 107 } 108 109 public void setDefinitionId(String defId) { 110 activityVariable.set("definitionId", defId); 111 } 112 113 public String getDefinitionId() { 114 return activityVariable.getString("definitionId"); 115 } 116 117 public void setValue(Object val) { 118 if (val instanceof String ) { 119 activityVariable.set("valueField", "strValue"); 120 activityVariable.set("strValue", val); 121 } else if (val instanceof Number ) { 122 if (val instanceof Double ) { 123 activityVariable.set("valueField", "dblValue"); 124 activityVariable.set("dblValue", val); 125 } else { 126 activityVariable.set("valueField", "numValue"); 127 activityVariable.set("numValue", val); 128 } 129 } else { 130 byte[] value = UtilObject.getBytes(val); 131 activityVariable.setBytes("objValue", (value != null ? value : null)); 132 } 133 } 134 135 public Object getValue() { 136 String fieldName = activityVariable.getString("valueField"); 137 if ("objValue".equals(fieldName)) { 138 byte[] value = activityVariable.getBytes(fieldName); 139 return UtilObject.getObject(value); 140 } else { 141 return activityVariable.get(fieldName); 142 } 143 } 144 145 public void setResultVariable(boolean modified) { 146 activityVariable.set("isModified", (modified ? "Y" : "N")); 147 } 148 149 public boolean isResultVariable() { 150 return (activityVariable.get("isModified") != null ? 151 ("Y".equals(activityVariable.getString("isModified")) ? true : false) : false); 152 } 153 154 public void store() throws GenericEntityException { 155 if (newValue) { 156 delegator.createOrStore(activityVariable); 157 newValue = false; 158 } else { 159 delegator.store(activityVariable); 160 } 161 } 162 163 public void reload() throws GenericEntityException { 164 if (!newValue) { 165 activityVariable.refresh(); 166 } 167 } 168 169 public void remove() throws GenericEntityException { 170 if (!newValue) { 171 delegator.removeValue(activityVariable); 172 } 173 } 174 } 175 | Popular Tags |