1 package org.tigris.scarab.om; 2 3 4 import java.math.BigDecimal ; 5 import java.sql.Connection ; 6 import java.util.ArrayList ; 7 import java.util.Collections ; 8 import java.util.Date ; 9 import java.util.List ; 10 11 import org.apache.commons.lang.ObjectUtils; 12 import org.apache.fulcrum.intake.Retrievable; 13 import org.apache.torque.TorqueException; 14 import org.apache.torque.om.BaseObject; 15 import org.apache.torque.om.ComboKey; 16 import org.apache.torque.om.DateKey; 17 import org.apache.torque.om.NumberKey; 18 import org.apache.torque.om.ObjectKey; 19 import org.apache.torque.om.SimpleKey; 20 import org.apache.torque.om.StringKey; 21 import org.apache.torque.om.Persistent; 22 import org.apache.torque.util.Criteria; 23 import org.apache.torque.util.Transaction; 24 25 26 27 31 public abstract class BaseGlobalParameter extends BaseObject 32 implements org.apache.fulcrum.intake.Retrievable 33 { 34 35 private static final GlobalParameterPeer peer = 36 new GlobalParameterPeer(); 37 38 39 40 private Integer parameterId; 41 42 43 private String name; 44 45 46 private String value; 47 48 49 private Integer moduleId; 50 51 52 57 public Integer getParameterId() 58 { 59 return parameterId; 60 } 61 62 63 68 public void setParameterId(Integer v) 69 { 70 71 if (!ObjectUtils.equals(this.parameterId, v)) 72 { 73 this.parameterId = v; 74 setModified(true); 75 } 76 77 78 } 79 80 85 public String getName() 86 { 87 return name; 88 } 89 90 91 96 public void setName(String v) 97 { 98 99 if (!ObjectUtils.equals(this.name, v)) 100 { 101 this.name = v; 102 setModified(true); 103 } 104 105 106 } 107 108 113 public String getValue() 114 { 115 return value; 116 } 117 118 119 124 public void setValue(String v) 125 { 126 127 if (!ObjectUtils.equals(this.value, v)) 128 { 129 this.value = v; 130 setModified(true); 131 } 132 133 134 } 135 136 141 public Integer getModuleId() 142 { 143 return moduleId; 144 } 145 146 147 152 public void setModuleId(Integer v) throws TorqueException 153 { 154 155 if (!ObjectUtils.equals(this.moduleId, v)) 156 { 157 this.moduleId = v; 158 setModified(true); 159 } 160 161 162 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v)) 163 { 164 aModule = null; 165 } 166 167 } 168 169 170 171 172 private Module aModule; 173 174 180 public void setModule(Module v) throws TorqueException 181 { 182 if (v == null) 183 { 184 setModuleId((Integer ) null); 185 } 186 else 187 { 188 setModuleId(v.getModuleId()); 189 } 190 aModule = v; 191 } 192 193 194 200 public Module getModule() throws TorqueException 201 { 202 if ( !ObjectUtils.equals(getModuleId(), null) ) 203 { 204 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId())); 205 } 206 return aModule; 207 } 208 209 215 public void setModuleKey(ObjectKey key) throws TorqueException 216 { 217 218 setModuleId(new Integer (((NumberKey) key).intValue())); 219 } 220 221 222 private static List fieldNames = null; 223 224 229 public static synchronized List getFieldNames() 230 { 231 if (fieldNames == null) 232 { 233 fieldNames = new ArrayList (); 234 fieldNames.add("ParameterId"); 235 fieldNames.add("Name"); 236 fieldNames.add("Value"); 237 fieldNames.add("ModuleId"); 238 fieldNames = Collections.unmodifiableList(fieldNames); 239 } 240 return fieldNames; 241 } 242 243 249 public Object getByName(String name) 250 { 251 if (name.equals("ParameterId")) 252 { 253 return getParameterId(); 254 } 255 if (name.equals("Name")) 256 { 257 return getName(); 258 } 259 if (name.equals("Value")) 260 { 261 return getValue(); 262 } 263 if (name.equals("ModuleId")) 264 { 265 return getModuleId(); 266 } 267 return null; 268 } 269 270 278 public Object getByPeerName(String name) 279 { 280 if (name.equals(GlobalParameterPeer.PARAMETER_ID)) 281 { 282 return getParameterId(); 283 } 284 if (name.equals(GlobalParameterPeer.NAME)) 285 { 286 return getName(); 287 } 288 if (name.equals(GlobalParameterPeer.VALUE)) 289 { 290 return getValue(); 291 } 292 if (name.equals(GlobalParameterPeer.MODULE_ID)) 293 { 294 return getModuleId(); 295 } 296 return null; 297 } 298 299 306 public Object getByPosition(int pos) 307 { 308 if (pos == 0) 309 { 310 return getParameterId(); 311 } 312 if (pos == 1) 313 { 314 return getName(); 315 } 316 if (pos == 2) 317 { 318 return getValue(); 319 } 320 if (pos == 3) 321 { 322 return getModuleId(); 323 } 324 return null; 325 } 326 327 333 public void save() throws Exception 334 { 335 save(GlobalParameterPeer.getMapBuilder() 336 .getDatabaseMap().getName()); 337 } 338 339 349 public void save(String dbName) throws TorqueException 350 { 351 Connection con = null; 352 try 353 { 354 con = Transaction.begin(dbName); 355 save(con); 356 Transaction.commit(con); 357 } 358 catch(TorqueException e) 359 { 360 Transaction.safeRollback(con); 361 throw e; 362 } 363 } 364 365 367 private boolean alreadyInSave = false; 368 378 public void save(Connection con) throws TorqueException 379 { 380 if (!alreadyInSave) 381 { 382 alreadyInSave = true; 383 384 385 386 if (isModified()) 388 { 389 if (isNew()) 390 { 391 GlobalParameterPeer.doInsert((GlobalParameter)this, con); 392 setNew(false); 393 } 394 else 395 { 396 GlobalParameterPeer.doUpdate((GlobalParameter)this, con); 397 } 398 399 if (isCacheOnSave()) 400 { 401 GlobalParameterManager.putInstance(this); 402 } 403 } 404 405 alreadyInSave = false; 406 } 407 } 408 409 413 protected boolean isCacheOnSave() 414 { 415 return true; 416 } 417 418 419 424 public void setPrimaryKey(ObjectKey parameterId) 425 { 426 setParameterId(new Integer (((NumberKey)parameterId).intValue())); 427 } 428 429 434 public void setPrimaryKey(String key) 435 { 436 setParameterId(new Integer (key)); 437 } 438 439 440 444 public ObjectKey getPrimaryKey() 445 { 446 return SimpleKey.keyFor(getParameterId()); 447 } 448 449 453 public String getQueryKey() 454 { 455 if (getPrimaryKey() == null) 456 { 457 return ""; 458 } 459 else 460 { 461 return getPrimaryKey().toString(); 462 } 463 } 464 465 469 public void setQueryKey(String key) 470 throws TorqueException 471 { 472 setPrimaryKey(key); 473 } 474 475 481 public GlobalParameter copy() throws TorqueException 482 { 483 GlobalParameter copyObj = new GlobalParameter(); 484 copyObj.setParameterId(parameterId); 485 copyObj.setName(name); 486 copyObj.setValue(value); 487 copyObj.setModuleId(moduleId); 488 489 copyObj.setParameterId((Integer )null); 490 491 return copyObj; 492 } 493 494 500 public GlobalParameterPeer getPeer() 501 { 502 return peer; 503 } 504 505 public String toString() 506 { 507 StringBuffer str = new StringBuffer (); 508 str.append("GlobalParameter:\n"); 509 str.append("ParameterId = ") 510 .append(getParameterId()) 511 .append("\n"); 512 str.append("Name = ") 513 .append(getName()) 514 .append("\n"); 515 str.append("Value = ") 516 .append(getValue()) 517 .append("\n"); 518 str.append("ModuleId = ") 519 .append(getModuleId()) 520 .append("\n"); 521 return(str.toString()); 522 } 523 } 524 | Popular Tags |