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 BaseLanguagePeer 41 extends BasePeer 42 { 43 44 45 public static final String DATABASE_NAME = "cream"; 46 47 48 public static final String TABLE_NAME = "LANGUAGE"; 49 50 55 public static MapBuilder getMapBuilder() 56 throws TorqueException 57 { 58 return getMapBuilder(LanguageMapBuilder.CLASS_NAME); 59 } 60 61 62 public static final String LANGUAGE_ID; 63 64 public static final String LANGUAGE_NAME; 65 66 public static final String LANGUAGE_CODE; 67 68 static 69 { 70 LANGUAGE_ID = "LANGUAGE.LANGUAGE_ID"; 71 LANGUAGE_NAME = "LANGUAGE.LANGUAGE_NAME"; 72 LANGUAGE_CODE = "LANGUAGE.LANGUAGE_CODE"; 73 if (Torque.isInit()) 74 { 75 try 76 { 77 getMapBuilder(LanguageMapBuilder.CLASS_NAME); 78 } 79 catch (Exception e) 80 { 81 log.error("Could not initialize Peer", e); 82 } 83 } 84 else 85 { 86 Torque.registerMapBuilder(LanguageMapBuilder.CLASS_NAME); 87 } 88 } 89 90 91 public static final int numColumns = 3; 92 93 94 protected static final String CLASSNAME_DEFAULT = 95 "org.campware.cream.om.Language"; 96 97 98 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 99 100 106 private static Class initClass(String className) 107 { 108 Class c = null; 109 try 110 { 111 c = Class.forName(className); 112 } 113 catch (Throwable t) 114 { 115 log.error("A FATAL ERROR has occurred which should not " 116 + "have happened under any circumstance. Please notify " 117 + "the Torque developers <torque-dev@db.apache.org> " 118 + "and give as many details as possible (including the error " 119 + "stack trace).", t); 120 121 if (t instanceof Error ) 123 { 124 throw (Error ) t.fillInStackTrace(); 125 } 126 } 127 return c; 128 } 129 130 140 public static List resultSet2Objects(java.sql.ResultSet results) 141 throws TorqueException 142 { 143 try 144 { 145 QueryDataSet qds = null; 146 List rows = null; 147 try 148 { 149 qds = new QueryDataSet(results); 150 rows = getSelectResults(qds); 151 } 152 finally 153 { 154 if (qds != null) 155 { 156 qds.close(); 157 } 158 } 159 160 return populateObjects(rows); 161 } 162 catch (SQLException e) 163 { 164 throw new TorqueException(e); 165 } 166 catch (DataSetException e) 167 { 168 throw new TorqueException(e); 169 } 170 } 171 172 173 174 181 public static ObjectKey doInsert(Criteria criteria) 182 throws TorqueException 183 { 184 return BaseLanguagePeer 185 .doInsert(criteria, (Connection ) null); 186 } 187 188 198 public static ObjectKey doInsert(Criteria criteria, Connection con) 199 throws TorqueException 200 { 201 202 setDbName(criteria); 203 204 if (con == null) 205 { 206 return BasePeer.doInsert(criteria); 207 } 208 else 209 { 210 return BasePeer.doInsert(criteria, con); 211 } 212 } 213 214 221 public static void addSelectColumns(Criteria criteria) 222 throws TorqueException 223 { 224 criteria.addSelectColumn(LANGUAGE_ID); 225 criteria.addSelectColumn(LANGUAGE_NAME); 226 criteria.addSelectColumn(LANGUAGE_CODE); 227 } 228 229 238 public static Language row2Object(Record row, 239 int offset, 240 Class cls) 241 throws TorqueException 242 { 243 try 244 { 245 Language obj = (Language) cls.newInstance(); 246 LanguagePeer.populateObject(row, offset, obj); 247 obj.setModified(false); 248 obj.setNew(false); 249 250 return obj; 251 } 252 catch (InstantiationException e) 253 { 254 throw new TorqueException(e); 255 } 256 catch (IllegalAccessException e) 257 { 258 throw new TorqueException(e); 259 } 260 } 261 262 271 public static void populateObject(Record row, 272 int offset, 273 Language obj) 274 throws TorqueException 275 { 276 try 277 { 278 obj.setLanguageId(row.getValue(offset + 0).asInt()); 279 obj.setLanguageName(row.getValue(offset + 1).asString()); 280 obj.setLanguageCode(row.getValue(offset + 2).asString()); 281 } 282 catch (DataSetException e) 283 { 284 throw new TorqueException(e); 285 } 286 } 287 288 296 public static List doSelect(Criteria criteria) throws TorqueException 297 { 298 return populateObjects(doSelectVillageRecords(criteria)); 299 } 300 301 310 public static List doSelect(Criteria criteria, Connection con) 311 throws TorqueException 312 { 313 return populateObjects(doSelectVillageRecords(criteria, con)); 314 } 315 316 326 public static List doSelectVillageRecords(Criteria criteria) 327 throws TorqueException 328 { 329 return BaseLanguagePeer 330 .doSelectVillageRecords(criteria, (Connection ) null); 331 } 332 333 342 public static List doSelectVillageRecords(Criteria criteria, Connection con) 343 throws TorqueException 344 { 345 if (criteria.getSelectColumns().size() == 0) 346 { 347 addSelectColumns(criteria); 348 } 349 350 351 setDbName(criteria); 352 353 if (con == null) 356 { 357 return BasePeer.doSelect(criteria); 358 } 359 else 360 { 361 return BasePeer.doSelect(criteria, con); 362 } 363 } 364 365 372 public static List populateObjects(List records) 373 throws TorqueException 374 { 375 List results = new ArrayList (records.size()); 376 377 for (int i = 0; i < records.size(); i++) 379 { 380 Record row = (Record) records.get(i); 381 results.add(LanguagePeer.row2Object(row, 1, 382 LanguagePeer.getOMClass())); 383 } 384 return results; 385 } 386 387 388 396 public static Class getOMClass() 397 throws TorqueException 398 { 399 return CLASS_DEFAULT; 400 } 401 402 410 public static void doUpdate(Criteria criteria) throws TorqueException 411 { 412 BaseLanguagePeer 413 .doUpdate(criteria, (Connection ) null); 414 } 415 416 427 public static void doUpdate(Criteria criteria, Connection con) 428 throws TorqueException 429 { 430 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 431 selectCriteria.put(LANGUAGE_ID, criteria.remove(LANGUAGE_ID)); 432 433 setDbName(criteria); 434 435 if (con == null) 436 { 437 BasePeer.doUpdate(selectCriteria, criteria); 438 } 439 else 440 { 441 BasePeer.doUpdate(selectCriteria, criteria, con); 442 } 443 } 444 445 452 public static void doDelete(Criteria criteria) throws TorqueException 453 { 454 LanguagePeer 455 .doDelete(criteria, (Connection ) null); 456 } 457 458 468 public static void doDelete(Criteria criteria, Connection con) 469 throws TorqueException 470 { 471 472 setDbName(criteria); 473 474 if (con == null) 475 { 476 BasePeer.doDelete(criteria); 477 } 478 else 479 { 480 BasePeer.doDelete(criteria, con); 481 } 482 } 483 484 490 public static List doSelect(Language obj) throws TorqueException 491 { 492 return doSelect(buildSelectCriteria(obj)); 493 } 494 495 501 public static void doInsert(Language obj) throws TorqueException 502 { 503 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 504 obj.setNew(false); 505 obj.setModified(false); 506 } 507 508 513 public static void doUpdate(Language obj) throws TorqueException 514 { 515 doUpdate(buildCriteria(obj)); 516 obj.setModified(false); 517 } 518 519 524 public static void doDelete(Language obj) throws TorqueException 525 { 526 doDelete(buildSelectCriteria(obj)); 527 } 528 529 539 public static void doInsert(Language obj, Connection con) 540 throws TorqueException 541 { 542 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 543 obj.setNew(false); 544 obj.setModified(false); 545 } 546 547 557 public static void doUpdate(Language obj, Connection con) 558 throws TorqueException 559 { 560 doUpdate(buildCriteria(obj), con); 561 obj.setModified(false); 562 } 563 564 574 public static void doDelete(Language obj, Connection con) 575 throws TorqueException 576 { 577 doDelete(buildSelectCriteria(obj), con); 578 } 579 580 587 public static void doDelete(ObjectKey pk) throws TorqueException 588 { 589 BaseLanguagePeer 590 .doDelete(pk, (Connection ) null); 591 } 592 593 603 public static void doDelete(ObjectKey pk, Connection con) 604 throws TorqueException 605 { 606 doDelete(buildCriteria(pk), con); 607 } 608 609 610 public static Criteria buildCriteria( ObjectKey pk ) 611 { 612 Criteria criteria = new Criteria(); 613 criteria.add(LANGUAGE_ID, pk); 614 return criteria; 615 } 616 617 618 public static Criteria buildCriteria( Language obj ) 619 { 620 Criteria criteria = new Criteria(DATABASE_NAME); 621 if (!obj.isNew()) 622 criteria.add(LANGUAGE_ID, obj.getLanguageId()); 623 criteria.add(LANGUAGE_NAME, obj.getLanguageName()); 624 criteria.add(LANGUAGE_CODE, obj.getLanguageCode()); 625 return criteria; 626 } 627 628 629 public static Criteria buildSelectCriteria( Language obj ) 630 { 631 Criteria criteria = new Criteria(DATABASE_NAME); 632 if (!obj.isNew()) 633 criteria.add(LANGUAGE_ID, obj.getLanguageId()); 634 criteria.add(LANGUAGE_NAME, obj.getLanguageName()); 635 criteria.add(LANGUAGE_CODE, obj.getLanguageCode()); 636 return criteria; 637 } 638 639 640 649 public static Language retrieveByPK(int pk) 650 throws TorqueException, NoRowsException, TooManyRowsException 651 { 652 return retrieveByPK(SimpleKey.keyFor(pk)); 653 } 654 655 665 public static Language retrieveByPK(int pk, Connection con) 666 throws TorqueException, NoRowsException, TooManyRowsException 667 { 668 return retrieveByPK(SimpleKey.keyFor(pk), con); 669 } 670 671 680 public static Language retrieveByPK(ObjectKey pk) 681 throws TorqueException, NoRowsException, TooManyRowsException 682 { 683 Connection db = null; 684 Language retVal = null; 685 try 686 { 687 db = Torque.getConnection(DATABASE_NAME); 688 retVal = retrieveByPK(pk, db); 689 } 690 finally 691 { 692 Torque.closeConnection(db); 693 } 694 return(retVal); 695 } 696 697 707 public static Language retrieveByPK(ObjectKey pk, Connection con) 708 throws TorqueException, NoRowsException, TooManyRowsException 709 { 710 Criteria criteria = buildCriteria(pk); 711 List v = doSelect(criteria, con); 712 if (v.size() == 0) 713 { 714 throw new NoRowsException("Failed to select a row."); 715 } 716 else if (v.size() > 1) 717 { 718 throw new TooManyRowsException("Failed to select only one row."); 719 } 720 else 721 { 722 return (Language)v.get(0); 723 } 724 } 725 726 733 public static List retrieveByPKs(List pks) 734 throws TorqueException 735 { 736 Connection db = null; 737 List retVal = null; 738 try 739 { 740 db = Torque.getConnection(DATABASE_NAME); 741 retVal = retrieveByPKs(pks, db); 742 } 743 finally 744 { 745 Torque.closeConnection(db); 746 } 747 return(retVal); 748 } 749 750 758 public static List retrieveByPKs( List pks, Connection dbcon ) 759 throws TorqueException 760 { 761 List objs = null; 762 if (pks == null || pks.size() == 0) 763 { 764 objs = new LinkedList (); 765 } 766 else 767 { 768 Criteria criteria = new Criteria(); 769 criteria.addIn( LANGUAGE_ID, pks ); 770 objs = doSelect(criteria, dbcon); 771 } 772 return objs; 773 } 774 775 776 777 778 779 780 781 782 783 784 791 protected static TableMap getTableMap() 792 throws TorqueException 793 { 794 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 795 } 796 797 private static void setDbName(Criteria crit) 798 { 799 if (crit.getDbName() == Torque.getDefaultDB()) 803 { 804 crit.setDbName(DATABASE_NAME); 805 } 806 } 807 } 808
| Popular Tags
|