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 BaseTransition extends BaseObject 34 implements org.apache.fulcrum.intake.Retrievable 35 { 36 37 private static final TransitionPeer peer = 38 new TransitionPeer(); 39 40 41 42 private Integer transitionId; 43 44 45 private Integer roleId; 46 47 48 private Integer attributeId; 49 50 51 private Integer fromOptionId; 52 53 54 private Integer toOptionId; 55 56 57 private boolean disabledIfBlocked = false; 58 59 60 65 public Integer getTransitionId() 66 { 67 return transitionId; 68 } 69 70 71 76 public void setTransitionId(Integer v) throws TorqueException 77 { 78 79 if (!ObjectUtils.equals(this.transitionId, v)) 80 { 81 this.transitionId = v; 82 setModified(true); 83 } 84 85 86 87 if (collConditions != null) 89 { 90 for (int i = 0; i < collConditions.size(); i++) 91 { 92 ((Condition) collConditions.get(i)) 93 .setTransitionId(v); 94 } 95 } 96 } 97 98 103 public Integer getRoleId() 104 { 105 return roleId; 106 } 107 108 109 114 public void setRoleId(Integer v) 115 { 116 117 if (!ObjectUtils.equals(this.roleId, v)) 118 { 119 this.roleId = v; 120 setModified(true); 121 } 122 123 124 } 125 126 131 public Integer getAttributeId() 132 { 133 return attributeId; 134 } 135 136 137 142 public void setAttributeId(Integer v) throws TorqueException 143 { 144 145 if (!ObjectUtils.equals(this.attributeId, v)) 146 { 147 this.attributeId = v; 148 setModified(true); 149 } 150 151 152 if (aAttribute != null && !ObjectUtils.equals(aAttribute.getAttributeId(), v)) 153 { 154 aAttribute = null; 155 } 156 157 } 158 159 164 public Integer getFromOptionId() 165 { 166 return fromOptionId; 167 } 168 169 170 175 public void setFromOptionId(Integer v) throws TorqueException 176 { 177 178 if (!ObjectUtils.equals(this.fromOptionId, v)) 179 { 180 this.fromOptionId = v; 181 setModified(true); 182 } 183 184 185 if (aAttributeOptionRelatedByFromOptionId != null && !ObjectUtils.equals(aAttributeOptionRelatedByFromOptionId.getOptionId(), v)) 186 { 187 aAttributeOptionRelatedByFromOptionId = null; 188 } 189 190 } 191 192 197 public Integer getToOptionId() 198 { 199 return toOptionId; 200 } 201 202 203 208 public void setToOptionId(Integer v) throws TorqueException 209 { 210 211 if (!ObjectUtils.equals(this.toOptionId, v)) 212 { 213 this.toOptionId = v; 214 setModified(true); 215 } 216 217 218 if (aAttributeOptionRelatedByToOptionId != null && !ObjectUtils.equals(aAttributeOptionRelatedByToOptionId.getOptionId(), v)) 219 { 220 aAttributeOptionRelatedByToOptionId = null; 221 } 222 223 } 224 225 230 public boolean getDisabledIfBlocked() 231 { 232 return disabledIfBlocked; 233 } 234 235 236 241 public void setDisabledIfBlocked(boolean v) 242 { 243 244 if (this.disabledIfBlocked != v) 245 { 246 this.disabledIfBlocked = v; 247 setModified(true); 248 } 249 250 251 } 252 253 254 255 256 private Attribute aAttribute; 257 258 264 public void setAttribute(Attribute v) throws TorqueException 265 { 266 if (v == null) 267 { 268 setAttributeId((Integer ) null); 269 } 270 else 271 { 272 setAttributeId(v.getAttributeId()); 273 } 274 aAttribute = v; 275 } 276 277 278 284 public Attribute getAttribute() throws TorqueException 285 { 286 if ( !ObjectUtils.equals(getAttributeId(), null) ) 287 { 288 return AttributeManager.getInstance(SimpleKey.keyFor(getAttributeId())); 289 } 290 return aAttribute; 291 } 292 293 299 public void setAttributeKey(ObjectKey key) throws TorqueException 300 { 301 302 setAttributeId(new Integer (((NumberKey) key).intValue())); 303 } 304 305 306 307 private AttributeOption aAttributeOptionRelatedByFromOptionId; 308 309 315 public void setAttributeOptionRelatedByFromOptionId(AttributeOption v) throws TorqueException 316 { 317 if (v == null) 318 { 319 setFromOptionId((Integer ) null); 320 } 321 else 322 { 323 setFromOptionId(v.getOptionId()); 324 } 325 aAttributeOptionRelatedByFromOptionId = v; 326 } 327 328 329 335 public AttributeOption getAttributeOptionRelatedByFromOptionId() throws TorqueException 336 { 337 if ( !ObjectUtils.equals(getFromOptionId(), null) ) 338 { 339 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getFromOptionId())); 340 } 341 return aAttributeOptionRelatedByFromOptionId; 342 } 343 344 350 public void setAttributeOptionRelatedByFromOptionIdKey(ObjectKey key) throws TorqueException 351 { 352 353 setFromOptionId(new Integer (((NumberKey) key).intValue())); 354 } 355 356 357 358 private AttributeOption aAttributeOptionRelatedByToOptionId; 359 360 366 public void setAttributeOptionRelatedByToOptionId(AttributeOption v) throws TorqueException 367 { 368 if (v == null) 369 { 370 setToOptionId((Integer ) null); 371 } 372 else 373 { 374 setToOptionId(v.getOptionId()); 375 } 376 aAttributeOptionRelatedByToOptionId = v; 377 } 378 379 380 386 public AttributeOption getAttributeOptionRelatedByToOptionId() throws TorqueException 387 { 388 if ( !ObjectUtils.equals(getToOptionId(), null) ) 389 { 390 return AttributeOptionManager.getInstance(SimpleKey.keyFor(getToOptionId())); 391 } 392 return aAttributeOptionRelatedByToOptionId; 393 } 394 395 401 public void setAttributeOptionRelatedByToOptionIdKey(ObjectKey key) throws TorqueException 402 { 403 404 setToOptionId(new Integer (((NumberKey) key).intValue())); 405 } 406 407 408 409 412 protected List collConditions; 413 414 419 protected void initConditions() 420 { 421 if (collConditions == null) 422 { 423 collConditions = new ArrayList (); 424 } 425 } 426 427 428 435 public void addCondition(Condition l) throws TorqueException 436 { 437 getConditions().add(l); 438 l.setTransition((Transition)this); 439 } 440 441 444 private Criteria lastConditionsCriteria = null; 445 446 453 public List getConditions() throws TorqueException 454 { 455 if (collConditions == null) 456 { 457 collConditions = getConditions(new Criteria(10)); 458 } 459 return collConditions; 460 } 461 462 473 public List getConditions(Criteria criteria) throws TorqueException 474 { 475 if (collConditions == null) 476 { 477 if (isNew()) 478 { 479 collConditions = new ArrayList (); 480 } 481 else 482 { 483 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 484 collConditions = ConditionPeer.doSelect(criteria); 485 } 486 } 487 else 488 { 489 if (!isNew()) 491 { 492 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 496 if (!lastConditionsCriteria.equals(criteria)) 497 { 498 collConditions = ConditionPeer.doSelect(criteria); 499 } 500 } 501 } 502 lastConditionsCriteria = criteria; 503 504 return collConditions; 505 } 506 507 515 public List getConditions(Connection con) throws TorqueException 516 { 517 if (collConditions == null) 518 { 519 collConditions = getConditions(new Criteria(10),con); 520 } 521 return collConditions; 522 } 523 524 536 public List getConditions(Criteria criteria,Connection con) throws TorqueException 537 { 538 if (collConditions == null) 539 { 540 if (isNew()) 541 { 542 collConditions = new ArrayList (); 543 } 544 else 545 { 546 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 547 collConditions = ConditionPeer.doSelect(criteria,con); 548 } 549 } 550 else 551 { 552 if (!isNew()) 554 { 555 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 559 if (!lastConditionsCriteria.equals(criteria)) 560 { 561 collConditions = ConditionPeer.doSelect(criteria,con); 562 } 563 } 564 } 565 lastConditionsCriteria = criteria; 566 567 return collConditions; 568 } 569 570 571 572 573 574 575 576 577 578 579 580 591 protected List getConditionsJoinRModuleAttribute(Criteria criteria) 592 throws TorqueException 593 { 594 if (collConditions == null) 595 { 596 if (isNew()) 597 { 598 collConditions = new ArrayList (); 599 } 600 else 601 { 602 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 603 collConditions = ConditionPeer.doSelectJoinRModuleAttribute(criteria); 604 } 605 } 606 else 607 { 608 612 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 613 if (!lastConditionsCriteria.equals(criteria)) 614 { 615 collConditions = ConditionPeer.doSelectJoinRModuleAttribute(criteria); 616 } 617 } 618 lastConditionsCriteria = criteria; 619 620 return collConditions; 621 } 622 623 624 625 626 627 628 629 630 631 642 protected List getConditionsJoinTransition(Criteria criteria) 643 throws TorqueException 644 { 645 if (collConditions == null) 646 { 647 if (isNew()) 648 { 649 collConditions = new ArrayList (); 650 } 651 else 652 { 653 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 654 collConditions = ConditionPeer.doSelectJoinTransition(criteria); 655 } 656 } 657 else 658 { 659 663 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 664 if (!lastConditionsCriteria.equals(criteria)) 665 { 666 collConditions = ConditionPeer.doSelectJoinTransition(criteria); 667 } 668 } 669 lastConditionsCriteria = criteria; 670 671 return collConditions; 672 } 673 674 675 676 677 678 679 680 681 682 693 protected List getConditionsJoinAttribute(Criteria criteria) 694 throws TorqueException 695 { 696 if (collConditions == null) 697 { 698 if (isNew()) 699 { 700 collConditions = new ArrayList (); 701 } 702 else 703 { 704 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 705 collConditions = ConditionPeer.doSelectJoinAttribute(criteria); 706 } 707 } 708 else 709 { 710 714 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 715 if (!lastConditionsCriteria.equals(criteria)) 716 { 717 collConditions = ConditionPeer.doSelectJoinAttribute(criteria); 718 } 719 } 720 lastConditionsCriteria = criteria; 721 722 return collConditions; 723 } 724 725 726 727 728 729 730 731 732 733 744 protected List getConditionsJoinAttributeOption(Criteria criteria) 745 throws TorqueException 746 { 747 if (collConditions == null) 748 { 749 if (isNew()) 750 { 751 collConditions = new ArrayList (); 752 } 753 else 754 { 755 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 756 collConditions = ConditionPeer.doSelectJoinAttributeOption(criteria); 757 } 758 } 759 else 760 { 761 765 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 766 if (!lastConditionsCriteria.equals(criteria)) 767 { 768 collConditions = ConditionPeer.doSelectJoinAttributeOption(criteria); 769 } 770 } 771 lastConditionsCriteria = criteria; 772 773 return collConditions; 774 } 775 776 777 778 779 780 781 782 783 784 795 protected List getConditionsJoinRModuleIssueType(Criteria criteria) 796 throws TorqueException 797 { 798 if (collConditions == null) 799 { 800 if (isNew()) 801 { 802 collConditions = new ArrayList (); 803 } 804 else 805 { 806 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 807 collConditions = ConditionPeer.doSelectJoinRModuleIssueType(criteria); 808 } 809 } 810 else 811 { 812 816 criteria.add(ConditionPeer.TRANSITION_ID, getTransitionId() ); 817 if (!lastConditionsCriteria.equals(criteria)) 818 { 819 collConditions = ConditionPeer.doSelectJoinRModuleIssueType(criteria); 820 } 821 } 822 lastConditionsCriteria = criteria; 823 824 return collConditions; 825 } 826 827 828 829 830 private static List fieldNames = null; 831 832 837 public static synchronized List getFieldNames() 838 { 839 if (fieldNames == null) 840 { 841 fieldNames = new ArrayList (); 842 fieldNames.add("TransitionId"); 843 fieldNames.add("RoleId"); 844 fieldNames.add("AttributeId"); 845 fieldNames.add("FromOptionId"); 846 fieldNames.add("ToOptionId"); 847 fieldNames.add("DisabledIfBlocked"); 848 fieldNames = Collections.unmodifiableList(fieldNames); 849 } 850 return fieldNames; 851 } 852 853 859 public Object getByName(String name) 860 { 861 if (name.equals("TransitionId")) 862 { 863 return getTransitionId(); 864 } 865 if (name.equals("RoleId")) 866 { 867 return getRoleId(); 868 } 869 if (name.equals("AttributeId")) 870 { 871 return getAttributeId(); 872 } 873 if (name.equals("FromOptionId")) 874 { 875 return getFromOptionId(); 876 } 877 if (name.equals("ToOptionId")) 878 { 879 return getToOptionId(); 880 } 881 if (name.equals("DisabledIfBlocked")) 882 { 883 return Boolean.valueOf(getDisabledIfBlocked()); 884 } 885 return null; 886 } 887 888 896 public Object getByPeerName(String name) 897 { 898 if (name.equals(TransitionPeer.TRANSITION_ID)) 899 { 900 return getTransitionId(); 901 } 902 if (name.equals(TransitionPeer.ROLE_ID)) 903 { 904 return getRoleId(); 905 } 906 if (name.equals(TransitionPeer.ATTRIBUTE_ID)) 907 { 908 return getAttributeId(); 909 } 910 if (name.equals(TransitionPeer.FROM_OPTION_ID)) 911 { 912 return getFromOptionId(); 913 } 914 if (name.equals(TransitionPeer.TO_OPTION_ID)) 915 { 916 return getToOptionId(); 917 } 918 if (name.equals(TransitionPeer.DISABLED_IF_BLOCKED)) 919 { 920 return Boolean.valueOf(getDisabledIfBlocked()); 921 } 922 return null; 923 } 924 925 932 public Object getByPosition(int pos) 933 { 934 if (pos == 0) 935 { 936 return getTransitionId(); 937 } 938 if (pos == 1) 939 { 940 return getRoleId(); 941 } 942 if (pos == 2) 943 { 944 return getAttributeId(); 945 } 946 if (pos == 3) 947 { 948 return getFromOptionId(); 949 } 950 if (pos == 4) 951 { 952 return getToOptionId(); 953 } 954 if (pos == 5) 955 { 956 return Boolean.valueOf(getDisabledIfBlocked()); 957 } 958 return null; 959 } 960 961 967 public void save() throws Exception 968 { 969 save(TransitionPeer.getMapBuilder() 970 .getDatabaseMap().getName()); 971 } 972 973 983 public void save(String dbName) throws TorqueException 984 { 985 Connection con = null; 986 try 987 { 988 con = Transaction.begin(dbName); 989 save(con); 990 Transaction.commit(con); 991 } 992 catch(TorqueException e) 993 { 994 Transaction.safeRollback(con); 995 throw e; 996 } 997 } 998 999 1001 private boolean alreadyInSave = false; 1002 1012 public void save(Connection con) throws TorqueException 1013 { 1014 if (!alreadyInSave) 1015 { 1016 alreadyInSave = true; 1017 1018 1019 1020 if (isModified()) 1022 { 1023 if (isNew()) 1024 { 1025 TransitionPeer.doInsert((Transition)this, con); 1026 setNew(false); 1027 } 1028 else 1029 { 1030 TransitionPeer.doUpdate((Transition)this, con); 1031 } 1032 1033 if (isCacheOnSave()) 1034 { 1035 TransitionManager.putInstance(this); 1036 } 1037 } 1038 1039 1040 if (collConditions != null) 1041 { 1042 for (int i = 0; i < collConditions.size(); i++) 1043 { 1044 ((Condition)collConditions.get(i)).save(con); 1045 } 1046 } 1047 alreadyInSave = false; 1048 } 1049 } 1050 1051 1055 protected boolean isCacheOnSave() 1056 { 1057 return true; 1058 } 1059 1060 1061 1066 public void setPrimaryKey(ObjectKey transitionId) 1067 throws TorqueException { 1068 setTransitionId(new Integer (((NumberKey)transitionId).intValue())); 1069 } 1070 1071 1076 public void setPrimaryKey(String key) throws TorqueException 1077 { 1078 setTransitionId(new Integer (key)); 1079 } 1080 1081 1082 1086 public ObjectKey getPrimaryKey() 1087 { 1088 return SimpleKey.keyFor(getTransitionId()); 1089 } 1090 1091 1095 public String getQueryKey() 1096 { 1097 if (getPrimaryKey() == null) 1098 { 1099 return ""; 1100 } 1101 else 1102 { 1103 return getPrimaryKey().toString(); 1104 } 1105 } 1106 1107 1111 public void setQueryKey(String key) 1112 throws TorqueException 1113 { 1114 setPrimaryKey(key); 1115 } 1116 1117 1123 public Transition copy() throws TorqueException 1124 { 1125 Transition copyObj = new Transition(); 1126 copyObj.setTransitionId(transitionId); 1127 copyObj.setRoleId(roleId); 1128 copyObj.setAttributeId(attributeId); 1129 copyObj.setFromOptionId(fromOptionId); 1130 copyObj.setToOptionId(toOptionId); 1131 copyObj.setDisabledIfBlocked(disabledIfBlocked); 1132 1133 copyObj.setTransitionId((Integer )null); 1134 1135 1136 1137 List v = getConditions(); 1138 for (int i = 0; i < v.size(); i++) 1139 { 1140 Condition obj = (Condition) v.get(i); 1141 copyObj.addCondition(obj.copy()); 1142 } 1143 return copyObj; 1144 } 1145 1146 1152 public TransitionPeer getPeer() 1153 { 1154 return peer; 1155 } 1156 1157 public String toString() 1158 { 1159 StringBuffer str = new StringBuffer (); 1160 str.append("Transition:\n"); 1161 str.append("TransitionId = ") 1162 .append(getTransitionId()) 1163 .append("\n"); 1164 str.append("RoleId = ") 1165 .append(getRoleId()) 1166 .append("\n"); 1167 str.append("AttributeId = ") 1168 .append(getAttributeId()) 1169 .append("\n"); 1170 str.append("FromOptionId = ") 1171 .append(getFromOptionId()) 1172 .append("\n"); 1173 str.append("ToOptionId = ") 1174 .append(getToOptionId()) 1175 .append("\n"); 1176 str.append("DisabledIfBlocked = ") 1177 .append(getDisabledIfBlocked()) 1178 .append("\n"); 1179 return(str.toString()); 1180 } 1181} 1182 | Popular Tags |