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 BaseTurbineScheduledJobPeer 41 extends BasePeer 42 { 43 44 45 public static final String DATABASE_NAME = "cream"; 46 47 48 public static final String TABLE_NAME = "TURBINE_SCHEDULED_JOB"; 49 50 55 public static MapBuilder getMapBuilder() 56 throws TorqueException 57 { 58 return getMapBuilder(TurbineScheduledJobMapBuilder.CLASS_NAME); 59 } 60 61 62 public static final String JOB_ID; 63 64 public static final String SECOND; 65 66 public static final String MINUTE; 67 68 public static final String HOUR; 69 70 public static final String WEEK_DAY; 71 72 public static final String DAY_OF_MONTH; 73 74 public static final String TASK; 75 76 public static final String EMAIL; 77 78 public static final String PROPERTY; 79 80 static 81 { 82 JOB_ID = "TURBINE_SCHEDULED_JOB.JOB_ID"; 83 SECOND = "TURBINE_SCHEDULED_JOB.SECOND"; 84 MINUTE = "TURBINE_SCHEDULED_JOB.MINUTE"; 85 HOUR = "TURBINE_SCHEDULED_JOB.HOUR"; 86 WEEK_DAY = "TURBINE_SCHEDULED_JOB.WEEK_DAY"; 87 DAY_OF_MONTH = "TURBINE_SCHEDULED_JOB.DAY_OF_MONTH"; 88 TASK = "TURBINE_SCHEDULED_JOB.TASK"; 89 EMAIL = "TURBINE_SCHEDULED_JOB.EMAIL"; 90 PROPERTY = "TURBINE_SCHEDULED_JOB.PROPERTY"; 91 if (Torque.isInit()) 92 { 93 try 94 { 95 getMapBuilder(TurbineScheduledJobMapBuilder.CLASS_NAME); 96 } 97 catch (Exception e) 98 { 99 log.error("Could not initialize Peer", e); 100 } 101 } 102 else 103 { 104 Torque.registerMapBuilder(TurbineScheduledJobMapBuilder.CLASS_NAME); 105 } 106 } 107 108 109 public static final int numColumns = 9; 110 111 112 protected static final String CLASSNAME_DEFAULT = 113 "org.campware.cream.om.TurbineScheduledJob"; 114 115 116 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT); 117 118 124 private static Class initClass(String className) 125 { 126 Class c = null; 127 try 128 { 129 c = Class.forName(className); 130 } 131 catch (Throwable t) 132 { 133 log.error("A FATAL ERROR has occurred which should not " 134 + "have happened under any circumstance. Please notify " 135 + "the Torque developers <torque-dev@db.apache.org> " 136 + "and give as many details as possible (including the error " 137 + "stack trace).", t); 138 139 if (t instanceof Error ) 141 { 142 throw (Error ) t.fillInStackTrace(); 143 } 144 } 145 return c; 146 } 147 148 158 public static List resultSet2Objects(java.sql.ResultSet results) 159 throws TorqueException 160 { 161 try 162 { 163 QueryDataSet qds = null; 164 List rows = null; 165 try 166 { 167 qds = new QueryDataSet(results); 168 rows = getSelectResults(qds); 169 } 170 finally 171 { 172 if (qds != null) 173 { 174 qds.close(); 175 } 176 } 177 178 return populateObjects(rows); 179 } 180 catch (SQLException e) 181 { 182 throw new TorqueException(e); 183 } 184 catch (DataSetException e) 185 { 186 throw new TorqueException(e); 187 } 188 } 189 190 191 192 199 public static ObjectKey doInsert(Criteria criteria) 200 throws TorqueException 201 { 202 return BaseTurbineScheduledJobPeer 203 .doInsert(criteria, (Connection ) null); 204 } 205 206 216 public static ObjectKey doInsert(Criteria criteria, Connection con) 217 throws TorqueException 218 { 219 220 setDbName(criteria); 221 222 if (con == null) 223 { 224 return BasePeer.doInsert(criteria); 225 } 226 else 227 { 228 return BasePeer.doInsert(criteria, con); 229 } 230 } 231 232 239 public static void addSelectColumns(Criteria criteria) 240 throws TorqueException 241 { 242 criteria.addSelectColumn(JOB_ID); 243 criteria.addSelectColumn(SECOND); 244 criteria.addSelectColumn(MINUTE); 245 criteria.addSelectColumn(HOUR); 246 criteria.addSelectColumn(WEEK_DAY); 247 criteria.addSelectColumn(DAY_OF_MONTH); 248 criteria.addSelectColumn(TASK); 249 criteria.addSelectColumn(EMAIL); 250 criteria.addSelectColumn(PROPERTY); 251 } 252 253 262 public static TurbineScheduledJob row2Object(Record row, 263 int offset, 264 Class cls) 265 throws TorqueException 266 { 267 try 268 { 269 TurbineScheduledJob obj = (TurbineScheduledJob) cls.newInstance(); 270 TurbineScheduledJobPeer.populateObject(row, offset, obj); 271 obj.setModified(false); 272 obj.setNew(false); 273 274 return obj; 275 } 276 catch (InstantiationException e) 277 { 278 throw new TorqueException(e); 279 } 280 catch (IllegalAccessException e) 281 { 282 throw new TorqueException(e); 283 } 284 } 285 286 295 public static void populateObject(Record row, 296 int offset, 297 TurbineScheduledJob obj) 298 throws TorqueException 299 { 300 try 301 { 302 obj.setJobId(row.getValue(offset + 0).asInt()); 303 obj.setSecond(row.getValue(offset + 1).asInt()); 304 obj.setMinute(row.getValue(offset + 2).asInt()); 305 obj.setHour(row.getValue(offset + 3).asInt()); 306 obj.setWeekDay(row.getValue(offset + 4).asInt()); 307 obj.setDayOfMonth(row.getValue(offset + 5).asInt()); 308 obj.setTask(row.getValue(offset + 6).asString()); 309 obj.setEmail(row.getValue(offset + 7).asString()); 310 obj.setProperty(row.getValue(offset + 8).asBytes()); 311 } 312 catch (DataSetException e) 313 { 314 throw new TorqueException(e); 315 } 316 } 317 318 326 public static List doSelect(Criteria criteria) throws TorqueException 327 { 328 return populateObjects(doSelectVillageRecords(criteria)); 329 } 330 331 340 public static List doSelect(Criteria criteria, Connection con) 341 throws TorqueException 342 { 343 return populateObjects(doSelectVillageRecords(criteria, con)); 344 } 345 346 356 public static List doSelectVillageRecords(Criteria criteria) 357 throws TorqueException 358 { 359 return BaseTurbineScheduledJobPeer 360 .doSelectVillageRecords(criteria, (Connection ) null); 361 } 362 363 372 public static List doSelectVillageRecords(Criteria criteria, Connection con) 373 throws TorqueException 374 { 375 if (criteria.getSelectColumns().size() == 0) 376 { 377 addSelectColumns(criteria); 378 } 379 380 381 setDbName(criteria); 382 383 if (con == null) 386 { 387 return BasePeer.doSelect(criteria); 388 } 389 else 390 { 391 return BasePeer.doSelect(criteria, con); 392 } 393 } 394 395 402 public static List populateObjects(List records) 403 throws TorqueException 404 { 405 List results = new ArrayList (records.size()); 406 407 for (int i = 0; i < records.size(); i++) 409 { 410 Record row = (Record) records.get(i); 411 results.add(TurbineScheduledJobPeer.row2Object(row, 1, 412 TurbineScheduledJobPeer.getOMClass())); 413 } 414 return results; 415 } 416 417 418 426 public static Class getOMClass() 427 throws TorqueException 428 { 429 return CLASS_DEFAULT; 430 } 431 432 440 public static void doUpdate(Criteria criteria) throws TorqueException 441 { 442 BaseTurbineScheduledJobPeer 443 .doUpdate(criteria, (Connection ) null); 444 } 445 446 457 public static void doUpdate(Criteria criteria, Connection con) 458 throws TorqueException 459 { 460 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2); 461 selectCriteria.put(JOB_ID, criteria.remove(JOB_ID)); 462 463 setDbName(criteria); 464 465 if (con == null) 466 { 467 BasePeer.doUpdate(selectCriteria, criteria); 468 } 469 else 470 { 471 BasePeer.doUpdate(selectCriteria, criteria, con); 472 } 473 } 474 475 482 public static void doDelete(Criteria criteria) throws TorqueException 483 { 484 TurbineScheduledJobPeer 485 .doDelete(criteria, (Connection ) null); 486 } 487 488 498 public static void doDelete(Criteria criteria, Connection con) 499 throws TorqueException 500 { 501 502 setDbName(criteria); 503 504 if (con == null) 505 { 506 BasePeer.doDelete(criteria); 507 } 508 else 509 { 510 BasePeer.doDelete(criteria, con); 511 } 512 } 513 514 520 public static List doSelect(TurbineScheduledJob obj) throws TorqueException 521 { 522 return doSelect(buildSelectCriteria(obj)); 523 } 524 525 531 public static void doInsert(TurbineScheduledJob obj) throws TorqueException 532 { 533 obj.setPrimaryKey(doInsert(buildCriteria(obj))); 534 obj.setNew(false); 535 obj.setModified(false); 536 } 537 538 543 public static void doUpdate(TurbineScheduledJob obj) throws TorqueException 544 { 545 doUpdate(buildCriteria(obj)); 546 obj.setModified(false); 547 } 548 549 554 public static void doDelete(TurbineScheduledJob obj) throws TorqueException 555 { 556 doDelete(buildSelectCriteria(obj)); 557 } 558 559 569 public static void doInsert(TurbineScheduledJob obj, Connection con) 570 throws TorqueException 571 { 572 obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); 573 obj.setNew(false); 574 obj.setModified(false); 575 } 576 577 587 public static void doUpdate(TurbineScheduledJob obj, Connection con) 588 throws TorqueException 589 { 590 doUpdate(buildCriteria(obj), con); 591 obj.setModified(false); 592 } 593 594 604 public static void doDelete(TurbineScheduledJob obj, Connection con) 605 throws TorqueException 606 { 607 doDelete(buildSelectCriteria(obj), con); 608 } 609 610 617 public static void doDelete(ObjectKey pk) throws TorqueException 618 { 619 BaseTurbineScheduledJobPeer 620 .doDelete(pk, (Connection ) null); 621 } 622 623 633 public static void doDelete(ObjectKey pk, Connection con) 634 throws TorqueException 635 { 636 doDelete(buildCriteria(pk), con); 637 } 638 639 640 public static Criteria buildCriteria( ObjectKey pk ) 641 { 642 Criteria criteria = new Criteria(); 643 criteria.add(JOB_ID, pk); 644 return criteria; 645 } 646 647 648 public static Criteria buildCriteria( TurbineScheduledJob obj ) 649 { 650 Criteria criteria = new Criteria(DATABASE_NAME); 651 if (!obj.isNew()) 652 criteria.add(JOB_ID, obj.getJobId()); 653 criteria.add(SECOND, obj.getSecond()); 654 criteria.add(MINUTE, obj.getMinute()); 655 criteria.add(HOUR, obj.getHour()); 656 criteria.add(WEEK_DAY, obj.getWeekDay()); 657 criteria.add(DAY_OF_MONTH, obj.getDayOfMonth()); 658 criteria.add(TASK, obj.getTask()); 659 criteria.add(EMAIL, obj.getEmail()); 660 criteria.add(PROPERTY, obj.getProperty()); 661 return criteria; 662 } 663 664 665 public static Criteria buildSelectCriteria( TurbineScheduledJob obj ) 666 { 667 Criteria criteria = new Criteria(DATABASE_NAME); 668 if (!obj.isNew()) 669 criteria.add(JOB_ID, obj.getJobId()); 670 criteria.add(SECOND, obj.getSecond()); 671 criteria.add(MINUTE, obj.getMinute()); 672 criteria.add(HOUR, obj.getHour()); 673 criteria.add(WEEK_DAY, obj.getWeekDay()); 674 criteria.add(DAY_OF_MONTH, obj.getDayOfMonth()); 675 criteria.add(TASK, obj.getTask()); 676 criteria.add(EMAIL, obj.getEmail()); 677 return criteria; 678 } 679 680 681 690 public static TurbineScheduledJob retrieveByPK(int pk) 691 throws TorqueException, NoRowsException, TooManyRowsException 692 { 693 return retrieveByPK(SimpleKey.keyFor(pk)); 694 } 695 696 706 public static TurbineScheduledJob retrieveByPK(int pk, Connection con) 707 throws TorqueException, NoRowsException, TooManyRowsException 708 { 709 return retrieveByPK(SimpleKey.keyFor(pk), con); 710 } 711 712 721 public static TurbineScheduledJob retrieveByPK(ObjectKey pk) 722 throws TorqueException, NoRowsException, TooManyRowsException 723 { 724 Connection db = null; 725 TurbineScheduledJob retVal = null; 726 try 727 { 728 db = Torque.getConnection(DATABASE_NAME); 729 retVal = retrieveByPK(pk, db); 730 } 731 finally 732 { 733 Torque.closeConnection(db); 734 } 735 return(retVal); 736 } 737 738 748 public static TurbineScheduledJob retrieveByPK(ObjectKey pk, Connection con) 749 throws TorqueException, NoRowsException, TooManyRowsException 750 { 751 Criteria criteria = buildCriteria(pk); 752 List v = doSelect(criteria, con); 753 if (v.size() == 0) 754 { 755 throw new NoRowsException("Failed to select a row."); 756 } 757 else if (v.size() > 1) 758 { 759 throw new TooManyRowsException("Failed to select only one row."); 760 } 761 else 762 { 763 return (TurbineScheduledJob)v.get(0); 764 } 765 } 766 767 774 public static List retrieveByPKs(List pks) 775 throws TorqueException 776 { 777 Connection db = null; 778 List retVal = null; 779 try 780 { 781 db = Torque.getConnection(DATABASE_NAME); 782 retVal = retrieveByPKs(pks, db); 783 } 784 finally 785 { 786 Torque.closeConnection(db); 787 } 788 return(retVal); 789 } 790 791 799 public static List retrieveByPKs( List pks, Connection dbcon ) 800 throws TorqueException 801 { 802 List objs = null; 803 if (pks == null || pks.size() == 0) 804 { 805 objs = new LinkedList (); 806 } 807 else 808 { 809 Criteria criteria = new Criteria(); 810 criteria.addIn( JOB_ID, pks ); 811 objs = doSelect(criteria, dbcon); 812 } 813 return objs; 814 } 815 816 817 818 819 820 821 822 823 824 825 832 protected static TableMap getTableMap() 833 throws TorqueException 834 { 835 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); 836 } 837 838 private static void setDbName(Criteria crit) 839 { 840 if (crit.getDbName() == Torque.getDefaultDB()) 844 { 845 crit.setDbName(DATABASE_NAME); 846 } 847 } 848 } 849
| Popular Tags
|