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 38 public abstract class BaseRIssueTypeOptionPeer 39 extends BasePeer 40 { 41 42 43 public static final String DATABASE_NAME = "scarab"; 44 45 46 public static final String TABLE_NAME = "SCARAB_R_ISSUETYPE_OPTION"; 47 48 53 public static MapBuilder getMapBuilder() 54 throws TorqueException 55 { 56 return getMapBuilder(RIssueTypeOptionMapBuilder.CLASS_NAME); 57 } 58 59 60 public static final String ISSUE_TYPE_ID; 61 62 public static final String OPTION_ID; 63 64 public static final String ACTIVE; 65 66 public static final String LOCKED; 67 68 public static final String PREFERRED_ORDER; 69 70 public static final String WEIGHT; 71 72 static 73 { 74 ISSUE_TYPE_ID = "SCARAB_R_ISSUETYPE_OPTION.ISSUE_TYPE_ID"; 75 OPTION_ID = "SCARAB_R_ISSUETYPE_OPTION.OPTION_ID"; 76 ACTIVE = "SCARAB_R_ISSUETYPE_OPTION.ACTIVE"; 77 LOCKED = "SCARAB_R_ISSUETYPE_OPTION.LOCKED"; 78 PREFERRED_ORDER = "SCARAB_R_ISSUETYPE_OPTION.PREFERRED_ORDER"; 79 WEIGHT = "SCARAB_R_ISSUETYPE_OPTION.WEIGHT"; 80 if (Torque.isInit()) 81 { 82 try 83 { 84 getMapBuilder(RIssueTypeOptionMapBuilder.CLASS_NAME); 85 } 86 catch (Exception e) 87 { 88 log.error("Could not initialize Peer", e); 89 } 90 } 91 else 92 { 93 Torque.registerMapBuilder(RIssueTypeOptionMapBuilder.CLASS_NAME); 94 } 95 } 96 97 98 public static final int numColumns = 6; 99 100 101 protected static final String CLASSNAME_DEFAULT = 102 "org.tigris.scarab.om.RIssueTypeOption"; 103 104 105 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 106 107 113 private static Class initClass(String className) 114 { 115 Class c = null; 116 try 117 { 118 c = Class.forName(className); 119 } 120 catch (Throwable t) 121 { 122 log.error("A FATAL ERROR has occurred which should not " 123 + "have happened under any circumstance. Please notify " 124 + "the Torque developers <torque-dev@db.apache.org> " 125 + "and give as many details as possible (including the error " 126 + "stack trace).", t); 127 128 if (t instanceof Error ) 130 { 131 throw (Error ) t.fillInStackTrace(); 132 } 133 } 134 return c; 135 } 136 137 147 public static List resultSet2Objects(java.sql.ResultSet results) 148 throws TorqueException 149 { 150 try 151 { 152 QueryDataSet qds = null; 153 List rows = null; 154 try 155 { 156 qds = new QueryDataSet(results); 157 rows = getSelectResults(qds); 158 } 159 finally 160 { 161 if (qds != null) 162 { 163 qds.close(); 164 } 165 } 166 167 return populateObjects(rows); 168 } 169 catch (SQLException e) 170 { 171 throw new TorqueException(e); 172 } 173 catch (DataSetException e) 174 { 175 throw new TorqueException(e); 176 } 177 } 178 179 180 181 188 public static ObjectKey doInsert(Criteria criteria) 189 throws TorqueException 190 { 191 return BaseRIssueTypeOptionPeer 192 .doInsert(criteria, (Connection ) null); 193 } 194 195 205 public static ObjectKey doInsert(Criteria criteria, Connection con) 206 throws TorqueException 207 { 208 if (criteria.containsKey(ACTIVE)) 210 { 211 Object possibleBoolean = criteria.get(ACTIVE); 212 if (possibleBoolean instanceof Boolean ) 213 { 214 criteria.add(ACTIVE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 215 } 216 } 217 if (criteria.containsKey(LOCKED)) 219 { 220 Object possibleBoolean = criteria.get(LOCKED); 221 if (possibleBoolean instanceof Boolean ) 222 { 223 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 224 } 225 } 226 227 setDbName(criteria); 228 229 if (con == null) 230 { 231 return BasePeer.doInsert(criteria); 232 } 233 else 234 { 235 return BasePeer.doInsert(criteria, con); 236 } 237 } 238 239 246 public static void addSelectColumns(Criteria criteria) 247 throws TorqueException 248 { 249 criteria.addSelectColumn(ISSUE_TYPE_ID); 250 criteria.addSelectColumn(OPTION_ID); 251 criteria.addSelectColumn(ACTIVE); 252 criteria.addSelectColumn(LOCKED); 253 criteria.addSelectColumn(PREFERRED_ORDER); 254 criteria.addSelectColumn(WEIGHT); 255 } 256 257 266 public static RIssueTypeOption row2Object(Record row, 267 int offset, 268 Class cls) 269 throws TorqueException 270 { 271 try 272 { 273 RIssueTypeOption obj = (RIssueTypeOption) cls.newInstance(); 274 RIssueTypeOptionPeer.populateObject(row, offset, obj); 275 obj.setModified(false); 276 obj.setNew(false); 277 278 return obj; 279 } 280 catch (InstantiationException e) 281 { 282 throw new TorqueException(e); 283 } 284 catch (IllegalAccessException e) 285 { 286 throw new TorqueException(e); 287 } 288 } 289 290 299 public static void populateObject(Record row, 300 int offset, 301 RIssueTypeOption obj) 302 throws TorqueException 303 { 304 try 305 { 306 obj.setIssueTypeId(row.getValue(offset + 0).asIntegerObj()); 307 obj.setOptionId(row.getValue(offset + 1).asIntegerObj()); 308 obj.setActive(row.getValue(offset + 2).asBoolean()); 309 obj.setLocked(row.getValue(offset + 3).asBoolean()); 310 obj.setOrder(row.getValue(offset + 4).asInt()); 311 obj.setWeight(row.getValue(offset + 5).asInt()); 312 } 313 catch (DataSetException e) 314 { 315 throw new TorqueException(e); 316 } 317 } 318 319 327 public static List doSelect(Criteria criteria) throws TorqueException 328 { 329 return populateObjects(doSelectVillageRecords(criteria)); 330 } 331 332 341 public static List doSelect(Criteria criteria, Connection con) 342 throws TorqueException 343 { 344 return populateObjects(doSelectVillageRecords(criteria, con)); 345 } 346 347 357 public static List doSelectVillageRecords(Criteria criteria) 358 throws TorqueException 359 { 360 return BaseRIssueTypeOptionPeer 361 .doSelectVillageRecords(criteria, (Connection ) null); 362 } 363 364 373 public static List doSelectVillageRecords(Criteria criteria, Connection con) 374 throws TorqueException 375 { 376 if (criteria.getSelectColumns().size() == 0) 377 { 378 addSelectColumns(criteria); 379 } 380 381 if (criteria.containsKey(ACTIVE)) 383 { 384 Object possibleBoolean = criteria.get(ACTIVE); 385 if (possibleBoolean instanceof Boolean ) 386 { 387 criteria.add(ACTIVE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 388 } 389 } 390 if (criteria.containsKey(LOCKED)) 392 { 393 Object possibleBoolean = criteria.get(LOCKED); 394 if (possibleBoolean instanceof Boolean ) 395 { 396 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 397 } 398 } 399 400 setDbName(criteria); 401 402 if (con == null) 405 { 406 return BasePeer.doSelect(criteria); 407 } 408 else 409 { 410 return BasePeer.doSelect(criteria, con); 411 } 412 } 413 414 421 public static List populateObjects(List records) 422 throws TorqueException 423 { 424 List results = new ArrayList (records.size()); 425 426 for (int i = 0; i < records.size(); i++) 428 { 429 Record row = (Record) records.get(i); 430 results.add(RIssueTypeOptionPeer.row2Object(row, 1, 431 RIssueTypeOptionPeer.getOMClass())); 432 } 433 return results; 434 } 435 436 437 445 public static Class getOMClass() 446 throws TorqueException 447 { 448 return CLASS_DEFAULT; 449 } 450 451 459 public static void doUpdate(Criteria criteria) throws TorqueException 460 { 461 BaseRIssueTypeOptionPeer 462 .doUpdate(criteria, (Connection ) null); 463 } 464 465 476 public static void doUpdate(Criteria criteria, Connection con) 477 throws TorqueException 478 { 479 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 480 selectCriteria.put(ISSUE_TYPE_ID, criteria.remove(ISSUE_TYPE_ID)); 481 selectCriteria.put(OPTION_ID, criteria.remove(OPTION_ID)); 482 if (criteria.containsKey(ACTIVE)) 484 { 485 Object possibleBoolean = criteria.get(ACTIVE); 486 if (possibleBoolean instanceof Boolean ) 487 { 488 criteria.add(ACTIVE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 489 } 490 } 491 if (criteria.containsKey(LOCKED)) 493 { 494 Object possibleBoolean = criteria.get(LOCKED); 495 if (possibleBoolean instanceof Boolean ) 496 { 497 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 498 } 499 } 500 501 setDbName(criteria); 502 503 if (con == null) 504 { 505 BasePeer.doUpdate(selectCriteria, criteria); 506 } 507 else 508 { 509 BasePeer.doUpdate(selectCriteria, criteria, con); 510 } 511 } 512 513 520 public static void doDelete(Criteria criteria) throws TorqueException 521 { 522 RIssueTypeOptionPeer 523 .doDelete(criteria, (Connection ) null); 524 } 525 526 536 public static void doDelete(Criteria criteria, Connection con) 537 throws TorqueException 538 { 539 if (criteria.containsKey(ACTIVE)) 541 { 542 Object possibleBoolean = criteria.get(ACTIVE); 543 if (possibleBoolean instanceof Boolean ) 544 { 545 criteria.add(ACTIVE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 546 } 547 } 548 if (criteria.containsKey(LOCKED)) 550 { 551 Object possibleBoolean = criteria.get(LOCKED); 552 if (possibleBoolean instanceof Boolean ) 553 { 554 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 555 } 556 } 557 558 setDbName(criteria); 559 560 if (con == null) 561 { 562 BasePeer.doDelete(criteria); 563 } 564 else 565 { 566 BasePeer.doDelete(criteria, con); 567 } 568 } 569 570 576 public static List doSelect(RIssueTypeOption obj) throws TorqueException 577 { 578 return doSelect(buildSelectCriteria(obj)); 579 } 580 581 587 public static void doInsert(RIssueTypeOption obj) throws TorqueException 588 { 589 doInsert(buildCriteria(obj)); 590 obj.setNew(false); 591 obj.setModified(false); 592 } 593 594 599 public static void doUpdate(RIssueTypeOption obj) throws TorqueException 600 { 601 doUpdate(buildCriteria(obj)); 602 obj.setModified(false); 603 } 604 605 610 public static void doDelete(RIssueTypeOption obj) throws TorqueException 611 { 612 doDelete(buildSelectCriteria(obj)); 613 } 614 615 625 public static void doInsert(RIssueTypeOption obj, Connection con) 626 throws TorqueException 627 { 628 doInsert(buildCriteria(obj), con); 629 obj.setNew(false); 630 obj.setModified(false); 631 } 632 633 643 public static void doUpdate(RIssueTypeOption obj, Connection con) 644 throws TorqueException 645 { 646 doUpdate(buildCriteria(obj), con); 647 obj.setModified(false); 648 } 649 650 660 public static void doDelete(RIssueTypeOption obj, Connection con) 661 throws TorqueException 662 { 663 doDelete(buildSelectCriteria(obj), con); 664 } 665 666 673 public static void doDelete(ObjectKey pk) throws TorqueException 674 { 675 BaseRIssueTypeOptionPeer 676 .doDelete(pk, (Connection ) null); 677 } 678 679 689 public static void doDelete(ObjectKey pk, Connection con) 690 throws TorqueException 691 { 692 doDelete(buildCriteria(pk), con); 693 } 694 695 696 public static Criteria buildCriteria( ObjectKey pk ) 697 { 698 Criteria criteria = new Criteria(); 699 SimpleKey[] keys = (SimpleKey[])pk.getValue(); 700 criteria.add(ISSUE_TYPE_ID, keys[0]); 701 criteria.add(OPTION_ID, keys[1]); 702 return criteria; 703 } 704 705 706 public static Criteria buildCriteria( RIssueTypeOption obj ) 707 { 708 Criteria criteria = new Criteria(DATABASE_NAME); 709 criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId()); 710 criteria.add(OPTION_ID, obj.getOptionId()); 711 criteria.add(ACTIVE, obj.getActive()); 712 criteria.add(LOCKED, obj.getLocked()); 713 criteria.add(PREFERRED_ORDER, obj.getOrder()); 714 criteria.add(WEIGHT, obj.getWeight()); 715 return criteria; 716 } 717 718 719 public static Criteria buildSelectCriteria( RIssueTypeOption obj ) 720 { 721 Criteria criteria = new Criteria(DATABASE_NAME); 722 criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId()); 723 criteria.add(OPTION_ID, obj.getOptionId()); 724 criteria.add(ACTIVE, obj.getActive()); 725 criteria.add(LOCKED, obj.getLocked()); 726 criteria.add(PREFERRED_ORDER, obj.getOrder()); 727 criteria.add(WEIGHT, obj.getWeight()); 728 return criteria; 729 } 730 731 732 733 742 public static RIssueTypeOption retrieveByPK(ObjectKey pk) 743 throws TorqueException, NoRowsException, TooManyRowsException 744 { 745 Connection db = null; 746 RIssueTypeOption retVal = null; 747 try 748 { 749 db = Torque.getConnection(DATABASE_NAME); 750 retVal = retrieveByPK(pk, db); 751 } 752 finally 753 { 754 Torque.closeConnection(db); 755 } 756 return(retVal); 757 } 758 759 769 public static RIssueTypeOption retrieveByPK(ObjectKey pk, Connection con) 770 throws TorqueException, NoRowsException, TooManyRowsException 771 { 772 Criteria criteria = buildCriteria(pk); 773 List v = doSelect(criteria, con); 774 if (v.size() == 0) 775 { 776 throw new NoRowsException("Failed to select a row."); 777 } 778 else if (v.size() > 1) 779 { 780 throw new TooManyRowsException("Failed to select only one row."); 781 } 782 else 783 { 784 return (RIssueTypeOption)v.get(0); 785 } 786 } 787 788 795 public static List retrieveByPKs(List pks) 796 throws TorqueException 797 { 798 Connection db = null; 799 List retVal = null; 800 try 801 { 802 db = Torque.getConnection(DATABASE_NAME); 803 retVal = retrieveByPKs(pks, db); 804 } 805 finally 806 { 807 Torque.closeConnection(db); 808 } 809 return(retVal); 810 } 811 812 820 public static List retrieveByPKs( List pks, Connection dbcon ) 821 throws TorqueException 822 { 823 List objs = null; 824 if (pks == null || pks.size() == 0) 825 { 826 objs = new LinkedList (); 827 } 828 else 829 { 830 Criteria criteria = new Criteria(); 831 Iterator iter = pks.iterator(); 832 while (iter.hasNext()) 833 { 834 ObjectKey pk = (ObjectKey)iter.next(); 835 SimpleKey[] keys = (SimpleKey[])pk.getValue(); 836 Criteria.Criterion c0 = criteria.getNewCriterion( 837 ISSUE_TYPE_ID, keys[0], Criteria.EQUAL); 838 Criteria.Criterion c1 = criteria.getNewCriterion( 839 OPTION_ID, keys[1], Criteria.EQUAL); 840 c0.and(c1); 841 criteria.or(c0); 842 } 843 objs = doSelect(criteria, dbcon); 844 } 845 return objs; 846 } 847 848 849 855 public static RIssueTypeOption retrieveByPK( 856 Integer issue_type_id 857 , Integer option_id 858 ) throws TorqueException 859 { 860 Connection db = null; 861 RIssueTypeOption retVal = null; 862 try 863 { 864 db = Torque.getConnection(DATABASE_NAME); 865 retVal = retrieveByPK( 866 issue_type_id 867 , option_id 868 , db); 869 } 870 finally 871 { 872 Torque.closeConnection(db); 873 } 874 return(retVal); 875 } 876 877 884 public static RIssueTypeOption retrieveByPK( 885 Integer issue_type_id 886 , Integer option_id 887 ,Connection con) throws TorqueException 888 { 889 890 Criteria criteria = new Criteria(5); 891 criteria.add(ISSUE_TYPE_ID, issue_type_id); 892 criteria.add(OPTION_ID, option_id); 893 List v = doSelect(criteria, con); 894 if (v.size() != 1) 895 { 896 throw new TorqueException("Failed to select one and only one row."); 897 } 898 else 899 { 900 return (RIssueTypeOption) v.get(0); 901 } 902 } 903 904 905 906 907 908 909 910 911 922 protected static List doSelectJoinAttributeOption(Criteria criteria) 923 throws TorqueException 924 { 925 setDbName(criteria); 926 927 RIssueTypeOptionPeer.addSelectColumns(criteria); 928 int offset = numColumns + 1; 929 AttributeOptionPeer.addSelectColumns(criteria); 930 931 932 criteria.addJoin(RIssueTypeOptionPeer.OPTION_ID, 933 AttributeOptionPeer.OPTION_ID); 934 935 936 if (criteria.containsKey(ACTIVE)) 938 { 939 Object possibleBoolean = criteria.get(ACTIVE); 940 if (possibleBoolean instanceof Boolean ) 941 { 942 criteria.add(ACTIVE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 943 } 944 } 945 if (criteria.containsKey(LOCKED)) 947 { 948 Object possibleBoolean = criteria.get(LOCKED); 949 if (possibleBoolean instanceof Boolean ) 950 { 951 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 952 } 953 } 954 955 List rows = BasePeer.doSelect(criteria); 956 List results = new ArrayList (); 957 958 for (int i = 0; i < rows.size(); i++) 959 { 960 Record row = (Record) rows.get(i); 961 962 Class omClass = RIssueTypeOptionPeer.getOMClass(); 963 RIssueTypeOption obj1 = (RIssueTypeOption) RIssueTypeOptionPeer 964 .row2Object(row, 1, omClass); 965 omClass = AttributeOptionPeer.getOMClass(); 966 AttributeOption obj2 = (AttributeOption)AttributeOptionPeer 967 .row2Object(row, offset, omClass); 968 969 boolean newObject = true; 970 for (int j = 0; j < results.size(); j++) 971 { 972 RIssueTypeOption temp_obj1 = (RIssueTypeOption)results.get(j); 973 AttributeOption temp_obj2 = (AttributeOption)temp_obj1.getAttributeOption(); 974 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 975 { 976 newObject = false; 977 temp_obj2.addRIssueTypeOption(obj1); 978 break; 979 } 980 } 981 if (newObject) 982 { 983 obj2.initRIssueTypeOptions(); 984 obj2.addRIssueTypeOption(obj1); 985 } 986 results.add(obj1); 987 } 988 return results; 989 } 990 991 992 993 994 1005 protected static List doSelectJoinIssueType(Criteria criteria) 1006 throws TorqueException 1007 { 1008 setDbName(criteria); 1009 1010 RIssueTypeOptionPeer.addSelectColumns(criteria); 1011 int offset = numColumns + 1; 1012 IssueTypePeer.addSelectColumns(criteria); 1013 1014 1015 criteria.addJoin(RIssueTypeOptionPeer.ISSUE_TYPE_ID, 1016 IssueTypePeer.ISSUE_TYPE_ID); 1017 1018 1019 if (criteria.containsKey(ACTIVE)) 1021 { 1022 Object possibleBoolean = criteria.get(ACTIVE); 1023 if (possibleBoolean instanceof Boolean ) 1024 { 1025 criteria.add(ACTIVE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 1026 } 1027 } 1028 if (criteria.containsKey(LOCKED)) 1030 { 1031 Object possibleBoolean = criteria.get(LOCKED); 1032 if (possibleBoolean instanceof Boolean ) 1033 { 1034 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 1035 } 1036 } 1037 1038 List rows = BasePeer.doSelect(criteria); 1039 List results = new ArrayList (); 1040 1041 for (int i = 0; i < rows.size(); i++) 1042 { 1043 Record row = (Record) rows.get(i); 1044 1045 Class omClass = RIssueTypeOptionPeer.getOMClass(); 1046 RIssueTypeOption obj1 = (RIssueTypeOption) RIssueTypeOptionPeer 1047 .row2Object(row, 1, omClass); 1048 omClass = IssueTypePeer.getOMClass(); 1049 IssueType obj2 = (IssueType)IssueTypePeer 1050 .row2Object(row, offset, omClass); 1051 1052 boolean newObject = true; 1053 for (int j = 0; j < results.size(); j++) 1054 { 1055 RIssueTypeOption temp_obj1 = (RIssueTypeOption)results.get(j); 1056 IssueType temp_obj2 = (IssueType)temp_obj1.getIssueType(); 1057 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 1058 { 1059 newObject = false; 1060 temp_obj2.addRIssueTypeOption(obj1); 1061 break; 1062 } 1063 } 1064 if (newObject) 1065 { 1066 obj2.initRIssueTypeOptions(); 1067 obj2.addRIssueTypeOption(obj1); 1068 } 1069 results.add(obj1); 1070 } 1071 return results; 1072 } 1073 1074 1075 1076 1077 1084 protected static TableMap getTableMap() 1085 throws TorqueException 1086 { 1087 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 1088 } 1089 1090 private static void setDbName(Criteria crit) 1091 { 1092 if (crit.getDbName() == Torque.getDefaultDB()) 1096 { 1097 crit.setDbName(DATABASE_NAME); 1098 } 1099 } 1100} 1101 | Popular Tags |