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 32 public abstract class BaseAttributeGroup extends BaseObject 33 implements org.apache.fulcrum.intake.Retrievable 34 { 35 36 private static final AttributeGroupPeer peer = 37 new AttributeGroupPeer(); 38 39 40 41 private Integer attributeGroupId; 42 43 44 private String name; 45 46 47 private String description; 48 49 50 private Integer moduleId; 51 52 53 private Integer issueTypeId; 54 55 56 private boolean active = false; 57 58 59 private boolean dedupe = false; 60 61 62 private int order = -1; 63 64 65 70 public Integer getAttributeGroupId() 71 { 72 return attributeGroupId; 73 } 74 75 76 81 public void setAttributeGroupId(Integer v) throws TorqueException 82 { 83 84 if (!ObjectUtils.equals(this.attributeGroupId, v)) 85 { 86 this.attributeGroupId = v; 87 setModified(true); 88 } 89 90 91 92 if (collRAttributeAttributeGroups != null) 94 { 95 for (int i = 0; i < collRAttributeAttributeGroups.size(); i++) 96 { 97 ((RAttributeAttributeGroup) collRAttributeAttributeGroups.get(i)) 98 .setGroupId(v); 99 } 100 } 101 } 102 103 108 public String getName() 109 { 110 return name; 111 } 112 113 114 119 public void setName(String v) 120 { 121 122 if (!ObjectUtils.equals(this.name, v)) 123 { 124 this.name = v; 125 setModified(true); 126 } 127 128 129 } 130 131 136 public String getDescription() 137 { 138 return description; 139 } 140 141 142 147 public void setDescription(String v) 148 { 149 150 if (!ObjectUtils.equals(this.description, v)) 151 { 152 this.description = v; 153 setModified(true); 154 } 155 156 157 } 158 159 164 public Integer getModuleId() 165 { 166 return moduleId; 167 } 168 169 170 175 public void setModuleId(Integer v) throws TorqueException 176 { 177 178 if (!ObjectUtils.equals(this.moduleId, v)) 179 { 180 this.moduleId = v; 181 setModified(true); 182 } 183 184 185 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v)) 186 { 187 aModule = null; 188 } 189 190 } 191 192 197 public Integer getIssueTypeId() 198 { 199 return issueTypeId; 200 } 201 202 203 208 public void setIssueTypeId(Integer v) throws TorqueException 209 { 210 211 if (!ObjectUtils.equals(this.issueTypeId, v)) 212 { 213 this.issueTypeId = v; 214 setModified(true); 215 } 216 217 218 if (aIssueType != null && !ObjectUtils.equals(aIssueType.getIssueTypeId(), v)) 219 { 220 aIssueType = null; 221 } 222 223 } 224 225 230 public boolean getActive() 231 { 232 return active; 233 } 234 235 236 241 public void setActive(boolean v) 242 { 243 244 if (this.active != v) 245 { 246 this.active = v; 247 setModified(true); 248 } 249 250 251 } 252 253 258 public boolean getDedupe() 259 { 260 return dedupe; 261 } 262 263 264 269 public void setDedupe(boolean v) 270 { 271 272 if (this.dedupe != v) 273 { 274 this.dedupe = v; 275 setModified(true); 276 } 277 278 279 } 280 281 286 public int getOrder() 287 { 288 return order; 289 } 290 291 292 297 public void setOrder(int v) 298 { 299 300 if (this.order != v) 301 { 302 this.order = v; 303 setModified(true); 304 } 305 306 307 } 308 309 310 311 312 private Module aModule; 313 314 320 public void setModule(Module v) throws TorqueException 321 { 322 if (v == null) 323 { 324 setModuleId((Integer ) null); 325 } 326 else 327 { 328 setModuleId(v.getModuleId()); 329 } 330 aModule = v; 331 } 332 333 334 340 public Module getModule() throws TorqueException 341 { 342 if ( !ObjectUtils.equals(getModuleId(), null) ) 343 { 344 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId())); 345 } 346 return aModule; 347 } 348 349 355 public void setModuleKey(ObjectKey key) throws TorqueException 356 { 357 358 setModuleId(new Integer (((NumberKey) key).intValue())); 359 } 360 361 362 363 private IssueType aIssueType; 364 365 371 public void setIssueType(IssueType v) throws TorqueException 372 { 373 if (v == null) 374 { 375 setIssueTypeId((Integer ) null); 376 } 377 else 378 { 379 setIssueTypeId(v.getIssueTypeId()); 380 } 381 aIssueType = v; 382 } 383 384 385 391 public IssueType getIssueType() throws TorqueException 392 { 393 if ( !ObjectUtils.equals(getIssueTypeId(), null) ) 394 { 395 return IssueTypeManager.getInstance(SimpleKey.keyFor(getIssueTypeId())); 396 } 397 return aIssueType; 398 } 399 400 406 public void setIssueTypeKey(ObjectKey key) throws TorqueException 407 { 408 409 setIssueTypeId(new Integer (((NumberKey) key).intValue())); 410 } 411 412 413 414 417 protected List collRAttributeAttributeGroups; 418 419 424 protected void initRAttributeAttributeGroups() 425 { 426 if (collRAttributeAttributeGroups == null) 427 { 428 collRAttributeAttributeGroups = new ArrayList (); 429 } 430 } 431 432 433 440 public void addRAttributeAttributeGroup(RAttributeAttributeGroup l) throws TorqueException 441 { 442 getRAttributeAttributeGroups().add(l); 443 l.setAttributeGroup((AttributeGroup)this); 444 } 445 446 449 private Criteria lastRAttributeAttributeGroupsCriteria = null; 450 451 458 public List getRAttributeAttributeGroups() throws TorqueException 459 { 460 if (collRAttributeAttributeGroups == null) 461 { 462 collRAttributeAttributeGroups = getRAttributeAttributeGroups(new Criteria(10)); 463 } 464 return collRAttributeAttributeGroups; 465 } 466 467 478 public List getRAttributeAttributeGroups(Criteria criteria) throws TorqueException 479 { 480 if (collRAttributeAttributeGroups == null) 481 { 482 if (isNew()) 483 { 484 collRAttributeAttributeGroups = new ArrayList (); 485 } 486 else 487 { 488 criteria.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId() ); 489 collRAttributeAttributeGroups = RAttributeAttributeGroupPeer.doSelect(criteria); 490 } 491 } 492 else 493 { 494 if (!isNew()) 496 { 497 criteria.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId() ); 501 if (!lastRAttributeAttributeGroupsCriteria.equals(criteria)) 502 { 503 collRAttributeAttributeGroups = RAttributeAttributeGroupPeer.doSelect(criteria); 504 } 505 } 506 } 507 lastRAttributeAttributeGroupsCriteria = criteria; 508 509 return collRAttributeAttributeGroups; 510 } 511 512 520 public List getRAttributeAttributeGroups(Connection con) throws TorqueException 521 { 522 if (collRAttributeAttributeGroups == null) 523 { 524 collRAttributeAttributeGroups = getRAttributeAttributeGroups(new Criteria(10),con); 525 } 526 return collRAttributeAttributeGroups; 527 } 528 529 541 public List getRAttributeAttributeGroups(Criteria criteria,Connection con) throws TorqueException 542 { 543 if (collRAttributeAttributeGroups == null) 544 { 545 if (isNew()) 546 { 547 collRAttributeAttributeGroups = new ArrayList (); 548 } 549 else 550 { 551 criteria.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId() ); 552 collRAttributeAttributeGroups = RAttributeAttributeGroupPeer.doSelect(criteria,con); 553 } 554 } 555 else 556 { 557 if (!isNew()) 559 { 560 criteria.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId() ); 564 if (!lastRAttributeAttributeGroupsCriteria.equals(criteria)) 565 { 566 collRAttributeAttributeGroups = RAttributeAttributeGroupPeer.doSelect(criteria,con); 567 } 568 } 569 } 570 lastRAttributeAttributeGroupsCriteria = criteria; 571 572 return collRAttributeAttributeGroups; 573 } 574 575 576 577 578 579 580 581 582 583 584 585 596 protected List getRAttributeAttributeGroupsJoinAttribute(Criteria criteria) 597 throws TorqueException 598 { 599 if (collRAttributeAttributeGroups == null) 600 { 601 if (isNew()) 602 { 603 collRAttributeAttributeGroups = new ArrayList (); 604 } 605 else 606 { 607 criteria.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId() ); 608 collRAttributeAttributeGroups = RAttributeAttributeGroupPeer.doSelectJoinAttribute(criteria); 609 } 610 } 611 else 612 { 613 617 criteria.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId() ); 618 if (!lastRAttributeAttributeGroupsCriteria.equals(criteria)) 619 { 620 collRAttributeAttributeGroups = RAttributeAttributeGroupPeer.doSelectJoinAttribute(criteria); 621 } 622 } 623 lastRAttributeAttributeGroupsCriteria = criteria; 624 625 return collRAttributeAttributeGroups; 626 } 627 628 629 630 631 632 633 634 635 636 647 protected List getRAttributeAttributeGroupsJoinAttributeGroup(Criteria criteria) 648 throws TorqueException 649 { 650 if (collRAttributeAttributeGroups == null) 651 { 652 if (isNew()) 653 { 654 collRAttributeAttributeGroups = new ArrayList (); 655 } 656 else 657 { 658 criteria.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId() ); 659 collRAttributeAttributeGroups = RAttributeAttributeGroupPeer.doSelectJoinAttributeGroup(criteria); 660 } 661 } 662 else 663 { 664 668 criteria.add(RAttributeAttributeGroupPeer.GROUP_ID, getAttributeGroupId() ); 669 if (!lastRAttributeAttributeGroupsCriteria.equals(criteria)) 670 { 671 collRAttributeAttributeGroups = RAttributeAttributeGroupPeer.doSelectJoinAttributeGroup(criteria); 672 } 673 } 674 lastRAttributeAttributeGroupsCriteria = criteria; 675 676 return collRAttributeAttributeGroups; 677 } 678 679 680 681 682 private static List fieldNames = null; 683 684 689 public static synchronized List getFieldNames() 690 { 691 if (fieldNames == null) 692 { 693 fieldNames = new ArrayList (); 694 fieldNames.add("AttributeGroupId"); 695 fieldNames.add("Name"); 696 fieldNames.add("Description"); 697 fieldNames.add("ModuleId"); 698 fieldNames.add("IssueTypeId"); 699 fieldNames.add("Active"); 700 fieldNames.add("Dedupe"); 701 fieldNames.add("Order"); 702 fieldNames = Collections.unmodifiableList(fieldNames); 703 } 704 return fieldNames; 705 } 706 707 713 public Object getByName(String name) 714 { 715 if (name.equals("AttributeGroupId")) 716 { 717 return getAttributeGroupId(); 718 } 719 if (name.equals("Name")) 720 { 721 return getName(); 722 } 723 if (name.equals("Description")) 724 { 725 return getDescription(); 726 } 727 if (name.equals("ModuleId")) 728 { 729 return getModuleId(); 730 } 731 if (name.equals("IssueTypeId")) 732 { 733 return getIssueTypeId(); 734 } 735 if (name.equals("Active")) 736 { 737 return Boolean.valueOf(getActive()); 738 } 739 if (name.equals("Dedupe")) 740 { 741 return Boolean.valueOf(getDedupe()); 742 } 743 if (name.equals("Order")) 744 { 745 return new Integer (getOrder()); 746 } 747 return null; 748 } 749 750 758 public Object getByPeerName(String name) 759 { 760 if (name.equals(AttributeGroupPeer.ATTRIBUTE_GROUP_ID)) 761 { 762 return getAttributeGroupId(); 763 } 764 if (name.equals(AttributeGroupPeer.NAME)) 765 { 766 return getName(); 767 } 768 if (name.equals(AttributeGroupPeer.DESCRIPTION)) 769 { 770 return getDescription(); 771 } 772 if (name.equals(AttributeGroupPeer.MODULE_ID)) 773 { 774 return getModuleId(); 775 } 776 if (name.equals(AttributeGroupPeer.ISSUE_TYPE_ID)) 777 { 778 return getIssueTypeId(); 779 } 780 if (name.equals(AttributeGroupPeer.ACTIVE)) 781 { 782 return Boolean.valueOf(getActive()); 783 } 784 if (name.equals(AttributeGroupPeer.DEDUPE)) 785 { 786 return Boolean.valueOf(getDedupe()); 787 } 788 if (name.equals(AttributeGroupPeer.PREFERRED_ORDER)) 789 { 790 return new Integer (getOrder()); 791 } 792 return null; 793 } 794 795 802 public Object getByPosition(int pos) 803 { 804 if (pos == 0) 805 { 806 return getAttributeGroupId(); 807 } 808 if (pos == 1) 809 { 810 return getName(); 811 } 812 if (pos == 2) 813 { 814 return getDescription(); 815 } 816 if (pos == 3) 817 { 818 return getModuleId(); 819 } 820 if (pos == 4) 821 { 822 return getIssueTypeId(); 823 } 824 if (pos == 5) 825 { 826 return Boolean.valueOf(getActive()); 827 } 828 if (pos == 6) 829 { 830 return Boolean.valueOf(getDedupe()); 831 } 832 if (pos == 7) 833 { 834 return new Integer (getOrder()); 835 } 836 return null; 837 } 838 839 845 public void save() throws Exception 846 { 847 save(AttributeGroupPeer.getMapBuilder() 848 .getDatabaseMap().getName()); 849 } 850 851 861 public void save(String dbName) throws TorqueException 862 { 863 Connection con = null; 864 try 865 { 866 con = Transaction.begin(dbName); 867 save(con); 868 Transaction.commit(con); 869 } 870 catch(TorqueException e) 871 { 872 Transaction.safeRollback(con); 873 throw e; 874 } 875 } 876 877 879 private boolean alreadyInSave = false; 880 890 public void save(Connection con) throws TorqueException 891 { 892 if (!alreadyInSave) 893 { 894 alreadyInSave = true; 895 896 897 898 if (isModified()) 900 { 901 if (isNew()) 902 { 903 AttributeGroupPeer.doInsert((AttributeGroup)this, con); 904 setNew(false); 905 } 906 else 907 { 908 AttributeGroupPeer.doUpdate((AttributeGroup)this, con); 909 } 910 911 if (isCacheOnSave()) 912 { 913 AttributeGroupManager.putInstance(this); 914 } 915 } 916 917 918 if (collRAttributeAttributeGroups != null) 919 { 920 for (int i = 0; i < collRAttributeAttributeGroups.size(); i++) 921 { 922 ((RAttributeAttributeGroup)collRAttributeAttributeGroups.get(i)).save(con); 923 } 924 } 925 alreadyInSave = false; 926 } 927 } 928 929 933 protected boolean isCacheOnSave() 934 { 935 return true; 936 } 937 938 939 944 public void setPrimaryKey(ObjectKey attributeGroupId) 945 throws TorqueException { 946 setAttributeGroupId(new Integer (((NumberKey)attributeGroupId).intValue())); 947 } 948 949 954 public void setPrimaryKey(String key) throws TorqueException 955 { 956 setAttributeGroupId(new Integer (key)); 957 } 958 959 960 964 public ObjectKey getPrimaryKey() 965 { 966 return SimpleKey.keyFor(getAttributeGroupId()); 967 } 968 969 973 public String getQueryKey() 974 { 975 if (getPrimaryKey() == null) 976 { 977 return ""; 978 } 979 else 980 { 981 return getPrimaryKey().toString(); 982 } 983 } 984 985 989 public void setQueryKey(String key) 990 throws TorqueException 991 { 992 setPrimaryKey(key); 993 } 994 995 1001 public AttributeGroup copy() throws TorqueException 1002 { 1003 AttributeGroup copyObj = new AttributeGroup(); 1004 copyObj.setAttributeGroupId(attributeGroupId); 1005 copyObj.setName(name); 1006 copyObj.setDescription(description); 1007 copyObj.setModuleId(moduleId); 1008 copyObj.setIssueTypeId(issueTypeId); 1009 copyObj.setActive(active); 1010 copyObj.setDedupe(dedupe); 1011 copyObj.setOrder(order); 1012 1013 copyObj.setAttributeGroupId((Integer )null); 1014 1015 1016 1017 List v = getRAttributeAttributeGroups(); 1018 for (int i = 0; i < v.size(); i++) 1019 { 1020 RAttributeAttributeGroup obj = (RAttributeAttributeGroup) v.get(i); 1021 copyObj.addRAttributeAttributeGroup(obj.copy()); 1022 } 1023 return copyObj; 1024 } 1025 1026 1032 public AttributeGroupPeer getPeer() 1033 { 1034 return peer; 1035 } 1036 1037 public String toString() 1038 { 1039 StringBuffer str = new StringBuffer (); 1040 str.append("AttributeGroup:\n"); 1041 str.append("AttributeGroupId = ") 1042 .append(getAttributeGroupId()) 1043 .append("\n"); 1044 str.append("Name = ") 1045 .append(getName()) 1046 .append("\n"); 1047 str.append("Description = ") 1048 .append(getDescription()) 1049 .append("\n"); 1050 str.append("ModuleId = ") 1051 .append(getModuleId()) 1052 .append("\n"); 1053 str.append("IssueTypeId = ") 1054 .append(getIssueTypeId()) 1055 .append("\n"); 1056 str.append("Active = ") 1057 .append(getActive()) 1058 .append("\n"); 1059 str.append("Dedupe = ") 1060 .append(getDedupe()) 1061 .append("\n"); 1062 str.append("Order = ") 1063 .append(getOrder()) 1064 .append("\n"); 1065 return(str.toString()); 1066 } 1067} 1068 | Popular Tags |