1 package org.tigris.scarab.om; 2 3 import java.math.BigDecimal ; 4 import java.sql.Connection ; 5 import java.sql.SQLException ; 6 import java.util.ArrayList ; 7 import java.util.Date ; 8 import java.util.Iterator ; 9 import java.util.LinkedList ; 10 import java.util.List ; 11 12 import org.apache.torque.NoRowsException; 13 import org.apache.torque.TooManyRowsException; 14 import org.apache.torque.Torque; 15 import org.apache.torque.TorqueException; 16 import org.apache.torque.map.MapBuilder; 17 import org.apache.torque.map.TableMap; 18 import org.apache.torque.om.DateKey; 19 import org.apache.torque.om.NumberKey; 20 import org.apache.torque.om.StringKey; 21 import org.apache.torque.om.ObjectKey; 22 import org.apache.torque.om.SimpleKey; 23 import org.apache.torque.util.BasePeer; 24 import org.apache.torque.util.Criteria; 25 26 import com.workingdogs.village.DataSetException; 27 import com.workingdogs.village.QueryDataSet; 28 import com.workingdogs.village.Record; 29 30 import org.tigris.scarab.om.map.*; 32 33 34 35 36 37 38 40 public abstract class BaseAttachmentPeer 41 extends BasePeer 42 { 43 44 45 public static final String DATABASE_NAME = "scarab"; 46 47 48 public static final String TABLE_NAME = "SCARAB_ATTACHMENT"; 49 50 55 public static MapBuilder getMapBuilder() 56 throws TorqueException 57 { 58 return getMapBuilder(AttachmentMapBuilder.CLASS_NAME); 59 } 60 61 62 public static final String ATTACHMENT_ID; 63 64 public static final String ISSUE_ID; 65 66 public static final String ATTACHMENT_TYPE_ID; 67 68 public static final String ATTACHMENT_NAME; 69 70 public static final String ATTACHMENT_DATA; 71 72 public static final String ATTACHMENT_FILE_PATH; 73 74 public static final String ATTACHMENT_MIME_TYPE; 75 76 public static final String MODIFIED_BY; 77 78 public static final String CREATED_BY; 79 80 public static final String MODIFIED_DATE; 81 82 public static final String CREATED_DATE; 83 84 public static final String DELETED; 85 86 static 87 { 88 ATTACHMENT_ID = "SCARAB_ATTACHMENT.ATTACHMENT_ID"; 89 ISSUE_ID = "SCARAB_ATTACHMENT.ISSUE_ID"; 90 ATTACHMENT_TYPE_ID = "SCARAB_ATTACHMENT.ATTACHMENT_TYPE_ID"; 91 ATTACHMENT_NAME = "SCARAB_ATTACHMENT.ATTACHMENT_NAME"; 92 ATTACHMENT_DATA = "SCARAB_ATTACHMENT.ATTACHMENT_DATA"; 93 ATTACHMENT_FILE_PATH = "SCARAB_ATTACHMENT.ATTACHMENT_FILE_PATH"; 94 ATTACHMENT_MIME_TYPE = "SCARAB_ATTACHMENT.ATTACHMENT_MIME_TYPE"; 95 MODIFIED_BY = "SCARAB_ATTACHMENT.MODIFIED_BY"; 96 CREATED_BY = "SCARAB_ATTACHMENT.CREATED_BY"; 97 MODIFIED_DATE = "SCARAB_ATTACHMENT.MODIFIED_DATE"; 98 CREATED_DATE = "SCARAB_ATTACHMENT.CREATED_DATE"; 99 DELETED = "SCARAB_ATTACHMENT.DELETED"; 100 if (Torque.isInit()) 101 { 102 try 103 { 104 getMapBuilder(AttachmentMapBuilder.CLASS_NAME); 105 } 106 catch (Exception e) 107 { 108 log.error("Could not initialize Peer", e); 109 } 110 } 111 else 112 { 113 Torque.registerMapBuilder(AttachmentMapBuilder.CLASS_NAME); 114 } 115 } 116 117 118 public static final int numColumns = 12; 119 120 121 protected static final String CLASSNAME_DEFAULT = 122 "org.tigris.scarab.om.Attachment"; 123 124 125 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 126 127 133 private static Class initClass(String className) 134 { 135 Class c = null; 136 try 137 { 138 c = Class.forName(className); 139 } 140 catch (Throwable t) 141 { 142 log.error("A FATAL ERROR has occurred which should not " 143 + "have happened under any circumstance. Please notify " 144 + "the Torque developers <torque-dev@db.apache.org> " 145 + "and give as many details as possible (including the error " 146 + "stack trace).", t); 147 148 if (t instanceof Error ) 150 { 151 throw (Error ) t.fillInStackTrace(); 152 } 153 } 154 return c; 155 } 156 157 167 public static List resultSet2Objects(java.sql.ResultSet results) 168 throws TorqueException 169 { 170 try 171 { 172 QueryDataSet qds = null; 173 List rows = null; 174 try 175 { 176 qds = new QueryDataSet(results); 177 rows = getSelectResults(qds); 178 } 179 finally 180 { 181 if (qds != null) 182 { 183 qds.close(); 184 } 185 } 186 187 return populateObjects(rows); 188 } 189 catch (SQLException e) 190 { 191 throw new TorqueException(e); 192 } 193 catch (DataSetException e) 194 { 195 throw new TorqueException(e); 196 } 197 } 198 199 200 201 208 public static ObjectKey doInsert(Criteria criteria) 209 throws TorqueException 210 { 211 return BaseAttachmentPeer 212 .doInsert(criteria, (Connection ) null); 213 } 214 215 225 public static ObjectKey doInsert(Criteria criteria, Connection con) 226 throws TorqueException 227 { 228 if (criteria.containsKey(DELETED)) 230 { 231 Object possibleBoolean = criteria.get(DELETED); 232 if (possibleBoolean instanceof Boolean ) 233 { 234 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 235 } 236 } 237 238 setDbName(criteria); 239 240 if (con == null) 241 { 242 return BasePeer.doInsert(criteria); 243 } 244 else 245 { 246 return BasePeer.doInsert(criteria, con); 247 } 248 } 249 250 257 public static void addSelectColumns(Criteria criteria) 258 throws TorqueException 259 { 260 criteria.addSelectColumn(ATTACHMENT_ID); 261 criteria.addSelectColumn(ISSUE_ID); 262 criteria.addSelectColumn(ATTACHMENT_TYPE_ID); 263 criteria.addSelectColumn(ATTACHMENT_NAME); 264 criteria.addSelectColumn(ATTACHMENT_DATA); 265 criteria.addSelectColumn(ATTACHMENT_FILE_PATH); 266 criteria.addSelectColumn(ATTACHMENT_MIME_TYPE); 267 criteria.addSelectColumn(MODIFIED_BY); 268 criteria.addSelectColumn(CREATED_BY); 269 criteria.addSelectColumn(MODIFIED_DATE); 270 criteria.addSelectColumn(CREATED_DATE); 271 criteria.addSelectColumn(DELETED); 272 } 273 274 283 public static Attachment row2Object(Record row, 284 int offset, 285 Class cls) 286 throws TorqueException 287 { 288 try 289 { 290 Attachment obj = (Attachment) cls.newInstance(); 291 AttachmentPeer.populateObject(row, offset, obj); 292 obj.setModified(false); 293 obj.setNew(false); 294 295 return obj; 296 } 297 catch (InstantiationException e) 298 { 299 throw new TorqueException(e); 300 } 301 catch (IllegalAccessException e) 302 { 303 throw new TorqueException(e); 304 } 305 } 306 307 316 public static void populateObject(Record row, 317 int offset, 318 Attachment obj) 319 throws TorqueException 320 { 321 try 322 { 323 obj.setAttachmentId(row.getValue(offset + 0).asLongObj()); 324 obj.setIssueId(row.getValue(offset + 1).asLongObj()); 325 obj.setTypeId(row.getValue(offset + 2).asIntegerObj()); 326 obj.setName(row.getValue(offset + 3).asString()); 327 obj.setData(row.getValue(offset + 4).asString()); 328 obj.setFileName(row.getValue(offset + 5).asString()); 329 obj.setMimeType(row.getValue(offset + 6).asString()); 330 obj.setModifiedBy(row.getValue(offset + 7).asIntegerObj()); 331 obj.setCreatedBy(row.getValue(offset + 8).asIntegerObj()); 332 obj.setModifiedDate(row.getValue(offset + 9).asUtilDate()); 333 obj.setCreatedDate(row.getValue(offset + 10).asUtilDate()); 334 obj.setDeleted(row.getValue(offset + 11).asBoolean()); 335 } 336 catch (DataSetException e) 337 { 338 throw new TorqueException(e); 339 } 340 } 341 342 350 public static List doSelect(Criteria criteria) throws TorqueException 351 { 352 return populateObjects(doSelectVillageRecords(criteria)); 353 } 354 355 364 public static List doSelect(Criteria criteria, Connection con) 365 throws TorqueException 366 { 367 return populateObjects(doSelectVillageRecords(criteria, con)); 368 } 369 370 380 public static List doSelectVillageRecords(Criteria criteria) 381 throws TorqueException 382 { 383 return BaseAttachmentPeer 384 .doSelectVillageRecords(criteria, (Connection ) null); 385 } 386 387 396 public static List doSelectVillageRecords(Criteria criteria, Connection con) 397 throws TorqueException 398 { 399 if (criteria.getSelectColumns().size() == 0) 400 { 401 addSelectColumns(criteria); 402 } 403 404 if (criteria.containsKey(DELETED)) 406 { 407 Object possibleBoolean = criteria.get(DELETED); 408 if (possibleBoolean instanceof Boolean ) 409 { 410 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 411 } 412 } 413 414 setDbName(criteria); 415 416 if (con == null) 419 { 420 return BasePeer.doSelect(criteria); 421 } 422 else 423 { 424 return BasePeer.doSelect(criteria, con); 425 } 426 } 427 428 435 public static List populateObjects(List records) 436 throws TorqueException 437 { 438 List results = new ArrayList (records.size()); 439 440 for (int i = 0; i < records.size(); i++) 442 { 443 Record row = (Record) records.get(i); 444 results.add(AttachmentPeer.row2Object(row, 1, 445 AttachmentPeer.getOMClass())); 446 } 447 return results; 448 } 449 450 451 459 public static Class getOMClass() 460 throws TorqueException 461 { 462 return CLASS_DEFAULT; 463 } 464 465 473 public static void doUpdate(Criteria criteria) throws TorqueException 474 { 475 BaseAttachmentPeer 476 .doUpdate(criteria, (Connection ) null); 477 } 478 479 490 public static void doUpdate(Criteria criteria, Connection con) 491 throws TorqueException 492 { 493 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 494 selectCriteria.put(ATTACHMENT_ID, criteria.remove(ATTACHMENT_ID)); 495 if (criteria.containsKey(DELETED)) 497 { 498 Object possibleBoolean = criteria.get(DELETED); 499 if (possibleBoolean instanceof Boolean ) 500 { 501 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 502 } 503 } 504 505 setDbName(criteria); 506 507 if (con == null) 508 { 509 BasePeer.doUpdate(selectCriteria, criteria); 510 } 511 else 512 { 513 BasePeer.doUpdate(selectCriteria, criteria, con); 514 } 515 } 516 517 524 public static void doDelete(Criteria criteria) throws TorqueException 525 { 526 AttachmentPeer 527 .doDelete(criteria, (Connection ) null); 528 } 529 530 540 public static void doDelete(Criteria criteria, Connection con) 541 throws TorqueException 542 { 543 if (criteria.containsKey(DELETED)) 545 { 546 Object possibleBoolean = criteria.get(DELETED); 547 if (possibleBoolean instanceof Boolean ) 548 { 549 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 550 } 551 } 552 553 setDbName(criteria); 554 555 if (con == null) 556 { 557 BasePeer.doDelete(criteria); 558 } 559 else 560 { 561 BasePeer.doDelete(criteria, con); 562 } 563 } 564 565 571 public static List doSelect(Attachment obj) throws TorqueException 572 { 573 return doSelect(buildSelectCriteria(obj)); 574 } 575 576 582 public static void doInsert(Attachment obj) throws TorqueException 583 { 584 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 585 obj.setNew(false); 586 obj.setModified(false); 587 } 588 589 594 public static void doUpdate(Attachment obj) throws TorqueException 595 { 596 doUpdate(buildCriteria(obj)); 597 obj.setModified(false); 598 } 599 600 605 public static void doDelete(Attachment obj) throws TorqueException 606 { 607 doDelete(buildSelectCriteria(obj)); 608 } 609 610 620 public static void doInsert(Attachment obj, Connection con) 621 throws TorqueException 622 { 623 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 624 obj.setNew(false); 625 obj.setModified(false); 626 } 627 628 638 public static void doUpdate(Attachment obj, Connection con) 639 throws TorqueException 640 { 641 doUpdate(buildCriteria(obj), con); 642 obj.setModified(false); 643 } 644 645 655 public static void doDelete(Attachment obj, Connection con) 656 throws TorqueException 657 { 658 doDelete(buildSelectCriteria(obj), con); 659 } 660 661 668 public static void doDelete(ObjectKey pk) throws TorqueException 669 { 670 BaseAttachmentPeer 671 .doDelete(pk, (Connection ) null); 672 } 673 674 684 public static void doDelete(ObjectKey pk, Connection con) 685 throws TorqueException 686 { 687 doDelete(buildCriteria(pk), con); 688 } 689 690 691 public static Criteria buildCriteria( ObjectKey pk ) 692 { 693 Criteria criteria = new Criteria(); 694 criteria.add(ATTACHMENT_ID, pk); 695 return criteria; 696 } 697 698 699 public static Criteria buildCriteria( Attachment obj ) 700 { 701 Criteria criteria = new Criteria(DATABASE_NAME); 702 if (!obj.isNew()) 703 criteria.add(ATTACHMENT_ID, obj.getAttachmentId()); 704 criteria.add(ISSUE_ID, obj.getIssueId()); 705 criteria.add(ATTACHMENT_TYPE_ID, obj.getTypeId()); 706 criteria.add(ATTACHMENT_NAME, obj.getName()); 707 criteria.add(ATTACHMENT_DATA, obj.getData()); 708 criteria.add(ATTACHMENT_FILE_PATH, obj.getFileName()); 709 criteria.add(ATTACHMENT_MIME_TYPE, obj.getMimeType()); 710 criteria.add(MODIFIED_BY, obj.getModifiedBy()); 711 criteria.add(CREATED_BY, obj.getCreatedBy()); 712 criteria.add(MODIFIED_DATE, obj.getModifiedDate()); 713 criteria.add(CREATED_DATE, obj.getCreatedDate()); 714 criteria.add(DELETED, obj.getDeleted()); 715 return criteria; 716 } 717 718 719 public static Criteria buildSelectCriteria( Attachment obj ) 720 { 721 Criteria criteria = new Criteria(DATABASE_NAME); 722 if (!obj.isNew()) 723 criteria.add(ATTACHMENT_ID, obj.getAttachmentId()); 724 criteria.add(ISSUE_ID, obj.getIssueId()); 725 criteria.add(ATTACHMENT_TYPE_ID, obj.getTypeId()); 726 criteria.add(ATTACHMENT_NAME, obj.getName()); 727 criteria.add(ATTACHMENT_DATA, obj.getData()); 728 criteria.add(ATTACHMENT_FILE_PATH, obj.getFileName()); 729 criteria.add(ATTACHMENT_MIME_TYPE, obj.getMimeType()); 730 criteria.add(MODIFIED_BY, obj.getModifiedBy()); 731 criteria.add(CREATED_BY, obj.getCreatedBy()); 732 criteria.add(MODIFIED_DATE, obj.getModifiedDate()); 733 criteria.add(CREATED_DATE, obj.getCreatedDate()); 734 criteria.add(DELETED, obj.getDeleted()); 735 return criteria; 736 } 737 738 739 748 public static Attachment retrieveByPK(Long pk) 749 throws TorqueException, NoRowsException, TooManyRowsException 750 { 751 return retrieveByPK(SimpleKey.keyFor(pk)); 752 } 753 754 764 public static Attachment retrieveByPK(Long pk, Connection con) 765 throws TorqueException, NoRowsException, TooManyRowsException 766 { 767 return retrieveByPK(SimpleKey.keyFor(pk), con); 768 } 769 770 779 public static Attachment retrieveByPK(ObjectKey pk) 780 throws TorqueException, NoRowsException, TooManyRowsException 781 { 782 Connection db = null; 783 Attachment retVal = null; 784 try 785 { 786 db = Torque.getConnection(DATABASE_NAME); 787 retVal = retrieveByPK(pk, db); 788 } 789 finally 790 { 791 Torque.closeConnection(db); 792 } 793 return(retVal); 794 } 795 796 806 public static Attachment retrieveByPK(ObjectKey pk, Connection con) 807 throws TorqueException, NoRowsException, TooManyRowsException 808 { 809 Criteria criteria = buildCriteria(pk); 810 List v = doSelect(criteria, con); 811 if (v.size() == 0) 812 { 813 throw new NoRowsException("Failed to select a row."); 814 } 815 else if (v.size() > 1) 816 { 817 throw new TooManyRowsException("Failed to select only one row."); 818 } 819 else 820 { 821 return (Attachment)v.get(0); 822 } 823 } 824 825 832 public static List retrieveByPKs(List pks) 833 throws TorqueException 834 { 835 Connection db = null; 836 List retVal = null; 837 try 838 { 839 db = Torque.getConnection(DATABASE_NAME); 840 retVal = retrieveByPKs(pks, db); 841 } 842 finally 843 { 844 Torque.closeConnection(db); 845 } 846 return(retVal); 847 } 848 849 857 public static List retrieveByPKs( List pks, Connection dbcon ) 858 throws TorqueException 859 { 860 List objs = null; 861 if (pks == null || pks.size() == 0) 862 { 863 objs = new LinkedList (); 864 } 865 else 866 { 867 Criteria criteria = new Criteria(); 868 criteria.addIn( ATTACHMENT_ID, pks ); 869 objs = doSelect(criteria, dbcon); 870 } 871 return objs; 872 } 873 874 875 876 877 878 879 880 881 882 883 894 protected static List doSelectJoinIssue(Criteria criteria) 895 throws TorqueException 896 { 897 setDbName(criteria); 898 899 AttachmentPeer.addSelectColumns(criteria); 900 int offset = numColumns + 1; 901 IssuePeer.addSelectColumns(criteria); 902 903 904 criteria.addJoin(AttachmentPeer.ISSUE_ID, 905 IssuePeer.ISSUE_ID); 906 907 908 if (criteria.containsKey(DELETED)) 910 { 911 Object possibleBoolean = criteria.get(DELETED); 912 if (possibleBoolean instanceof Boolean ) 913 { 914 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 915 } 916 } 917 918 List rows = BasePeer.doSelect(criteria); 919 List results = new ArrayList (); 920 921 for (int i = 0; i < rows.size(); i++) 922 { 923 Record row = (Record) rows.get(i); 924 925 Class omClass = AttachmentPeer.getOMClass(); 926 Attachment obj1 = (Attachment) AttachmentPeer 927 .row2Object(row, 1, omClass); 928 omClass = IssuePeer.getOMClass(); 929 Issue obj2 = (Issue)IssuePeer 930 .row2Object(row, offset, omClass); 931 932 boolean newObject = true; 933 for (int j = 0; j < results.size(); j++) 934 { 935 Attachment temp_obj1 = (Attachment)results.get(j); 936 Issue temp_obj2 = (Issue)temp_obj1.getIssue(); 937 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 938 { 939 newObject = false; 940 temp_obj2.addAttachment(obj1); 941 break; 942 } 943 } 944 if (newObject) 945 { 946 obj2.initAttachments(); 947 obj2.addAttachment(obj1); 948 } 949 results.add(obj1); 950 } 951 return results; 952 } 953 954 955 956 957 968 protected static List doSelectJoinAttachmentType(Criteria criteria) 969 throws TorqueException 970 { 971 setDbName(criteria); 972 973 AttachmentPeer.addSelectColumns(criteria); 974 int offset = numColumns + 1; 975 AttachmentTypePeer.addSelectColumns(criteria); 976 977 978 criteria.addJoin(AttachmentPeer.ATTACHMENT_TYPE_ID, 979 AttachmentTypePeer.ATTACHMENT_TYPE_ID); 980 981 982 if (criteria.containsKey(DELETED)) 984 { 985 Object possibleBoolean = criteria.get(DELETED); 986 if (possibleBoolean instanceof Boolean ) 987 { 988 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 989 } 990 } 991 992 List rows = BasePeer.doSelect(criteria); 993 List results = new ArrayList (); 994 995 for (int i = 0; i < rows.size(); i++) 996 { 997 Record row = (Record) rows.get(i); 998 999 Class omClass = AttachmentPeer.getOMClass(); 1000 Attachment obj1 = (Attachment) AttachmentPeer 1001 .row2Object(row, 1, omClass); 1002 omClass = AttachmentTypePeer.getOMClass(); 1003 AttachmentType obj2 = (AttachmentType)AttachmentTypePeer 1004 .row2Object(row, offset, omClass); 1005 1006 boolean newObject = true; 1007 for (int j = 0; j < results.size(); j++) 1008 { 1009 Attachment temp_obj1 = (Attachment)results.get(j); 1010 AttachmentType temp_obj2 = (AttachmentType)temp_obj1.getAttachmentType(); 1011 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1012 { 1013 newObject = false; 1014 temp_obj2.addAttachment(obj1); 1015 break; 1016 } 1017 } 1018 if (newObject) 1019 { 1020 obj2.initAttachments(); 1021 obj2.addAttachment(obj1); 1022 } 1023 results.add(obj1); 1024 } 1025 return results; 1026 } 1027 1028 1029 1030 1031 1042 protected static List doSelectJoinScarabUserImplRelatedByCreatedBy(Criteria criteria) 1043 throws TorqueException 1044 { 1045 setDbName(criteria); 1046 1047 AttachmentPeer.addSelectColumns(criteria); 1048 int offset = numColumns + 1; 1049 ScarabUserImplPeer.addSelectColumns(criteria); 1050 1051 1052 criteria.addJoin(AttachmentPeer.CREATED_BY, 1053 ScarabUserImplPeer.USER_ID); 1054 1055 1056 if (criteria.containsKey(DELETED)) 1058 { 1059 Object possibleBoolean = criteria.get(DELETED); 1060 if (possibleBoolean instanceof Boolean ) 1061 { 1062 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 1063 } 1064 } 1065 1066 List rows = BasePeer.doSelect(criteria); 1067 List results = new ArrayList (); 1068 1069 for (int i = 0; i < rows.size(); i++) 1070 { 1071 Record row = (Record) rows.get(i); 1072 1073 Class omClass = AttachmentPeer.getOMClass(); 1074 Attachment obj1 = (Attachment) AttachmentPeer 1075 .row2Object(row, 1, omClass); 1076 omClass = ScarabUserImplPeer.getOMClass(); 1077 ScarabUserImpl obj2 = (ScarabUserImpl)ScarabUserImplPeer 1078 .row2Object(row, offset, omClass); 1079 1080 boolean newObject = true; 1081 for (int j = 0; j < results.size(); j++) 1082 { 1083 Attachment temp_obj1 = (Attachment)results.get(j); 1084 ScarabUserImpl temp_obj2 = (ScarabUserImpl)temp_obj1.getScarabUserRelatedByCreatedBy(); 1085 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1086 { 1087 newObject = false; 1088 temp_obj2.addAttachmentRelatedByCreatedBy(obj1); 1089 break; 1090 } 1091 } 1092 if (newObject) 1093 { 1094 obj2.initAttachmentsRelatedByCreatedBy(); 1095 obj2.addAttachmentRelatedByCreatedBy(obj1); 1096 } 1097 results.add(obj1); 1098 } 1099 return results; 1100 } 1101 1102 1103 1104 1105 1116 protected static List doSelectJoinScarabUserImplRelatedByModifiedBy(Criteria criteria) 1117 throws TorqueException 1118 { 1119 setDbName(criteria); 1120 1121 AttachmentPeer.addSelectColumns(criteria); 1122 int offset = numColumns + 1; 1123 ScarabUserImplPeer.addSelectColumns(criteria); 1124 1125 1126 criteria.addJoin(AttachmentPeer.MODIFIED_BY, 1127 ScarabUserImplPeer.USER_ID); 1128 1129 1130 if (criteria.containsKey(DELETED)) 1132 { 1133 Object possibleBoolean = criteria.get(DELETED); 1134 if (possibleBoolean instanceof Boolean ) 1135 { 1136 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 1137 } 1138 } 1139 1140 List rows = BasePeer.doSelect(criteria); 1141 List results = new ArrayList (); 1142 1143 for (int i = 0; i < rows.size(); i++) 1144 { 1145 Record row = (Record) rows.get(i); 1146 1147 Class omClass = AttachmentPeer.getOMClass(); 1148 Attachment obj1 = (Attachment) AttachmentPeer 1149 .row2Object(row, 1, omClass); 1150 omClass = ScarabUserImplPeer.getOMClass(); 1151 ScarabUserImpl obj2 = (ScarabUserImpl)ScarabUserImplPeer 1152 .row2Object(row, offset, omClass); 1153 1154 boolean newObject = true; 1155 for (int j = 0; j < results.size(); j++) 1156 { 1157 Attachment temp_obj1 = (Attachment)results.get(j); 1158 ScarabUserImpl temp_obj2 = (ScarabUserImpl)temp_obj1.getScarabUserRelatedByModifiedBy(); 1159 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1160 { 1161 newObject = false; 1162 temp_obj2.addAttachmentRelatedByModifiedBy(obj1); 1163 break; 1164 } 1165 } 1166 if (newObject) 1167 { 1168 obj2.initAttachmentsRelatedByModifiedBy(); 1169 obj2.addAttachmentRelatedByModifiedBy(obj1); 1170 } 1171 results.add(obj1); 1172 } 1173 return results; 1174 } 1175 1176 1177 1178 1179 1180 1181 1182 1183 1194 protected static List doSelectJoinAllExceptIssue(Criteria criteria) 1195 throws TorqueException 1196 { 1197 setDbName(criteria); 1198 1199 addSelectColumns(criteria); 1200 int offset2 = numColumns + 1; 1201 1202 1203 AttachmentTypePeer.addSelectColumns(criteria); 1204 int offset3 = offset2 + AttachmentTypePeer.numColumns; 1205 1206 ScarabUserImplPeer.addSelectColumns(criteria); 1207 int offset4 = offset3 + ScarabUserImplPeer.numColumns; 1208 1209 ScarabUserImplPeer.addSelectColumns(criteria); 1210 int offset5 = offset4 + ScarabUserImplPeer.numColumns; 1211 if (criteria.containsKey(DELETED)) 1213 { 1214 Object possibleBoolean = criteria.get(DELETED); 1215 if (possibleBoolean instanceof Boolean ) 1216 { 1217 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 1218 } 1219 } 1220 1221 List rows = BasePeer.doSelect(criteria); 1222 List results = new ArrayList (); 1223 1224 for (int i = 0; i < rows.size(); i++) 1225 { 1226 Record row = (Record)rows.get(i); 1227 1228 Class omClass = AttachmentPeer.getOMClass(); 1229 Attachment obj1 = (Attachment)AttachmentPeer 1230 .row2Object(row, 1, omClass); 1231 1232 1233 1234 1235 1236 omClass = AttachmentTypePeer.getOMClass(); 1237 AttachmentType obj2 = (AttachmentType)AttachmentTypePeer 1238 .row2Object( row, offset2, omClass); 1239 1240 boolean newObject = true; 1241 for (int j = 0; j < results.size(); j++) 1242 { 1243 Attachment temp_obj1 = (Attachment)results.get(j); 1244 AttachmentType temp_obj2 = (AttachmentType)temp_obj1.getAttachmentType(); 1245 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1246 { 1247 newObject = false; 1248 temp_obj2.addAttachment(obj1); 1249 break; 1250 } 1251 } 1252 if (newObject) 1253 { 1254 obj2.initAttachments(); 1255 obj2.addAttachment(obj1); 1256 } 1257 1258 1259 1260 1261 omClass = ScarabUserImplPeer.getOMClass(); 1262 ScarabUserImpl obj3 = (ScarabUserImpl)ScarabUserImplPeer 1263 .row2Object( row, offset3, omClass); 1264 1265 newObject = true; 1266 for (int j = 0; j < results.size(); j++) 1267 { 1268 Attachment temp_obj1 = (Attachment)results.get(j); 1269 ScarabUserImpl temp_obj3 = (ScarabUserImpl)temp_obj1.getScarabUserRelatedByCreatedBy(); 1270 if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey())) 1271 { 1272 newObject = false; 1273 temp_obj3.addAttachmentRelatedByCreatedBy(obj1); 1274 break; 1275 } 1276 } 1277 if (newObject) 1278 { 1279 obj3.initAttachmentsRelatedByCreatedBy(); 1280 obj3.addAttachmentRelatedByCreatedBy(obj1); 1281 } 1282 1283 1284 1285 1286 omClass = ScarabUserImplPeer.getOMClass(); 1287 ScarabUserImpl obj4 = (ScarabUserImpl)ScarabUserImplPeer 1288 .row2Object( row, offset4, omClass); 1289 1290 newObject = true; 1291 for (int j = 0; j < results.size(); j++) 1292 { 1293 Attachment temp_obj1 = (Attachment)results.get(j); 1294 ScarabUserImpl temp_obj4 = (ScarabUserImpl)temp_obj1.getScarabUserRelatedByModifiedBy(); 1295 if (temp_obj4.getPrimaryKey().equals(obj4.getPrimaryKey())) 1296 { 1297 newObject = false; 1298 temp_obj4.addAttachmentRelatedByModifiedBy(obj1); 1299 break; 1300 } 1301 } 1302 if (newObject) 1303 { 1304 obj4.initAttachmentsRelatedByModifiedBy(); 1305 obj4.addAttachmentRelatedByModifiedBy(obj1); 1306 } 1307 results.add(obj1); 1308 } 1309 return results; 1310 } 1311 1312 1313 1314 1315 1316 1327 protected static List doSelectJoinAllExceptAttachmentType(Criteria criteria) 1328 throws TorqueException 1329 { 1330 setDbName(criteria); 1331 1332 addSelectColumns(criteria); 1333 int offset2 = numColumns + 1; 1334 1335 IssuePeer.addSelectColumns(criteria); 1336 int offset3 = offset2 + IssuePeer.numColumns; 1337 1338 1339 ScarabUserImplPeer.addSelectColumns(criteria); 1340 int offset4 = offset3 + ScarabUserImplPeer.numColumns; 1341 1342 ScarabUserImplPeer.addSelectColumns(criteria); 1343 int offset5 = offset4 + ScarabUserImplPeer.numColumns; 1344 if (criteria.containsKey(DELETED)) 1346 { 1347 Object possibleBoolean = criteria.get(DELETED); 1348 if (possibleBoolean instanceof Boolean ) 1349 { 1350 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 1351 } 1352 } 1353 1354 List rows = BasePeer.doSelect(criteria); 1355 List results = new ArrayList (); 1356 1357 for (int i = 0; i < rows.size(); i++) 1358 { 1359 Record row = (Record)rows.get(i); 1360 1361 Class omClass = AttachmentPeer.getOMClass(); 1362 Attachment obj1 = (Attachment)AttachmentPeer 1363 .row2Object(row, 1, omClass); 1364 1365 1366 1367 1368 omClass = IssuePeer.getOMClass(); 1369 Issue obj2 = (Issue)IssuePeer 1370 .row2Object( row, offset2, omClass); 1371 1372 boolean newObject = true; 1373 for (int j = 0; j < results.size(); j++) 1374 { 1375 Attachment temp_obj1 = (Attachment)results.get(j); 1376 Issue temp_obj2 = (Issue)temp_obj1.getIssue(); 1377 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1378 { 1379 newObject = false; 1380 temp_obj2.addAttachment(obj1); 1381 break; 1382 } 1383 } 1384 if (newObject) 1385 { 1386 obj2.initAttachments(); 1387 obj2.addAttachment(obj1); 1388 } 1389 1390 1391 1392 1393 1394 omClass = ScarabUserImplPeer.getOMClass(); 1395 ScarabUserImpl obj3 = (ScarabUserImpl)ScarabUserImplPeer 1396 .row2Object( row, offset3, omClass); 1397 1398 newObject = true; 1399 for (int j = 0; j < results.size(); j++) 1400 { 1401 Attachment temp_obj1 = (Attachment)results.get(j); 1402 ScarabUserImpl temp_obj3 = (ScarabUserImpl)temp_obj1.getScarabUserRelatedByCreatedBy(); 1403 if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey())) 1404 { 1405 newObject = false; 1406 temp_obj3.addAttachmentRelatedByCreatedBy(obj1); 1407 break; 1408 } 1409 } 1410 if (newObject) 1411 { 1412 obj3.initAttachmentsRelatedByCreatedBy(); 1413 obj3.addAttachmentRelatedByCreatedBy(obj1); 1414 } 1415 1416 1417 1418 1419 omClass = ScarabUserImplPeer.getOMClass(); 1420 ScarabUserImpl obj4 = (ScarabUserImpl)ScarabUserImplPeer 1421 .row2Object( row, offset4, omClass); 1422 1423 newObject = true; 1424 for (int j = 0; j < results.size(); j++) 1425 { 1426 Attachment temp_obj1 = (Attachment)results.get(j); 1427 ScarabUserImpl temp_obj4 = (ScarabUserImpl)temp_obj1.getScarabUserRelatedByModifiedBy(); 1428 if (temp_obj4.getPrimaryKey().equals(obj4.getPrimaryKey())) 1429 { 1430 newObject = false; 1431 temp_obj4.addAttachmentRelatedByModifiedBy(obj1); 1432 break; 1433 } 1434 } 1435 if (newObject) 1436 { 1437 obj4.initAttachmentsRelatedByModifiedBy(); 1438 obj4.addAttachmentRelatedByModifiedBy(obj1); 1439 } 1440 results.add(obj1); 1441 } 1442 return results; 1443 } 1444 1445 1446 1447 1448 1449 1460 protected static List doSelectJoinAllExceptScarabUserImplRelatedByCreatedBy(Criteria criteria) 1461 throws TorqueException 1462 { 1463 setDbName(criteria); 1464 1465 addSelectColumns(criteria); 1466 int offset2 = numColumns + 1; 1467 1468 IssuePeer.addSelectColumns(criteria); 1469 int offset3 = offset2 + IssuePeer.numColumns; 1470 1471 AttachmentTypePeer.addSelectColumns(criteria); 1472 int offset4 = offset3 + AttachmentTypePeer.numColumns; 1473 1474 1475 if (criteria.containsKey(DELETED)) 1477 { 1478 Object possibleBoolean = criteria.get(DELETED); 1479 if (possibleBoolean instanceof Boolean ) 1480 { 1481 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 1482 } 1483 } 1484 1485 List rows = BasePeer.doSelect(criteria); 1486 List results = new ArrayList (); 1487 1488 for (int i = 0; i < rows.size(); i++) 1489 { 1490 Record row = (Record)rows.get(i); 1491 1492 Class omClass = AttachmentPeer.getOMClass(); 1493 Attachment obj1 = (Attachment)AttachmentPeer 1494 .row2Object(row, 1, omClass); 1495 1496 1497 1498 1499 omClass = IssuePeer.getOMClass(); 1500 Issue obj2 = (Issue)IssuePeer 1501 .row2Object( row, offset2, omClass); 1502 1503 boolean newObject = true; 1504 for (int j = 0; j < results.size(); j++) 1505 { 1506 Attachment temp_obj1 = (Attachment)results.get(j); 1507 Issue temp_obj2 = (Issue)temp_obj1.getIssue(); 1508 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1509 { 1510 newObject = false; 1511 temp_obj2.addAttachment(obj1); 1512 break; 1513 } 1514 } 1515 if (newObject) 1516 { 1517 obj2.initAttachments(); 1518 obj2.addAttachment(obj1); 1519 } 1520 1521 1522 1523 1524 omClass = AttachmentTypePeer.getOMClass(); 1525 AttachmentType obj3 = (AttachmentType)AttachmentTypePeer 1526 .row2Object( row, offset3, omClass); 1527 1528 newObject = true; 1529 for (int j = 0; j < results.size(); j++) 1530 { 1531 Attachment temp_obj1 = (Attachment)results.get(j); 1532 AttachmentType temp_obj3 = (AttachmentType)temp_obj1.getAttachmentType(); 1533 if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey())) 1534 { 1535 newObject = false; 1536 temp_obj3.addAttachment(obj1); 1537 break; 1538 } 1539 } 1540 if (newObject) 1541 { 1542 obj3.initAttachments(); 1543 obj3.addAttachment(obj1); 1544 } 1545 1546 1547 results.add(obj1); 1548 } 1549 return results; 1550 } 1551 1552 1553 1554 1555 1556 1567 protected static List doSelectJoinAllExceptScarabUserImplRelatedByModifiedBy(Criteria criteria) 1568 throws TorqueException 1569 { 1570 setDbName(criteria); 1571 1572 addSelectColumns(criteria); 1573 int offset2 = numColumns + 1; 1574 1575 IssuePeer.addSelectColumns(criteria); 1576 int offset3 = offset2 + IssuePeer.numColumns; 1577 1578 AttachmentTypePeer.addSelectColumns(criteria); 1579 int offset4 = offset3 + AttachmentTypePeer.numColumns; 1580 1581 1582 if (criteria.containsKey(DELETED)) 1584 { 1585 Object possibleBoolean = criteria.get(DELETED); 1586 if (possibleBoolean instanceof Boolean ) 1587 { 1588 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 1589 } 1590 } 1591 1592 List rows = BasePeer.doSelect(criteria); 1593 List results = new ArrayList (); 1594 1595 for (int i = 0; i < rows.size(); i++) 1596 { 1597 Record row = (Record)rows.get(i); 1598 1599 Class omClass = AttachmentPeer.getOMClass(); 1600 Attachment obj1 = (Attachment)AttachmentPeer 1601 .row2Object(row, 1, omClass); 1602 1603 1604 1605 1606 omClass = IssuePeer.getOMClass(); 1607 Issue obj2 = (Issue)IssuePeer 1608 .row2Object( row, offset2, omClass); 1609 1610 boolean newObject = true; 1611 for (int j = 0; j < results.size(); j++) 1612 { 1613 Attachment temp_obj1 = (Attachment)results.get(j); 1614 Issue temp_obj2 = (Issue)temp_obj1.getIssue(); 1615 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1616 { 1617 newObject = false; 1618 temp_obj2.addAttachment(obj1); 1619 break; 1620 } 1621 } 1622 if (newObject) 1623 { 1624 obj2.initAttachments(); 1625 obj2.addAttachment(obj1); 1626 } 1627 1628 1629 1630 1631 omClass = AttachmentTypePeer.getOMClass(); 1632 AttachmentType obj3 = (AttachmentType)AttachmentTypePeer 1633 .row2Object( row, offset3, omClass); 1634 1635 newObject = true; 1636 for (int j = 0; j < results.size(); j++) 1637 { 1638 Attachment temp_obj1 = (Attachment)results.get(j); 1639 AttachmentType temp_obj3 = (AttachmentType)temp_obj1.getAttachmentType(); 1640 if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey())) 1641 { 1642 newObject = false; 1643 temp_obj3.addAttachment(obj1); 1644 break; 1645 } 1646 } 1647 if (newObject) 1648 { 1649 obj3.initAttachments(); 1650 obj3.addAttachment(obj1); 1651 } 1652 1653 1654 results.add(obj1); 1655 } 1656 return results; 1657 } 1658 1659 1660 1667 protected static TableMap getTableMap() 1668 throws TorqueException 1669 { 1670 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 1671 } 1672 1673 private static void setDbName(Criteria crit) 1674 { 1675 if (crit.getDbName() == Torque.getDefaultDB()) 1679 { 1680 crit.setDbName(DATABASE_NAME); 1681 } 1682 } 1683} 1684 | Popular Tags |