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 28 29 33 public abstract class BaseRModuleOption extends BaseObject 34 implements org.apache.fulcrum.intake.Retrievable 35 { 36 37 private static final RModuleOptionPeer peer = 38 new RModuleOptionPeer(); 39 40 41 42 private Integer moduleId; 43 44 45 private Integer issueTypeId; 46 47 48 private Integer optionId; 49 50 51 private String displayValue; 52 53 54 private boolean active = true; 55 56 57 private int order = -1; 58 59 60 private int weight = -1; 61 62 63 68 public Integer getModuleId() 69 { 70 return moduleId; 71 } 72 73 74 79 public void setModuleId(Integer v) throws TorqueException 80 { 81 82 if (!ObjectUtils.equals(this.moduleId, v)) 83 { 84 this.moduleId = v; 85 setModified(true); 86 } 87 88 89 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v)) 90 { 91 aModule = null; 92 } 93 94 } 95 96 101 public Integer getIssueTypeId() 102 { 103 return issueTypeId; 104 } 105 106 107 112 public void setIssueTypeId(Integer v) throws TorqueException 113 { 114 115 if (!ObjectUtils.equals(this.issueTypeId, v)) 116 { 117 this.issueTypeId = v; 118 setModified(true); 119 } 120 121 122 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v)) 123 { 124 aIssueType = null; 125 } 126 127 } 128 129 134 public Integer getOptionId() 135 { 136 return optionId; 137 } 138 139 140 145 public void setOptionId(Integer v) throws TorqueException 146 { 147 148 if (!ObjectUtils.equals(this.optionId, v)) 149 { 150 this.optionId = v; 151 setModified(true); 152 } 153 154 155 if (aAttributeOption != null && !ObjectUtils.equals(aAttributeOption.getOptionId(), v)) 156 { 157 aAttributeOption = null; 158 } 159 160 } 161 162 167 public String getDisplayValue() 168 { 169 return displayValue; 170 } 171 172 173 178 public void setDisplayValue(String v) 179 { 180 181 if (!ObjectUtils.equals(this.displayValue, v)) 182 { 183 this.displayValue = v; 184 setModified(true); 185 } 186 187 188 } 189 190 195 public boolean getActive() 196 { 197 return active; 198 } 199 200 201 206 public void setActive(boolean v) 207 { 208 209 if (this.active != v) 210 { 211 this.active = v; 212 setModified(true); 213 } 214 215 216 } 217 218 223 public int getOrder() 224 { 225 return order; 226 } 227 228 229 234 public void setOrder(int v) 235 { 236 237 if (this.order != v) 238 { 239 this.order = v; 240 setModified(true); 241 } 242 243 244 } 245 246 251 public int getWeight() 252 { 253 return weight; 254 } 255 256 257 262 public void setWeight(int v) 263 { 264 265 if (this.weight != v) 266 { 267 this.weight = v; 268 setModified(true); 269 } 270 271 272 } 273 274 275 276 277 private AttributeOption aAttributeOption; 278 279 285 public void setAttributeOption(AttributeOption v) throws TorqueException 286 { 287 if (v == null) 288 { 289 setOptionId((Integer ) null); 290 } 291 else 292 { 293 setOptionId(v.getOptionId()); 294 } 295 aAttributeOption = v; 296 } 297 298 299 305 public AttributeOption getAttributeOption() throws TorqueException 306 { 307 if ( !ObjectUtils.equals(getOptionId(), null) ) 308 { 309 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOptionId())); 310 } 311 return aAttributeOption; 312 } 313 314 320 public void setAttributeOptionKey(ObjectKey key) throws TorqueException 321 { 322 323 setOptionId(new Integer (((NumberKey) key).intValue())); 324 } 325 326 327 328 private Module aModule; 329 330 336 public void setModule(Module v) throws TorqueException 337 { 338 if (v == null) 339 { 340 setModuleId((Integer ) null); 341 } 342 else 343 { 344 setModuleId(v.getModuleId()); 345 } 346 aModule = v; 347 } 348 349 350 356 public Module getModule() throws TorqueException 357 { 358 if ( !ObjectUtils.equals(getModuleId(), null) ) 359 { 360 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId())); 361 } 362 return aModule; 363 } 364 365 371 public void setModuleKey(ObjectKey key) throws TorqueException 372 { 373 374 setModuleId(new Integer (((NumberKey) key).intValue())); 375 } 376 377 378 379 private IssueType aIssueType; 380 381 387 public void setIssueType(IssueType v) throws TorqueException 388 { 389 if (v == null) 390 { 391 setIssueTypeId((Integer ) null); 392 } 393 else 394 { 395 setIssueTypeId(v.getIssueTypeId()); 396 } 397 aIssueType = v; 398 } 399 400 401 407 public IssueType getIssueType() throws TorqueException 408 { 409 if ( !ObjectUtils.equals(getIssueTypeId(), null) ) 410 { 411 return IssueTypeManager.getInstance(SimpleKey.keyFor(getIssueTypeId())); 412 } 413 return aIssueType; 414 } 415 416 422 public void setIssueTypeKey(ObjectKey key) throws TorqueException 423 { 424 425 setIssueTypeId(new Integer (((NumberKey) key).intValue())); 426 } 427 428 429 private static List fieldNames = null; 430 431 436 public static synchronized List getFieldNames() 437 { 438 if (fieldNames == null) 439 { 440 fieldNames = new ArrayList (); 441 fieldNames.add("ModuleId"); 442 fieldNames.add("IssueTypeId"); 443 fieldNames.add("OptionId"); 444 fieldNames.add("DisplayValue"); 445 fieldNames.add("Active"); 446 fieldNames.add("Order"); 447 fieldNames.add("Weight"); 448 fieldNames = Collections.unmodifiableList(fieldNames); 449 } 450 return fieldNames; 451 } 452 453 459 public Object getByName(String name) 460 { 461 if (name.equals("ModuleId")) 462 { 463 return getModuleId(); 464 } 465 if (name.equals("IssueTypeId")) 466 { 467 return getIssueTypeId(); 468 } 469 if (name.equals("OptionId")) 470 { 471 return getOptionId(); 472 } 473 if (name.equals("DisplayValue")) 474 { 475 return getDisplayValue(); 476 } 477 if (name.equals("Active")) 478 { 479 return Boolean.valueOf(getActive()); 480 } 481 if (name.equals("Order")) 482 { 483 return new Integer (getOrder()); 484 } 485 if (name.equals("Weight")) 486 { 487 return new Integer (getWeight()); 488 } 489 return null; 490 } 491 492 500 public Object getByPeerName(String name) 501 { 502 if (name.equals(RModuleOptionPeer.MODULE_ID)) 503 { 504 return getModuleId(); 505 } 506 if (name.equals(RModuleOptionPeer.ISSUE_TYPE_ID)) 507 { 508 return getIssueTypeId(); 509 } 510 if (name.equals(RModuleOptionPeer.OPTION_ID)) 511 { 512 return getOptionId(); 513 } 514 if (name.equals(RModuleOptionPeer.DISPLAY_VALUE)) 515 { 516 return getDisplayValue(); 517 } 518 if (name.equals(RModuleOptionPeer.ACTIVE)) 519 { 520 return Boolean.valueOf(getActive()); 521 } 522 if (name.equals(RModuleOptionPeer.PREFERRED_ORDER)) 523 { 524 return new Integer (getOrder()); 525 } 526 if (name.equals(RModuleOptionPeer.WEIGHT)) 527 { 528 return new Integer (getWeight()); 529 } 530 return null; 531 } 532 533 540 public Object getByPosition(int pos) 541 { 542 if (pos == 0) 543 { 544 return getModuleId(); 545 } 546 if (pos == 1) 547 { 548 return getIssueTypeId(); 549 } 550 if (pos == 2) 551 { 552 return getOptionId(); 553 } 554 if (pos == 3) 555 { 556 return getDisplayValue(); 557 } 558 if (pos == 4) 559 { 560 return Boolean.valueOf(getActive()); 561 } 562 if (pos == 5) 563 { 564 return new Integer (getOrder()); 565 } 566 if (pos == 6) 567 { 568 return new Integer (getWeight()); 569 } 570 return null; 571 } 572 573 579 public void save() throws Exception 580 { 581 save(RModuleOptionPeer.getMapBuilder() 582 .getDatabaseMap().getName()); 583 } 584 585 595 public void save(String dbName) throws TorqueException 596 { 597 Connection con = null; 598 try 599 { 600 con = Transaction.begin(dbName); 601 save(con); 602 Transaction.commit(con); 603 } 604 catch(TorqueException e) 605 { 606 Transaction.safeRollback(con); 607 throw e; 608 } 609 } 610 611 613 private boolean alreadyInSave = false; 614 624 public void save(Connection con) throws TorqueException 625 { 626 if (!alreadyInSave) 627 { 628 alreadyInSave = true; 629 630 631 632 if (isModified()) 634 { 635 if (isNew()) 636 { 637 RModuleOptionPeer.doInsert((RModuleOption)this, con); 638 setNew(false); 639 } 640 else 641 { 642 RModuleOptionPeer.doUpdate((RModuleOption)this, con); 643 } 644 645 if (isCacheOnSave()) 646 { 647 RModuleOptionManager.putInstance(this); 648 } 649 } 650 651 alreadyInSave = false; 652 } 653 } 654 655 659 protected boolean isCacheOnSave() 660 { 661 return true; 662 } 663 664 665 666 private final SimpleKey[] pks = new SimpleKey[3]; 667 private final ComboKey comboPK = new ComboKey(pks); 668 669 674 public void setPrimaryKey(ObjectKey key) throws TorqueException 675 { 676 SimpleKey[] keys = (SimpleKey[]) key.getValue(); 677 SimpleKey tmpKey = null; 678 setModuleId(new Integer (((NumberKey)keys[0]).intValue())); 679 setIssueTypeId(new Integer (((NumberKey)keys[1]).intValue())); 680 setOptionId(new Integer (((NumberKey)keys[2]).intValue())); 681 } 682 683 690 public void setPrimaryKey( Integer moduleId, Integer issueTypeId, Integer optionId) 691 throws TorqueException 692 { 693 setModuleId(moduleId); 694 setIssueTypeId(issueTypeId); 695 setOptionId(optionId); 696 } 697 698 701 public void setPrimaryKey(String key) throws TorqueException 702 { 703 setPrimaryKey(new ComboKey(key)); 704 } 705 706 710 public ObjectKey getPrimaryKey() 711 { 712 pks[0] = SimpleKey.keyFor(getModuleId()); 713 pks[1] = SimpleKey.keyFor(getIssueTypeId()); 714 pks[2] = SimpleKey.keyFor(getOptionId()); 715 return comboPK; 716 } 717 718 722 public String getQueryKey() 723 { 724 if (getPrimaryKey() == null) 725 { 726 return ""; 727 } 728 else 729 { 730 return getPrimaryKey().toString(); 731 } 732 } 733 734 738 public void setQueryKey(String key) 739 throws TorqueException 740 { 741 setPrimaryKey(key); 742 } 743 744 750 public RModuleOption copy() throws TorqueException 751 { 752 RModuleOption copyObj = new RModuleOption(); 753 copyObj.setModuleId(moduleId); 754 copyObj.setIssueTypeId(issueTypeId); 755 copyObj.setOptionId(optionId); 756 copyObj.setDisplayValue(displayValue); 757 copyObj.setActive(active); 758 copyObj.setOrder(order); 759 copyObj.setWeight(weight); 760 761 copyObj.setModuleId((Integer )null); 762 copyObj.setIssueTypeId((Integer )null); 763 copyObj.setOptionId((Integer )null); 764 765 return copyObj; 766 } 767 768 774 public RModuleOptionPeer getPeer() 775 { 776 return peer; 777 } 778 779 public String toString() 780 { 781 StringBuffer str = new StringBuffer (); 782 str.append("RModuleOption:\n"); 783 str.append("ModuleId = ") 784 .append(getModuleId()) 785 .append("\n"); 786 str.append("IssueTypeId = ") 787 .append(getIssueTypeId()) 788 .append("\n"); 789 str.append("OptionId = ") 790 .append(getOptionId()) 791 .append("\n"); 792 str.append("DisplayValue = ") 793 .append(getDisplayValue()) 794 .append("\n"); 795 str.append("Active = ") 796 .append(getActive()) 797 .append("\n"); 798 str.append("Order = ") 799 .append(getOrder()) 800 .append("\n"); 801 str.append("Weight = ") 802 .append(getWeight()) 803 .append("\n"); 804 return(str.toString()); 805 } 806 } 807 | Popular Tags |