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 30 31 35 public abstract class BaseCondition extends BaseObject 36 implements org.apache.fulcrum.intake.Retrievable 37 { 38 39 private static final ConditionPeer peer = 40 new ConditionPeer(); 41 42 43 44 private Long conditionId; 45 46 47 private Integer transitionId; 48 49 50 private Integer moduleId; 51 52 53 private Integer issueTypeId; 54 55 56 private Integer attributeId; 57 58 59 private Integer optionId; 60 61 62 67 public Long getConditionId() 68 { 69 return conditionId; 70 } 71 72 73 78 public void setConditionId(Long v) 79 { 80 81 if (!ObjectUtils.equals(this.conditionId, v)) 82 { 83 this.conditionId = v; 84 setModified(true); 85 } 86 87 88 } 89 90 95 public Integer getTransitionId() 96 { 97 return transitionId; 98 } 99 100 101 106 public void setTransitionId(Integer v) throws TorqueException 107 { 108 109 if (!ObjectUtils.equals(this.transitionId, v)) 110 { 111 this.transitionId = v; 112 setModified(true); 113 } 114 115 116 if (aTransition != null && !ObjectUtils.equals(aTransition.getTransitionId(), v)) 117 { 118 aTransition = null; 119 } 120 121 } 122 123 128 public Integer getModuleId() 129 { 130 return moduleId; 131 } 132 133 134 139 public void setModuleId(Integer v) throws TorqueException 140 { 141 142 if (!ObjectUtils.equals(this.moduleId, v)) 143 { 144 this.moduleId = v; 145 setModified(true); 146 } 147 148 149 if (aRModuleAttribute != null && !ObjectUtils.equals(aRModuleAttribute.getModuleId(), v)) 150 { 151 aRModuleAttribute = null; 152 } 153 154 } 155 156 161 public Integer getIssueTypeId() 162 { 163 return issueTypeId; 164 } 165 166 167 172 public void setIssueTypeId(Integer v) throws TorqueException 173 { 174 175 if (!ObjectUtils.equals(this.issueTypeId, v)) 176 { 177 this.issueTypeId = v; 178 setModified(true); 179 } 180 181 182 if (aRModuleAttribute != null && !ObjectUtils.equals(aRModuleAttribute.getIssueTypeId(), v)) 183 { 184 aRModuleAttribute = null; 185 } 186 187 } 188 189 194 public Integer getAttributeId() 195 { 196 return attributeId; 197 } 198 199 200 205 public void setAttributeId(Integer v) throws TorqueException 206 { 207 208 if (!ObjectUtils.equals(this.attributeId, v)) 209 { 210 this.attributeId = v; 211 setModified(true); 212 } 213 214 215 if (aRModuleAttribute != null && !ObjectUtils.equals(aRModuleAttribute.getAttributeId(), v)) 216 { 217 aRModuleAttribute = null; 218 } 219 220 } 221 222 227 public Integer getOptionId() 228 { 229 return optionId; 230 } 231 232 233 238 public void setOptionId(Integer v) throws TorqueException 239 { 240 241 if (!ObjectUtils.equals(this.optionId, v)) 242 { 243 this.optionId = v; 244 setModified(true); 245 } 246 247 248 if (aAttributeOption != null && !ObjectUtils.equals(aAttributeOption.getOptionId(), v)) 249 { 250 aAttributeOption = null; 251 } 252 253 } 254 255 256 257 258 private RModuleAttribute aRModuleAttribute; 259 260 266 public void setRModuleAttribute(RModuleAttribute v) throws TorqueException 267 { 268 if (v == null) 269 { 270 setModuleId((Integer ) null); 271 } 272 else 273 { 274 setModuleId(v.getModuleId()); 275 } 276 if (v == null) 277 { 278 setAttributeId((Integer ) null); 279 } 280 else 281 { 282 setAttributeId(v.getAttributeId()); 283 } 284 if (v == null) 285 { 286 setIssueTypeId((Integer ) null); 287 } 288 else 289 { 290 setIssueTypeId(v.getIssueTypeId()); 291 } 292 aRModuleAttribute = v; 293 } 294 295 296 302 public RModuleAttribute getRModuleAttribute() throws TorqueException 303 { 304 if ( !ObjectUtils.equals(getModuleId(), null) && !ObjectUtils.equals(getAttributeId(), null) && !ObjectUtils.equals(getIssueTypeId(), null) ) 305 { 306 SimpleKey[] keys = { SimpleKey.keyFor(getModuleId()), SimpleKey.keyFor(getAttributeId()), SimpleKey.keyFor(getIssueTypeId()) }; 307 return RModuleAttributeManager.getInstance(new ComboKey(keys)); 308 } 309 return aRModuleAttribute; 310 } 311 312 323 public void setRModuleAttributeKey(ObjectKey key) throws TorqueException 324 { 325 SimpleKey[] keys = (SimpleKey[])key.getValue(); 326 setModuleId(new Integer (((NumberKey) keys[0]).intValue())); 327 328 setAttributeId(new Integer (((NumberKey) keys[1]).intValue())); 329 330 setIssueTypeId(new Integer (((NumberKey) keys[2]).intValue())); 331 332 } 333 334 335 336 private Transition aTransition; 337 338 344 public void setTransition(Transition v) throws TorqueException 345 { 346 if (v == null) 347 { 348 setTransitionId((Integer ) null); 349 } 350 else 351 { 352 setTransitionId(v.getTransitionId()); 353 } 354 aTransition = v; 355 } 356 357 358 364 public Transition getTransition() throws TorqueException 365 { 366 if ( !ObjectUtils.equals(getTransitionId(), null) ) 367 { 368 return TransitionManager.getInstance(SimpleKey.keyFor(getTransitionId())); 369 } 370 return aTransition; 371 } 372 373 379 public void setTransitionKey(ObjectKey key) throws TorqueException 380 { 381 382 setTransitionId(new Integer (((NumberKey) key).intValue())); 383 } 384 385 386 387 private Attribute aAttribute; 388 389 395 public void setAttribute(Attribute v) throws TorqueException 396 { 397 if (v == null) 398 { 399 setAttributeId((Integer ) null); 400 } 401 else 402 { 403 setAttributeId(v.getAttributeId()); 404 } 405 aAttribute = v; 406 } 407 408 409 415 public Attribute getAttribute() throws TorqueException 416 { 417 if ( !ObjectUtils.equals(getAttributeId(), null) ) 418 { 419 return AttributeManager.getInstance(SimpleKey.keyFor(getAttributeId())); 420 } 421 return aAttribute; 422 } 423 424 430 public void setAttributeKey(ObjectKey key) throws TorqueException 431 { 432 433 setAttributeId(new Integer (((NumberKey) key).intValue())); 434 } 435 436 437 438 private AttributeOption aAttributeOption; 439 440 446 public void setAttributeOption(AttributeOption v) throws TorqueException 447 { 448 if (v == null) 449 { 450 setOptionId((Integer ) null); 451 } 452 else 453 { 454 setOptionId(v.getOptionId()); 455 } 456 aAttributeOption = v; 457 } 458 459 460 466 public AttributeOption getAttributeOption() throws TorqueException 467 { 468 if ( !ObjectUtils.equals(getOptionId(), null) ) 469 { 470 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getOptionId())); 471 } 472 return aAttributeOption; 473 } 474 475 481 public void setAttributeOptionKey(ObjectKey key) throws TorqueException 482 { 483 484 setOptionId(new Integer (((NumberKey) key).intValue())); 485 } 486 487 488 489 private RModuleIssueType aRModuleIssueType; 490 491 497 public void setRModuleIssueType(RModuleIssueType v) throws TorqueException 498 { 499 if (v == null) 500 { 501 setModuleId((Integer ) null); 502 } 503 else 504 { 505 setModuleId(v.getModuleId()); 506 } 507 if (v == null) 508 { 509 setIssueTypeId((Integer ) null); 510 } 511 else 512 { 513 setIssueTypeId(v.getIssueTypeId()); 514 } 515 aRModuleIssueType = v; 516 } 517 518 519 525 public RModuleIssueType getRModuleIssueType() throws TorqueException 526 { 527 if ( !ObjectUtils.equals(getModuleId(), null) && !ObjectUtils.equals(getIssueTypeId(), null) ) 528 { 529 SimpleKey[] keys = { SimpleKey.keyFor(getModuleId()), SimpleKey.keyFor(getIssueTypeId()) }; 530 return RModuleIssueTypeManager.getInstance(new ComboKey(keys)); 531 } 532 return aRModuleIssueType; 533 } 534 535 546 public void setRModuleIssueTypeKey(ObjectKey key) throws TorqueException 547 { 548 SimpleKey[] keys = (SimpleKey[])key.getValue(); 549 setModuleId(new Integer (((NumberKey) keys[0]).intValue())); 550 551 setIssueTypeId(new Integer (((NumberKey) keys[1]).intValue())); 552 553 } 554 555 556 private static List fieldNames = null; 557 558 563 public static synchronized List getFieldNames() 564 { 565 if (fieldNames == null) 566 { 567 fieldNames = new ArrayList (); 568 fieldNames.add("ConditionId"); 569 fieldNames.add("TransitionId"); 570 fieldNames.add("ModuleId"); 571 fieldNames.add("IssueTypeId"); 572 fieldNames.add("AttributeId"); 573 fieldNames.add("OptionId"); 574 fieldNames = Collections.unmodifiableList(fieldNames); 575 } 576 return fieldNames; 577 } 578 579 585 public Object getByName(String name) 586 { 587 if (name.equals("ConditionId")) 588 { 589 return getConditionId(); 590 } 591 if (name.equals("TransitionId")) 592 { 593 return getTransitionId(); 594 } 595 if (name.equals("ModuleId")) 596 { 597 return getModuleId(); 598 } 599 if (name.equals("IssueTypeId")) 600 { 601 return getIssueTypeId(); 602 } 603 if (name.equals("AttributeId")) 604 { 605 return getAttributeId(); 606 } 607 if (name.equals("OptionId")) 608 { 609 return getOptionId(); 610 } 611 return null; 612 } 613 614 622 public Object getByPeerName(String name) 623 { 624 if (name.equals(ConditionPeer.CONDITION_ID)) 625 { 626 return getConditionId(); 627 } 628 if (name.equals(ConditionPeer.TRANSITION_ID)) 629 { 630 return getTransitionId(); 631 } 632 if (name.equals(ConditionPeer.MODULE_ID)) 633 { 634 return getModuleId(); 635 } 636 if (name.equals(ConditionPeer.ISSUE_TYPE_ID)) 637 { 638 return getIssueTypeId(); 639 } 640 if (name.equals(ConditionPeer.ATTRIBUTE_ID)) 641 { 642 return getAttributeId(); 643 } 644 if (name.equals(ConditionPeer.OPTION_ID)) 645 { 646 return getOptionId(); 647 } 648 return null; 649 } 650 651 658 public Object getByPosition(int pos) 659 { 660 if (pos == 0) 661 { 662 return getConditionId(); 663 } 664 if (pos == 1) 665 { 666 return getTransitionId(); 667 } 668 if (pos == 2) 669 { 670 return getModuleId(); 671 } 672 if (pos == 3) 673 { 674 return getIssueTypeId(); 675 } 676 if (pos == 4) 677 { 678 return getAttributeId(); 679 } 680 if (pos == 5) 681 { 682 return getOptionId(); 683 } 684 return null; 685 } 686 687 693 public void save() throws Exception 694 { 695 save(ConditionPeer.getMapBuilder() 696 .getDatabaseMap().getName()); 697 } 698 699 709 public void save(String dbName) throws TorqueException 710 { 711 Connection con = null; 712 try 713 { 714 con = Transaction.begin(dbName); 715 save(con); 716 Transaction.commit(con); 717 } 718 catch(TorqueException e) 719 { 720 Transaction.safeRollback(con); 721 throw e; 722 } 723 } 724 725 727 private boolean alreadyInSave = false; 728 738 public void save(Connection con) throws TorqueException 739 { 740 if (!alreadyInSave) 741 { 742 alreadyInSave = true; 743 744 745 746 if (isModified()) 748 { 749 if (isNew()) 750 { 751 ConditionPeer.doInsert((Condition)this, con); 752 setNew(false); 753 } 754 else 755 { 756 ConditionPeer.doUpdate((Condition)this, con); 757 } 758 759 if (isCacheOnSave()) 760 { 761 ConditionManager.putInstance(this); 762 } 763 } 764 765 alreadyInSave = false; 766 } 767 } 768 769 773 protected boolean isCacheOnSave() 774 { 775 return true; 776 } 777 778 779 784 public void setPrimaryKey(ObjectKey conditionId) 785 { 786 setConditionId(new Long (((NumberKey)conditionId).longValue())); 787 } 788 789 794 public void setPrimaryKey(String key) 795 { 796 setConditionId(new Long (key)); 797 } 798 799 800 804 public ObjectKey getPrimaryKey() 805 { 806 return SimpleKey.keyFor(getConditionId()); 807 } 808 809 813 public String getQueryKey() 814 { 815 if (getPrimaryKey() == null) 816 { 817 return ""; 818 } 819 else 820 { 821 return getPrimaryKey().toString(); 822 } 823 } 824 825 829 public void setQueryKey(String key) 830 throws TorqueException 831 { 832 setPrimaryKey(key); 833 } 834 835 841 public Condition copy() throws TorqueException 842 { 843 Condition copyObj = new Condition(); 844 copyObj.setConditionId(conditionId); 845 copyObj.setTransitionId(transitionId); 846 copyObj.setModuleId(moduleId); 847 copyObj.setIssueTypeId(issueTypeId); 848 copyObj.setAttributeId(attributeId); 849 copyObj.setOptionId(optionId); 850 851 copyObj.setConditionId((Long )null); 852 853 return copyObj; 854 } 855 856 862 public ConditionPeer getPeer() 863 { 864 return peer; 865 } 866 867 public String toString() 868 { 869 StringBuffer str = new StringBuffer (); 870 str.append("Condition:\n"); 871 str.append("ConditionId = ") 872 .append(getConditionId()) 873 .append("\n"); 874 str.append("TransitionId = ") 875 .append(getTransitionId()) 876 .append("\n"); 877 str.append("ModuleId = ") 878 .append(getModuleId()) 879 .append("\n"); 880 str.append("IssueTypeId = ") 881 .append(getIssueTypeId()) 882 .append("\n"); 883 str.append("AttributeId = ") 884 .append(getAttributeId()) 885 .append("\n"); 886 str.append("OptionId = ") 887 .append(getOptionId()) 888 .append("\n"); 889 return(str.toString()); 890 } 891 } 892 | Popular Tags |