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 30 public abstract class BaseFrequency extends BaseObject 31 implements org.apache.fulcrum.intake.Retrievable 32 { 33 34 private static final FrequencyPeer peer = 35 new FrequencyPeer(); 36 37 38 39 private Integer frequencyId; 40 41 42 private String name; 43 44 45 50 public Integer getFrequencyId() 51 { 52 return frequencyId; 53 } 54 55 56 61 public void setFrequencyId(Integer v) throws TorqueException 62 { 63 64 if (!ObjectUtils.equals(this.frequencyId, v)) 65 { 66 this.frequencyId = v; 67 setModified(true); 68 } 69 70 71 72 if (collQuerys != null) 74 { 75 for (int i = 0; i < collQuerys.size(); i++) 76 { 77 ((Query) collQuerys.get(i)) 78 .setSubscriptionFrequencyId(v); 79 } 80 } 81 82 if (collRQueryUsers != null) 84 { 85 for (int i = 0; i < collRQueryUsers.size(); i++) 86 { 87 ((RQueryUser) collRQueryUsers.get(i)) 88 .setSubscriptionFrequency(v); 89 } 90 } 91 } 92 93 98 public String getName() 99 { 100 return name; 101 } 102 103 104 109 public void setName(String v) 110 { 111 112 if (!ObjectUtils.equals(this.name, v)) 113 { 114 this.name = v; 115 setModified(true); 116 } 117 118 119 } 120 121 122 123 124 127 protected List collQuerys; 128 129 134 protected void initQuerys() 135 { 136 if (collQuerys == null) 137 { 138 collQuerys = new ArrayList (); 139 } 140 } 141 142 143 150 public void addQuery(Query l) throws TorqueException 151 { 152 getQuerys().add(l); 153 l.setFrequency((Frequency)this); 154 } 155 156 159 private Criteria lastQuerysCriteria = null; 160 161 168 public List getQuerys() throws TorqueException 169 { 170 if (collQuerys == null) 171 { 172 collQuerys = getQuerys(new Criteria(10)); 173 } 174 return collQuerys; 175 } 176 177 188 public List getQuerys(Criteria criteria) throws TorqueException 189 { 190 if (collQuerys == null) 191 { 192 if (isNew()) 193 { 194 collQuerys = new ArrayList (); 195 } 196 else 197 { 198 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 199 collQuerys = QueryPeer.doSelect(criteria); 200 } 201 } 202 else 203 { 204 if (!isNew()) 206 { 207 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 211 if (!lastQuerysCriteria.equals(criteria)) 212 { 213 collQuerys = QueryPeer.doSelect(criteria); 214 } 215 } 216 } 217 lastQuerysCriteria = criteria; 218 219 return collQuerys; 220 } 221 222 230 public List getQuerys(Connection con) throws TorqueException 231 { 232 if (collQuerys == null) 233 { 234 collQuerys = getQuerys(new Criteria(10),con); 235 } 236 return collQuerys; 237 } 238 239 251 public List getQuerys(Criteria criteria,Connection con) throws TorqueException 252 { 253 if (collQuerys == null) 254 { 255 if (isNew()) 256 { 257 collQuerys = new ArrayList (); 258 } 259 else 260 { 261 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 262 collQuerys = QueryPeer.doSelect(criteria,con); 263 } 264 } 265 else 266 { 267 if (!isNew()) 269 { 270 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 274 if (!lastQuerysCriteria.equals(criteria)) 275 { 276 collQuerys = QueryPeer.doSelect(criteria,con); 277 } 278 } 279 } 280 lastQuerysCriteria = criteria; 281 282 return collQuerys; 283 } 284 285 286 287 288 289 290 291 292 293 294 295 306 protected List getQuerysJoinScarabUserImpl(Criteria criteria) 307 throws TorqueException 308 { 309 if (collQuerys == null) 310 { 311 if (isNew()) 312 { 313 collQuerys = new ArrayList (); 314 } 315 else 316 { 317 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 318 collQuerys = QueryPeer.doSelectJoinScarabUserImpl(criteria); 319 } 320 } 321 else 322 { 323 327 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 328 if (!lastQuerysCriteria.equals(criteria)) 329 { 330 collQuerys = QueryPeer.doSelectJoinScarabUserImpl(criteria); 331 } 332 } 333 lastQuerysCriteria = criteria; 334 335 return collQuerys; 336 } 337 338 339 340 341 342 343 344 345 346 357 protected List getQuerysJoinScope(Criteria criteria) 358 throws TorqueException 359 { 360 if (collQuerys == null) 361 { 362 if (isNew()) 363 { 364 collQuerys = new ArrayList (); 365 } 366 else 367 { 368 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 369 collQuerys = QueryPeer.doSelectJoinScope(criteria); 370 } 371 } 372 else 373 { 374 378 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 379 if (!lastQuerysCriteria.equals(criteria)) 380 { 381 collQuerys = QueryPeer.doSelectJoinScope(criteria); 382 } 383 } 384 lastQuerysCriteria = criteria; 385 386 return collQuerys; 387 } 388 389 390 391 392 393 394 395 396 397 408 protected List getQuerysJoinScarabModule(Criteria criteria) 409 throws TorqueException 410 { 411 if (collQuerys == null) 412 { 413 if (isNew()) 414 { 415 collQuerys = new ArrayList (); 416 } 417 else 418 { 419 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 420 collQuerys = QueryPeer.doSelectJoinScarabModule(criteria); 421 } 422 } 423 else 424 { 425 429 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 430 if (!lastQuerysCriteria.equals(criteria)) 431 { 432 collQuerys = QueryPeer.doSelectJoinScarabModule(criteria); 433 } 434 } 435 lastQuerysCriteria = criteria; 436 437 return collQuerys; 438 } 439 440 441 442 443 444 445 446 447 448 459 protected List getQuerysJoinIssueType(Criteria criteria) 460 throws TorqueException 461 { 462 if (collQuerys == null) 463 { 464 if (isNew()) 465 { 466 collQuerys = new ArrayList (); 467 } 468 else 469 { 470 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 471 collQuerys = QueryPeer.doSelectJoinIssueType(criteria); 472 } 473 } 474 else 475 { 476 480 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 481 if (!lastQuerysCriteria.equals(criteria)) 482 { 483 collQuerys = QueryPeer.doSelectJoinIssueType(criteria); 484 } 485 } 486 lastQuerysCriteria = criteria; 487 488 return collQuerys; 489 } 490 491 492 493 494 495 496 497 498 499 510 protected List getQuerysJoinMITList(Criteria criteria) 511 throws TorqueException 512 { 513 if (collQuerys == null) 514 { 515 if (isNew()) 516 { 517 collQuerys = new ArrayList (); 518 } 519 else 520 { 521 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 522 collQuerys = QueryPeer.doSelectJoinMITList(criteria); 523 } 524 } 525 else 526 { 527 531 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 532 if (!lastQuerysCriteria.equals(criteria)) 533 { 534 collQuerys = QueryPeer.doSelectJoinMITList(criteria); 535 } 536 } 537 lastQuerysCriteria = criteria; 538 539 return collQuerys; 540 } 541 542 543 544 545 546 547 548 549 550 561 protected List getQuerysJoinFrequency(Criteria criteria) 562 throws TorqueException 563 { 564 if (collQuerys == null) 565 { 566 if (isNew()) 567 { 568 collQuerys = new ArrayList (); 569 } 570 else 571 { 572 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 573 collQuerys = QueryPeer.doSelectJoinFrequency(criteria); 574 } 575 } 576 else 577 { 578 582 criteria.add(QueryPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 583 if (!lastQuerysCriteria.equals(criteria)) 584 { 585 collQuerys = QueryPeer.doSelectJoinFrequency(criteria); 586 } 587 } 588 lastQuerysCriteria = criteria; 589 590 return collQuerys; 591 } 592 593 594 595 596 597 600 protected List collRQueryUsers; 601 602 607 protected void initRQueryUsers() 608 { 609 if (collRQueryUsers == null) 610 { 611 collRQueryUsers = new ArrayList (); 612 } 613 } 614 615 616 623 public void addRQueryUser(RQueryUser l) throws TorqueException 624 { 625 getRQueryUsers().add(l); 626 l.setFrequency((Frequency)this); 627 } 628 629 632 private Criteria lastRQueryUsersCriteria = null; 633 634 641 public List getRQueryUsers() throws TorqueException 642 { 643 if (collRQueryUsers == null) 644 { 645 collRQueryUsers = getRQueryUsers(new Criteria(10)); 646 } 647 return collRQueryUsers; 648 } 649 650 661 public List getRQueryUsers(Criteria criteria) throws TorqueException 662 { 663 if (collRQueryUsers == null) 664 { 665 if (isNew()) 666 { 667 collRQueryUsers = new ArrayList (); 668 } 669 else 670 { 671 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 672 collRQueryUsers = RQueryUserPeer.doSelect(criteria); 673 } 674 } 675 else 676 { 677 if (!isNew()) 679 { 680 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 684 if (!lastRQueryUsersCriteria.equals(criteria)) 685 { 686 collRQueryUsers = RQueryUserPeer.doSelect(criteria); 687 } 688 } 689 } 690 lastRQueryUsersCriteria = criteria; 691 692 return collRQueryUsers; 693 } 694 695 703 public List getRQueryUsers(Connection con) throws TorqueException 704 { 705 if (collRQueryUsers == null) 706 { 707 collRQueryUsers = getRQueryUsers(new Criteria(10),con); 708 } 709 return collRQueryUsers; 710 } 711 712 724 public List getRQueryUsers(Criteria criteria,Connection con) throws TorqueException 725 { 726 if (collRQueryUsers == null) 727 { 728 if (isNew()) 729 { 730 collRQueryUsers = new ArrayList (); 731 } 732 else 733 { 734 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 735 collRQueryUsers = RQueryUserPeer.doSelect(criteria,con); 736 } 737 } 738 else 739 { 740 if (!isNew()) 742 { 743 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 747 if (!lastRQueryUsersCriteria.equals(criteria)) 748 { 749 collRQueryUsers = RQueryUserPeer.doSelect(criteria,con); 750 } 751 } 752 } 753 lastRQueryUsersCriteria = criteria; 754 755 return collRQueryUsers; 756 } 757 758 759 760 761 762 763 764 765 766 767 768 779 protected List getRQueryUsersJoinQuery(Criteria criteria) 780 throws TorqueException 781 { 782 if (collRQueryUsers == null) 783 { 784 if (isNew()) 785 { 786 collRQueryUsers = new ArrayList (); 787 } 788 else 789 { 790 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 791 collRQueryUsers = RQueryUserPeer.doSelectJoinQuery(criteria); 792 } 793 } 794 else 795 { 796 800 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 801 if (!lastRQueryUsersCriteria.equals(criteria)) 802 { 803 collRQueryUsers = RQueryUserPeer.doSelectJoinQuery(criteria); 804 } 805 } 806 lastRQueryUsersCriteria = criteria; 807 808 return collRQueryUsers; 809 } 810 811 812 813 814 815 816 817 818 819 830 protected List getRQueryUsersJoinScarabUserImpl(Criteria criteria) 831 throws TorqueException 832 { 833 if (collRQueryUsers == null) 834 { 835 if (isNew()) 836 { 837 collRQueryUsers = new ArrayList (); 838 } 839 else 840 { 841 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 842 collRQueryUsers = RQueryUserPeer.doSelectJoinScarabUserImpl(criteria); 843 } 844 } 845 else 846 { 847 851 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 852 if (!lastRQueryUsersCriteria.equals(criteria)) 853 { 854 collRQueryUsers = RQueryUserPeer.doSelectJoinScarabUserImpl(criteria); 855 } 856 } 857 lastRQueryUsersCriteria = criteria; 858 859 return collRQueryUsers; 860 } 861 862 863 864 865 866 867 868 869 870 881 protected List getRQueryUsersJoinFrequency(Criteria criteria) 882 throws TorqueException 883 { 884 if (collRQueryUsers == null) 885 { 886 if (isNew()) 887 { 888 collRQueryUsers = new ArrayList (); 889 } 890 else 891 { 892 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 893 collRQueryUsers = RQueryUserPeer.doSelectJoinFrequency(criteria); 894 } 895 } 896 else 897 { 898 902 criteria.add(RQueryUserPeer.SUBSCRIPTION_FREQUENCY_ID, getFrequencyId() ); 903 if (!lastRQueryUsersCriteria.equals(criteria)) 904 { 905 collRQueryUsers = RQueryUserPeer.doSelectJoinFrequency(criteria); 906 } 907 } 908 lastRQueryUsersCriteria = criteria; 909 910 return collRQueryUsers; 911 } 912 913 914 915 916 private static List fieldNames = null; 917 918 923 public static synchronized List getFieldNames() 924 { 925 if (fieldNames == null) 926 { 927 fieldNames = new ArrayList (); 928 fieldNames.add("FrequencyId"); 929 fieldNames.add("Name"); 930 fieldNames = Collections.unmodifiableList(fieldNames); 931 } 932 return fieldNames; 933 } 934 935 941 public Object getByName(String name) 942 { 943 if (name.equals("FrequencyId")) 944 { 945 return getFrequencyId(); 946 } 947 if (name.equals("Name")) 948 { 949 return getName(); 950 } 951 return null; 952 } 953 954 962 public Object getByPeerName(String name) 963 { 964 if (name.equals(FrequencyPeer.FREQUENCY_ID)) 965 { 966 return getFrequencyId(); 967 } 968 if (name.equals(FrequencyPeer.FREQUENCY_NAME)) 969 { 970 return getName(); 971 } 972 return null; 973 } 974 975 982 public Object getByPosition(int pos) 983 { 984 if (pos == 0) 985 { 986 return getFrequencyId(); 987 } 988 if (pos == 1) 989 { 990 return getName(); 991 } 992 return null; 993 } 994 995 1001 public void save() throws Exception 1002 { 1003 save(FrequencyPeer.getMapBuilder() 1004 .getDatabaseMap().getName()); 1005 } 1006 1007 1017 public void save(String dbName) throws TorqueException 1018 { 1019 Connection con = null; 1020 try 1021 { 1022 con = Transaction.begin(dbName); 1023 save(con); 1024 Transaction.commit(con); 1025 } 1026 catch(TorqueException e) 1027 { 1028 Transaction.safeRollback(con); 1029 throw e; 1030 } 1031 } 1032 1033 1035 private boolean alreadyInSave = false; 1036 1046 public void save(Connection con) throws TorqueException 1047 { 1048 if (!alreadyInSave) 1049 { 1050 alreadyInSave = true; 1051 1052 1053 1054 if (isModified()) 1056 { 1057 if (isNew()) 1058 { 1059 FrequencyPeer.doInsert((Frequency)this, con); 1060 setNew(false); 1061 } 1062 else 1063 { 1064 FrequencyPeer.doUpdate((Frequency)this, con); 1065 } 1066 1067 if (isCacheOnSave()) 1068 { 1069 FrequencyManager.putInstance(this); 1070 } 1071 } 1072 1073 1074 if (collQuerys != null) 1075 { 1076 for (int i = 0; i < collQuerys.size(); i++) 1077 { 1078 ((Query)collQuerys.get(i)).save(con); 1079 } 1080 } 1081 1082 if (collRQueryUsers != null) 1083 { 1084 for (int i = 0; i < collRQueryUsers.size(); i++) 1085 { 1086 ((RQueryUser)collRQueryUsers.get(i)).save(con); 1087 } 1088 } 1089 alreadyInSave = false; 1090 } 1091 } 1092 1093 1097 protected boolean isCacheOnSave() 1098 { 1099 return true; 1100 } 1101 1102 1103 1108 public void setPrimaryKey(ObjectKey frequencyId) 1109 throws TorqueException { 1110 setFrequencyId(new Integer (((NumberKey)frequencyId).intValue())); 1111 } 1112 1113 1118 public void setPrimaryKey(String key) throws TorqueException 1119 { 1120 setFrequencyId(new Integer (key)); 1121 } 1122 1123 1124 1128 public ObjectKey getPrimaryKey() 1129 { 1130 return SimpleKey.keyFor(getFrequencyId()); 1131 } 1132 1133 1137 public String getQueryKey() 1138 { 1139 if (getPrimaryKey() == null) 1140 { 1141 return ""; 1142 } 1143 else 1144 { 1145 return getPrimaryKey().toString(); 1146 } 1147 } 1148 1149 1153 public void setQueryKey(String key) 1154 throws TorqueException 1155 { 1156 setPrimaryKey(key); 1157 } 1158 1159 1165 public Frequency copy() throws TorqueException 1166 { 1167 Frequency copyObj = new Frequency(); 1168 copyObj.setFrequencyId(frequencyId); 1169 copyObj.setName(name); 1170 1171 copyObj.setFrequencyId((Integer )null); 1172 1173 1174 1175 List v = getQuerys(); 1176 for (int i = 0; i < v.size(); i++) 1177 { 1178 Query obj = (Query) v.get(i); 1179 copyObj.addQuery(obj.copy()); 1180 } 1181 1182 1183 v = getRQueryUsers(); 1184 for (int i = 0; i < v.size(); i++) 1185 { 1186 RQueryUser obj = (RQueryUser) v.get(i); 1187 copyObj.addRQueryUser(obj.copy()); 1188 } 1189 return copyObj; 1190 } 1191 1192 1198 public FrequencyPeer getPeer() 1199 { 1200 return peer; 1201 } 1202 1203 public String toString() 1204 { 1205 StringBuffer str = new StringBuffer (); 1206 str.append("Frequency:\n"); 1207 str.append("FrequencyId = ") 1208 .append(getFrequencyId()) 1209 .append("\n"); 1210 str.append("Name = ") 1211 .append(getName()) 1212 .append("\n"); 1213 return(str.toString()); 1214 } 1215} 1216 | Popular Tags |