View Javadoc

1   package org.apache.james.mailboxmanager.torque.om;
2   
3   import org.apache.james.mailboxmanager.torque.om.map.MessageFlagsMapBuilder;
4   import org.apache.torque.NoRowsException;
5   import org.apache.torque.TooManyRowsException;
6   import org.apache.torque.Torque;
7   import org.apache.torque.TorqueException;
8   import org.apache.torque.map.MapBuilder;
9   import org.apache.torque.map.TableMap;
10  import org.apache.torque.om.ObjectKey;
11  import org.apache.torque.om.SimpleKey;
12  import org.apache.torque.util.BasePeer;
13  import org.apache.torque.util.Criteria;
14  
15  import com.workingdogs.village.DataSetException;
16  import com.workingdogs.village.QueryDataSet;
17  import com.workingdogs.village.Record;
18  
19  import java.sql.Connection;
20  import java.sql.SQLException;
21  import java.util.ArrayList;
22  import java.util.Iterator;
23  import java.util.LinkedList;
24  import java.util.List;
25  
26  /**
27   * This class was autogenerated by Torque on:
28   * 
29   * [Sun Dec 09 17:45:09 GMT 2007]
30   * 
31   */
32  public abstract class BaseMessageFlagsPeer extends BasePeer {
33      /** Serial version */
34      private static final long serialVersionUID = 1197222309712L;
35  
36      /** the default database name for this class */
37      public static final String DATABASE_NAME;
38  
39      /** the table name for this class */
40      public static final String TABLE_NAME;
41  
42      /**
43       * @return the map builder for this peer
44       * @throws TorqueException
45       *             Any exceptions caught during processing will be rethrown
46       *             wrapped into a TorqueException.
47       * @deprecated Torque.getMapBuilder(MessageFlagsMapBuilder.CLASS_NAME)
48       *             instead
49       */
50      public static MapBuilder getMapBuilder() throws TorqueException {
51          return Torque.getMapBuilder(MessageFlagsMapBuilder.CLASS_NAME);
52      }
53  
54      /** the column name for the mailbox_id field */
55      public static final String MAILBOX_ID;
56  
57      /** the column name for the uid field */
58      public static final String UID;
59  
60      /** the column name for the answered field */
61      public static final String ANSWERED;
62  
63      /** the column name for the deleted field */
64      public static final String DELETED;
65  
66      /** the column name for the draft field */
67      public static final String DRAFT;
68  
69      /** the column name for the flagged field */
70      public static final String FLAGGED;
71  
72      /** the column name for the recent field */
73      public static final String RECENT;
74  
75      /** the column name for the seen field */
76      public static final String SEEN;
77  
78      static {
79          DATABASE_NAME = "mailboxmanager";
80          TABLE_NAME = "message_flags";
81  
82          MAILBOX_ID = "message_flags.mailbox_id";
83          UID = "message_flags.uid";
84          ANSWERED = "message_flags.answered";
85          DELETED = "message_flags.deleted";
86          DRAFT = "message_flags.draft";
87          FLAGGED = "message_flags.flagged";
88          RECENT = "message_flags.recent";
89          SEEN = "message_flags.seen";
90          if (Torque.isInit()) {
91              try {
92                  Torque.getMapBuilder(MessageFlagsMapBuilder.CLASS_NAME);
93              } catch (TorqueException e) {
94                  log.error("Could not initialize Peer", e);
95                  throw new RuntimeException(e);
96              }
97          } else {
98              Torque.registerMapBuilder(MessageFlagsMapBuilder.CLASS_NAME);
99          }
100     }
101 
102     /** number of columns for this peer */
103     public static final int numColumns = 8;
104 
105     /** A class that can be returned by this peer. */
106     protected static final String CLASSNAME_DEFAULT = "org.apache.james.mailboxmanager.torque.om.MessageFlags";
107 
108     /** A class that can be returned by this peer. */
109     protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
110 
111     /**
112      * Class object initialization method.
113      * 
114      * @param className
115      *            name of the class to initialize
116      * @return the initialized class
117      */
118     private static Class initClass(String className) {
119         Class c = null;
120         try {
121             c = Class.forName(className);
122         } catch (Throwable t) {
123             log
124                     .error(
125                             "A FATAL ERROR has occurred which should not "
126                                     + "have happened under any circumstance.  Please notify "
127                                     + "the Torque developers <torque-dev@db.apache.org> "
128                                     + "and give as many details as possible (including the error "
129                                     + "stack trace).", t);
130 
131             // Error objects should always be propogated.
132             if (t instanceof Error) {
133                 throw (Error) t.fillInStackTrace();
134             }
135         }
136         return c;
137     }
138 
139     /**
140      * Get the list of objects for a ResultSet. Please not that your resultset
141      * MUST return columns in the right order. You can use getFieldNames() in
142      * BaseObject to get the correct sequence.
143      * 
144      * @param results
145      *            the ResultSet
146      * @return the list of objects
147      * @throws TorqueException
148      *             Any exceptions caught during processing will be rethrown
149      *             wrapped into a TorqueException.
150      */
151     public static List resultSet2Objects(java.sql.ResultSet results)
152             throws TorqueException {
153         try {
154             QueryDataSet qds = null;
155             List rows = null;
156             try {
157                 qds = new QueryDataSet(results);
158                 rows = getSelectResults(qds);
159             } finally {
160                 if (qds != null) {
161                     qds.close();
162                 }
163             }
164 
165             return populateObjects(rows);
166         } catch (SQLException e) {
167             throw new TorqueException(e);
168         } catch (DataSetException e) {
169             throw new TorqueException(e);
170         }
171     }
172 
173     /**
174      * Method to do inserts.
175      * 
176      * @param criteria
177      *            object used to create the INSERT statement.
178      * @throws TorqueException
179      *             Any exceptions caught during processing will be rethrown
180      *             wrapped into a TorqueException.
181      */
182     public static ObjectKey doInsert(Criteria criteria) throws TorqueException {
183         return BaseMessageFlagsPeer.doInsert(criteria, (Connection) null);
184     }
185 
186     /**
187      * Method to do inserts. This method is to be used during a transaction,
188      * otherwise use the doInsert(Criteria) method. It will take care of the
189      * connection details internally.
190      * 
191      * @param criteria
192      *            object used to create the INSERT statement.
193      * @param con
194      *            the connection to use
195      * @throws TorqueException
196      *             Any exceptions caught during processing will be rethrown
197      *             wrapped into a TorqueException.
198      */
199     public static ObjectKey doInsert(Criteria criteria, Connection con)
200             throws TorqueException {
201         correctBooleans(criteria);
202 
203         setDbName(criteria);
204 
205         if (con == null) {
206             return BasePeer.doInsert(criteria);
207         } else {
208             return BasePeer.doInsert(criteria, con);
209         }
210     }
211 
212     /**
213      * Add all the columns needed to create a new object.
214      * 
215      * @param criteria
216      *            object containing the columns to add.
217      * @throws TorqueException
218      *             Any exceptions caught during processing will be rethrown
219      *             wrapped into a TorqueException.
220      */
221     public static void addSelectColumns(Criteria criteria)
222             throws TorqueException {
223         criteria.addSelectColumn(MAILBOX_ID);
224         criteria.addSelectColumn(UID);
225         criteria.addSelectColumn(ANSWERED);
226         criteria.addSelectColumn(DELETED);
227         criteria.addSelectColumn(DRAFT);
228         criteria.addSelectColumn(FLAGGED);
229         criteria.addSelectColumn(RECENT);
230         criteria.addSelectColumn(SEEN);
231     }
232 
233     /**
234      * changes the boolean values in the criteria to the appropriate type,
235      * whenever a booleanchar or booleanint column is involved. This enables the
236      * user to create criteria using Boolean values for booleanchar or
237      * booleanint columns
238      * 
239      * @param criteria
240      *            the criteria in which the boolean values should be corrected
241      * @throws TorqueException
242      *             if the database map for the criteria cannot be obtained.
243      */
244     public static void correctBooleans(Criteria criteria)
245             throws TorqueException {
246         correctBooleans(criteria, getTableMap());
247     }
248 
249     /**
250      * Create a new object of type cls from a resultset row starting from a
251      * specified offset. This is done so that you can select other rows than
252      * just those needed for this object. You may for example want to create two
253      * objects from the same row.
254      * 
255      * @throws TorqueException
256      *             Any exceptions caught during processing will be rethrown
257      *             wrapped into a TorqueException.
258      */
259     public static MessageFlags row2Object(Record row, int offset, Class cls)
260             throws TorqueException {
261         try {
262             MessageFlags obj = (MessageFlags) cls.newInstance();
263             MessageFlagsPeer.populateObject(row, offset, obj);
264             obj.setModified(false);
265             obj.setNew(false);
266 
267             return obj;
268         } catch (InstantiationException e) {
269             throw new TorqueException(e);
270         } catch (IllegalAccessException e) {
271             throw new TorqueException(e);
272         }
273     }
274 
275     /**
276      * Populates an object from a resultset row starting from a specified
277      * offset. This is done so that you can select other rows than just those
278      * needed for this object. You may for example want to create two objects
279      * from the same row.
280      * 
281      * @throws TorqueException
282      *             Any exceptions caught during processing will be rethrown
283      *             wrapped into a TorqueException.
284      */
285     public static void populateObject(Record row, int offset, MessageFlags obj)
286             throws TorqueException {
287         try {
288             obj.setMailboxId(row.getValue(offset + 0).asLong());
289             obj.setUid(row.getValue(offset + 1).asLong());
290             obj.setAnswered(row.getValue(offset + 2).asBoolean());
291             obj.setDeleted(row.getValue(offset + 3).asBoolean());
292             obj.setDraft(row.getValue(offset + 4).asBoolean());
293             obj.setFlagged(row.getValue(offset + 5).asBoolean());
294             obj.setRecent(row.getValue(offset + 6).asBoolean());
295             obj.setSeen(row.getValue(offset + 7).asBoolean());
296         } catch (DataSetException e) {
297             throw new TorqueException(e);
298         }
299     }
300 
301     /**
302      * Method to do selects.
303      * 
304      * @param criteria
305      *            object used to create the SELECT statement.
306      * @return List of selected Objects
307      * @throws TorqueException
308      *             Any exceptions caught during processing will be rethrown
309      *             wrapped into a TorqueException.
310      */
311     public static List doSelect(Criteria criteria) throws TorqueException {
312         return populateObjects(doSelectVillageRecords(criteria));
313     }
314 
315     /**
316      * Method to do selects within a transaction.
317      * 
318      * @param criteria
319      *            object used to create the SELECT statement.
320      * @param con
321      *            the connection to use
322      * @return List of selected Objects
323      * @throws TorqueException
324      *             Any exceptions caught during processing will be rethrown
325      *             wrapped into a TorqueException.
326      */
327     public static List doSelect(Criteria criteria, Connection con)
328             throws TorqueException {
329         return populateObjects(doSelectVillageRecords(criteria, con));
330     }
331 
332     /**
333      * Grabs the raw Village records to be formed into objects. This method
334      * handles connections internally. The Record objects returned by this
335      * method should be considered readonly. Do not alter the data and call
336      * save(), your results may vary, but are certainly likely to result in hard
337      * to track MT bugs.
338      * 
339      * @throws TorqueException
340      *             Any exceptions caught during processing will be rethrown
341      *             wrapped into a TorqueException.
342      */
343     public static List doSelectVillageRecords(Criteria criteria)
344             throws TorqueException {
345         return BaseMessageFlagsPeer.doSelectVillageRecords(criteria,
346                 (Connection) null);
347     }
348 
349     /**
350      * Grabs the raw Village records to be formed into objects. This method
351      * should be used for transactions
352      * 
353      * @param criteria
354      *            object used to create the SELECT statement.
355      * @param con
356      *            the connection to use
357      * @throws TorqueException
358      *             Any exceptions caught during processing will be rethrown
359      *             wrapped into a TorqueException.
360      */
361     public static List doSelectVillageRecords(Criteria criteria, Connection con)
362             throws TorqueException {
363         if (criteria.getSelectColumns().size() == 0) {
364             addSelectColumns(criteria);
365         }
366         correctBooleans(criteria);
367 
368         setDbName(criteria);
369 
370         // BasePeer returns a List of Value (Village) arrays. The array
371         // order follows the order columns were placed in the Select clause.
372         if (con == null) {
373             return BasePeer.doSelect(criteria);
374         } else {
375             return BasePeer.doSelect(criteria, con);
376         }
377     }
378 
379     /**
380      * The returned List will contain objects of the default type or objects
381      * that inherit from the default.
382      * 
383      * @throws TorqueException
384      *             Any exceptions caught during processing will be rethrown
385      *             wrapped into a TorqueException.
386      */
387     public static List populateObjects(List records) throws TorqueException {
388         List results = new ArrayList(records.size());
389 
390         // populate the object(s)
391         for (int i = 0; i < records.size(); i++) {
392             Record row = (Record) records.get(i);
393             results.add(MessageFlagsPeer.row2Object(row, 1, MessageFlagsPeer
394                     .getOMClass()));
395         }
396         return results;
397     }
398 
399     /**
400      * The class that the Peer will make instances of. If the BO is abstract
401      * then you must implement this method in the BO.
402      * 
403      * @throws TorqueException
404      *             Any exceptions caught during processing will be rethrown
405      *             wrapped into a TorqueException.
406      */
407     public static Class getOMClass() throws TorqueException {
408         return CLASS_DEFAULT;
409     }
410 
411     /**
412      * Method to do updates.
413      * 
414      * @param criteria
415      *            object containing data that is used to create the UPDATE
416      *            statement.
417      * @throws TorqueException
418      *             Any exceptions caught during processing will be rethrown
419      *             wrapped into a TorqueException.
420      */
421     public static void doUpdate(Criteria criteria) throws TorqueException {
422         BaseMessageFlagsPeer.doUpdate(criteria, (Connection) null);
423     }
424 
425     /**
426      * Method to do updates. This method is to be used during a transaction,
427      * otherwise use the doUpdate(Criteria) method. It will take care of the
428      * connection details internally.
429      * 
430      * @param criteria
431      *            object containing data that is used to create the UPDATE
432      *            statement.
433      * @param con
434      *            the connection to use
435      * @throws TorqueException
436      *             Any exceptions caught during processing will be rethrown
437      *             wrapped into a TorqueException.
438      */
439     public static void doUpdate(Criteria criteria, Connection con)
440             throws TorqueException {
441         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
442         correctBooleans(criteria);
443 
444         selectCriteria.put(MAILBOX_ID, criteria.remove(MAILBOX_ID));
445 
446         selectCriteria.put(UID, criteria.remove(UID));
447 
448         setDbName(criteria);
449 
450         if (con == null) {
451             BasePeer.doUpdate(selectCriteria, criteria);
452         } else {
453             BasePeer.doUpdate(selectCriteria, criteria, con);
454         }
455     }
456 
457     /**
458      * Method to do deletes.
459      * 
460      * @param criteria
461      *            object containing data that is used DELETE from database.
462      * @throws TorqueException
463      *             Any exceptions caught during processing will be rethrown
464      *             wrapped into a TorqueException.
465      */
466     public static void doDelete(Criteria criteria) throws TorqueException {
467         MessageFlagsPeer.doDelete(criteria, (Connection) null);
468     }
469 
470     /**
471      * Method to do deletes. This method is to be used during a transaction,
472      * otherwise use the doDelete(Criteria) method. It will take care of the
473      * connection details internally.
474      * 
475      * @param criteria
476      *            object containing data that is used DELETE from database.
477      * @param con
478      *            the connection to use
479      * @throws TorqueException
480      *             Any exceptions caught during processing will be rethrown
481      *             wrapped into a TorqueException.
482      */
483     public static void doDelete(Criteria criteria, Connection con)
484             throws TorqueException {
485         correctBooleans(criteria);
486 
487         setDbName(criteria);
488 
489         if (con == null) {
490             BasePeer.doDelete(criteria);
491         } else {
492             BasePeer.doDelete(criteria, con);
493         }
494     }
495 
496     /**
497      * Method to do selects
498      * 
499      * @throws TorqueException
500      *             Any exceptions caught during processing will be rethrown
501      *             wrapped into a TorqueException.
502      */
503     public static List doSelect(MessageFlags obj) throws TorqueException {
504         return doSelect(buildSelectCriteria(obj));
505     }
506 
507     /**
508      * Method to do inserts
509      * 
510      * @throws TorqueException
511      *             Any exceptions caught during processing will be rethrown
512      *             wrapped into a TorqueException.
513      */
514     public static void doInsert(MessageFlags obj) throws TorqueException {
515         doInsert(buildCriteria(obj));
516         obj.setNew(false);
517         obj.setModified(false);
518     }
519 
520     /**
521      * @param obj
522      *            the data object to update in the database.
523      * @throws TorqueException
524      *             Any exceptions caught during processing will be rethrown
525      *             wrapped into a TorqueException.
526      */
527     public static void doUpdate(MessageFlags obj) throws TorqueException {
528         doUpdate(buildCriteria(obj));
529         obj.setModified(false);
530     }
531 
532     /**
533      * @param obj
534      *            the data object to delete in the database.
535      * @throws TorqueException
536      *             Any exceptions caught during processing will be rethrown
537      *             wrapped into a TorqueException.
538      */
539     public static void doDelete(MessageFlags obj) throws TorqueException {
540         doDelete(buildSelectCriteria(obj));
541     }
542 
543     /**
544      * Method to do inserts. This method is to be used during a transaction,
545      * otherwise use the doInsert(MessageFlags) method. It will take care of the
546      * connection details internally.
547      * 
548      * @param obj
549      *            the data object to insert into the database.
550      * @param con
551      *            the connection to use
552      * @throws TorqueException
553      *             Any exceptions caught during processing will be rethrown
554      *             wrapped into a TorqueException.
555      */
556     public static void doInsert(MessageFlags obj, Connection con)
557             throws TorqueException {
558         doInsert(buildCriteria(obj), con);
559         obj.setNew(false);
560         obj.setModified(false);
561     }
562 
563     /**
564      * Method to do update. This method is to be used during a transaction,
565      * otherwise use the doUpdate(MessageFlags) method. It will take care of the
566      * connection details internally.
567      * 
568      * @param obj
569      *            the data object to update in the database.
570      * @param con
571      *            the connection to use
572      * @throws TorqueException
573      *             Any exceptions caught during processing will be rethrown
574      *             wrapped into a TorqueException.
575      */
576     public static void doUpdate(MessageFlags obj, Connection con)
577             throws TorqueException {
578         doUpdate(buildCriteria(obj), con);
579         obj.setModified(false);
580     }
581 
582     /**
583      * Method to delete. This method is to be used during a transaction,
584      * otherwise use the doDelete(MessageFlags) method. It will take care of the
585      * connection details internally.
586      * 
587      * @param obj
588      *            the data object to delete in the database.
589      * @param con
590      *            the connection to use
591      * @throws TorqueException
592      *             Any exceptions caught during processing will be rethrown
593      *             wrapped into a TorqueException.
594      */
595     public static void doDelete(MessageFlags obj, Connection con)
596             throws TorqueException {
597         doDelete(buildSelectCriteria(obj), con);
598     }
599 
600     /**
601      * Method to do deletes.
602      * 
603      * @param pk
604      *            ObjectKey that is used DELETE from database.
605      * @throws TorqueException
606      *             Any exceptions caught during processing will be rethrown
607      *             wrapped into a TorqueException.
608      */
609     public static void doDelete(ObjectKey pk) throws TorqueException {
610         BaseMessageFlagsPeer.doDelete(pk, (Connection) null);
611     }
612 
613     /**
614      * Method to delete. This method is to be used during a transaction,
615      * otherwise use the doDelete(ObjectKey) method. It will take care of the
616      * connection details internally.
617      * 
618      * @param pk
619      *            the primary key for the object to delete in the database.
620      * @param con
621      *            the connection to use
622      * @throws TorqueException
623      *             Any exceptions caught during processing will be rethrown
624      *             wrapped into a TorqueException.
625      */
626     public static void doDelete(ObjectKey pk, Connection con)
627             throws TorqueException {
628         doDelete(buildCriteria(pk), con);
629     }
630 
631     /** Build a Criteria object from an ObjectKey */
632     public static Criteria buildCriteria(ObjectKey pk) {
633         Criteria criteria = new Criteria();
634         SimpleKey[] keys = (SimpleKey[]) pk.getValue();
635         criteria.add(MAILBOX_ID, keys[0]);
636         criteria.add(UID, keys[1]);
637         return criteria;
638     }
639 
640     /** Build a Criteria object from the data object for this peer */
641     public static Criteria buildCriteria(MessageFlags obj) {
642         Criteria criteria = new Criteria(DATABASE_NAME);
643         criteria.add(MAILBOX_ID, obj.getMailboxId());
644         criteria.add(UID, obj.getUid());
645         criteria.add(ANSWERED, obj.getAnswered());
646         criteria.add(DELETED, obj.getDeleted());
647         criteria.add(DRAFT, obj.getDraft());
648         criteria.add(FLAGGED, obj.getFlagged());
649         criteria.add(RECENT, obj.getRecent());
650         criteria.add(SEEN, obj.getSeen());
651         return criteria;
652     }
653 
654     /**
655      * Build a Criteria object from the data object for this peer, skipping all
656      * binary columns
657      */
658     public static Criteria buildSelectCriteria(MessageFlags obj) {
659         Criteria criteria = new Criteria(DATABASE_NAME);
660         criteria.add(MAILBOX_ID, obj.getMailboxId());
661         criteria.add(UID, obj.getUid());
662         criteria.add(ANSWERED, obj.getAnswered());
663         criteria.add(DELETED, obj.getDeleted());
664         criteria.add(DRAFT, obj.getDraft());
665         criteria.add(FLAGGED, obj.getFlagged());
666         criteria.add(RECENT, obj.getRecent());
667         criteria.add(SEEN, obj.getSeen());
668         return criteria;
669     }
670 
671     /**
672      * Retrieve a single object by pk
673      * 
674      * @param pk
675      *            the primary key
676      * @throws TorqueException
677      *             Any exceptions caught during processing will be rethrown
678      *             wrapped into a TorqueException.
679      * @throws NoRowsException
680      *             Primary key was not found in database.
681      * @throws TooManyRowsException
682      *             Primary key was not found in database.
683      */
684     public static MessageFlags retrieveByPK(ObjectKey pk)
685             throws TorqueException, NoRowsException, TooManyRowsException {
686         Connection db = null;
687         MessageFlags retVal = null;
688         try {
689             db = Torque.getConnection(DATABASE_NAME);
690             retVal = retrieveByPK(pk, db);
691         } finally {
692             Torque.closeConnection(db);
693         }
694         return retVal;
695     }
696 
697     /**
698      * Retrieve a single object by pk
699      * 
700      * @param pk
701      *            the primary key
702      * @param con
703      *            the connection to use
704      * @throws TorqueException
705      *             Any exceptions caught during processing will be rethrown
706      *             wrapped into a TorqueException.
707      * @throws NoRowsException
708      *             Primary key was not found in database.
709      * @throws TooManyRowsException
710      *             Primary key was not found in database.
711      */
712     public static MessageFlags retrieveByPK(ObjectKey pk, Connection con)
713             throws TorqueException, NoRowsException, TooManyRowsException {
714         Criteria criteria = buildCriteria(pk);
715         List v = doSelect(criteria, con);
716         if (v.size() == 0) {
717             throw new NoRowsException("Failed to select a row.");
718         } else if (v.size() > 1) {
719             throw new TooManyRowsException("Failed to select only one row.");
720         } else {
721             return (MessageFlags) v.get(0);
722         }
723     }
724 
725     /**
726      * Retrieve a multiple objects by pk
727      * 
728      * @param pks
729      *            List of primary keys
730      * @throws TorqueException
731      *             Any exceptions caught during processing will be rethrown
732      *             wrapped into a TorqueException.
733      */
734     public static List retrieveByPKs(List pks) throws TorqueException {
735         Connection db = null;
736         List retVal = null;
737         try {
738             db = Torque.getConnection(DATABASE_NAME);
739             retVal = retrieveByPKs(pks, db);
740         } finally {
741             Torque.closeConnection(db);
742         }
743         return retVal;
744     }
745 
746     /**
747      * Retrieve a multiple objects by pk
748      * 
749      * @param pks
750      *            List of primary keys
751      * @param dbcon
752      *            the connection to use
753      * @throws TorqueException
754      *             Any exceptions caught during processing will be rethrown
755      *             wrapped into a TorqueException.
756      */
757     public static List retrieveByPKs(List pks, Connection dbcon)
758             throws TorqueException {
759         List objs = null;
760         if (pks == null || pks.size() == 0) {
761             objs = new LinkedList();
762         } else {
763             Criteria criteria = new Criteria();
764             Iterator iter = pks.iterator();
765             while (iter.hasNext()) {
766                 ObjectKey pk = (ObjectKey) iter.next();
767                 SimpleKey[] keys = (SimpleKey[]) pk.getValue();
768                 Criteria.Criterion c0 = criteria.getNewCriterion(MAILBOX_ID,
769                         keys[0], Criteria.EQUAL);
770                 Criteria.Criterion c1 = criteria.getNewCriterion(UID, keys[1],
771                         Criteria.EQUAL);
772                 c0.and(c1);
773                 criteria.or(c0);
774             }
775             objs = doSelect(criteria, dbcon);
776         }
777         return objs;
778     }
779 
780     /**
781      * retrieve object using using pk values.
782      * 
783      * @param mailboxId
784      *            long
785      * @param uid
786      *            long
787      */
788     public static MessageFlags retrieveByPK(long mailboxId, long uid)
789             throws TorqueException {
790         Connection db = null;
791         MessageFlags retVal = null;
792         try {
793             db = Torque.getConnection(DATABASE_NAME);
794             retVal = retrieveByPK(mailboxId, uid, db);
795         } finally {
796             Torque.closeConnection(db);
797         }
798         return retVal;
799     }
800 
801     /**
802      * retrieve object using using pk values.
803      * 
804      * @param mailboxId
805      *            long
806      * @param uid
807      *            long
808      * @param con
809      *            Connection
810      */
811     public static MessageFlags retrieveByPK(long mailboxId, long uid,
812             Connection con) throws TorqueException {
813 
814         Criteria criteria = new Criteria(5);
815         criteria.add(MAILBOX_ID, mailboxId);
816         criteria.add(UID, uid);
817         List v = doSelect(criteria, con);
818         if (v.size() == 1) {
819             return (MessageFlags) v.get(0);
820         } else {
821             throw new TorqueException("Failed to select one and only one row.");
822         }
823     }
824 
825     /**
826      * selects a collection of MessageFlags objects pre-filled with their
827      * MessageRow objects.
828      * 
829      * This method is protected by default in order to keep the public api
830      * reasonable. You can provide public methods for those you actually need in
831      * MessageFlagsPeer.
832      * 
833      * @throws TorqueException
834      *             Any exceptions caught during processing will be rethrown
835      *             wrapped into a TorqueException.
836      */
837     protected static List doSelectJoinMessageRow(Criteria criteria)
838             throws TorqueException {
839         return doSelectJoinMessageRow(criteria, null);
840     }
841 
842     /**
843      * selects a collection of MessageFlags objects pre-filled with their
844      * MessageRow objects.
845      * 
846      * This method is protected by default in order to keep the public api
847      * reasonable. You can provide public methods for those you actually need in
848      * MessageFlagsPeer.
849      * 
850      * @throws TorqueException
851      *             Any exceptions caught during processing will be rethrown
852      *             wrapped into a TorqueException.
853      */
854     protected static List doSelectJoinMessageRow(Criteria criteria,
855             Connection conn) throws TorqueException {
856         setDbName(criteria);
857 
858         MessageFlagsPeer.addSelectColumns(criteria);
859         int offset = numColumns + 1;
860         MessageRowPeer.addSelectColumns(criteria);
861 
862         criteria
863                 .addJoin(MessageFlagsPeer.MAILBOX_ID, MessageRowPeer.MAILBOX_ID);
864         criteria.addJoin(MessageFlagsPeer.UID, MessageRowPeer.UID);
865 
866         correctBooleans(criteria);
867 
868         List rows;
869         if (conn == null) {
870             rows = BasePeer.doSelect(criteria);
871         } else {
872             rows = BasePeer.doSelect(criteria, conn);
873         }
874 
875         List results = new ArrayList();
876 
877         for (int i = 0; i < rows.size(); i++) {
878             Record row = (Record) rows.get(i);
879 
880             Class omClass = MessageFlagsPeer.getOMClass();
881             MessageFlags obj1 = (MessageFlags) MessageFlagsPeer.row2Object(row,
882                     1, omClass);
883             omClass = MessageRowPeer.getOMClass();
884             MessageRow obj2 = (MessageRow) MessageRowPeer.row2Object(row,
885                     offset, omClass);
886 
887             boolean newObject = true;
888             for (int j = 0; j < results.size(); j++) {
889                 MessageFlags temp_obj1 = (MessageFlags) results.get(j);
890                 MessageRow temp_obj2 = (MessageRow) temp_obj1.getMessageRow();
891                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) {
892                     newObject = false;
893                     temp_obj2.addMessageFlags(obj1);
894                     break;
895                 }
896             }
897             if (newObject) {
898                 obj2.initMessageFlagss();
899                 obj2.addMessageFlags(obj1);
900             }
901             results.add(obj1);
902         }
903         return results;
904     }
905 
906     /**
907      * Returns the TableMap related to this peer.
908      * 
909      * @throws TorqueException
910      *             Any exceptions caught during processing will be rethrown
911      *             wrapped into a TorqueException.
912      */
913     public static TableMap getTableMap() throws TorqueException {
914         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
915     }
916 
917     private static void setDbName(Criteria crit) {
918         // Set the correct dbName if it has not been overridden
919         // crit.getDbName will return the same object if not set to
920         // another value so == check is okay and faster
921         if (crit.getDbName() == Torque.getDefaultDB()) {
922             crit.setDbName(DATABASE_NAME);
923         }
924     }
925 
926 }