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 BaseDepend extends BaseObject 34 implements org.apache.fulcrum.intake.Retrievable 35 { 36 37 private static final DependPeer peer = 38 new DependPeer(); 39 40 41 42 private Integer dependId; 43 44 45 private Long observedId; 46 47 48 private Long observerId; 49 50 51 private Integer typeId; 52 53 54 private boolean deleted = false; 55 56 57 62 public Integer getDependId() 63 { 64 return dependId; 65 } 66 67 68 73 public void setDependId(Integer v) throws TorqueException 74 { 75 76 if (!ObjectUtils.equals(this.dependId, v)) 77 { 78 this.dependId = v; 79 setModified(true); 80 } 81 82 83 84 if (collActivitys != null) 86 { 87 for (int i = 0; i < collActivitys.size(); i++) 88 { 89 ((Activity) collActivitys.get(i)) 90 .setDependId(v); 91 } 92 } 93 } 94 95 100 public Long getObservedId() 101 { 102 return observedId; 103 } 104 105 106 111 public void setObservedId(Long v) throws TorqueException 112 { 113 114 if (!ObjectUtils.equals(this.observedId, v)) 115 { 116 this.observedId = v; 117 setModified(true); 118 } 119 120 121 if (aIssueRelatedByObservedId != null && !ObjectUtils.equals(aIssueRelatedByObservedId.getIssueId(), v)) 122 { 123 aIssueRelatedByObservedId = null; 124 } 125 126 } 127 128 133 public Long getObserverId() 134 { 135 return observerId; 136 } 137 138 139 144 public void setObserverId(Long v) throws TorqueException 145 { 146 147 if (!ObjectUtils.equals(this.observerId, v)) 148 { 149 this.observerId = v; 150 setModified(true); 151 } 152 153 154 if (aIssueRelatedByObserverId != null && !ObjectUtils.equals(aIssueRelatedByObserverId.getIssueId(), v)) 155 { 156 aIssueRelatedByObserverId = null; 157 } 158 159 } 160 161 166 public Integer getTypeId() 167 { 168 return typeId; 169 } 170 171 172 177 public void setTypeId(Integer v) throws TorqueException 178 { 179 180 if (!ObjectUtils.equals(this.typeId, v)) 181 { 182 this.typeId = v; 183 setModified(true); 184 } 185 186 187 if (aDependType != null && !ObjectUtils.equals(aDependType.getDependTypeId(), v)) 188 { 189 aDependType = null; 190 } 191 192 } 193 194 199 public boolean getDeleted() 200 { 201 return deleted; 202 } 203 204 205 210 public void setDeleted(boolean v) 211 { 212 213 if (this.deleted != v) 214 { 215 this.deleted = v; 216 setModified(true); 217 } 218 219 220 } 221 222 223 224 225 private Issue aIssueRelatedByObservedId; 226 227 233 public void setIssueRelatedByObservedId(Issue v) throws TorqueException 234 { 235 if (v == null) 236 { 237 setObservedId((Long ) null); 238 } 239 else 240 { 241 setObservedId(v.getIssueId()); 242 } 243 aIssueRelatedByObservedId = v; 244 } 245 246 247 253 public Issue getIssueRelatedByObservedId() throws TorqueException 254 { 255 if ( !ObjectUtils.equals(getObservedId(), null) ) 256 { 257 return IssueManager.getInstance(SimpleKey.keyFor(getObservedId())); 258 } 259 return aIssueRelatedByObservedId; 260 } 261 262 268 public void setIssueRelatedByObservedIdKey(ObjectKey key) throws TorqueException 269 { 270 271 setObservedId(new Long (((NumberKey) key).longValue())); 272 } 273 274 275 276 private Issue aIssueRelatedByObserverId; 277 278 284 public void setIssueRelatedByObserverId(Issue v) throws TorqueException 285 { 286 if (v == null) 287 { 288 setObserverId((Long ) null); 289 } 290 else 291 { 292 setObserverId(v.getIssueId()); 293 } 294 aIssueRelatedByObserverId = v; 295 } 296 297 298 304 public Issue getIssueRelatedByObserverId() throws TorqueException 305 { 306 if ( !ObjectUtils.equals(getObserverId(), null) ) 307 { 308 return IssueManager.getInstance(SimpleKey.keyFor(getObserverId())); 309 } 310 return aIssueRelatedByObserverId; 311 } 312 313 319 public void setIssueRelatedByObserverIdKey(ObjectKey key) throws TorqueException 320 { 321 322 setObserverId(new Long (((NumberKey) key).longValue())); 323 } 324 325 326 327 private DependType aDependType; 328 329 335 public void setDependType(DependType v) throws TorqueException 336 { 337 if (v == null) 338 { 339 setTypeId((Integer ) null); 340 } 341 else 342 { 343 setTypeId(v.getDependTypeId()); 344 } 345 aDependType = v; 346 } 347 348 349 355 public DependType getDependType() throws TorqueException 356 { 357 if ( !ObjectUtils.equals(getTypeId(), null) ) 358 { 359 return DependTypeManager.getInstance(SimpleKey.keyFor(getTypeId())); 360 } 361 return aDependType; 362 } 363 364 370 public void setDependTypeKey(ObjectKey key) throws TorqueException 371 { 372 373 setTypeId(new Integer (((NumberKey) key).intValue())); 374 } 375 376 377 378 381 protected List collActivitys; 382 383 388 protected void initActivitys() 389 { 390 if (collActivitys == null) 391 { 392 collActivitys = new ArrayList (); 393 } 394 } 395 396 397 404 public void addActivity(Activity l) throws TorqueException 405 { 406 getActivitys().add(l); 407 l.setDepend((Depend)this); 408 } 409 410 413 private Criteria lastActivitysCriteria = null; 414 415 422 public List getActivitys() throws TorqueException 423 { 424 if (collActivitys == null) 425 { 426 collActivitys = getActivitys(new Criteria(10)); 427 } 428 return collActivitys; 429 } 430 431 442 public List getActivitys(Criteria criteria) throws TorqueException 443 { 444 if (collActivitys == null) 445 { 446 if (isNew()) 447 { 448 collActivitys = new ArrayList (); 449 } 450 else 451 { 452 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 453 collActivitys = ActivityPeer.doSelect(criteria); 454 } 455 } 456 else 457 { 458 if (!isNew()) 460 { 461 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 465 if (!lastActivitysCriteria.equals(criteria)) 466 { 467 collActivitys = ActivityPeer.doSelect(criteria); 468 } 469 } 470 } 471 lastActivitysCriteria = criteria; 472 473 return collActivitys; 474 } 475 476 484 public List getActivitys(Connection con) throws TorqueException 485 { 486 if (collActivitys == null) 487 { 488 collActivitys = getActivitys(new Criteria(10),con); 489 } 490 return collActivitys; 491 } 492 493 505 public List getActivitys(Criteria criteria,Connection con) throws TorqueException 506 { 507 if (collActivitys == null) 508 { 509 if (isNew()) 510 { 511 collActivitys = new ArrayList (); 512 } 513 else 514 { 515 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 516 collActivitys = ActivityPeer.doSelect(criteria,con); 517 } 518 } 519 else 520 { 521 if (!isNew()) 523 { 524 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 528 if (!lastActivitysCriteria.equals(criteria)) 529 { 530 collActivitys = ActivityPeer.doSelect(criteria,con); 531 } 532 } 533 } 534 lastActivitysCriteria = criteria; 535 536 return collActivitys; 537 } 538 539 540 541 542 543 544 545 546 547 548 549 560 protected List getActivitysJoinIssue(Criteria criteria) 561 throws TorqueException 562 { 563 if (collActivitys == null) 564 { 565 if (isNew()) 566 { 567 collActivitys = new ArrayList (); 568 } 569 else 570 { 571 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 572 collActivitys = ActivityPeer.doSelectJoinIssue(criteria); 573 } 574 } 575 else 576 { 577 581 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 582 if (!lastActivitysCriteria.equals(criteria)) 583 { 584 collActivitys = ActivityPeer.doSelectJoinIssue(criteria); 585 } 586 } 587 lastActivitysCriteria = criteria; 588 589 return collActivitys; 590 } 591 592 593 594 595 596 597 598 599 600 611 protected List getActivitysJoinAttribute(Criteria criteria) 612 throws TorqueException 613 { 614 if (collActivitys == null) 615 { 616 if (isNew()) 617 { 618 collActivitys = new ArrayList (); 619 } 620 else 621 { 622 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 623 collActivitys = ActivityPeer.doSelectJoinAttribute(criteria); 624 } 625 } 626 else 627 { 628 632 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 633 if (!lastActivitysCriteria.equals(criteria)) 634 { 635 collActivitys = ActivityPeer.doSelectJoinAttribute(criteria); 636 } 637 } 638 lastActivitysCriteria = criteria; 639 640 return collActivitys; 641 } 642 643 644 645 646 647 648 649 650 651 662 protected List getActivitysJoinActivitySet(Criteria criteria) 663 throws TorqueException 664 { 665 if (collActivitys == null) 666 { 667 if (isNew()) 668 { 669 collActivitys = new ArrayList (); 670 } 671 else 672 { 673 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 674 collActivitys = ActivityPeer.doSelectJoinActivitySet(criteria); 675 } 676 } 677 else 678 { 679 683 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 684 if (!lastActivitysCriteria.equals(criteria)) 685 { 686 collActivitys = ActivityPeer.doSelectJoinActivitySet(criteria); 687 } 688 } 689 lastActivitysCriteria = criteria; 690 691 return collActivitys; 692 } 693 694 695 696 697 698 699 700 701 702 713 protected List getActivitysJoinScarabUserImplRelatedByOldUserId(Criteria criteria) 714 throws TorqueException 715 { 716 if (collActivitys == null) 717 { 718 if (isNew()) 719 { 720 collActivitys = new ArrayList (); 721 } 722 else 723 { 724 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 725 collActivitys = ActivityPeer.doSelectJoinScarabUserImplRelatedByOldUserId(criteria); 726 } 727 } 728 else 729 { 730 734 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 735 if (!lastActivitysCriteria.equals(criteria)) 736 { 737 collActivitys = ActivityPeer.doSelectJoinScarabUserImplRelatedByOldUserId(criteria); 738 } 739 } 740 lastActivitysCriteria = criteria; 741 742 return collActivitys; 743 } 744 745 746 747 748 749 750 751 752 753 764 protected List getActivitysJoinScarabUserImplRelatedByNewUserId(Criteria criteria) 765 throws TorqueException 766 { 767 if (collActivitys == null) 768 { 769 if (isNew()) 770 { 771 collActivitys = new ArrayList (); 772 } 773 else 774 { 775 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 776 collActivitys = ActivityPeer.doSelectJoinScarabUserImplRelatedByNewUserId(criteria); 777 } 778 } 779 else 780 { 781 785 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 786 if (!lastActivitysCriteria.equals(criteria)) 787 { 788 collActivitys = ActivityPeer.doSelectJoinScarabUserImplRelatedByNewUserId(criteria); 789 } 790 } 791 lastActivitysCriteria = criteria; 792 793 return collActivitys; 794 } 795 796 797 798 799 800 801 802 803 804 815 protected List getActivitysJoinAttributeOptionRelatedByOldOptionId(Criteria criteria) 816 throws TorqueException 817 { 818 if (collActivitys == null) 819 { 820 if (isNew()) 821 { 822 collActivitys = new ArrayList (); 823 } 824 else 825 { 826 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 827 collActivitys = ActivityPeer.doSelectJoinAttributeOptionRelatedByOldOptionId(criteria); 828 } 829 } 830 else 831 { 832 836 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 837 if (!lastActivitysCriteria.equals(criteria)) 838 { 839 collActivitys = ActivityPeer.doSelectJoinAttributeOptionRelatedByOldOptionId(criteria); 840 } 841 } 842 lastActivitysCriteria = criteria; 843 844 return collActivitys; 845 } 846 847 848 849 850 851 852 853 854 855 866 protected List getActivitysJoinAttributeOptionRelatedByNewOptionId(Criteria criteria) 867 throws TorqueException 868 { 869 if (collActivitys == null) 870 { 871 if (isNew()) 872 { 873 collActivitys = new ArrayList (); 874 } 875 else 876 { 877 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 878 collActivitys = ActivityPeer.doSelectJoinAttributeOptionRelatedByNewOptionId(criteria); 879 } 880 } 881 else 882 { 883 887 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 888 if (!lastActivitysCriteria.equals(criteria)) 889 { 890 collActivitys = ActivityPeer.doSelectJoinAttributeOptionRelatedByNewOptionId(criteria); 891 } 892 } 893 lastActivitysCriteria = criteria; 894 895 return collActivitys; 896 } 897 898 899 900 901 902 903 904 905 906 917 protected List getActivitysJoinAttachment(Criteria criteria) 918 throws TorqueException 919 { 920 if (collActivitys == null) 921 { 922 if (isNew()) 923 { 924 collActivitys = new ArrayList (); 925 } 926 else 927 { 928 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 929 collActivitys = ActivityPeer.doSelectJoinAttachment(criteria); 930 } 931 } 932 else 933 { 934 938 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 939 if (!lastActivitysCriteria.equals(criteria)) 940 { 941 collActivitys = ActivityPeer.doSelectJoinAttachment(criteria); 942 } 943 } 944 lastActivitysCriteria = criteria; 945 946 return collActivitys; 947 } 948 949 950 951 952 953 954 955 956 957 968 protected List getActivitysJoinDepend(Criteria criteria) 969 throws TorqueException 970 { 971 if (collActivitys == null) 972 { 973 if (isNew()) 974 { 975 collActivitys = new ArrayList (); 976 } 977 else 978 { 979 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 980 collActivitys = ActivityPeer.doSelectJoinDepend(criteria); 981 } 982 } 983 else 984 { 985 989 criteria.add(ActivityPeer.DEPEND_ID, getDependId() ); 990 if (!lastActivitysCriteria.equals(criteria)) 991 { 992 collActivitys = ActivityPeer.doSelectJoinDepend(criteria); 993 } 994 } 995 lastActivitysCriteria = criteria; 996 997 return collActivitys; 998 } 999 1000 1001 1002 1003 private static List fieldNames = null; 1004 1005 1010 public static synchronized List getFieldNames() 1011 { 1012 if (fieldNames == null) 1013 { 1014 fieldNames = new ArrayList (); 1015 fieldNames.add("DependId"); 1016 fieldNames.add("ObservedId"); 1017 fieldNames.add("ObserverId"); 1018 fieldNames.add("TypeId"); 1019 fieldNames.add("Deleted"); 1020 fieldNames = Collections.unmodifiableList(fieldNames); 1021 } 1022 return fieldNames; 1023 } 1024 1025 1031 public Object getByName(String name) 1032 { 1033 if (name.equals("DependId")) 1034 { 1035 return getDependId(); 1036 } 1037 if (name.equals("ObservedId")) 1038 { 1039 return getObservedId(); 1040 } 1041 if (name.equals("ObserverId")) 1042 { 1043 return getObserverId(); 1044 } 1045 if (name.equals("TypeId")) 1046 { 1047 return getTypeId(); 1048 } 1049 if (name.equals("Deleted")) 1050 { 1051 return Boolean.valueOf(getDeleted()); 1052 } 1053 return null; 1054 } 1055 1056 1064 public Object getByPeerName(String name) 1065 { 1066 if (name.equals(DependPeer.DEPEND_ID)) 1067 { 1068 return getDependId(); 1069 } 1070 if (name.equals(DependPeer.OBSERVED_ID)) 1071 { 1072 return getObservedId(); 1073 } 1074 if (name.equals(DependPeer.OBSERVER_ID)) 1075 { 1076 return getObserverId(); 1077 } 1078 if (name.equals(DependPeer.DEPEND_TYPE_ID)) 1079 { 1080 return getTypeId(); 1081 } 1082 if (name.equals(DependPeer.DELETED)) 1083 { 1084 return Boolean.valueOf(getDeleted()); 1085 } 1086 return null; 1087 } 1088 1089 1096 public Object getByPosition(int pos) 1097 { 1098 if (pos == 0) 1099 { 1100 return getDependId(); 1101 } 1102 if (pos == 1) 1103 { 1104 return getObservedId(); 1105 } 1106 if (pos == 2) 1107 { 1108 return getObserverId(); 1109 } 1110 if (pos == 3) 1111 { 1112 return getTypeId(); 1113 } 1114 if (pos == 4) 1115 { 1116 return Boolean.valueOf(getDeleted()); 1117 } 1118 return null; 1119 } 1120 1121 1127 public void save() throws Exception 1128 { 1129 save(DependPeer.getMapBuilder() 1130 .getDatabaseMap().getName()); 1131 } 1132 1133 1143 public void save(String dbName) throws TorqueException 1144 { 1145 Connection con = null; 1146 try 1147 { 1148 con = Transaction.begin(dbName); 1149 save(con); 1150 Transaction.commit(con); 1151 } 1152 catch(TorqueException e) 1153 { 1154 Transaction.safeRollback(con); 1155 throw e; 1156 } 1157 } 1158 1159 1161 private boolean alreadyInSave = false; 1162 1172 public void save(Connection con) throws TorqueException 1173 { 1174 if (!alreadyInSave) 1175 { 1176 alreadyInSave = true; 1177 1178 1179 1180 if (isModified()) 1182 { 1183 if (isNew()) 1184 { 1185 DependPeer.doInsert((Depend)this, con); 1186 setNew(false); 1187 } 1188 else 1189 { 1190 DependPeer.doUpdate((Depend)this, con); 1191 } 1192 1193 if (isCacheOnSave()) 1194 { 1195 DependManager.putInstance(this); 1196 } 1197 } 1198 1199 1200 if (collActivitys != null) 1201 { 1202 for (int i = 0; i < collActivitys.size(); i++) 1203 { 1204 ((Activity)collActivitys.get(i)).save(con); 1205 } 1206 } 1207 alreadyInSave = false; 1208 } 1209 } 1210 1211 1215 protected boolean isCacheOnSave() 1216 { 1217 return true; 1218 } 1219 1220 1221 1226 public void setPrimaryKey(ObjectKey dependId) 1227 throws TorqueException { 1228 setDependId(new Integer (((NumberKey)dependId).intValue())); 1229 } 1230 1231 1236 public void setPrimaryKey(String key) throws TorqueException 1237 { 1238 setDependId(new Integer (key)); 1239 } 1240 1241 1242 1246 public ObjectKey getPrimaryKey() 1247 { 1248 return SimpleKey.keyFor(getDependId()); 1249 } 1250 1251 1255 public String getQueryKey() 1256 { 1257 if (getPrimaryKey() == null) 1258 { 1259 return ""; 1260 } 1261 else 1262 { 1263 return getPrimaryKey().toString(); 1264 } 1265 } 1266 1267 1271 public void setQueryKey(String key) 1272 throws TorqueException 1273 { 1274 setPrimaryKey(key); 1275 } 1276 1277 1283 public Depend copy() throws TorqueException 1284 { 1285 Depend copyObj = new Depend(); 1286 copyObj.setDependId(dependId); 1287 copyObj.setObservedId(observedId); 1288 copyObj.setObserverId(observerId); 1289 copyObj.setTypeId(typeId); 1290 copyObj.setDeleted(deleted); 1291 1292 copyObj.setDependId((Integer )null); 1293 1294 1295 1296 List v = getActivitys(); 1297 for (int i = 0; i < v.size(); i++) 1298 { 1299 Activity obj = (Activity) v.get(i); 1300 copyObj.addActivity(obj.copy()); 1301 } 1302 return copyObj; 1303 } 1304 1305 1311 public DependPeer getPeer() 1312 { 1313 return peer; 1314 } 1315 1316 public String toString() 1317 { 1318 StringBuffer str = new StringBuffer (); 1319 str.append("Depend:\n"); 1320 str.append("DependId = ") 1321 .append(getDependId()) 1322 .append("\n"); 1323 str.append("ObservedId = ") 1324 .append(getObservedId()) 1325 .append("\n"); 1326 str.append("ObserverId = ") 1327 .append(getObserverId()) 1328 .append("\n"); 1329 str.append("TypeId = ") 1330 .append(getTypeId()) 1331 .append("\n"); 1332 str.append("Deleted = ") 1333 .append(getDeleted()) 1334 .append("\n"); 1335 return(str.toString()); 1336 } 1337} 1338 | Popular Tags |