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 37 public abstract class BaseIssueTypePeer 38 extends BasePeer 39 { 40 41 42 public static final String DATABASE_NAME = "scarab"; 43 44 45 public static final String TABLE_NAME = "SCARAB_ISSUE_TYPE"; 46 47 52 public static MapBuilder getMapBuilder() 53 throws TorqueException 54 { 55 return getMapBuilder(IssueTypeMapBuilder.CLASS_NAME); 56 } 57 58 59 public static final String ISSUE_TYPE_ID; 60 61 public static final String NAME; 62 63 public static final String DESCRIPTION; 64 65 public static final String PARENT_ID; 66 67 public static final String DEDUPE; 68 69 public static final String DELETED; 70 71 public static final String LOCKED; 72 73 public static final String ISDEFAULT; 74 75 static 76 { 77 ISSUE_TYPE_ID = "SCARAB_ISSUE_TYPE.ISSUE_TYPE_ID"; 78 NAME = "SCARAB_ISSUE_TYPE.NAME"; 79 DESCRIPTION = "SCARAB_ISSUE_TYPE.DESCRIPTION"; 80 PARENT_ID = "SCARAB_ISSUE_TYPE.PARENT_ID"; 81 DEDUPE = "SCARAB_ISSUE_TYPE.DEDUPE"; 82 DELETED = "SCARAB_ISSUE_TYPE.DELETED"; 83 LOCKED = "SCARAB_ISSUE_TYPE.LOCKED"; 84 ISDEFAULT = "SCARAB_ISSUE_TYPE.ISDEFAULT"; 85 if (Torque.isInit()) 86 { 87 try 88 { 89 getMapBuilder(IssueTypeMapBuilder.CLASS_NAME); 90 } 91 catch (Exception e) 92 { 93 log.error("Could not initialize Peer", e); 94 } 95 } 96 else 97 { 98 Torque.registerMapBuilder(IssueTypeMapBuilder.CLASS_NAME); 99 } 100 } 101 102 103 public static final int numColumns = 8; 104 105 106 protected static final String CLASSNAME_DEFAULT = 107 "org.tigris.scarab.om.IssueType"; 108 109 110 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 111 112 118 private static Class initClass(String className) 119 { 120 Class c = null; 121 try 122 { 123 c = Class.forName(className); 124 } 125 catch (Throwable t) 126 { 127 log.error("A FATAL ERROR has occurred which should not " 128 + "have happened under any circumstance. Please notify " 129 + "the Torque developers <torque-dev@db.apache.org> " 130 + "and give as many details as possible (including the error " 131 + "stack trace).", t); 132 133 if (t instanceof Error ) 135 { 136 throw (Error ) t.fillInStackTrace(); 137 } 138 } 139 return c; 140 } 141 142 152 public static List resultSet2Objects(java.sql.ResultSet results) 153 throws TorqueException 154 { 155 try 156 { 157 QueryDataSet qds = null; 158 List rows = null; 159 try 160 { 161 qds = new QueryDataSet(results); 162 rows = getSelectResults(qds); 163 } 164 finally 165 { 166 if (qds != null) 167 { 168 qds.close(); 169 } 170 } 171 172 return populateObjects(rows); 173 } 174 catch (SQLException e) 175 { 176 throw new TorqueException(e); 177 } 178 catch (DataSetException e) 179 { 180 throw new TorqueException(e); 181 } 182 } 183 184 185 186 193 public static ObjectKey doInsert(Criteria criteria) 194 throws TorqueException 195 { 196 return BaseIssueTypePeer 197 .doInsert(criteria, (Connection ) null); 198 } 199 200 210 public static ObjectKey doInsert(Criteria criteria, Connection con) 211 throws TorqueException 212 { 213 if (criteria.containsKey(DEDUPE)) 215 { 216 Object possibleBoolean = criteria.get(DEDUPE); 217 if (possibleBoolean instanceof Boolean ) 218 { 219 criteria.add(DEDUPE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 220 } 221 } 222 if (criteria.containsKey(DELETED)) 224 { 225 Object possibleBoolean = criteria.get(DELETED); 226 if (possibleBoolean instanceof Boolean ) 227 { 228 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 229 } 230 } 231 if (criteria.containsKey(LOCKED)) 233 { 234 Object possibleBoolean = criteria.get(LOCKED); 235 if (possibleBoolean instanceof Boolean ) 236 { 237 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 238 } 239 } 240 if (criteria.containsKey(ISDEFAULT)) 242 { 243 Object possibleBoolean = criteria.get(ISDEFAULT); 244 if (possibleBoolean instanceof Boolean ) 245 { 246 criteria.add(ISDEFAULT, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 247 } 248 } 249 250 setDbName(criteria); 251 252 if (con == null) 253 { 254 return BasePeer.doInsert(criteria); 255 } 256 else 257 { 258 return BasePeer.doInsert(criteria, con); 259 } 260 } 261 262 269 public static void addSelectColumns(Criteria criteria) 270 throws TorqueException 271 { 272 criteria.addSelectColumn(ISSUE_TYPE_ID); 273 criteria.addSelectColumn(NAME); 274 criteria.addSelectColumn(DESCRIPTION); 275 criteria.addSelectColumn(PARENT_ID); 276 criteria.addSelectColumn(DEDUPE); 277 criteria.addSelectColumn(DELETED); 278 criteria.addSelectColumn(LOCKED); 279 criteria.addSelectColumn(ISDEFAULT); 280 } 281 282 291 public static IssueType row2Object(Record row, 292 int offset, 293 Class cls) 294 throws TorqueException 295 { 296 try 297 { 298 IssueType obj = (IssueType) cls.newInstance(); 299 IssueTypePeer.populateObject(row, offset, obj); 300 obj.setModified(false); 301 obj.setNew(false); 302 303 return obj; 304 } 305 catch (InstantiationException e) 306 { 307 throw new TorqueException(e); 308 } 309 catch (IllegalAccessException e) 310 { 311 throw new TorqueException(e); 312 } 313 } 314 315 324 public static void populateObject(Record row, 325 int offset, 326 IssueType obj) 327 throws TorqueException 328 { 329 try 330 { 331 obj.setIssueTypeId(row.getValue(offset + 0).asIntegerObj()); 332 obj.setName(row.getValue(offset + 1).asString()); 333 obj.setDescription(row.getValue(offset + 2).asString()); 334 obj.setParentId(row.getValue(offset + 3).asIntegerObj()); 335 obj.setDedupe(row.getValue(offset + 4).asBoolean()); 336 obj.setDeleted(row.getValue(offset + 5).asBoolean()); 337 obj.setLocked(row.getValue(offset + 6).asBoolean()); 338 obj.setIsdefault(row.getValue(offset + 7).asBoolean()); 339 } 340 catch (DataSetException e) 341 { 342 throw new TorqueException(e); 343 } 344 } 345 346 354 public static List doSelect(Criteria criteria) throws TorqueException 355 { 356 return populateObjects(doSelectVillageRecords(criteria)); 357 } 358 359 368 public static List doSelect(Criteria criteria, Connection con) 369 throws TorqueException 370 { 371 return populateObjects(doSelectVillageRecords(criteria, con)); 372 } 373 374 384 public static List doSelectVillageRecords(Criteria criteria) 385 throws TorqueException 386 { 387 return BaseIssueTypePeer 388 .doSelectVillageRecords(criteria, (Connection ) null); 389 } 390 391 400 public static List doSelectVillageRecords(Criteria criteria, Connection con) 401 throws TorqueException 402 { 403 if (criteria.getSelectColumns().size() == 0) 404 { 405 addSelectColumns(criteria); 406 } 407 408 if (criteria.containsKey(DEDUPE)) 410 { 411 Object possibleBoolean = criteria.get(DEDUPE); 412 if (possibleBoolean instanceof Boolean ) 413 { 414 criteria.add(DEDUPE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 415 } 416 } 417 if (criteria.containsKey(DELETED)) 419 { 420 Object possibleBoolean = criteria.get(DELETED); 421 if (possibleBoolean instanceof Boolean ) 422 { 423 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 424 } 425 } 426 if (criteria.containsKey(LOCKED)) 428 { 429 Object possibleBoolean = criteria.get(LOCKED); 430 if (possibleBoolean instanceof Boolean ) 431 { 432 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 433 } 434 } 435 if (criteria.containsKey(ISDEFAULT)) 437 { 438 Object possibleBoolean = criteria.get(ISDEFAULT); 439 if (possibleBoolean instanceof Boolean ) 440 { 441 criteria.add(ISDEFAULT, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 442 } 443 } 444 445 setDbName(criteria); 446 447 if (con == null) 450 { 451 return BasePeer.doSelect(criteria); 452 } 453 else 454 { 455 return BasePeer.doSelect(criteria, con); 456 } 457 } 458 459 466 public static List populateObjects(List records) 467 throws TorqueException 468 { 469 List results = new ArrayList (records.size()); 470 471 for (int i = 0; i < records.size(); i++) 473 { 474 Record row = (Record) records.get(i); 475 results.add(IssueTypePeer.row2Object(row, 1, 476 IssueTypePeer.getOMClass())); 477 } 478 return results; 479 } 480 481 482 490 public static Class getOMClass() 491 throws TorqueException 492 { 493 return CLASS_DEFAULT; 494 } 495 496 504 public static void doUpdate(Criteria criteria) throws TorqueException 505 { 506 BaseIssueTypePeer 507 .doUpdate(criteria, (Connection ) null); 508 } 509 510 521 public static void doUpdate(Criteria criteria, Connection con) 522 throws TorqueException 523 { 524 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 525 selectCriteria.put(ISSUE_TYPE_ID, criteria.remove(ISSUE_TYPE_ID)); 526 if (criteria.containsKey(DEDUPE)) 528 { 529 Object possibleBoolean = criteria.get(DEDUPE); 530 if (possibleBoolean instanceof Boolean ) 531 { 532 criteria.add(DEDUPE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 533 } 534 } 535 if (criteria.containsKey(DELETED)) 537 { 538 Object possibleBoolean = criteria.get(DELETED); 539 if (possibleBoolean instanceof Boolean ) 540 { 541 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 542 } 543 } 544 if (criteria.containsKey(LOCKED)) 546 { 547 Object possibleBoolean = criteria.get(LOCKED); 548 if (possibleBoolean instanceof Boolean ) 549 { 550 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 551 } 552 } 553 if (criteria.containsKey(ISDEFAULT)) 555 { 556 Object possibleBoolean = criteria.get(ISDEFAULT); 557 if (possibleBoolean instanceof Boolean ) 558 { 559 criteria.add(ISDEFAULT, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 560 } 561 } 562 563 setDbName(criteria); 564 565 if (con == null) 566 { 567 BasePeer.doUpdate(selectCriteria, criteria); 568 } 569 else 570 { 571 BasePeer.doUpdate(selectCriteria, criteria, con); 572 } 573 } 574 575 582 public static void doDelete(Criteria criteria) throws TorqueException 583 { 584 IssueTypePeer 585 .doDelete(criteria, (Connection ) null); 586 } 587 588 598 public static void doDelete(Criteria criteria, Connection con) 599 throws TorqueException 600 { 601 if (criteria.containsKey(DEDUPE)) 603 { 604 Object possibleBoolean = criteria.get(DEDUPE); 605 if (possibleBoolean instanceof Boolean ) 606 { 607 criteria.add(DEDUPE, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 608 } 609 } 610 if (criteria.containsKey(DELETED)) 612 { 613 Object possibleBoolean = criteria.get(DELETED); 614 if (possibleBoolean instanceof Boolean ) 615 { 616 criteria.add(DELETED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 617 } 618 } 619 if (criteria.containsKey(LOCKED)) 621 { 622 Object possibleBoolean = criteria.get(LOCKED); 623 if (possibleBoolean instanceof Boolean ) 624 { 625 criteria.add(LOCKED, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 626 } 627 } 628 if (criteria.containsKey(ISDEFAULT)) 630 { 631 Object possibleBoolean = criteria.get(ISDEFAULT); 632 if (possibleBoolean instanceof Boolean ) 633 { 634 criteria.add(ISDEFAULT, ((Boolean ) possibleBoolean).booleanValue() ? 1 : 0); 635 } 636 } 637 638 setDbName(criteria); 639 640 if (con == null) 641 { 642 BasePeer.doDelete(criteria); 643 } 644 else 645 { 646 BasePeer.doDelete(criteria, con); 647 } 648 } 649 650 656 public static List doSelect(IssueType obj) throws TorqueException 657 { 658 return doSelect(buildSelectCriteria(obj)); 659 } 660 661 667 public static void doInsert(IssueType obj) throws TorqueException 668 { 669 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 670 obj.setNew(false); 671 obj.setModified(false); 672 } 673 674 679 public static void doUpdate(IssueType obj) throws TorqueException 680 { 681 doUpdate(buildCriteria(obj)); 682 obj.setModified(false); 683 } 684 685 690 public static void doDelete(IssueType obj) throws TorqueException 691 { 692 doDelete(buildSelectCriteria(obj)); 693 } 694 695 705 public static void doInsert(IssueType obj, Connection con) 706 throws TorqueException 707 { 708 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 709 obj.setNew(false); 710 obj.setModified(false); 711 } 712 713 723 public static void doUpdate(IssueType obj, Connection con) 724 throws TorqueException 725 { 726 doUpdate(buildCriteria(obj), con); 727 obj.setModified(false); 728 } 729 730 740 public static void doDelete(IssueType obj, Connection con) 741 throws TorqueException 742 { 743 doDelete(buildSelectCriteria(obj), con); 744 } 745 746 753 public static void doDelete(ObjectKey pk) throws TorqueException 754 { 755 BaseIssueTypePeer 756 .doDelete(pk, (Connection ) null); 757 } 758 759 769 public static void doDelete(ObjectKey pk, Connection con) 770 throws TorqueException 771 { 772 doDelete(buildCriteria(pk), con); 773 } 774 775 776 public static Criteria buildCriteria( ObjectKey pk ) 777 { 778 Criteria criteria = new Criteria(); 779 criteria.add(ISSUE_TYPE_ID, pk); 780 return criteria; 781 } 782 783 784 public static Criteria buildCriteria( IssueType obj ) 785 { 786 Criteria criteria = new Criteria(DATABASE_NAME); 787 if (!obj.isNew()) 788 criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId()); 789 criteria.add(NAME, obj.getName()); 790 criteria.add(DESCRIPTION, obj.getDescription()); 791 criteria.add(PARENT_ID, obj.getParentId()); 792 criteria.add(DEDUPE, obj.getDedupe()); 793 criteria.add(DELETED, obj.getDeleted()); 794 criteria.add(LOCKED, obj.getLocked()); 795 criteria.add(ISDEFAULT, obj.getIsdefault()); 796 return criteria; 797 } 798 799 800 public static Criteria buildSelectCriteria( IssueType obj ) 801 { 802 Criteria criteria = new Criteria(DATABASE_NAME); 803 if (!obj.isNew()) 804 criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId()); 805 criteria.add(NAME, obj.getName()); 806 criteria.add(DESCRIPTION, obj.getDescription()); 807 criteria.add(PARENT_ID, obj.getParentId()); 808 criteria.add(DEDUPE, obj.getDedupe()); 809 criteria.add(DELETED, obj.getDeleted()); 810 criteria.add(LOCKED, obj.getLocked()); 811 criteria.add(ISDEFAULT, obj.getIsdefault()); 812 return criteria; 813 } 814 815 816 825 public static IssueType retrieveByPK(Integer pk) 826 throws TorqueException, NoRowsException, TooManyRowsException 827 { 828 return retrieveByPK(SimpleKey.keyFor(pk)); 829 } 830 831 841 public static IssueType retrieveByPK(Integer pk, Connection con) 842 throws TorqueException, NoRowsException, TooManyRowsException 843 { 844 return retrieveByPK(SimpleKey.keyFor(pk), con); 845 } 846 847 856 public static IssueType retrieveByPK(ObjectKey pk) 857 throws TorqueException, NoRowsException, TooManyRowsException 858 { 859 Connection db = null; 860 IssueType retVal = null; 861 try 862 { 863 db = Torque.getConnection(DATABASE_NAME); 864 retVal = retrieveByPK(pk, db); 865 } 866 finally 867 { 868 Torque.closeConnection(db); 869 } 870 return(retVal); 871 } 872 873 883 public static IssueType retrieveByPK(ObjectKey pk, Connection con) 884 throws TorqueException, NoRowsException, TooManyRowsException 885 { 886 Criteria criteria = buildCriteria(pk); 887 List v = doSelect(criteria, con); 888 if (v.size() == 0) 889 { 890 throw new NoRowsException("Failed to select a row."); 891 } 892 else if (v.size() > 1) 893 { 894 throw new TooManyRowsException("Failed to select only one row."); 895 } 896 else 897 { 898 return (IssueType)v.get(0); 899 } 900 } 901 902 909 public static List retrieveByPKs(List pks) 910 throws TorqueException 911 { 912 Connection db = null; 913 List retVal = null; 914 try 915 { 916 db = Torque.getConnection(DATABASE_NAME); 917 retVal = retrieveByPKs(pks, db); 918 } 919 finally 920 { 921 Torque.closeConnection(db); 922 } 923 return(retVal); 924 } 925 926 934 public static List retrieveByPKs( List pks, Connection dbcon ) 935 throws TorqueException 936 { 937 List objs = null; 938 if (pks == null || pks.size() == 0) 939 { 940 objs = new LinkedList (); 941 } 942 else 943 { 944 Criteria criteria = new Criteria(); 945 criteria.addIn( ISSUE_TYPE_ID, pks ); 946 objs = doSelect(criteria, dbcon); 947 } 948 return objs; 949 } 950 951 952 953 954 955 956 957 958 959 960 967 protected static TableMap getTableMap() 968 throws TorqueException 969 { 970 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 971 } 972 973 private static void setDbName(Criteria crit) 974 { 975 if (crit.getDbName() == Torque.getDefaultDB()) 979 { 980 crit.setDbName(DATABASE_NAME); 981 } 982 } 983 } 984 | Popular Tags |