1packageorg.apache.jetspeed.om.apps.email;
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.email.map.*;
323334/***35 * This class was autogenerated by Torque on:36 *37 * [Thu Apr 22 23:12:36 EDT 2004]38 *39 */40publicabstractclassBaseEmailInboxPeer41extends 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 = "EMAIL_INBOX";
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(EmailInboxMapBuilder.CLASS_NAME);
59 }
6061/*** the column name for the EMAIL_INBOX_ID field */62publicstaticfinal String EMAIL_INBOX_ID;
63/*** the column name for the MESSAGE_ID field */64publicstaticfinal String MESSAGE_ID;
65/*** the column name for the FILENAME field */66publicstaticfinal String FILENAME;
67/*** the column name for the ATTACHMENT field */68publicstaticfinal String ATTACHMENT;
69/*** the column name for the READFLAG field */70publicstaticfinal String READFLAG;
7172static73 {
74 EMAIL_INBOX_ID = "EMAIL_INBOX.EMAIL_INBOX_ID";
75 MESSAGE_ID = "EMAIL_INBOX.MESSAGE_ID";
76 FILENAME = "EMAIL_INBOX.FILENAME";
77 ATTACHMENT = "EMAIL_INBOX.ATTACHMENT";
78 READFLAG = "EMAIL_INBOX.READFLAG";
79if (Torque.isInit())
80 {
81try82 {
83 getMapBuilder();
84 }
85catch (Exception e)
86 {
87 log.error("Could not initialize Peer", e);
88 }
89 }
90else91 {
92 Torque.registerMapBuilder(EmailInboxMapBuilder.CLASS_NAME);
93 }
94 }
9596/*** number of columns for this peer */97publicstaticfinalint numColumns = 5;
9899/*** A class that can be returned by this peer. */100protectedstaticfinal String CLASSNAME_DEFAULT =
101"org.apache.jetspeed.om.apps.email.EmailInbox";
102103/*** A class that can be returned by this peer. */104protectedstaticfinal Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
105106/***107 * Class object initialization method.108 *109 * @param className name of the class to initialize110 * @return the initialized class111 */112privatestatic Class initClass(String className)
113 {
114 Class c = null;
115try116 {
117 c = Class.forName(className);
118 }
119catch (Throwable t)
120 {
121 log.error("A FATAL ERROR has occurred which should not "122 + "have happened under any circumstance. Please notify "123 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> "124 + "and give as many details as possible (including the error "125 + "stack trace).", t);
126127// Error objects should always be propogated.128if (t instanceof Error)
129 {
130throw (Error) t.fillInStackTrace();
131 }
132 }
133return c;
134 }
135136/***137 * Get the list of objects for a ResultSet. Please not that your138 * resultset MUST return columns in the right order. You can use139 * getFieldNames() in BaseObject to get the correct sequence.140 *141 * @param results the ResultSet142 * @return the list of objects143 * @throws TorqueException Any exceptions caught during processing will be144 * rethrown wrapped into a TorqueException.145 */146publicstatic List resultSet2Objects(java.sql.ResultSet results)
147 throws TorqueException
148 {
149try150 {
151 QueryDataSet qds = null;
152 List rows = null;
153try154 {
155 qds = new QueryDataSet(results);
156 rows = getSelectResults(qds);
157 }
158finally159 {
160if (qds != null)
161 {
162 qds.close();
163 }
164 }
165166return populateObjects(rows);
167 }
168catch (SQLException e)
169 {
170thrownew TorqueException(e);
171 }
172catch (DataSetException e)
173 {
174thrownew TorqueException(e);
175 }
176 }
177178179180/***181 * Method to do inserts.182 *183 * @param criteria object used to create the INSERT statement.184 * @throws TorqueException Any exceptions caught during processing will be185 * rethrown wrapped into a TorqueException.186 */187publicstatic ObjectKey doInsert(Criteria criteria)
188 throws TorqueException
189 {
190returnBaseEmailInboxPeer191 .doInsert(criteria, (Connection) null);
192 }
193194/***195 * Method to do inserts. This method is to be used during a transaction,196 * otherwise use the doInsert(Criteria) method. It will take care of197 * the connection details internally.198 *199 * @param criteria object used to create the INSERT statement.200 * @param con the connection to use201 * @throws TorqueException Any exceptions caught during processing will be202 * rethrown wrapped into a TorqueException.203 */204publicstatic ObjectKey doInsert(Criteria criteria, Connection con)
205 throws TorqueException
206 {
207208// Set the correct dbName if it has not been overridden209// criteria.getDbName will return the same object if not set to210// another value so == check is okay and faster211if (criteria.getDbName() == Torque.getDefaultDB())
212 {
213 criteria.setDbName(DATABASE_NAME);
214 }
215if (con == null)
216 {
217return BasePeer.doInsert(criteria);
218 }
219else220 {
221return BasePeer.doInsert(criteria, con);
222 }
223 }
224225/***226 * Add all the columns needed to create a new object.227 *228 * @param criteria object containing the columns to add.229 * @throws TorqueException Any exceptions caught during processing will be230 * rethrown wrapped into a TorqueException.231 */232publicstaticvoid addSelectColumns(Criteria criteria)
233 throws TorqueException
234 {
235 criteria.addSelectColumn(EMAIL_INBOX_ID);
236 criteria.addSelectColumn(MESSAGE_ID);
237 criteria.addSelectColumn(FILENAME);
238 criteria.addSelectColumn(ATTACHMENT);
239 criteria.addSelectColumn(READFLAG);
240 }
241242/***243 * Create a new object of type cls from a resultset row starting244 * from a specified offset. This is done so that you can select245 * other rows than just those needed for this object. You may246 * for example want to create two objects from the same row.247 *248 * @throws TorqueException Any exceptions caught during processing will be249 * rethrown wrapped into a TorqueException.250 */251publicstaticEmailInbox row2Object(Record row,
252int offset,
253 Class cls)
254 throws TorqueException
255 {
256try257 {
258EmailInbox obj = (EmailInbox) cls.newInstance();
259 EmailInboxPeer.populateObject(row, offset, obj);
260 obj.setModified(false);
261 obj.setNew(false);
262263return obj;
264 }
265catch (InstantiationException e)
266 {
267thrownew TorqueException(e);
268 }
269catch (IllegalAccessException e)
270 {
271thrownew TorqueException(e);
272 }
273 }
274275/***276 * Populates an object from a resultset row starting277 * from a specified offset. This is done so that you can select278 * other rows than just those needed for this object. You may279 * for example want to create two objects from the same row.280 *281 * @throws TorqueException Any exceptions caught during processing will be282 * rethrown wrapped into a TorqueException.283 */284publicstaticvoid populateObject(Record row,
285int offset,
286EmailInbox obj)
287 throws TorqueException
288 {
289try290 {
291 obj.setEmailInboxId(row.getValue(offset + 0).asInt());
292 obj.setMessageId(row.getValue(offset + 1).asString());
293 obj.setFilename(row.getValue(offset + 2).asString());
294 obj.setAttachment(row.getValue(offset + 3).asBytes());
295 obj.setReadflag(row.getValue(offset + 4).asInt());
296 }
297catch (DataSetException e)
298 {
299thrownew TorqueException(e);
300 }
301 }
302303/***304 * Method to do selects.305 *306 * @param criteria object used to create the SELECT statement.307 * @return List of selected Objects308 * @throws TorqueException Any exceptions caught during processing will be309 * rethrown wrapped into a TorqueException.310 */311publicstatic List doSelect(Criteria criteria) throws TorqueException
312 {
313return populateObjects(doSelectVillageRecords(criteria));
314 }
315316/***317 * Method to do selects within a transaction.318 *319 * @param criteria object used to create the SELECT statement.320 * @param con the connection to use321 * @return List of selected Objects322 * @throws TorqueException Any exceptions caught during processing will be323 * rethrown wrapped into a TorqueException.324 */325publicstatic List doSelect(Criteria criteria, Connection con)
326 throws TorqueException
327 {
328return populateObjects(doSelectVillageRecords(criteria, con));
329 }
330331/***332 * Grabs the raw Village records to be formed into objects.333 * This method handles connections internally. The Record objects334 * returned by this method should be considered readonly. Do not335 * alter the data and call save(), your results may vary, but are336 * certainly likely to result in hard to track MT bugs.337 *338 * @throws TorqueException Any exceptions caught during processing will be339 * rethrown wrapped into a TorqueException.340 */341publicstatic List doSelectVillageRecords(Criteria criteria)
342 throws TorqueException
343 {
344returnBaseEmailInboxPeer345 .doSelectVillageRecords(criteria, (Connection) null);
346 }
347348/***349 * Grabs the raw Village records to be formed into objects.350 * This method should be used for transactions351 *352 * @param con the connection to use353 * @throws TorqueException Any exceptions caught during processing will be354 * rethrown wrapped into a TorqueException.355 */356publicstatic List doSelectVillageRecords(Criteria criteria, Connection con)
357 throws TorqueException
358 {
359if (criteria.getSelectColumns().size() == 0)
360 {
361 addSelectColumns(criteria);
362 }
363364365// Set the correct dbName if it has not been overridden366// criteria.getDbName will return the same object if not set to367// another value so == check is okay and faster368if (criteria.getDbName() == Torque.getDefaultDB())
369 {
370 criteria.setDbName(DATABASE_NAME);
371 }
372// BasePeer returns a List of Value (Village) arrays. The array373// order follows the order columns were placed in the Select clause.374if (con == null)
375 {
376return BasePeer.doSelect(criteria);
377 }
378else379 {
380return BasePeer.doSelect(criteria, con);
381 }
382 }
383384/***385 * The returned List will contain objects of the default type or386 * objects that inherit from the default.387 *388 * @throws TorqueException Any exceptions caught during processing will be389 * rethrown wrapped into a TorqueException.390 */391publicstatic List populateObjects(List records)
392 throws TorqueException
393 {
394 List results = new ArrayList(records.size());
395396// populate the object(s)397for (int i = 0; i < records.size(); i++)
398 {
399 Record row = (Record) records.get(i);
400 results.add(EmailInboxPeer.row2Object(row, 1,
401 EmailInboxPeer.getOMClass()));
402 }
403return results;
404 }
405406407/***408 * The class that the Peer will make instances of.409 * If the BO is abstract then you must implement this method410 * in the BO.411 *412 * @throws TorqueException Any exceptions caught during processing will be413 * rethrown wrapped into a TorqueException.414 */415publicstatic Class getOMClass()
416 throws TorqueException
417 {
418return CLASS_DEFAULT;
419 }
420421/***422 * Method to do updates.423 *424 * @param criteria object containing data that is used to create the UPDATE425 * statement.426 * @throws TorqueException Any exceptions caught during processing will be427 * rethrown wrapped into a TorqueException.428 */429publicstaticvoid doUpdate(Criteria criteria) throws TorqueException
430 {
431BaseEmailInboxPeer432 .doUpdate(criteria, (Connection) null);
433 }
434435/***436 * Method to do updates. This method is to be used during a transaction,437 * otherwise use the doUpdate(Criteria) method. It will take care of438 * the connection details internally.439 *440 * @param criteria object containing data that is used to create the UPDATE441 * statement.442 * @param con the connection to use443 * @throws TorqueException Any exceptions caught during processing will be444 * rethrown wrapped into a TorqueException.445 */446publicstaticvoid doUpdate(Criteria criteria, Connection con)
447 throws TorqueException
448 {
449 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
450 selectCriteria.put(EMAIL_INBOX_ID, criteria.remove(EMAIL_INBOX_ID));
451452// Set the correct dbName if it has not been overridden453// criteria.getDbName will return the same object if not set to454// another value so == check is okay and faster455if (criteria.getDbName() == Torque.getDefaultDB())
456 {
457 criteria.setDbName(DATABASE_NAME);
458 }
459if (con == null)
460 {
461 BasePeer.doUpdate(selectCriteria, criteria);
462 }
463else464 {
465 BasePeer.doUpdate(selectCriteria, criteria, con);
466 }
467 }
468469/***470 * Method to do deletes.471 *472 * @param criteria object containing data that is used DELETE from database.473 * @throws TorqueException Any exceptions caught during processing will be474 * rethrown wrapped into a TorqueException.475 */476publicstaticvoid doDelete(Criteria criteria) throws TorqueException
477 {
478BaseEmailInboxPeer479 .doDelete(criteria, (Connection) null);
480 }
481482/***483 * Method to do deletes. This method is to be used during a transaction,484 * otherwise use the doDelete(Criteria) method. It will take care of485 * the connection details internally.486 *487 * @param criteria object containing data that is used DELETE from database.488 * @param con the connection to use489 * @throws TorqueException Any exceptions caught during processing will be490 * rethrown wrapped into a TorqueException.491 */492publicstaticvoid doDelete(Criteria criteria, Connection con)
493 throws TorqueException
494 {
495496// Set the correct dbName if it has not been overridden497// criteria.getDbName will return the same object if not set to498// another value so == check is okay and faster499if (criteria.getDbName() == Torque.getDefaultDB())
500 {
501 criteria.setDbName(DATABASE_NAME);
502 }
503if (con == null)
504 {
505 BasePeer.doDelete(criteria);
506 }
507else508 {
509 BasePeer.doDelete(criteria, con);
510 }
511 }
512513/***514 * Method to do selects515 *516 * @throws TorqueException Any exceptions caught during processing will be517 * rethrown wrapped into a TorqueException.518 */519publicstatic List doSelect(EmailInbox obj) throws TorqueException
520 {
521return doSelect(buildCriteria(obj));
522 }
523524/***525 * Method to do inserts526 *527 * @throws TorqueException Any exceptions caught during processing will be528 * rethrown wrapped into a TorqueException.529 */530publicstaticvoid doInsert(EmailInbox obj) throws TorqueException
531 {
532 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
533 obj.setNew(false);
534 obj.setModified(false);
535 }
536537/***538 * @param obj the data object to update in the database.539 * @throws TorqueException Any exceptions caught during processing will be540 * rethrown wrapped into a TorqueException.541 */542publicstaticvoid doUpdate(EmailInbox obj) throws TorqueException
543 {
544 doUpdate(buildCriteria(obj));
545 obj.setModified(false);
546 }
547548/***549 * @param obj the data object to delete in the database.550 * @throws TorqueException Any exceptions caught during processing will be551 * rethrown wrapped into a TorqueException.552 */553publicstaticvoid doDelete(EmailInbox obj) throws TorqueException
554 {
555 doDelete(buildCriteria(obj));
556 }
557558/***559 * Method to do inserts. This method is to be used during a transaction,560 * otherwise use the doInsert(EmailInbox) method. It will take561 * care of the connection details internally.562 *563 * @param obj the data object to insert into the database.564 * @param con the connection to use565 * @throws TorqueException Any exceptions caught during processing will be566 * rethrown wrapped into a TorqueException.567 */568publicstaticvoid doInsert(EmailInbox obj, Connection con)
569 throws TorqueException
570 {
571 obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
572 obj.setNew(false);
573 obj.setModified(false);
574 }
575576/***577 * Method to do update. This method is to be used during a transaction,578 * otherwise use the doUpdate(EmailInbox) method. It will take579 * care of the connection details internally.580 *581 * @param obj the data object to update in the database.582 * @param con the connection to use583 * @throws TorqueException Any exceptions caught during processing will be584 * rethrown wrapped into a TorqueException.585 */586publicstaticvoid doUpdate(EmailInbox obj, Connection con)
587 throws TorqueException
588 {
589 doUpdate(buildCriteria(obj), con);
590 obj.setModified(false);
591 }
592593/***594 * Method to delete. This method is to be used during a transaction,595 * otherwise use the doDelete(EmailInbox) method. It will take596 * care of the connection details internally.597 *598 * @param obj the data object to delete in the database.599 * @param con the connection to use600 * @throws TorqueException Any exceptions caught during processing will be601 * rethrown wrapped into a TorqueException.602 */603publicstaticvoid doDelete(EmailInbox obj, Connection con)
604 throws TorqueException
605 {
606 doDelete(buildCriteria(obj), con);
607 }
608609/***610 * Method to do deletes.611 *612 * @param pk ObjectKey that is used DELETE from database.613 * @throws TorqueException Any exceptions caught during processing will be614 * rethrown wrapped into a TorqueException.615 */616publicstaticvoid doDelete(ObjectKey pk) throws TorqueException
617 {
618BaseEmailInboxPeer619 .doDelete(pk, (Connection) null);
620 }
621622/***623 * Method to delete. This method is to be used during a transaction,624 * otherwise use the doDelete(ObjectKey) method. It will take625 * care of the connection details internally.626 *627 * @param pk the primary key for the object to delete in the database.628 * @param con the connection to use629 * @throws TorqueException Any exceptions caught during processing will be630 * rethrown wrapped into a TorqueException.631 */632publicstaticvoid doDelete(ObjectKey pk, Connection con)
633 throws TorqueException
634 {
635 doDelete(buildCriteria(pk), con);
636 }
637638/*** Build a Criteria object from an ObjectKey */639publicstatic Criteria buildCriteria( ObjectKey pk )
640 {
641 Criteria criteria = new Criteria();
642 criteria.add(EMAIL_INBOX_ID, pk);
643return criteria;
644 }
645646/*** Build a Criteria object from the data object for this peer */647publicstatic Criteria buildCriteria( EmailInbox obj )
648 {
649 Criteria criteria = new Criteria(DATABASE_NAME);
650if (!obj.isNew())
651 criteria.add(EMAIL_INBOX_ID, obj.getEmailInboxId());
652 criteria.add(MESSAGE_ID, obj.getMessageId());
653 criteria.add(FILENAME, obj.getFilename());
654 criteria.add(ATTACHMENT, obj.getAttachment());
655 criteria.add(READFLAG, obj.getReadflag());
656return criteria;
657 }
658659660/***661 * Retrieve a single object by pk662 *663 * @param pk the primary key664 * @throws TorqueException Any exceptions caught during processing will be665 * rethrown wrapped into a TorqueException.666 * @throws NoRowsException Primary key was not found in database.667 * @throws TooManyRowsException Primary key was not found in database.668 */669publicstaticEmailInbox retrieveByPK(int pk)
670 throws TorqueException, NoRowsException, TooManyRowsException
671 {
672return retrieveByPK(SimpleKey.keyFor(pk));
673 }
674675/***676 * Retrieve a single object by pk677 *678 * @param pk the primary key679 * @throws TorqueException Any exceptions caught during processing will be680 * rethrown wrapped into a TorqueException.681 * @throws NoRowsException Primary key was not found in database.682 * @throws TooManyRowsException Primary key was not found in database.683 */684publicstaticEmailInbox retrieveByPK(ObjectKey pk)
685 throws TorqueException, NoRowsException, TooManyRowsException
686 {
687 Connection db = null;
688EmailInbox retVal = null;
689try690 {
691 db = Torque.getConnection(DATABASE_NAME);
692 retVal = retrieveByPK(pk, db);
693 }
694finally695 {
696 Torque.closeConnection(db);
697 }
698return(retVal);
699 }
700701/***702 * Retrieve a single object by pk703 *704 * @param pk the primary key705 * @param con the connection to use706 * @throws TorqueException Any exceptions caught during processing will be707 * rethrown wrapped into a TorqueException.708 * @throws NoRowsException Primary key was not found in database.709 * @throws TooManyRowsException Primary key was not found in database.710 */711publicstaticEmailInbox retrieveByPK(ObjectKey pk, Connection con)
712 throws TorqueException, NoRowsException, TooManyRowsException
713 {
714 Criteria criteria = buildCriteria(pk);
715 List v = doSelect(criteria, con);
716if (v.size() == 0)
717 {
718thrownew NoRowsException("Failed to select a row.");
719 }
720elseif (v.size() > 1)
721 {
722thrownew TooManyRowsException("Failed to select only one row.");
723 }
724else725 {
726return (EmailInbox)v.get(0);
727 }
728 }
729730/***731 * Retrieve a multiple objects by pk732 *733 * @param pks List of primary keys734 * @throws TorqueException Any exceptions caught during processing will be735 * rethrown wrapped into a TorqueException.736 */737publicstatic List retrieveByPKs(List pks)
738 throws TorqueException
739 {
740 Connection db = null;
741 List retVal = null;
742try743 {
744 db = Torque.getConnection(DATABASE_NAME);
745 retVal = retrieveByPKs(pks, db);
746 }
747finally748 {
749 Torque.closeConnection(db);
750 }
751return(retVal);
752 }
753754/***755 * Retrieve a multiple objects by pk756 *757 * @param pks List of primary keys758 * @param dbcon the connection to use759 * @throws TorqueException Any exceptions caught during processing will be760 * rethrown wrapped into a TorqueException.761 */762publicstatic List retrieveByPKs( List pks, Connection dbcon )
763 throws TorqueException
764 {
765 List objs = null;
766if (pks == null || pks.size() == 0)
767 {
768 objs = new LinkedList();
769 }
770else771 {
772 Criteria criteria = new Criteria();
773 criteria.addIn( EMAIL_INBOX_ID, pks );
774 objs = doSelect(criteria, dbcon);
775 }
776return objs;
777 }
778779780781782783784785786787788/***789 * Returns the TableMap related to this peer. This method is not790 * needed for general use but a specific application could have a need.791 *792 * @throws TorqueException Any exceptions caught during processing will be793 * rethrown wrapped into a TorqueException.794 */795protectedstatic TableMap getTableMap()
796 throws TorqueException
797 {
798return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
799 }
800 }