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 BaseCurrencyPeer 41 extends BasePeer 42 { 43 44 45 public static final String DATABASE_NAME = "cream"; 46 47 48 public static final String TABLE_NAME = "CURRENCY"; 49 50 55 public static MapBuilder getMapBuilder() 56 throws TorqueException 57 { 58 return getMapBuilder(CurrencyMapBuilder.CLASS_NAME); 59 } 60 61 62 public static final String CURRENCY_ID; 63 64 public static final String CURRENCY_NAME; 65 66 public static final String CURRENCY_CODE; 67 68 public static final String CURRENCY_RATE; 69 70 static 71 { 72 CURRENCY_ID = "CURRENCY.CURRENCY_ID"; 73 CURRENCY_NAME = "CURRENCY.CURRENCY_NAME"; 74 CURRENCY_CODE = "CURRENCY.CURRENCY_CODE"; 75 CURRENCY_RATE = "CURRENCY.CURRENCY_RATE"; 76 if (Torque.isInit()) 77 { 78 try 79 { 80 getMapBuilder(CurrencyMapBuilder.CLASS_NAME); 81 } 82 catch (Exception e) 83 { 84 log.error("Could not initialize Peer", e); 85 } 86 } 87 else 88 { 89 Torque.registerMapBuilder(CurrencyMapBuilder.CLASS_NAME); 90 } 91 } 92 93 94 public static final int numColumns = 4; 95 96 97 protected static final String CLASSNAME_DEFAULT = 98 "org.campware.cream.om.Currency"; 99 100 101 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 102 103 109 private static Class initClass(String className) 110 { 111 Class c = null; 112 try 113 { 114 c = Class.forName(className); 115 } 116 catch (Throwable t) 117 { 118 log.error("A FATAL ERROR has occurred which should not " 119 + "have happened under any circumstance. Please notify " 120 + "the Torque developers <torque-dev@db.apache.org> " 121 + "and give as many details as possible (including the error " 122 + "stack trace).", t); 123 124 if (t instanceof Error ) 126 { 127 throw (Error ) t.fillInStackTrace(); 128 } 129 } 130 return c; 131 } 132 133 143 public static List resultSet2Objects(java.sql.ResultSet results) 144 throws TorqueException 145 { 146 try 147 { 148 QueryDataSet qds = null; 149 List rows = null; 150 try 151 { 152 qds = new QueryDataSet(results); 153 rows = getSelectResults(qds); 154 } 155 finally 156 { 157 if (qds != null) 158 { 159 qds.close(); 160 } 161 } 162 163 return populateObjects(rows); 164 } 165 catch (SQLException e) 166 { 167 throw new TorqueException(e); 168 } 169 catch (DataSetException e) 170 { 171 throw new TorqueException(e); 172 } 173 } 174 175 176 177 184 public static ObjectKey doInsert(Criteria criteria) 185 throws TorqueException 186 { 187 return BaseCurrencyPeer 188 .doInsert(criteria, (Connection ) null); 189 } 190 191 201 public static ObjectKey doInsert(Criteria criteria, Connection con) 202 throws TorqueException 203 { 204 205 setDbName(criteria); 206 207 if (con == null) 208 { 209 return BasePeer.doInsert(criteria); 210 } 211 else 212 { 213 return BasePeer.doInsert(criteria, con); 214 } 215 } 216 217 224 public static void addSelectColumns(Criteria criteria) 225 throws TorqueException 226 { 227 criteria.addSelectColumn(CURRENCY_ID); 228 criteria.addSelectColumn(CURRENCY_NAME); 229 criteria.addSelectColumn(CURRENCY_CODE); 230 criteria.addSelectColumn(CURRENCY_RATE); 231 } 232 233 242 public static Currency row2Object(Record row, 243 int offset, 244 Class cls) 245 throws TorqueException 246 { 247 try 248 { 249 Currency obj = (Currency) cls.newInstance(); 250 CurrencyPeer.populateObject(row, offset, obj); 251 obj.setModified(false); 252 obj.setNew(false); 253 254 return obj; 255 } 256 catch (InstantiationException e) 257 { 258 throw new TorqueException(e); 259 } 260 catch (IllegalAccessException e) 261 { 262 throw new TorqueException(e); 263 } 264 } 265 266 275 public static void populateObject(Record row, 276 int offset, 277 Currency obj) 278 throws TorqueException 279 { 280 try 281 { 282 obj.setCurrencyId(row.getValue(offset + 0).asInt()); 283 obj.setCurrencyName(row.getValue(offset + 1).asString()); 284 obj.setCurrencyCode(row.getValue(offset + 2).asString()); 285 obj.setCurrencyRate(row.getValue(offset + 3).asBigDecimal()); 286 } 287 catch (DataSetException e) 288 { 289 throw new TorqueException(e); 290 } 291 } 292 293 301 public static List doSelect(Criteria criteria) throws TorqueException 302 { 303 return populateObjects(doSelectVillageRecords(criteria)); 304 } 305 306 315 public static List doSelect(Criteria criteria, Connection con) 316 throws TorqueException 317 { 318 return populateObjects(doSelectVillageRecords(criteria, con)); 319 } 320 321 331 public static List doSelectVillageRecords(Criteria criteria) 332 throws TorqueException 333 { 334 return BaseCurrencyPeer 335 .doSelectVillageRecords(criteria, (Connection ) null); 336 } 337 338 347 public static List doSelectVillageRecords(Criteria criteria, Connection con) 348 throws TorqueException 349 { 350 if (criteria.getSelectColumns().size() == 0) 351 { 352 addSelectColumns(criteria); 353 } 354 355 356 setDbName(criteria); 357 358 if (con == null) 361 { 362 return BasePeer.doSelect(criteria); 363 } 364 else 365 { 366 return BasePeer.doSelect(criteria, con); 367 } 368 } 369 370 377 public static List populateObjects(List records) 378 throws TorqueException 379 { 380 List results = new ArrayList (records.size()); 381 382 for (int i = 0; i < records.size(); i++) 384 { 385 Record row = (Record) records.get(i); 386 results.add(CurrencyPeer.row2Object(row, 1, 387 CurrencyPeer.getOMClass())); 388 } 389 return results; 390 } 391 392 393 401 public static Class getOMClass() 402 throws TorqueException 403 { 404 return CLASS_DEFAULT; 405 } 406 407 415 public static void doUpdate(Criteria criteria) throws TorqueException 416 { 417 BaseCurrencyPeer 418 .doUpdate(criteria, (Connection ) null); 419 } 420 421 432 public static void doUpdate(Criteria criteria, Connection con) 433 throws TorqueException 434 { 435 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 436 selectCriteria.put(CURRENCY_ID, criteria.remove(CURRENCY_ID)); 437 438 setDbName(criteria); 439 440 if (con == null) 441 { 442 BasePeer.doUpdate(selectCriteria, criteria); 443 } 444 else 445 { 446 BasePeer.doUpdate(selectCriteria, criteria, con); 447 } 448 } 449 450 457 public static void doDelete(Criteria criteria) throws TorqueException 458 { 459 CurrencyPeer 460 .doDelete(criteria, (Connection ) null); 461 } 462 463 473 public static void doDelete(Criteria criteria, Connection con) 474 throws TorqueException 475 { 476 477 setDbName(criteria); 478 479 if (con == null) 480 { 481 BasePeer.doDelete(criteria); 482 } 483 else 484 { 485 BasePeer.doDelete(criteria, con); 486 } 487 } 488 489 495 public static List doSelect(Currency obj) throws TorqueException 496 { 497 return doSelect(buildSelectCriteria(obj)); 498 } 499 500 506 public static void doInsert(Currency obj) throws TorqueException 507 { 508 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 509 obj.setNew(false); 510 obj.setModified(false); 511 } 512 513 518 public static void doUpdate(Currency obj) throws TorqueException 519 { 520 doUpdate(buildCriteria(obj)); 521 obj.setModified(false); 522 } 523 524 529 public static void doDelete(Currency obj) throws TorqueException 530 { 531 doDelete(buildSelectCriteria(obj)); 532 } 533 534 544 public static void doInsert(Currency obj, Connection con) 545 throws TorqueException 546 { 547 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 548 obj.setNew(false); 549 obj.setModified(false); 550 } 551 552 562 public static void doUpdate(Currency obj, Connection con) 563 throws TorqueException 564 { 565 doUpdate(buildCriteria(obj), con); 566 obj.setModified(false); 567 } 568 569 579 public static void doDelete(Currency obj, Connection con) 580 throws TorqueException 581 { 582 doDelete(buildSelectCriteria(obj), con); 583 } 584 585 592 public static void doDelete(ObjectKey pk) throws TorqueException 593 { 594 BaseCurrencyPeer 595 .doDelete(pk, (Connection ) null); 596 } 597 598 608 public static void doDelete(ObjectKey pk, Connection con) 609 throws TorqueException 610 { 611 doDelete(buildCriteria(pk), con); 612 } 613 614 615 public static Criteria buildCriteria( ObjectKey pk ) 616 { 617 Criteria criteria = new Criteria(); 618 criteria.add(CURRENCY_ID, pk); 619 return criteria; 620 } 621 622 623 public static Criteria buildCriteria( Currency obj ) 624 { 625 Criteria criteria = new Criteria(DATABASE_NAME); 626 if (!obj.isNew()) 627 criteria.add(CURRENCY_ID, obj.getCurrencyId()); 628 criteria.add(CURRENCY_NAME, obj.getCurrencyName()); 629 criteria.add(CURRENCY_CODE, obj.getCurrencyCode()); 630 criteria.add(CURRENCY_RATE, obj.getCurrencyRate()); 631 return criteria; 632 } 633 634 635 public static Criteria buildSelectCriteria( Currency obj ) 636 { 637 Criteria criteria = new Criteria(DATABASE_NAME); 638 if (!obj.isNew()) 639 criteria.add(CURRENCY_ID, obj.getCurrencyId()); 640 criteria.add(CURRENCY_NAME, obj.getCurrencyName()); 641 criteria.add(CURRENCY_CODE, obj.getCurrencyCode()); 642 criteria.add(CURRENCY_RATE, obj.getCurrencyRate()); 643 return criteria; 644 } 645 646 647 656 public static Currency retrieveByPK(int pk) 657 throws TorqueException, NoRowsException, TooManyRowsException 658 { 659 return retrieveByPK(SimpleKey.keyFor(pk)); 660 } 661 662 672 public static Currency retrieveByPK(int pk, Connection con) 673 throws TorqueException, NoRowsException, TooManyRowsException 674 { 675 return retrieveByPK(SimpleKey.keyFor(pk), con); 676 } 677 678 687 public static Currency retrieveByPK(ObjectKey pk) 688 throws TorqueException, NoRowsException, TooManyRowsException 689 { 690 Connection db = null; 691 Currency retVal = null; 692 try 693 { 694 db = Torque.getConnection(DATABASE_NAME); 695 retVal = retrieveByPK(pk, db); 696 } 697 finally 698 { 699 Torque.closeConnection(db); 700 } 701 return(retVal); 702 } 703 704 714 public static Currency retrieveByPK(ObjectKey pk, Connection con) 715 throws TorqueException, NoRowsException, TooManyRowsException 716 { 717 Criteria criteria = buildCriteria(pk); 718 List v = doSelect(criteria, con); 719 if (v.size() == 0) 720 { 721 throw new NoRowsException("Failed to select a row."); 722 } 723 else if (v.size() > 1) 724 { 725 throw new TooManyRowsException("Failed to select only one row."); 726 } 727 else 728 { 729 return (Currency)v.get(0); 730 } 731 } 732 733 740 public static List retrieveByPKs(List pks) 741 throws TorqueException 742 { 743 Connection db = null; 744 List retVal = null; 745 try 746 { 747 db = Torque.getConnection(DATABASE_NAME); 748 retVal = retrieveByPKs(pks, db); 749 } 750 finally 751 { 752 Torque.closeConnection(db); 753 } 754 return(retVal); 755 } 756 757 765 public static List retrieveByPKs( List pks, Connection dbcon ) 766 throws TorqueException 767 { 768 List objs = null; 769 if (pks == null || pks.size() == 0) 770 { 771 objs = new LinkedList (); 772 } 773 else 774 { 775 Criteria criteria = new Criteria(); 776 criteria.addIn( CURRENCY_ID, pks ); 777 objs = doSelect(criteria, dbcon); 778 } 779 return objs; 780 } 781 782 783 784 785 786 787 788 789 790 791 798 protected static TableMap getTableMap() 799 throws TorqueException 800 { 801 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 802 } 803 804 private static void setDbName(Criteria crit) 805 { 806 if (crit.getDbName() == Torque.getDefaultDB()) 810 { 811 crit.setDbName(DATABASE_NAME); 812 } 813 } 814 } 815
| Popular Tags
|