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 BaseIssueTemplateInfoPeer 39 extends BasePeer 40 { 41 42 43 public static final String DATABASE_NAME = "scarab"; 44 45 46 public static final String TABLE_NAME = "SCARAB_ISSUE_TEMPLATE_INFO"; 47 48 53 public static MapBuilder getMapBuilder() 54 throws TorqueException 55 { 56 return getMapBuilder(IssueTemplateInfoMapBuilder.CLASS_NAME); 57 } 58 59 60 public static final String ISSUE_ID; 61 62 public static final String NAME; 63 64 public static final String DESCRIPTION; 65 66 public static final String APPROVED; 67 68 public static final String SCOPE_ID; 69 70 static 71 { 72 ISSUE_ID = "SCARAB_ISSUE_TEMPLATE_INFO.ISSUE_ID"; 73 NAME = "SCARAB_ISSUE_TEMPLATE_INFO.NAME"; 74 DESCRIPTION = "SCARAB_ISSUE_TEMPLATE_INFO.DESCRIPTION"; 75 APPROVED = "SCARAB_ISSUE_TEMPLATE_INFO.APPROVED"; 76 SCOPE_ID = "SCARAB_ISSUE_TEMPLATE_INFO.SCOPE_ID"; 77 if (Torque.isInit()) 78 { 79 try 80 { 81 getMapBuilder(IssueTemplateInfoMapBuilder.CLASS_NAME); 82 } 83 catch (Exception e) 84 { 85 log.error("Could not initialize Peer", e); 86 } 87 } 88 else 89 { 90 Torque.registerMapBuilder(IssueTemplateInfoMapBuilder.CLASS_NAME); 91 } 92 } 93 94 95 public static final int numColumns = 5; 96 97 98 protected static final String CLASSNAME_DEFAULT = 99 "org.tigris.scarab.om.IssueTemplateInfo"; 100 101 102 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 103 104 110 private static Class initClass(String className) 111 { 112 Class c = null; 113 try 114 { 115 c = Class.forName(className); 116 } 117 catch (Throwable t) 118 { 119 log.error("A FATAL ERROR has occurred which should not " 120 + "have happened under any circumstance. Please notify " 121 + "the Torque developers <torque-dev@db.apache.org> " 122 + "and give as many details as possible (including the error " 123 + "stack trace).", t); 124 125 if (t instanceof Error ) 127 { 128 throw (Error ) t.fillInStackTrace(); 129 } 130 } 131 return c; 132 } 133 134 144 public static List resultSet2Objects(java.sql.ResultSet results) 145 throws TorqueException 146 { 147 try 148 { 149 QueryDataSet qds = null; 150 List rows = null; 151 try 152 { 153 qds = new QueryDataSet(results); 154 rows = getSelectResults(qds); 155 } 156 finally 157 { 158 if (qds != null) 159 { 160 qds.close(); 161 } 162 } 163 164 return populateObjects(rows); 165 } 166 catch (SQLException e) 167 { 168 throw new TorqueException(e); 169 } 170 catch (DataSetException e) 171 { 172 throw new TorqueException(e); 173 } 174 } 175 176 177 178 185 public static ObjectKey doInsert(Criteria criteria) 186 throws TorqueException 187 { 188 return BaseIssueTemplateInfoPeer 189 .doInsert(criteria, (Connection ) null); 190 } 191 192 202 public static ObjectKey doInsert(Criteria criteria, Connection con) 203 throws TorqueException 204 { 205 if (criteria.containsKey(APPROVED)) 207 { 208 Object possibleBoolean = criteria.get(APPROVED); 209 if (possibleBoolean instanceof Boolean ) 210 { 211 criteria.add(APPROVED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 212 } 213 } 214 215 setDbName(criteria); 216 217 if (con == null) 218 { 219 return BasePeer.doInsert(criteria); 220 } 221 else 222 { 223 return BasePeer.doInsert(criteria, con); 224 } 225 } 226 227 234 public static void addSelectColumns(Criteria criteria) 235 throws TorqueException 236 { 237 criteria.addSelectColumn(ISSUE_ID); 238 criteria.addSelectColumn(NAME); 239 criteria.addSelectColumn(DESCRIPTION); 240 criteria.addSelectColumn(APPROVED); 241 criteria.addSelectColumn(SCOPE_ID); 242 } 243 244 253 public static IssueTemplateInfo row2Object(Record row, 254 int offset, 255 Class cls) 256 throws TorqueException 257 { 258 try 259 { 260 IssueTemplateInfo obj = (IssueTemplateInfo) cls.newInstance(); 261 IssueTemplateInfoPeer.populateObject(row, offset, obj); 262 obj.setModified(false); 263 obj.setNew(false); 264 265 return obj; 266 } 267 catch (InstantiationException e) 268 { 269 throw new TorqueException(e); 270 } 271 catch (IllegalAccessException e) 272 { 273 throw new TorqueException(e); 274 } 275 } 276 277 286 public static void populateObject(Record row, 287 int offset, 288 IssueTemplateInfo obj) 289 throws TorqueException 290 { 291 try 292 { 293 obj.setIssueId(row.getValue(offset + 0).asLongObj()); 294 obj.setName(row.getValue(offset + 1).asString()); 295 obj.setDescription(row.getValue(offset + 2).asString()); 296 obj.setApproved(row.getValue(offset + 3).asBoolean()); 297 obj.setScopeId(row.getValue(offset + 4).asIntegerObj()); 298 } 299 catch (DataSetException e) 300 { 301 throw new TorqueException(e); 302 } 303 } 304 305 313 public static List doSelect(Criteria criteria) throws TorqueException 314 { 315 return populateObjects(doSelectVillageRecords(criteria)); 316 } 317 318 327 public static List doSelect(Criteria criteria, Connection con) 328 throws TorqueException 329 { 330 return populateObjects(doSelectVillageRecords(criteria, con)); 331 } 332 333 343 public static List doSelectVillageRecords(Criteria criteria) 344 throws TorqueException 345 { 346 return BaseIssueTemplateInfoPeer 347 .doSelectVillageRecords(criteria, (Connection ) null); 348 } 349 350 359 public static List doSelectVillageRecords(Criteria criteria, Connection con) 360 throws TorqueException 361 { 362 if (criteria.getSelectColumns().size() == 0) 363 { 364 addSelectColumns(criteria); 365 } 366 367 if (criteria.containsKey(APPROVED)) 369 { 370 Object possibleBoolean = criteria.get(APPROVED); 371 if (possibleBoolean instanceof Boolean ) 372 { 373 criteria.add(APPROVED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 374 } 375 } 376 377 setDbName(criteria); 378 379 if (con == null) 382 { 383 return BasePeer.doSelect(criteria); 384 } 385 else 386 { 387 return BasePeer.doSelect(criteria, con); 388 } 389 } 390 391 398 public static List populateObjects(List records) 399 throws TorqueException 400 { 401 List results = new ArrayList (records.size()); 402 403 for (int i = 0; i < records.size(); i++) 405 { 406 Record row = (Record) records.get(i); 407 results.add(IssueTemplateInfoPeer.row2Object(row, 1, 408 IssueTemplateInfoPeer.getOMClass())); 409 } 410 return results; 411 } 412 413 414 422 public static Class getOMClass() 423 throws TorqueException 424 { 425 return CLASS_DEFAULT; 426 } 427 428 436 public static void doUpdate(Criteria criteria) throws TorqueException 437 { 438 BaseIssueTemplateInfoPeer 439 .doUpdate(criteria, (Connection ) null); 440 } 441 442 453 public static void doUpdate(Criteria criteria, Connection con) 454 throws TorqueException 455 { 456 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 457 selectCriteria.put(ISSUE_ID, criteria.remove(ISSUE_ID)); 458 if (criteria.containsKey(APPROVED)) 460 { 461 Object possibleBoolean = criteria.get(APPROVED); 462 if (possibleBoolean instanceof Boolean ) 463 { 464 criteria.add(APPROVED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 465 } 466 } 467 468 setDbName(criteria); 469 470 if (con == null) 471 { 472 BasePeer.doUpdate(selectCriteria, criteria); 473 } 474 else 475 { 476 BasePeer.doUpdate(selectCriteria, criteria, con); 477 } 478 } 479 480 487 public static void doDelete(Criteria criteria) throws TorqueException 488 { 489 IssueTemplateInfoPeer 490 .doDelete(criteria, (Connection ) null); 491 } 492 493 503 public static void doDelete(Criteria criteria, Connection con) 504 throws TorqueException 505 { 506 if (criteria.containsKey(APPROVED)) 508 { 509 Object possibleBoolean = criteria.get(APPROVED); 510 if (possibleBoolean instanceof Boolean ) 511 { 512 criteria.add(APPROVED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 513 } 514 } 515 516 setDbName(criteria); 517 518 if (con == null) 519 { 520 BasePeer.doDelete(criteria); 521 } 522 else 523 { 524 BasePeer.doDelete(criteria, con); 525 } 526 } 527 528 534 public static List doSelect(IssueTemplateInfo obj) throws TorqueException 535 { 536 return doSelect(buildSelectCriteria(obj)); 537 } 538 539 545 public static void doInsert(IssueTemplateInfo obj) throws TorqueException 546 { 547 doInsert(buildCriteria(obj)); 548 obj.setNew(false); 549 obj.setModified(false); 550 } 551 552 557 public static void doUpdate(IssueTemplateInfo obj) throws TorqueException 558 { 559 doUpdate(buildCriteria(obj)); 560 obj.setModified(false); 561 } 562 563 568 public static void doDelete(IssueTemplateInfo obj) throws TorqueException 569 { 570 doDelete(buildSelectCriteria(obj)); 571 } 572 573 583 public static void doInsert(IssueTemplateInfo obj, Connection con) 584 throws TorqueException 585 { 586 doInsert(buildCriteria(obj), con); 587 obj.setNew(false); 588 obj.setModified(false); 589 } 590 591 601 public static void doUpdate(IssueTemplateInfo obj, Connection con) 602 throws TorqueException 603 { 604 doUpdate(buildCriteria(obj), con); 605 obj.setModified(false); 606 } 607 608 618 public static void doDelete(IssueTemplateInfo obj, Connection con) 619 throws TorqueException 620 { 621 doDelete(buildSelectCriteria(obj), con); 622 } 623 624 631 public static void doDelete(ObjectKey pk) throws TorqueException 632 { 633 BaseIssueTemplateInfoPeer 634 .doDelete(pk, (Connection ) null); 635 } 636 637 647 public static void doDelete(ObjectKey pk, Connection con) 648 throws TorqueException 649 { 650 doDelete(buildCriteria(pk), con); 651 } 652 653 654 public static Criteria buildCriteria( ObjectKey pk ) 655 { 656 Criteria criteria = new Criteria(); 657 criteria.add(ISSUE_ID, pk); 658 return criteria; 659 } 660 661 662 public static Criteria buildCriteria( IssueTemplateInfo obj ) 663 { 664 Criteria criteria = new Criteria(DATABASE_NAME); 665 criteria.add(ISSUE_ID, obj.getIssueId()); 666 criteria.add(NAME, obj.getName()); 667 criteria.add(DESCRIPTION, obj.getDescription()); 668 criteria.add(APPROVED, obj.getApproved()); 669 criteria.add(SCOPE_ID, obj.getScopeId()); 670 return criteria; 671 } 672 673 674 public static Criteria buildSelectCriteria( IssueTemplateInfo obj ) 675 { 676 Criteria criteria = new Criteria(DATABASE_NAME); 677 criteria.add(ISSUE_ID, obj.getIssueId()); 678 criteria.add(NAME, obj.getName()); 679 criteria.add(DESCRIPTION, obj.getDescription()); 680 criteria.add(APPROVED, obj.getApproved()); 681 criteria.add(SCOPE_ID, obj.getScopeId()); 682 return criteria; 683 } 684 685 686 695 public static IssueTemplateInfo retrieveByPK(Long pk) 696 throws TorqueException, NoRowsException, TooManyRowsException 697 { 698 return retrieveByPK(SimpleKey.keyFor(pk)); 699 } 700 701 711 public static IssueTemplateInfo retrieveByPK(Long pk, Connection con) 712 throws TorqueException, NoRowsException, TooManyRowsException 713 { 714 return retrieveByPK(SimpleKey.keyFor(pk), con); 715 } 716 717 726 public static IssueTemplateInfo retrieveByPK(ObjectKey pk) 727 throws TorqueException, NoRowsException, TooManyRowsException 728 { 729 Connection db = null; 730 IssueTemplateInfo retVal = null; 731 try 732 { 733 db = Torque.getConnection(DATABASE_NAME); 734 retVal = retrieveByPK(pk, db); 735 } 736 finally 737 { 738 Torque.closeConnection(db); 739 } 740 return(retVal); 741 } 742 743 753 public static IssueTemplateInfo retrieveByPK(ObjectKey pk, Connection con) 754 throws TorqueException, NoRowsException, TooManyRowsException 755 { 756 Criteria criteria = buildCriteria(pk); 757 List v = doSelect(criteria, con); 758 if (v.size() == 0) 759 { 760 throw new NoRowsException("Failed to select a row."); 761 } 762 else if (v.size() > 1) 763 { 764 throw new TooManyRowsException("Failed to select only one row."); 765 } 766 else 767 { 768 return (IssueTemplateInfo)v.get(0); 769 } 770 } 771 772 779 public static List retrieveByPKs(List pks) 780 throws TorqueException 781 { 782 Connection db = null; 783 List retVal = null; 784 try 785 { 786 db = Torque.getConnection(DATABASE_NAME); 787 retVal = retrieveByPKs(pks, db); 788 } 789 finally 790 { 791 Torque.closeConnection(db); 792 } 793 return(retVal); 794 } 795 796 804 public static List retrieveByPKs( List pks, Connection dbcon ) 805 throws TorqueException 806 { 807 List objs = null; 808 if (pks == null || pks.size() == 0) 809 { 810 objs = new LinkedList (); 811 } 812 else 813 { 814 Criteria criteria = new Criteria(); 815 criteria.addIn( ISSUE_ID, pks ); 816 objs = doSelect(criteria, dbcon); 817 } 818 return objs; 819 } 820 821 822 823 824 825 826 827 828 829 830 841 protected static List doSelectJoinIssue(Criteria criteria) 842 throws TorqueException 843 { 844 setDbName(criteria); 845 846 IssueTemplateInfoPeer.addSelectColumns(criteria); 847 int offset = numColumns + 1; 848 IssuePeer.addSelectColumns(criteria); 849 850 851 criteria.addJoin(IssueTemplateInfoPeer.ISSUE_ID, 852 IssuePeer.ISSUE_ID); 853 854 855 if (criteria.containsKey(APPROVED)) 857 { 858 Object possibleBoolean = criteria.get(APPROVED); 859 if (possibleBoolean instanceof Boolean ) 860 { 861 criteria.add(APPROVED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 862 } 863 } 864 865 List rows = BasePeer.doSelect(criteria); 866 List results = new ArrayList (); 867 868 for (int i = 0; i < rows.size(); i++) 869 { 870 Record row = (Record) rows.get(i); 871 872 Class omClass = IssueTemplateInfoPeer.getOMClass(); 873 IssueTemplateInfo obj1 = (IssueTemplateInfo) IssueTemplateInfoPeer 874 .row2Object(row, 1, omClass); 875 omClass = IssuePeer.getOMClass(); 876 Issue obj2 = (Issue)IssuePeer 877 .row2Object(row, offset, omClass); 878 879 boolean newObject = true; 880 for (int j = 0; j < results.size(); j++) 881 { 882 IssueTemplateInfo temp_obj1 = (IssueTemplateInfo)results.get(j); 883 Issue temp_obj2 = (Issue)temp_obj1.getIssue(); 884 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 885 { 886 newObject = false; 887 temp_obj2.addIssueTemplateInfo(obj1); 888 break; 889 } 890 } 891 if (newObject) 892 { 893 obj2.initIssueTemplateInfos(); 894 obj2.addIssueTemplateInfo(obj1); 895 } 896 results.add(obj1); 897 } 898 return results; 899 } 900 901 902 903 904 915 protected static List doSelectJoinScope(Criteria criteria) 916 throws TorqueException 917 { 918 setDbName(criteria); 919 920 IssueTemplateInfoPeer.addSelectColumns(criteria); 921 int offset = numColumns + 1; 922 ScopePeer.addSelectColumns(criteria); 923 924 925 criteria.addJoin(IssueTemplateInfoPeer.SCOPE_ID, 926 ScopePeer.SCOPE_ID); 927 928 929 if (criteria.containsKey(APPROVED)) 931 { 932 Object possibleBoolean = criteria.get(APPROVED); 933 if (possibleBoolean instanceof Boolean ) 934 { 935 criteria.add(APPROVED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 936 } 937 } 938 939 List rows = BasePeer.doSelect(criteria); 940 List results = new ArrayList (); 941 942 for (int i = 0; i < rows.size(); i++) 943 { 944 Record row = (Record) rows.get(i); 945 946 Class omClass = IssueTemplateInfoPeer.getOMClass(); 947 IssueTemplateInfo obj1 = (IssueTemplateInfo) IssueTemplateInfoPeer 948 .row2Object(row, 1, omClass); 949 omClass = ScopePeer.getOMClass(); 950 Scope obj2 = (Scope)ScopePeer 951 .row2Object(row, offset, omClass); 952 953 boolean newObject = true; 954 for (int j = 0; j < results.size(); j++) 955 { 956 IssueTemplateInfo temp_obj1 = (IssueTemplateInfo)results.get(j); 957 Scope temp_obj2 = (Scope)temp_obj1.getScope(); 958 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) 959 { 960 newObject = false; 961 temp_obj2.addIssueTemplateInfo(obj1); 962 break; 963 } 964 } 965 if (newObject) 966 { 967 obj2.initIssueTemplateInfos(); 968 obj2.addIssueTemplateInfo(obj1); 969 } 970 results.add(obj1); 971 } 972 return results; 973 } 974 975 976 977 978 985 protected static TableMap getTableMap() 986 throws TorqueException 987 { 988 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 989 } 990 991 private static void setDbName(Criteria crit) 992 { 993 if (crit.getDbName() == Torque.getDefaultDB()) 997 { 998 crit.setDbName(DATABASE_NAME); 999 } 1000 } 1001} 1002 | Popular Tags |