1packageorg.apache.jetspeed.om.apps.coffees;
23import java.math.BigDecimal;
4import java.sql.Connection;
5import java.sql.SQLException;
6import java.util.ArrayList;
7import java.util.Date;
8import java.util.Iterator;
9import java.util.LinkedList;
10import java.util.List;
1112import org.apache.torque.NoRowsException;
13import org.apache.torque.TooManyRowsException;
14import org.apache.torque.Torque;
15import org.apache.torque.TorqueException;
16import org.apache.torque.map.MapBuilder;
17import org.apache.torque.map.TableMap;
18import org.apache.torque.om.DateKey;
19import org.apache.torque.om.NumberKey;
20import org.apache.torque.om.StringKey;
21import org.apache.torque.om.ObjectKey;
22import org.apache.torque.om.SimpleKey;
23import org.apache.torque.util.BasePeer;
24import org.apache.torque.util.Criteria;
2526import com.workingdogs.village.DataSetException;
27import com.workingdogs.village.QueryDataSet;
28import com.workingdogs.village.Record;
2930// Local classes31importorg.apache.jetspeed.om.apps.coffees.map.*;
323334/***35 * This class was autogenerated by Torque on:36 *37 * [Thu Apr 22 23:12:36 EDT 2004]38 *39 */40publicabstractclassBaseCoffeesPeer41extends BasePeer
42 {
4344/*** the default database name for this class */45publicstaticfinal String DATABASE_NAME = "default";
4647/*** the table name for this class */48publicstaticfinal String TABLE_NAME = "COFFEES";
4950/***51 * @return the map builder for this peer52 * @throws TorqueException Any exceptions caught during processing will be53 * rethrown wrapped into a TorqueException.54 */55publicstatic MapBuilder getMapBuilder()
56 throws TorqueException
57 {
58return getMapBuilder(CoffeesMapBuilder.CLASS_NAME);
59 }
6061/*** the column name for the COFFEE_ID field */62publicstaticfinal String COFFEE_ID;
63/*** the column name for the COFFEE_NAME field */64publicstaticfinal String COFFEE_NAME;
65/*** the column name for the SUPPLIER_ID field */66publicstaticfinal String SUPPLIER_ID;
67/*** the column name for the PRICE field */68publicstaticfinal String PRICE;
69/*** the column name for the SALES field */70publicstaticfinal String SALES;
71/*** the column name for the TOTAL field */72publicstaticfinal String TOTAL;
7374static75 {
76 COFFEE_ID = "COFFEES.COFFEE_ID";
77 COFFEE_NAME = "COFFEES.COFFEE_NAME";
78 SUPPLIER_ID = "COFFEES.SUPPLIER_ID";
79 PRICE = "COFFEES.PRICE";
80 SALES = "COFFEES.SALES";
81 TOTAL = "COFFEES.TOTAL";
82if (Torque.isInit())
83 {
84try85 {
86 getMapBuilder();
87 }
88catch (Exception e)
89 {
90 log.error("Could not initialize Peer", e);
91 }
92 }
93else94 {
95 Torque.registerMapBuilder(CoffeesMapBuilder.CLASS_NAME);
96 }
97 }
9899/*** number of columns for this peer */100publicstaticfinalint numColumns = 6;
101102/*** A class that can be returned by this peer. */103protectedstaticfinal String CLASSNAME_DEFAULT =
104"org.apache.jetspeed.om.apps.coffees.Coffees";
105106/*** A class that can be returned by this peer. */107protectedstaticfinal Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
108109/***110 * Class object initialization method.111 *112 * @param className name of the class to initialize113 * @return the initialized class114 */115privatestatic Class initClass(String className)
116 {
117 Class c = null;
118try119 {
120 c = Class.forName(className);
121 }
122catch (Throwable t)
123 {
124 log.error("A FATAL ERROR has occurred which should not "125 + "have happened under any circumstance. Please notify "126 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> "127 + "and give as many details as possible (including the error "128 + "stack trace).", t);
129130// Error objects should always be propogated.131if (t instanceof Error)
132 {
133throw (Error) t.fillInStackTrace();
134 }
135 }
136return c;
137 }
138139/***140 * Get the list of objects for a ResultSet. Please not that your141 * resultset MUST return columns in the right order. You can use142 * getFieldNames() in BaseObject to get the correct sequence.143 *144 * @param results the ResultSet145 * @return the list of objects146 * @throws TorqueException Any exceptions caught during processing will be147 * rethrown wrapped into a TorqueException.148 */149publicstatic List resultSet2Objects(java.sql.ResultSet results)
150 throws TorqueException
151 {
152try153 {
154 QueryDataSet qds = null;
155 List rows = null;
156try157 {
158 qds = new QueryDataSet(results);
159 rows = getSelectResults(qds);
160 }
161finally162 {
163if (qds != null)
164 {
165 qds.close();
166 }
167 }
168169return populateObjects(rows);
170 }
171catch (SQLException e)
172 {
173thrownew TorqueException(e);
174 }
175catch (DataSetException e)
176 {
177thrownew TorqueException(e);
178 }
179 }
180181182183/***184 * Method to do inserts.185 *186 * @param criteria object used to create the INSERT statement.187 * @throws TorqueException Any exceptions caught during processing will be188 * rethrown wrapped into a TorqueException.189 */190publicstatic ObjectKey doInsert(Criteria criteria)
191 throws TorqueException
192 {
193returnBaseCoffeesPeer194 .doInsert(criteria, (Connection) null);
195 }
196197/***198 * Method to do inserts. This method is to be used during a transaction,199 * otherwise use the doInsert(Criteria) method. It will take care of200 * the connection details internally.201 *202 * @param criteria object used to create the INSERT statement.203 * @param con the connection to use204 * @throws TorqueException Any exceptions caught during processing will be205 * rethrown wrapped into a TorqueException.206 */207publicstatic ObjectKey doInsert(Criteria criteria, Connection con)
208 throws TorqueException
209 {
210211// Set the correct dbName if it has not been overridden212// criteria.getDbName will return the same object if not set to213// another value so == check is okay and faster214if (criteria.getDbName() == Torque.getDefaultDB())
215 {
216 criteria.setDbName(DATABASE_NAME);
217 }
218if (con == null)
219 {
220return BasePeer.doInsert(criteria);
221 }
222else223 {
224return BasePeer.doInsert(criteria, con);
225 }
226 }
227228/***229 * Add all the columns needed to create a new object.230 *231 * @param criteria object containing the columns to add.232 * @throws TorqueException Any exceptions caught during processing will be233 * rethrown wrapped into a TorqueException.234 */235publicstaticvoid addSelectColumns(Criteria criteria)
236 throws TorqueException
237 {
238 criteria.addSelectColumn(COFFEE_ID);
239 criteria.addSelectColumn(COFFEE_NAME);
240 criteria.addSelectColumn(SUPPLIER_ID);
241 criteria.addSelectColumn(PRICE);
242 criteria.addSelectColumn(SALES);
243 criteria.addSelectColumn(TOTAL);
244 }
245246/***247 * Create a new object of type cls from a resultset row starting248 * from a specified offset. This is done so that you can select249 * other rows than just those needed for this object. You may250 * for example want to create two objects from the same row.251 *252 * @throws TorqueException Any exceptions caught during processing will be253 * rethrown wrapped into a TorqueException.254 */255publicstaticCoffees row2Object(Record row,
256int offset,
257 Class cls)
258 throws TorqueException
259 {
260try261 {
262Coffees obj = (Coffees) cls.newInstance();
263 CoffeesPeer.populateObject(row, offset, obj);
264 obj.setModified(false);
265 obj.setNew(false);
266267return obj;
268 }
269catch (InstantiationException e)
270 {
271thrownew TorqueException(e);
272 }
273catch (IllegalAccessException e)
274 {
275thrownew TorqueException(e);
276 }
277 }
278279/***280 * Populates an object from a resultset row starting281 * from a specified offset. This is done so that you can select282 * other rows than just those needed for this object. You may283 * for example want to create two objects from the same row.284 *285 * @throws TorqueException Any exceptions caught during processing will be286 * rethrown wrapped into a TorqueException.287 */288publicstaticvoid populateObject(Record row,
289int offset,
290Coffees obj)
291 throws TorqueException
292 {
293try294 {
295 obj.setCoffeeId(row.getValue(offset + 0).asInt());
296 obj.setCoffeeName(row.getValue(offset + 1).asString());
297 obj.setSupplierId(row.getValue(offset + 2).asInt());
298 obj.setPrice(row.getValue(offset + 3).asDouble());
299 obj.setSales(row.getValue(offset + 4).asInt());
300 obj.setTotal(row.getValue(offset + 5).asInt());
301 }
302catch (DataSetException e)
303 {
304thrownew TorqueException(e);
305 }
306 }
307308/***309 * Method to do selects.310 *311 * @param criteria object used to create the SELECT statement.312 * @return List of selected Objects313 * @throws TorqueException Any exceptions caught during processing will be314 * rethrown wrapped into a TorqueException.315 */316publicstatic List doSelect(Criteria criteria) throws TorqueException
317 {
318return populateObjects(doSelectVillageRecords(criteria));
319 }
320321/***322 * Method to do selects within a transaction.323 *324 * @param criteria object used to create the SELECT statement.325 * @param con the connection to use326 * @return List of selected Objects327 * @throws TorqueException Any exceptions caught during processing will be328 * rethrown wrapped into a TorqueException.329 */330publicstatic List doSelect(Criteria criteria, Connection con)
331 throws TorqueException
332 {
333return populateObjects(doSelectVillageRecords(criteria, con));
334 }
335336/***337 * Grabs the raw Village records to be formed into objects.338 * This method handles connections internally. The Record objects339 * returned by this method should be considered readonly. Do not340 * alter the data and call save(), your results may vary, but are341 * certainly likely to result in hard to track MT bugs.342 *343 * @throws TorqueException Any exceptions caught during processing will be344 * rethrown wrapped into a TorqueException.345 */346publicstatic List doSelectVillageRecords(Criteria criteria)
347 throws TorqueException
348 {
349returnBaseCoffeesPeer350 .doSelectVillageRecords(criteria, (Connection) null);
351 }
352353/***354 * Grabs the raw Village records to be formed into objects.355 * This method should be used for transactions356 *357 * @param con the connection to use358 * @throws TorqueException Any exceptions caught during processing will be359 * rethrown wrapped into a TorqueException.360 */361publicstatic List doSelectVillageRecords(Criteria criteria, Connection con)
362 throws TorqueException
363 {
364if (criteria.getSelectColumns().size() == 0)
365 {
366 addSelectColumns(criteria);
367 }
368369370// Set the correct dbName if it has not been overridden371// criteria.getDbName will return the same object if not set to372// another value so == check is okay and faster373if (criteria.getDbName() == Torque.getDefaultDB())
374 {
375 criteria.setDbName(DATABASE_NAME);
376 }
377// BasePeer returns a List of Value (Village) arrays. The array378// order follows the order columns were placed in the Select clause.379if (con == null)
380 {
381return BasePeer.doSelect(criteria);
382 }
383else384 {
385return BasePeer.doSelect(criteria, con);
386 }
387 }
388389/***390 * The returned List will contain objects of the default type or391 * objects that inherit from the default.392 *393 * @throws TorqueException Any exceptions caught during processing will be394 * rethrown wrapped into a TorqueException.395 */396publicstatic List populateObjects(List records)
397 throws TorqueException
398 {
399 List results = new ArrayList(records.size());
400401// populate the object(s)402for (int i = 0; i < records.size(); i++)
403 {
404 Record row = (Record) records.get(i);
405 results.add(CoffeesPeer.row2Object(row, 1,
406 CoffeesPeer.getOMClass()));
407 }
408return results;
409 }
410411412/***413 * The class that the Peer will make instances of.414 * If the BO is abstract then you must implement this method415 * in the BO.416 *417 * @throws TorqueException Any exceptions caught during processing will be418 * rethrown wrapped into a TorqueException.419 */420publicstatic Class getOMClass()
421 throws TorqueException
422 {
423return CLASS_DEFAULT;
424 }
425426/***427 * Method to do updates.428 *429 * @param criteria object containing data that is used to create the UPDATE430 * statement.431 * @throws TorqueException Any exceptions caught during processing will be432 * rethrown wrapped into a TorqueException.433 */434publicstaticvoid doUpdate(Criteria criteria) throws TorqueException
435 {
436BaseCoffeesPeer437 .doUpdate(criteria, (Connection) null);
438 }
439440/***441 * Method to do updates. This method is to be used during a transaction,442 * otherwise use the doUpdate(Criteria) method. It will take care of443 * the connection details internally.444 *445 * @param criteria object containing data that is used to create the UPDATE446 * statement.447 * @param con the connection to use448 * @throws TorqueException Any exceptions caught during processing will be449 * rethrown wrapped into a TorqueException.450 */451publicstaticvoid doUpdate(Criteria criteria, Connection con)
452 throws TorqueException
453 {
454 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
455 selectCriteria.put(COFFEE_ID, criteria.remove(COFFEE_ID));
456457// Set the correct dbName if it has not been overridden458// criteria.getDbName will return the same object if not set to459// another value so == check is okay and faster460if (criteria.getDbName() == Torque.getDefaultDB())
461 {
462 criteria.setDbName(DATABASE_NAME);
463 }
464if (con == null)
465 {
466 BasePeer.doUpdate(selectCriteria, criteria);
467 }
468else469 {
470 BasePeer.doUpdate(selectCriteria, criteria, con);
471 }
472 }
473474/***475 * Method to do deletes.476 *477 * @param criteria object containing data that is used DELETE from database.478 * @throws TorqueException Any exceptions caught during processing will be479 * rethrown wrapped into a TorqueException.480 */481publicstaticvoid doDelete(Criteria criteria) throws TorqueException
482 {
483BaseCoffeesPeer484 .doDelete(criteria, (Connection) null);
485 }
486487/***488 * Method to do deletes. This method is to be used during a transaction,489 * otherwise use the doDelete(Criteria) method. It will take care of490 * the connection details internally.491 *492 * @param criteria object containing data that is used DELETE from database.493 * @param con the connection to use494 * @throws TorqueException Any exceptions caught during processing will be495 * rethrown wrapped into a TorqueException.496 */497publicstaticvoid doDelete(Criteria criteria, Connection con)
498 throws TorqueException
499 {
500501// Set the correct dbName if it has not been overridden502// criteria.getDbName will return the same object if not set to503// another value so == check is okay and faster504if (criteria.getDbName() == Torque.getDefaultDB())
505 {
506 criteria.setDbName(DATABASE_NAME);
507 }
508if (con == null)
509 {
510 BasePeer.doDelete(criteria);
511 }
512else513 {
514 BasePeer.doDelete(criteria, con);
515 }
516 }
517518/***519 * Method to do selects520 *521 * @throws TorqueException Any exceptions caught during processing will be522 * rethrown wrapped into a TorqueException.523 */524publicstatic List doSelect(Coffees obj) throws TorqueException
525 {
526return doSelect(buildCriteria(obj));
527 }
528529/***530 * Method to do inserts531 *532 * @throws TorqueException Any exceptions caught during processing will be533 * rethrown wrapped into a TorqueException.534 */535publicstaticvoid doInsert(Coffees obj) throws TorqueException
536 {
537 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
538 obj.setNew(false);
539 obj.setModified(false);
540 }
541542/***543 * @param obj the data object to update in the database.544 * @throws TorqueException Any exceptions caught during processing will be545 * rethrown wrapped into a TorqueException.546 */547publicstaticvoid doUpdate(Coffees obj) throws TorqueException
548 {
549 doUpdate(buildCriteria(obj));
550 obj.setModified(false);
551 }
552553/***554 * @param obj the data object to delete in the database.555 * @throws TorqueException Any exceptions caught during processing will be556 * rethrown wrapped into a TorqueException.557 */558publicstaticvoid doDelete(Coffees obj) throws TorqueException
559 {
560 doDelete(buildCriteria(obj));
561 }
562563/***564 * Method to do inserts. This method is to be used during a transaction,565 * otherwise use the doInsert(Coffees) method. It will take566 * care of the connection details internally.567 *568 * @param obj the data object to insert into the database.569 * @param con the connection to use570 * @throws TorqueException Any exceptions caught during processing will be571 * rethrown wrapped into a TorqueException.572 */573publicstaticvoid doInsert(Coffees obj, Connection con)
574 throws TorqueException
575 {
576 obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
577 obj.setNew(false);
578 obj.setModified(false);
579 }
580581/***582 * Method to do update. This method is to be used during a transaction,583 * otherwise use the doUpdate(Coffees) method. It will take584 * care of the connection details internally.585 *586 * @param obj the data object to update in the database.587 * @param con the connection to use588 * @throws TorqueException Any exceptions caught during processing will be589 * rethrown wrapped into a TorqueException.590 */591publicstaticvoid doUpdate(Coffees obj, Connection con)
592 throws TorqueException
593 {
594 doUpdate(buildCriteria(obj), con);
595 obj.setModified(false);
596 }
597598/***599 * Method to delete. This method is to be used during a transaction,600 * otherwise use the doDelete(Coffees) method. It will take601 * care of the connection details internally.602 *603 * @param obj the data object to delete in the database.604 * @param con the connection to use605 * @throws TorqueException Any exceptions caught during processing will be606 * rethrown wrapped into a TorqueException.607 */608publicstaticvoid doDelete(Coffees obj, Connection con)
609 throws TorqueException
610 {
611 doDelete(buildCriteria(obj), con);
612 }
613614/***615 * Method to do deletes.616 *617 * @param pk ObjectKey that is used DELETE from database.618 * @throws TorqueException Any exceptions caught during processing will be619 * rethrown wrapped into a TorqueException.620 */621publicstaticvoid doDelete(ObjectKey pk) throws TorqueException
622 {
623BaseCoffeesPeer624 .doDelete(pk, (Connection) null);
625 }
626627/***628 * Method to delete. This method is to be used during a transaction,629 * otherwise use the doDelete(ObjectKey) method. It will take630 * care of the connection details internally.631 *632 * @param pk the primary key for the object to delete in the database.633 * @param con the connection to use634 * @throws TorqueException Any exceptions caught during processing will be635 * rethrown wrapped into a TorqueException.636 */637publicstaticvoid doDelete(ObjectKey pk, Connection con)
638 throws TorqueException
639 {
640 doDelete(buildCriteria(pk), con);
641 }
642643/*** Build a Criteria object from an ObjectKey */644publicstatic Criteria buildCriteria( ObjectKey pk )
645 {
646 Criteria criteria = new Criteria();
647 criteria.add(COFFEE_ID, pk);
648return criteria;
649 }
650651/*** Build a Criteria object from the data object for this peer */652publicstatic Criteria buildCriteria( Coffees obj )
653 {
654 Criteria criteria = new Criteria(DATABASE_NAME);
655if (!obj.isNew())
656 criteria.add(COFFEE_ID, obj.getCoffeeId());
657 criteria.add(COFFEE_NAME, obj.getCoffeeName());
658 criteria.add(SUPPLIER_ID, obj.getSupplierId());
659 criteria.add(PRICE, obj.getPrice());
660 criteria.add(SALES, obj.getSales());
661 criteria.add(TOTAL, obj.getTotal());
662return criteria;
663 }
664665666/***667 * Retrieve a single object by pk668 *669 * @param pk the primary key670 * @throws TorqueException Any exceptions caught during processing will be671 * rethrown wrapped into a TorqueException.672 * @throws NoRowsException Primary key was not found in database.673 * @throws TooManyRowsException Primary key was not found in database.674 */675publicstaticCoffees retrieveByPK(int pk)
676 throws TorqueException, NoRowsException, TooManyRowsException
677 {
678return retrieveByPK(SimpleKey.keyFor(pk));
679 }
680681/***682 * Retrieve a single object by pk683 *684 * @param pk the primary key685 * @throws TorqueException Any exceptions caught during processing will be686 * rethrown wrapped into a TorqueException.687 * @throws NoRowsException Primary key was not found in database.688 * @throws TooManyRowsException Primary key was not found in database.689 */690publicstaticCoffees retrieveByPK(ObjectKey pk)
691 throws TorqueException, NoRowsException, TooManyRowsException
692 {
693 Connection db = null;
694Coffees retVal = null;
695try696 {
697 db = Torque.getConnection(DATABASE_NAME);
698 retVal = retrieveByPK(pk, db);
699 }
700finally701 {
702 Torque.closeConnection(db);
703 }
704return(retVal);
705 }
706707/***708 * Retrieve a single object by pk709 *710 * @param pk the primary key711 * @param con the connection to use712 * @throws TorqueException Any exceptions caught during processing will be713 * rethrown wrapped into a TorqueException.714 * @throws NoRowsException Primary key was not found in database.715 * @throws TooManyRowsException Primary key was not found in database.716 */717publicstaticCoffees retrieveByPK(ObjectKey pk, Connection con)
718 throws TorqueException, NoRowsException, TooManyRowsException
719 {
720 Criteria criteria = buildCriteria(pk);
721 List v = doSelect(criteria, con);
722if (v.size() == 0)
723 {
724thrownew NoRowsException("Failed to select a row.");
725 }
726elseif (v.size() > 1)
727 {
728thrownew TooManyRowsException("Failed to select only one row.");
729 }
730else731 {
732return (Coffees)v.get(0);
733 }
734 }
735736/***737 * Retrieve a multiple objects by pk738 *739 * @param pks List of primary keys740 * @throws TorqueException Any exceptions caught during processing will be741 * rethrown wrapped into a TorqueException.742 */743publicstatic List retrieveByPKs(List pks)
744 throws TorqueException
745 {
746 Connection db = null;
747 List retVal = null;
748try749 {
750 db = Torque.getConnection(DATABASE_NAME);
751 retVal = retrieveByPKs(pks, db);
752 }
753finally754 {
755 Torque.closeConnection(db);
756 }
757return(retVal);
758 }
759760/***761 * Retrieve a multiple objects by pk762 *763 * @param pks List of primary keys764 * @param dbcon the connection to use765 * @throws TorqueException Any exceptions caught during processing will be766 * rethrown wrapped into a TorqueException.767 */768publicstatic List retrieveByPKs( List pks, Connection dbcon )
769 throws TorqueException
770 {
771 List objs = null;
772if (pks == null || pks.size() == 0)
773 {
774 objs = new LinkedList();
775 }
776else777 {
778 Criteria criteria = new Criteria();
779 criteria.addIn( COFFEE_ID, pks );
780 objs = doSelect(criteria, dbcon);
781 }
782return objs;
783 }
784785786787788789790791792793794/***795 * Returns the TableMap related to this peer. This method is not796 * needed for general use but a specific application could have a need.797 *798 * @throws TorqueException Any exceptions caught during processing will be799 * rethrown wrapped into a TorqueException.800 */801protectedstatic TableMap getTableMap()
802 throws TorqueException
803 {
804return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
805 }
806 }