1 package org.apache.jetspeed.om.apps.email;
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
31 import org.apache.jetspeed.om.apps.email.map.*;
32
33
34 /***
35 * This class was autogenerated by Torque on:
36 *
37 * [Thu Apr 22 23:12:36 EDT 2004]
38 *
39 */
40 public abstract class BaseEmailInboxPeer
41 extends BasePeer
42 {
43
44 /*** the default database name for this class */
45 public static final String DATABASE_NAME = "default";
46
47 /*** the table name for this class */
48 public static final String TABLE_NAME = "EMAIL_INBOX";
49
50 /***
51 * @return the map builder for this peer
52 * @throws TorqueException Any exceptions caught during processing will be
53 * rethrown wrapped into a TorqueException.
54 */
55 public static MapBuilder getMapBuilder()
56 throws TorqueException
57 {
58 return getMapBuilder(EmailInboxMapBuilder.CLASS_NAME);
59 }
60
61 /*** the column name for the EMAIL_INBOX_ID field */
62 public static final String EMAIL_INBOX_ID;
63 /*** the column name for the MESSAGE_ID field */
64 public static final String MESSAGE_ID;
65 /*** the column name for the FILENAME field */
66 public static final String FILENAME;
67 /*** the column name for the ATTACHMENT field */
68 public static final String ATTACHMENT;
69 /*** the column name for the READFLAG field */
70 public static final String READFLAG;
71
72 static
73 {
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";
79 if (Torque.isInit())
80 {
81 try
82 {
83 getMapBuilder();
84 }
85 catch (Exception e)
86 {
87 log.error("Could not initialize Peer", e);
88 }
89 }
90 else
91 {
92 Torque.registerMapBuilder(EmailInboxMapBuilder.CLASS_NAME);
93 }
94 }
95
96 /*** number of columns for this peer */
97 public static final int numColumns = 5;
98
99 /*** A class that can be returned by this peer. */
100 protected static final String CLASSNAME_DEFAULT =
101 "org.apache.jetspeed.om.apps.email.EmailInbox";
102
103 /*** A class that can be returned by this peer. */
104 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
105
106 /***
107 * Class object initialization method.
108 *
109 * @param className name of the class to initialize
110 * @return the initialized class
111 */
112 private static Class initClass(String className)
113 {
114 Class c = null;
115 try
116 {
117 c = Class.forName(className);
118 }
119 catch (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);
126
127
128 if (t instanceof Error)
129 {
130 throw (Error) t.fillInStackTrace();
131 }
132 }
133 return c;
134 }
135
136 /***
137 * Get the list of objects for a ResultSet. Please not that your
138 * resultset MUST return columns in the right order. You can use
139 * getFieldNames() in BaseObject to get the correct sequence.
140 *
141 * @param results the ResultSet
142 * @return the list of objects
143 * @throws TorqueException Any exceptions caught during processing will be
144 * rethrown wrapped into a TorqueException.
145 */
146 public static List resultSet2Objects(java.sql.ResultSet results)
147 throws TorqueException
148 {
149 try
150 {
151 QueryDataSet qds = null;
152 List rows = null;
153 try
154 {
155 qds = new QueryDataSet(results);
156 rows = getSelectResults(qds);
157 }
158 finally
159 {
160 if (qds != null)
161 {
162 qds.close();
163 }
164 }
165
166 return populateObjects(rows);
167 }
168 catch (SQLException e)
169 {
170 throw new TorqueException(e);
171 }
172 catch (DataSetException e)
173 {
174 throw new TorqueException(e);
175 }
176 }
177
178
179
180 /***
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 be
185 * rethrown wrapped into a TorqueException.
186 */
187 public static ObjectKey doInsert(Criteria criteria)
188 throws TorqueException
189 {
190 return BaseEmailInboxPeer
191 .doInsert(criteria, (Connection) null);
192 }
193
194 /***
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 of
197 * the connection details internally.
198 *
199 * @param criteria object used to create the INSERT statement.
200 * @param con the connection to use
201 * @throws TorqueException Any exceptions caught during processing will be
202 * rethrown wrapped into a TorqueException.
203 */
204 public static ObjectKey doInsert(Criteria criteria, Connection con)
205 throws TorqueException
206 {
207
208
209
210
211 if (criteria.getDbName() == Torque.getDefaultDB())
212 {
213 criteria.setDbName(DATABASE_NAME);
214 }
215 if (con == null)
216 {
217 return BasePeer.doInsert(criteria);
218 }
219 else
220 {
221 return BasePeer.doInsert(criteria, con);
222 }
223 }
224
225 /***
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 be
230 * rethrown wrapped into a TorqueException.
231 */
232 public static void 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 }
241
242 /***
243 * Create a new object of type cls from a resultset row starting
244 * from a specified offset. This is done so that you can select
245 * other rows than just those needed for this object. You may
246 * for example want to create two objects from the same row.
247 *
248 * @throws TorqueException Any exceptions caught during processing will be
249 * rethrown wrapped into a TorqueException.
250 */
251 public static EmailInbox row2Object(Record row,
252 int offset,
253 Class cls)
254 throws TorqueException
255 {
256 try
257 {
258 EmailInbox obj = (EmailInbox) cls.newInstance();
259 EmailInboxPeer.populateObject(row, offset, obj);
260 obj.setModified(false);
261 obj.setNew(false);
262
263 return obj;
264 }
265 catch (InstantiationException e)
266 {
267 throw new TorqueException(e);
268 }
269 catch (IllegalAccessException e)
270 {
271 throw new TorqueException(e);
272 }
273 }
274
275 /***
276 * Populates an object from a resultset row starting
277 * from a specified offset. This is done so that you can select
278 * other rows than just those needed for this object. You may
279 * for example want to create two objects from the same row.
280 *
281 * @throws TorqueException Any exceptions caught during processing will be
282 * rethrown wrapped into a TorqueException.
283 */
284 public static void populateObject(Record row,
285 int offset,
286 EmailInbox obj)
287 throws TorqueException
288 {
289 try
290 {
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 }
297 catch (DataSetException e)
298 {
299 throw new TorqueException(e);
300 }
301 }
302
303 /***
304 * Method to do selects.
305 *
306 * @param criteria object used to create the SELECT statement.
307 * @return List of selected Objects
308 * @throws TorqueException Any exceptions caught during processing will be
309 * rethrown wrapped into a TorqueException.
310 */
311 public static List doSelect(Criteria criteria) throws TorqueException
312 {
313 return populateObjects(doSelectVillageRecords(criteria));
314 }
315
316 /***
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 use
321 * @return List of selected Objects
322 * @throws TorqueException Any exceptions caught during processing will be
323 * rethrown wrapped into a TorqueException.
324 */
325 public static List doSelect(Criteria criteria, Connection con)
326 throws TorqueException
327 {
328 return populateObjects(doSelectVillageRecords(criteria, con));
329 }
330
331 /***
332 * Grabs the raw Village records to be formed into objects.
333 * This method handles connections internally. The Record objects
334 * returned by this method should be considered readonly. Do not
335 * alter the data and call save(), your results may vary, but are
336 * certainly likely to result in hard to track MT bugs.
337 *
338 * @throws TorqueException Any exceptions caught during processing will be
339 * rethrown wrapped into a TorqueException.
340 */
341 public static List doSelectVillageRecords(Criteria criteria)
342 throws TorqueException
343 {
344 return BaseEmailInboxPeer
345 .doSelectVillageRecords(criteria, (Connection) null);
346 }
347
348 /***
349 * Grabs the raw Village records to be formed into objects.
350 * This method should be used for transactions
351 *
352 * @param con the connection to use
353 * @throws TorqueException Any exceptions caught during processing will be
354 * rethrown wrapped into a TorqueException.
355 */
356 public static List doSelectVillageRecords(Criteria criteria, Connection con)
357 throws TorqueException
358 {
359 if (criteria.getSelectColumns().size() == 0)
360 {
361 addSelectColumns(criteria);
362 }
363
364
365
366
367
368 if (criteria.getDbName() == Torque.getDefaultDB())
369 {
370 criteria.setDbName(DATABASE_NAME);
371 }
372
373
374 if (con == null)
375 {
376 return BasePeer.doSelect(criteria);
377 }
378 else
379 {
380 return BasePeer.doSelect(criteria, con);
381 }
382 }
383
384 /***
385 * The returned List will contain objects of the default type or
386 * objects that inherit from the default.
387 *
388 * @throws TorqueException Any exceptions caught during processing will be
389 * rethrown wrapped into a TorqueException.
390 */
391 public static List populateObjects(List records)
392 throws TorqueException
393 {
394 List results = new ArrayList(records.size());
395
396
397 for (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 }
403 return results;
404 }
405
406
407 /***
408 * The class that the Peer will make instances of.
409 * If the BO is abstract then you must implement this method
410 * in the BO.
411 *
412 * @throws TorqueException Any exceptions caught during processing will be
413 * rethrown wrapped into a TorqueException.
414 */
415 public static Class getOMClass()
416 throws TorqueException
417 {
418 return CLASS_DEFAULT;
419 }
420
421 /***
422 * Method to do updates.
423 *
424 * @param criteria object containing data that is used to create the UPDATE
425 * statement.
426 * @throws TorqueException Any exceptions caught during processing will be
427 * rethrown wrapped into a TorqueException.
428 */
429 public static void doUpdate(Criteria criteria) throws TorqueException
430 {
431 BaseEmailInboxPeer
432 .doUpdate(criteria, (Connection) null);
433 }
434
435 /***
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 of
438 * the connection details internally.
439 *
440 * @param criteria object containing data that is used to create the UPDATE
441 * statement.
442 * @param con the connection to use
443 * @throws TorqueException Any exceptions caught during processing will be
444 * rethrown wrapped into a TorqueException.
445 */
446 public static void 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));
451
452
453
454
455 if (criteria.getDbName() == Torque.getDefaultDB())
456 {
457 criteria.setDbName(DATABASE_NAME);
458 }
459 if (con == null)
460 {
461 BasePeer.doUpdate(selectCriteria, criteria);
462 }
463 else
464 {
465 BasePeer.doUpdate(selectCriteria, criteria, con);
466 }
467 }
468
469 /***
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 be
474 * rethrown wrapped into a TorqueException.
475 */
476 public static void doDelete(Criteria criteria) throws TorqueException
477 {
478 BaseEmailInboxPeer
479 .doDelete(criteria, (Connection) null);
480 }
481
482 /***
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 of
485 * the connection details internally.
486 *
487 * @param criteria object containing data that is used DELETE from database.
488 * @param con the connection to use
489 * @throws TorqueException Any exceptions caught during processing will be
490 * rethrown wrapped into a TorqueException.
491 */
492 public static void doDelete(Criteria criteria, Connection con)
493 throws TorqueException
494 {
495
496
497
498
499 if (criteria.getDbName() == Torque.getDefaultDB())
500 {
501 criteria.setDbName(DATABASE_NAME);
502 }
503 if (con == null)
504 {
505 BasePeer.doDelete(criteria);
506 }
507 else
508 {
509 BasePeer.doDelete(criteria, con);
510 }
511 }
512
513 /***
514 * Method to do selects
515 *
516 * @throws TorqueException Any exceptions caught during processing will be
517 * rethrown wrapped into a TorqueException.
518 */
519 public static List doSelect(EmailInbox obj) throws TorqueException
520 {
521 return doSelect(buildCriteria(obj));
522 }
523
524 /***
525 * Method to do inserts
526 *
527 * @throws TorqueException Any exceptions caught during processing will be
528 * rethrown wrapped into a TorqueException.
529 */
530 public static void doInsert(EmailInbox obj) throws TorqueException
531 {
532 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
533 obj.setNew(false);
534 obj.setModified(false);
535 }
536
537 /***
538 * @param obj the data object to update in the database.
539 * @throws TorqueException Any exceptions caught during processing will be
540 * rethrown wrapped into a TorqueException.
541 */
542 public static void doUpdate(EmailInbox obj) throws TorqueException
543 {
544 doUpdate(buildCriteria(obj));
545 obj.setModified(false);
546 }
547
548 /***
549 * @param obj the data object to delete in the database.
550 * @throws TorqueException Any exceptions caught during processing will be
551 * rethrown wrapped into a TorqueException.
552 */
553 public static void doDelete(EmailInbox obj) throws TorqueException
554 {
555 doDelete(buildCriteria(obj));
556 }
557
558 /***
559 * Method to do inserts. This method is to be used during a transaction,
560 * otherwise use the doInsert(EmailInbox) method. It will take
561 * care of the connection details internally.
562 *
563 * @param obj the data object to insert into the database.
564 * @param con the connection to use
565 * @throws TorqueException Any exceptions caught during processing will be
566 * rethrown wrapped into a TorqueException.
567 */
568 public static void 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 }
575
576 /***
577 * Method to do update. This method is to be used during a transaction,
578 * otherwise use the doUpdate(EmailInbox) method. It will take
579 * care of the connection details internally.
580 *
581 * @param obj the data object to update in the database.
582 * @param con the connection to use
583 * @throws TorqueException Any exceptions caught during processing will be
584 * rethrown wrapped into a TorqueException.
585 */
586 public static void doUpdate(EmailInbox obj, Connection con)
587 throws TorqueException
588 {
589 doUpdate(buildCriteria(obj), con);
590 obj.setModified(false);
591 }
592
593 /***
594 * Method to delete. This method is to be used during a transaction,
595 * otherwise use the doDelete(EmailInbox) method. It will take
596 * care of the connection details internally.
597 *
598 * @param obj the data object to delete in the database.
599 * @param con the connection to use
600 * @throws TorqueException Any exceptions caught during processing will be
601 * rethrown wrapped into a TorqueException.
602 */
603 public static void doDelete(EmailInbox obj, Connection con)
604 throws TorqueException
605 {
606 doDelete(buildCriteria(obj), con);
607 }
608
609 /***
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 be
614 * rethrown wrapped into a TorqueException.
615 */
616 public static void doDelete(ObjectKey pk) throws TorqueException
617 {
618 BaseEmailInboxPeer
619 .doDelete(pk, (Connection) null);
620 }
621
622 /***
623 * Method to delete. This method is to be used during a transaction,
624 * otherwise use the doDelete(ObjectKey) method. It will take
625 * 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 use
629 * @throws TorqueException Any exceptions caught during processing will be
630 * rethrown wrapped into a TorqueException.
631 */
632 public static void doDelete(ObjectKey pk, Connection con)
633 throws TorqueException
634 {
635 doDelete(buildCriteria(pk), con);
636 }
637
638 /*** Build a Criteria object from an ObjectKey */
639 public static Criteria buildCriteria( ObjectKey pk )
640 {
641 Criteria criteria = new Criteria();
642 criteria.add(EMAIL_INBOX_ID, pk);
643 return criteria;
644 }
645
646 /*** Build a Criteria object from the data object for this peer */
647 public static Criteria buildCriteria( EmailInbox obj )
648 {
649 Criteria criteria = new Criteria(DATABASE_NAME);
650 if (!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());
656 return criteria;
657 }
658
659
660 /***
661 * Retrieve a single object by pk
662 *
663 * @param pk the primary key
664 * @throws TorqueException Any exceptions caught during processing will be
665 * 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 */
669 public static EmailInbox retrieveByPK(int pk)
670 throws TorqueException, NoRowsException, TooManyRowsException
671 {
672 return retrieveByPK(SimpleKey.keyFor(pk));
673 }
674
675 /***
676 * Retrieve a single object by pk
677 *
678 * @param pk the primary key
679 * @throws TorqueException Any exceptions caught during processing will be
680 * 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 */
684 public static EmailInbox retrieveByPK(ObjectKey pk)
685 throws TorqueException, NoRowsException, TooManyRowsException
686 {
687 Connection db = null;
688 EmailInbox retVal = null;
689 try
690 {
691 db = Torque.getConnection(DATABASE_NAME);
692 retVal = retrieveByPK(pk, db);
693 }
694 finally
695 {
696 Torque.closeConnection(db);
697 }
698 return(retVal);
699 }
700
701 /***
702 * Retrieve a single object by pk
703 *
704 * @param pk the primary key
705 * @param con the connection to use
706 * @throws TorqueException Any exceptions caught during processing will be
707 * 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 */
711 public static EmailInbox retrieveByPK(ObjectKey pk, Connection con)
712 throws TorqueException, NoRowsException, TooManyRowsException
713 {
714 Criteria criteria = buildCriteria(pk);
715 List v = doSelect(criteria, con);
716 if (v.size() == 0)
717 {
718 throw new NoRowsException("Failed to select a row.");
719 }
720 else if (v.size() > 1)
721 {
722 throw new TooManyRowsException("Failed to select only one row.");
723 }
724 else
725 {
726 return (EmailInbox)v.get(0);
727 }
728 }
729
730 /***
731 * Retrieve a multiple objects by pk
732 *
733 * @param pks List of primary keys
734 * @throws TorqueException Any exceptions caught during processing will be
735 * rethrown wrapped into a TorqueException.
736 */
737 public static List retrieveByPKs(List pks)
738 throws TorqueException
739 {
740 Connection db = null;
741 List retVal = null;
742 try
743 {
744 db = Torque.getConnection(DATABASE_NAME);
745 retVal = retrieveByPKs(pks, db);
746 }
747 finally
748 {
749 Torque.closeConnection(db);
750 }
751 return(retVal);
752 }
753
754 /***
755 * Retrieve a multiple objects by pk
756 *
757 * @param pks List of primary keys
758 * @param dbcon the connection to use
759 * @throws TorqueException Any exceptions caught during processing will be
760 * rethrown wrapped into a TorqueException.
761 */
762 public static List retrieveByPKs( List pks, Connection dbcon )
763 throws TorqueException
764 {
765 List objs = null;
766 if (pks == null || pks.size() == 0)
767 {
768 objs = new LinkedList();
769 }
770 else
771 {
772 Criteria criteria = new Criteria();
773 criteria.addIn( EMAIL_INBOX_ID, pks );
774 objs = doSelect(criteria, dbcon);
775 }
776 return objs;
777 }
778
779
780
781
782
783
784
785
786
787
788 /***
789 * Returns the TableMap related to this peer. This method is not
790 * needed for general use but a specific application could have a need.
791 *
792 * @throws TorqueException Any exceptions caught during processing will be
793 * rethrown wrapped into a TorqueException.
794 */
795 protected static TableMap getTableMap()
796 throws TorqueException
797 {
798 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
799 }
800 }