1 package org.campware.cream.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.campware.cream.om.map.*; 32 33 34 40 public abstract class BaseTurbineRolePeer 41 extends BasePeer 42 { 43 44 45 public static final String DATABASE_NAME = "cream"; 46 47 48 public static final String TABLE_NAME = "TURBINE_ROLE"; 49 50 55 public static MapBuilder getMapBuilder() 56 throws TorqueException 57 { 58 return getMapBuilder(TurbineRoleMapBuilder.CLASS_NAME); 59 } 60 61 62 public static final String ROLE_ID; 63 64 public static final String ROLE_NAME; 65 66 static 67 { 68 ROLE_ID = "TURBINE_ROLE.ROLE_ID"; 69 ROLE_NAME = "TURBINE_ROLE.ROLE_NAME"; 70 if (Torque.isInit()) 71 { 72 try 73 { 74 getMapBuilder(TurbineRoleMapBuilder.CLASS_NAME); 75 } 76 catch (Exception e) 77 { 78 log.error("Could not initialize Peer", e); 79 } 80 } 81 else 82 { 83 Torque.registerMapBuilder(TurbineRoleMapBuilder.CLASS_NAME); 84 } 85 } 86 87 88 public static final int numColumns = 2; 89 90 91 protected static final String CLASSNAME_DEFAULT = 92 "org.campware.cream.om.TurbineRole"; 93 94 95 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 96 97 103 private static Class initClass(String className) 104 { 105 Class c = null; 106 try 107 { 108 c = Class.forName(className); 109 } 110 catch (Throwable t) 111 { 112 log.error("A FATAL ERROR has occurred which should not " 113 + "have happened under any circumstance. Please notify " 114 + "the Torque developers <torque-dev@db.apache.org> " 115 + "and give as many details as possible (including the error " 116 + "stack trace).", t); 117 118 if (t instanceof Error ) 120 { 121 throw (Error ) t.fillInStackTrace(); 122 } 123 } 124 return c; 125 } 126 127 137 public static List resultSet2Objects(java.sql.ResultSet results) 138 throws TorqueException 139 { 140 try 141 { 142 QueryDataSet qds = null; 143 List rows = null; 144 try 145 { 146 qds = new QueryDataSet(results); 147 rows = getSelectResults(qds); 148 } 149 finally 150 { 151 if (qds != null) 152 { 153 qds.close(); 154 } 155 } 156 157 return populateObjects(rows); 158 } 159 catch (SQLException e) 160 { 161 throw new TorqueException(e); 162 } 163 catch (DataSetException e) 164 { 165 throw new TorqueException(e); 166 } 167 } 168 169 170 171 178 public static ObjectKey doInsert(Criteria criteria) 179 throws TorqueException 180 { 181 return BaseTurbineRolePeer 182 .doInsert(criteria, (Connection ) null); 183 } 184 185 195 public static ObjectKey doInsert(Criteria criteria, Connection con) 196 throws TorqueException 197 { 198 199 setDbName(criteria); 200 201 if (con == null) 202 { 203 return BasePeer.doInsert(criteria); 204 } 205 else 206 { 207 return BasePeer.doInsert(criteria, con); 208 } 209 } 210 211 218 public static void addSelectColumns(Criteria criteria) 219 throws TorqueException 220 { 221 criteria.addSelectColumn(ROLE_ID); 222 criteria.addSelectColumn(ROLE_NAME); 223 } 224 225 234 public static TurbineRole row2Object(Record row, 235 int offset, 236 Class cls) 237 throws TorqueException 238 { 239 try 240 { 241 TurbineRole obj = (TurbineRole) cls.newInstance(); 242 TurbineRolePeer.populateObject(row, offset, obj); 243 obj.setModified(false); 244 obj.setNew(false); 245 246 return obj; 247 } 248 catch (InstantiationException e) 249 { 250 throw new TorqueException(e); 251 } 252 catch (IllegalAccessException e) 253 { 254 throw new TorqueException(e); 255 } 256 } 257 258 267 public static void populateObject(Record row, 268 int offset, 269 TurbineRole obj) 270 throws TorqueException 271 { 272 try 273 { 274 obj.setRoleId(row.getValue(offset + 0).asInt()); 275 obj.setName(row.getValue(offset + 1).asString()); 276 } 277 catch (DataSetException e) 278 { 279 throw new TorqueException(e); 280 } 281 } 282 283 291 public static List doSelect(Criteria criteria) throws TorqueException 292 { 293 return populateObjects(doSelectVillageRecords(criteria)); 294 } 295 296 305 public static List doSelect(Criteria criteria, Connection con) 306 throws TorqueException 307 { 308 return populateObjects(doSelectVillageRecords(criteria, con)); 309 } 310 311 321 public static List doSelectVillageRecords(Criteria criteria) 322 throws TorqueException 323 { 324 return BaseTurbineRolePeer 325 .doSelectVillageRecords(criteria, (Connection ) null); 326 } 327 328 337 public static List doSelectVillageRecords(Criteria criteria, Connection con) 338 throws TorqueException 339 { 340 if (criteria.getSelectColumns().size() == 0) 341 { 342 addSelectColumns(criteria); 343 } 344 345 346 setDbName(criteria); 347 348 if (con == null) 351 { 352 return BasePeer.doSelect(criteria); 353 } 354 else 355 { 356 return BasePeer.doSelect(criteria, con); 357 } 358 } 359 360 367 public static List populateObjects(List records) 368 throws TorqueException 369 { 370 List results = new ArrayList (records.size()); 371 372 for (int i = 0; i < records.size(); i++) 374 { 375 Record row = (Record) records.get(i); 376 results.add(TurbineRolePeer.row2Object(row, 1, 377 TurbineRolePeer.getOMClass())); 378 } 379 return results; 380 } 381 382 383 391 public static Class getOMClass() 392 throws TorqueException 393 { 394 return CLASS_DEFAULT; 395 } 396 397 405 public static void doUpdate(Criteria criteria) throws TorqueException 406 { 407 BaseTurbineRolePeer 408 .doUpdate(criteria, (Connection ) null); 409 } 410 411 422 public static void doUpdate(Criteria criteria, Connection con) 423 throws TorqueException 424 { 425 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 426 selectCriteria.put(ROLE_ID, criteria.remove(ROLE_ID)); 427 428 setDbName(criteria); 429 430 if (con == null) 431 { 432 BasePeer.doUpdate(selectCriteria, criteria); 433 } 434 else 435 { 436 BasePeer.doUpdate(selectCriteria, criteria, con); 437 } 438 } 439 440 447 public static void doDelete(Criteria criteria) throws TorqueException 448 { 449 TurbineRolePeer 450 .doDelete(criteria, (Connection ) null); 451 } 452 453 463 public static void doDelete(Criteria criteria, Connection con) 464 throws TorqueException 465 { 466 467 setDbName(criteria); 468 469 if (con == null) 470 { 471 BasePeer.doDelete(criteria); 472 } 473 else 474 { 475 BasePeer.doDelete(criteria, con); 476 } 477 } 478 479 485 public static List doSelect(TurbineRole obj) throws TorqueException 486 { 487 return doSelect(buildSelectCriteria(obj)); 488 } 489 490 496 public static void doInsert(TurbineRole obj) throws TorqueException 497 { 498 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 499 obj.setNew(false); 500 obj.setModified(false); 501 } 502 503 508 public static void doUpdate(TurbineRole obj) throws TorqueException 509 { 510 doUpdate(buildCriteria(obj)); 511 obj.setModified(false); 512 } 513 514 519 public static void doDelete(TurbineRole obj) throws TorqueException 520 { 521 doDelete(buildSelectCriteria(obj)); 522 } 523 524 534 public static void doInsert(TurbineRole obj, Connection con) 535 throws TorqueException 536 { 537 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 538 obj.setNew(false); 539 obj.setModified(false); 540 } 541 542 552 public static void doUpdate(TurbineRole obj, Connection con) 553 throws TorqueException 554 { 555 doUpdate(buildCriteria(obj), con); 556 obj.setModified(false); 557 } 558 559 569 public static void doDelete(TurbineRole obj, Connection con) 570 throws TorqueException 571 { 572 doDelete(buildSelectCriteria(obj), con); 573 } 574 575 582 public static void doDelete(ObjectKey pk) throws TorqueException 583 { 584 BaseTurbineRolePeer 585 .doDelete(pk, (Connection ) null); 586 } 587 588 598 public static void doDelete(ObjectKey pk, Connection con) 599 throws TorqueException 600 { 601 doDelete(buildCriteria(pk), con); 602 } 603 604 605 public static Criteria buildCriteria( ObjectKey pk ) 606 { 607 Criteria criteria = new Criteria(); 608 criteria.add(ROLE_ID, pk); 609 return criteria; 610 } 611 612 613 public static Criteria buildCriteria( TurbineRole obj ) 614 { 615 Criteria criteria = new Criteria(DATABASE_NAME); 616 if (!obj.isNew()) 617 criteria.add(ROLE_ID, obj.getRoleId()); 618 criteria.add(ROLE_NAME, obj.getName()); 619 return criteria; 620 } 621 622 623 public static Criteria buildSelectCriteria( TurbineRole obj ) 624 { 625 Criteria criteria = new Criteria(DATABASE_NAME); 626 if (!obj.isNew()) 627 criteria.add(ROLE_ID, obj.getRoleId()); 628 criteria.add(ROLE_NAME, obj.getName()); 629 return criteria; 630 } 631 632 633 642 public static TurbineRole retrieveByPK(int pk) 643 throws TorqueException, NoRowsException, TooManyRowsException 644 { 645 return retrieveByPK(SimpleKey.keyFor(pk)); 646 } 647 648 658 public static TurbineRole retrieveByPK(int pk, Connection con) 659 throws TorqueException, NoRowsException, TooManyRowsException 660 { 661 return retrieveByPK(SimpleKey.keyFor(pk), con); 662 } 663 664 673 public static TurbineRole retrieveByPK(ObjectKey pk) 674 throws TorqueException, NoRowsException, TooManyRowsException 675 { 676 Connection db = null; 677 TurbineRole retVal = null; 678 try 679 { 680 db = Torque.getConnection(DATABASE_NAME); 681 retVal = retrieveByPK(pk, db); 682 } 683 finally 684 { 685 Torque.closeConnection(db); 686 } 687 return(retVal); 688 } 689 690 700 public static TurbineRole retrieveByPK(ObjectKey pk, Connection con) 701 throws TorqueException, NoRowsException, TooManyRowsException 702 { 703 Criteria criteria = buildCriteria(pk); 704 List v = doSelect(criteria, con); 705 if (v.size() == 0) 706 { 707 throw new NoRowsException("Failed to select a row."); 708 } 709 else if (v.size() > 1) 710 { 711 throw new TooManyRowsException("Failed to select only one row."); 712 } 713 else 714 { 715 return (TurbineRole)v.get(0); 716 } 717 } 718 719 726 public static List retrieveByPKs(List pks) 727 throws TorqueException 728 { 729 Connection db = null; 730 List retVal = null; 731 try 732 { 733 db = Torque.getConnection(DATABASE_NAME); 734 retVal = retrieveByPKs(pks, db); 735 } 736 finally 737 { 738 Torque.closeConnection(db); 739 } 740 return(retVal); 741 } 742 743 751 public static List retrieveByPKs( List pks, Connection dbcon ) 752 throws TorqueException 753 { 754 List objs = null; 755 if (pks == null || pks.size() == 0) 756 { 757 objs = new LinkedList (); 758 } 759 else 760 { 761 Criteria criteria = new Criteria(); 762 criteria.addIn( ROLE_ID, pks ); 763 objs = doSelect(criteria, dbcon); 764 } 765 return objs; 766 } 767 768 769 770 771 772 773 774 775 776 777 784 protected static TableMap getTableMap() 785 throws TorqueException 786 { 787 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 788 } 789 790 private static void setDbName(Criteria crit) 791 { 792 if (crit.getDbName() == Torque.getDefaultDB()) 796 { 797 crit.setDbName(DATABASE_NAME); 798 } 799 } 800 } 801
| Popular Tags
|