KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > om > BaseInboxAttachmentPeer


1 package org.campware.cream.om;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.sql.Connection JavaDoc;
5 import java.sql.SQLException JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.LinkedList JavaDoc;
10 import java.util.List JavaDoc;
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 // Local classes
31
import org.campware.cream.om.map.*;
32
33
34   
35 /**
36  * This class was autogenerated by Torque on:
37  *
38  * [Wed May 04 09:10:56 CEST 2005]
39  *
40  */

41 public abstract class BaseInboxAttachmentPeer
42     extends BasePeer
43 {
44
45     /** the default database name for this class */
46     public static final String JavaDoc DATABASE_NAME = "cream";
47
48      /** the table name for this class */
49     public static final String JavaDoc TABLE_NAME = "INBOX_ATTACHMENT";
50
51     /**
52      * @return the map builder for this peer
53      * @throws TorqueException Any exceptions caught during processing will be
54      * rethrown wrapped into a TorqueException.
55      */

56     public static MapBuilder getMapBuilder()
57         throws TorqueException
58     {
59         return getMapBuilder(InboxAttachmentMapBuilder.CLASS_NAME);
60     }
61
62       /** the column name for the INBOX_ATTACHMENT_ID field */
63     public static final String JavaDoc INBOX_ATTACHMENT_ID;
64       /** the column name for the INBOX_EVENT_ID field */
65     public static final String JavaDoc INBOX_EVENT_ID;
66       /** the column name for the CONTENT_TYPE field */
67     public static final String JavaDoc CONTENT_TYPE;
68       /** the column name for the CONTENT_DISPOSITION field */
69     public static final String JavaDoc CONTENT_DISPOSITION;
70       /** the column name for the CONTENT_ID field */
71     public static final String JavaDoc CONTENT_ID;
72       /** the column name for the FILE_NAME field */
73     public static final String JavaDoc FILE_NAME;
74       /** the column name for the CONTENT field */
75     public static final String JavaDoc CONTENT;
76   
77     static
78     {
79           INBOX_ATTACHMENT_ID = "INBOX_ATTACHMENT.INBOX_ATTACHMENT_ID";
80           INBOX_EVENT_ID = "INBOX_ATTACHMENT.INBOX_EVENT_ID";
81           CONTENT_TYPE = "INBOX_ATTACHMENT.CONTENT_TYPE";
82           CONTENT_DISPOSITION = "INBOX_ATTACHMENT.CONTENT_DISPOSITION";
83           CONTENT_ID = "INBOX_ATTACHMENT.CONTENT_ID";
84           FILE_NAME = "INBOX_ATTACHMENT.FILE_NAME";
85           CONTENT = "INBOX_ATTACHMENT.CONTENT";
86           if (Torque.isInit())
87         {
88             try
89             {
90                 getMapBuilder(InboxAttachmentMapBuilder.CLASS_NAME);
91             }
92             catch (Exception JavaDoc e)
93             {
94                 log.error("Could not initialize Peer", e);
95             }
96         }
97         else
98         {
99             Torque.registerMapBuilder(InboxAttachmentMapBuilder.CLASS_NAME);
100         }
101     }
102  
103     /** number of columns for this peer */
104     public static final int numColumns = 7;
105
106     /** A class that can be returned by this peer. */
107     protected static final String JavaDoc CLASSNAME_DEFAULT =
108         "org.campware.cream.om.InboxAttachment";
109
110     /** A class that can be returned by this peer. */
111     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
112
113     /**
114      * Class object initialization method.
115      *
116      * @param className name of the class to initialize
117      * @return the initialized class
118      */

119     private static Class JavaDoc initClass(String JavaDoc className)
120     {
121         Class JavaDoc c = null;
122         try
123         {
124             c = Class.forName(className);
125         }
126         catch (Throwable JavaDoc t)
127         {
128             log.error("A FATAL ERROR has occurred which should not "
129                 + "have happened under any circumstance. Please notify "
130                 + "the Torque developers <torque-dev@db.apache.org> "
131                 + "and give as many details as possible (including the error "
132                 + "stack trace).", t);
133
134             // Error objects should always be propogated.
135
if (t instanceof Error JavaDoc)
136             {
137                 throw (Error JavaDoc) t.fillInStackTrace();
138             }
139         }
140         return c;
141     }
142
143     /**
144      * Get the list of objects for a ResultSet. Please not that your
145      * resultset MUST return columns in the right order. You can use
146      * getFieldNames() in BaseObject to get the correct sequence.
147      *
148      * @param results the ResultSet
149      * @return the list of objects
150      * @throws TorqueException Any exceptions caught during processing will be
151      * rethrown wrapped into a TorqueException.
152      */

153     public static List JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
154             throws TorqueException
155     {
156         try
157         {
158             QueryDataSet qds = null;
159             List JavaDoc rows = null;
160             try
161             {
162                 qds = new QueryDataSet(results);
163                 rows = getSelectResults(qds);
164             }
165             finally
166             {
167                 if (qds != null)
168                 {
169                     qds.close();
170                 }
171             }
172
173             return populateObjects(rows);
174         }
175         catch (SQLException JavaDoc e)
176         {
177             throw new TorqueException(e);
178         }
179         catch (DataSetException e)
180         {
181             throw new TorqueException(e);
182         }
183     }
184
185
186   
187     /**
188      * Method to do inserts.
189      *
190      * @param criteria object used to create the INSERT statement.
191      * @throws TorqueException Any exceptions caught during processing will be
192      * rethrown wrapped into a TorqueException.
193      */

194     public static ObjectKey doInsert(Criteria criteria)
195         throws TorqueException
196     {
197         return BaseInboxAttachmentPeer
198             .doInsert(criteria, (Connection JavaDoc) null);
199     }
200
201     /**
202      * Method to do inserts. This method is to be used during a transaction,
203      * otherwise use the doInsert(Criteria) method. It will take care of
204      * the connection details internally.
205      *
206      * @param criteria object used to create the INSERT statement.
207      * @param con the connection to use
208      * @throws TorqueException Any exceptions caught during processing will be
209      * rethrown wrapped into a TorqueException.
210      */

211     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
212         throws TorqueException
213     {
214                                             
215         setDbName(criteria);
216
217         if (con == null)
218         {
219             return BasePeer.doInsert(criteria);
220         }
221         else
222         {
223             return BasePeer.doInsert(criteria, con);
224         }
225     }
226
227     /**
228      * Add all the columns needed to create a new object.
229      *
230      * @param criteria object containing the columns to add.
231      * @throws TorqueException Any exceptions caught during processing will be
232      * rethrown wrapped into a TorqueException.
233      */

234     public static void addSelectColumns(Criteria criteria)
235             throws TorqueException
236     {
237           criteria.addSelectColumn(INBOX_ATTACHMENT_ID);
238           criteria.addSelectColumn(INBOX_EVENT_ID);
239           criteria.addSelectColumn(CONTENT_TYPE);
240           criteria.addSelectColumn(CONTENT_DISPOSITION);
241           criteria.addSelectColumn(CONTENT_ID);
242           criteria.addSelectColumn(FILE_NAME);
243           criteria.addSelectColumn(CONTENT);
244       }
245
246     /**
247      * Create a new object of type cls from a resultset row starting
248      * from a specified offset. This is done so that you can select
249      * other rows than just those needed for this object. You may
250      * for example want to create two objects from the same row.
251      *
252      * @throws TorqueException Any exceptions caught during processing will be
253      * rethrown wrapped into a TorqueException.
254      */

255     public static InboxAttachment row2Object(Record row,
256                                              int offset,
257                                              Class JavaDoc cls)
258         throws TorqueException
259     {
260         try
261         {
262             InboxAttachment obj = (InboxAttachment) cls.newInstance();
263             InboxAttachmentPeer.populateObject(row, offset, obj);
264                   obj.setModified(false);
265               obj.setNew(false);
266
267             return obj;
268         }
269         catch (InstantiationException JavaDoc e)
270         {
271             throw new TorqueException(e);
272         }
273         catch (IllegalAccessException JavaDoc e)
274         {
275             throw new TorqueException(e);
276         }
277     }
278
279     /**
280      * Populates an object from a resultset row starting
281      * from a specified offset. This is done so that you can select
282      * other rows than just those needed for this object. You may
283      * for example want to create two objects from the same row.
284      *
285      * @throws TorqueException Any exceptions caught during processing will be
286      * rethrown wrapped into a TorqueException.
287      */

288     public static void populateObject(Record row,
289                                       int offset,
290                                       InboxAttachment obj)
291         throws TorqueException
292     {
293         try
294         {
295                 obj.setInboxAttachmentId(row.getValue(offset + 0).asInt());
296                   obj.setInboxEventId(row.getValue(offset + 1).asInt());
297                   obj.setContentType(row.getValue(offset + 2).asString());
298                   obj.setContentDisposition(row.getValue(offset + 3).asString());
299                   obj.setContentId(row.getValue(offset + 4).asString());
300                   obj.setFileName(row.getValue(offset + 5).asString());
301                   obj.setContent(row.getValue(offset + 6).asString());
302               }
303         catch (DataSetException e)
304         {
305             throw new TorqueException(e);
306         }
307     }
308
309     /**
310      * Method to do selects.
311      *
312      * @param criteria object used to create the SELECT statement.
313      * @return List of selected Objects
314      * @throws TorqueException Any exceptions caught during processing will be
315      * rethrown wrapped into a TorqueException.
316      */

317     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
318     {
319         return populateObjects(doSelectVillageRecords(criteria));
320     }
321
322     /**
323      * Method to do selects within a transaction.
324      *
325      * @param criteria object used to create the SELECT statement.
326      * @param con the connection to use
327      * @return List of selected Objects
328      * @throws TorqueException Any exceptions caught during processing will be
329      * rethrown wrapped into a TorqueException.
330      */

331     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
332         throws TorqueException
333     {
334         return populateObjects(doSelectVillageRecords(criteria, con));
335     }
336
337     /**
338      * Grabs the raw Village records to be formed into objects.
339      * This method handles connections internally. The Record objects
340      * returned by this method should be considered readonly. Do not
341      * alter the data and call save(), your results may vary, but are
342      * certainly likely to result in hard to track MT bugs.
343      *
344      * @throws TorqueException Any exceptions caught during processing will be
345      * rethrown wrapped into a TorqueException.
346      */

347     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
348         throws TorqueException
349     {
350         return BaseInboxAttachmentPeer
351             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
352     }
353
354     /**
355      * Grabs the raw Village records to be formed into objects.
356      * This method should be used for transactions
357      *
358      * @param criteria object used to create the SELECT statement.
359      * @param con the connection to use
360      * @throws TorqueException Any exceptions caught during processing will be
361      * rethrown wrapped into a TorqueException.
362      */

363     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
364         throws TorqueException
365     {
366         if (criteria.getSelectColumns().size() == 0)
367         {
368             addSelectColumns(criteria);
369         }
370
371                                             
372         setDbName(criteria);
373
374         // BasePeer returns a List of Value (Village) arrays. The array
375
// order follows the order columns were placed in the Select clause.
376
if (con == null)
377         {
378             return BasePeer.doSelect(criteria);
379         }
380         else
381         {
382             return BasePeer.doSelect(criteria, con);
383         }
384     }
385
386     /**
387      * The returned List will contain objects of the default type or
388      * objects that inherit from the default.
389      *
390      * @throws TorqueException Any exceptions caught during processing will be
391      * rethrown wrapped into a TorqueException.
392      */

393     public static List JavaDoc populateObjects(List JavaDoc records)
394         throws TorqueException
395     {
396         List JavaDoc results = new ArrayList JavaDoc(records.size());
397
398         // populate the object(s)
399
for (int i = 0; i < records.size(); i++)
400         {
401             Record row = (Record) records.get(i);
402               results.add(InboxAttachmentPeer.row2Object(row, 1,
403                 InboxAttachmentPeer.getOMClass()));
404           }
405         return results;
406     }
407  
408
409     /**
410      * The class that the Peer will make instances of.
411      * If the BO is abstract then you must implement this method
412      * in the BO.
413      *
414      * @throws TorqueException Any exceptions caught during processing will be
415      * rethrown wrapped into a TorqueException.
416      */

417     public static Class JavaDoc getOMClass()
418         throws TorqueException
419     {
420         return CLASS_DEFAULT;
421     }
422
423     /**
424      * Method to do updates.
425      *
426      * @param criteria object containing data that is used to create the UPDATE
427      * statement.
428      * @throws TorqueException Any exceptions caught during processing will be
429      * rethrown wrapped into a TorqueException.
430      */

431     public static void doUpdate(Criteria criteria) throws TorqueException
432     {
433          BaseInboxAttachmentPeer
434             .doUpdate(criteria, (Connection JavaDoc) null);
435     }
436
437     /**
438      * Method to do updates. This method is to be used during a transaction,
439      * otherwise use the doUpdate(Criteria) method. It will take care of
440      * the connection details internally.
441      *
442      * @param criteria object containing data that is used to create the UPDATE
443      * statement.
444      * @param con the connection to use
445      * @throws TorqueException Any exceptions caught during processing will be
446      * rethrown wrapped into a TorqueException.
447      */

448     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
449         throws TorqueException
450     {
451         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
452                    selectCriteria.put(INBOX_ATTACHMENT_ID, criteria.remove(INBOX_ATTACHMENT_ID));
453                                                                   
454         setDbName(criteria);
455
456         if (con == null)
457         {
458             BasePeer.doUpdate(selectCriteria, criteria);
459         }
460         else
461         {
462             BasePeer.doUpdate(selectCriteria, criteria, con);
463         }
464     }
465
466     /**
467      * Method to do deletes.
468      *
469      * @param criteria object containing data that is used DELETE from database.
470      * @throws TorqueException Any exceptions caught during processing will be
471      * rethrown wrapped into a TorqueException.
472      */

473      public static void doDelete(Criteria criteria) throws TorqueException
474      {
475          InboxAttachmentPeer
476             .doDelete(criteria, (Connection JavaDoc) null);
477      }
478
479     /**
480      * Method to do deletes. This method is to be used during a transaction,
481      * otherwise use the doDelete(Criteria) method. It will take care of
482      * the connection details internally.
483      *
484      * @param criteria object containing data that is used DELETE from database.
485      * @param con the connection to use
486      * @throws TorqueException Any exceptions caught during processing will be
487      * rethrown wrapped into a TorqueException.
488      */

489      public static void doDelete(Criteria criteria, Connection JavaDoc con)
490         throws TorqueException
491      {
492                                             
493         setDbName(criteria);
494
495         if (con == null)
496         {
497             BasePeer.doDelete(criteria);
498         }
499         else
500         {
501             BasePeer.doDelete(criteria, con);
502         }
503      }
504
505     /**
506      * Method to do selects
507      *
508      * @throws TorqueException Any exceptions caught during processing will be
509      * rethrown wrapped into a TorqueException.
510      */

511     public static List JavaDoc doSelect(InboxAttachment obj) throws TorqueException
512     {
513         return doSelect(buildSelectCriteria(obj));
514     }
515
516     /**
517      * Method to do inserts
518      *
519      * @throws TorqueException Any exceptions caught during processing will be
520      * rethrown wrapped into a TorqueException.
521      */

522     public static void doInsert(InboxAttachment obj) throws TorqueException
523     {
524           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
525           obj.setNew(false);
526         obj.setModified(false);
527     }
528
529     /**
530      * @param obj the data object to update in the database.
531      * @throws TorqueException Any exceptions caught during processing will be
532      * rethrown wrapped into a TorqueException.
533      */

534     public static void doUpdate(InboxAttachment obj) throws TorqueException
535     {
536         doUpdate(buildCriteria(obj));
537         obj.setModified(false);
538     }
539
540     /**
541      * @param obj the data object to delete in the database.
542      * @throws TorqueException Any exceptions caught during processing will be
543      * rethrown wrapped into a TorqueException.
544      */

545     public static void doDelete(InboxAttachment obj) throws TorqueException
546     {
547         doDelete(buildSelectCriteria(obj));
548     }
549
550     /**
551      * Method to do inserts. This method is to be used during a transaction,
552      * otherwise use the doInsert(InboxAttachment) method. It will take
553      * care of the connection details internally.
554      *
555      * @param obj the data object to insert into the database.
556      * @param con the connection to use
557      * @throws TorqueException Any exceptions caught during processing will be
558      * rethrown wrapped into a TorqueException.
559      */

560     public static void doInsert(InboxAttachment obj, Connection JavaDoc con)
561         throws TorqueException
562     {
563           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
564           obj.setNew(false);
565         obj.setModified(false);
566     }
567
568     /**
569      * Method to do update. This method is to be used during a transaction,
570      * otherwise use the doUpdate(InboxAttachment) method. It will take
571      * care of the connection details internally.
572      *
573      * @param obj the data object to update in the database.
574      * @param con the connection to use
575      * @throws TorqueException Any exceptions caught during processing will be
576      * rethrown wrapped into a TorqueException.
577      */

578     public static void doUpdate(InboxAttachment obj, Connection JavaDoc con)
579         throws TorqueException
580     {
581         doUpdate(buildCriteria(obj), con);
582         obj.setModified(false);
583     }
584
585     /**
586      * Method to delete. This method is to be used during a transaction,
587      * otherwise use the doDelete(InboxAttachment) method. It will take
588      * care of the connection details internally.
589      *
590      * @param obj the data object to delete in the database.
591      * @param con the connection to use
592      * @throws TorqueException Any exceptions caught during processing will be
593      * rethrown wrapped into a TorqueException.
594      */

595     public static void doDelete(InboxAttachment obj, Connection JavaDoc con)
596         throws TorqueException
597     {
598         doDelete(buildSelectCriteria(obj), con);
599     }
600
601     /**
602      * Method to do deletes.
603      *
604      * @param pk ObjectKey that is used DELETE from database.
605      * @throws TorqueException Any exceptions caught during processing will be
606      * rethrown wrapped into a TorqueException.
607      */

608     public static void doDelete(ObjectKey pk) throws TorqueException
609     {
610         BaseInboxAttachmentPeer
611            .doDelete(pk, (Connection JavaDoc) null);
612     }
613
614     /**
615      * Method to delete. This method is to be used during a transaction,
616      * otherwise use the doDelete(ObjectKey) method. It will take
617      * care of the connection details internally.
618      *
619      * @param pk the primary key for the object to delete in the database.
620      * @param con the connection to use
621      * @throws TorqueException Any exceptions caught during processing will be
622      * rethrown wrapped into a TorqueException.
623      */

624     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
625         throws TorqueException
626     {
627         doDelete(buildCriteria(pk), con);
628     }
629
630     /** Build a Criteria object from an ObjectKey */
631     public static Criteria buildCriteria( ObjectKey pk )
632     {
633         Criteria criteria = new Criteria();
634               criteria.add(INBOX_ATTACHMENT_ID, pk);
635           return criteria;
636      }
637
638     /** Build a Criteria object from the data object for this peer */
639     public static Criteria buildCriteria( InboxAttachment obj )
640     {
641         Criteria criteria = new Criteria(DATABASE_NAME);
642               if (!obj.isNew())
643             criteria.add(INBOX_ATTACHMENT_ID, obj.getInboxAttachmentId());
644               criteria.add(INBOX_EVENT_ID, obj.getInboxEventId());
645               criteria.add(CONTENT_TYPE, obj.getContentType());
646               criteria.add(CONTENT_DISPOSITION, obj.getContentDisposition());
647               criteria.add(CONTENT_ID, obj.getContentId());
648               criteria.add(FILE_NAME, obj.getFileName());
649               criteria.add(CONTENT, obj.getContent());
650           return criteria;
651     }
652
653     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
654     public static Criteria buildSelectCriteria( InboxAttachment obj )
655     {
656         Criteria criteria = new Criteria(DATABASE_NAME);
657               if (!obj.isNew())
658                     criteria.add(INBOX_ATTACHMENT_ID, obj.getInboxAttachmentId());
659                           criteria.add(INBOX_EVENT_ID, obj.getInboxEventId());
660                           criteria.add(CONTENT_TYPE, obj.getContentType());
661                           criteria.add(CONTENT_DISPOSITION, obj.getContentDisposition());
662                           criteria.add(CONTENT_ID, obj.getContentId());
663                           criteria.add(FILE_NAME, obj.getFileName());
664                           criteria.add(CONTENT, obj.getContent());
665               return criteria;
666     }
667  
668     
669         /**
670      * Retrieve a single object by pk
671      *
672      * @param pk the primary key
673      * @throws TorqueException Any exceptions caught during processing will be
674      * rethrown wrapped into a TorqueException.
675      * @throws NoRowsException Primary key was not found in database.
676      * @throws TooManyRowsException Primary key was not found in database.
677      */

678     public static InboxAttachment retrieveByPK(int pk)
679         throws TorqueException, NoRowsException, TooManyRowsException
680     {
681         return retrieveByPK(SimpleKey.keyFor(pk));
682     }
683
684     /**
685      * Retrieve a single object by pk
686      *
687      * @param pk the primary key
688      * @param con the connection to use
689      * @throws TorqueException Any exceptions caught during processing will be
690      * rethrown wrapped into a TorqueException.
691      * @throws NoRowsException Primary key was not found in database.
692      * @throws TooManyRowsException Primary key was not found in database.
693      */

694     public static InboxAttachment retrieveByPK(int pk, Connection JavaDoc con)
695         throws TorqueException, NoRowsException, TooManyRowsException
696     {
697         return retrieveByPK(SimpleKey.keyFor(pk), con);
698     }
699   
700     /**
701      * Retrieve a single object by pk
702      *
703      * @param pk the primary key
704      * @throws TorqueException Any exceptions caught during processing will be
705      * rethrown wrapped into a TorqueException.
706      * @throws NoRowsException Primary key was not found in database.
707      * @throws TooManyRowsException Primary key was not found in database.
708      */

709     public static InboxAttachment retrieveByPK(ObjectKey pk)
710         throws TorqueException, NoRowsException, TooManyRowsException
711     {
712         Connection JavaDoc db = null;
713         InboxAttachment retVal = null;
714         try
715         {
716             db = Torque.getConnection(DATABASE_NAME);
717             retVal = retrieveByPK(pk, db);
718         }
719         finally
720         {
721             Torque.closeConnection(db);
722         }
723         return(retVal);
724     }
725
726     /**
727      * Retrieve a single object by pk
728      *
729      * @param pk the primary key
730      * @param con the connection to use
731      * @throws TorqueException Any exceptions caught during processing will be
732      * rethrown wrapped into a TorqueException.
733      * @throws NoRowsException Primary key was not found in database.
734      * @throws TooManyRowsException Primary key was not found in database.
735      */

736     public static InboxAttachment retrieveByPK(ObjectKey pk, Connection JavaDoc con)
737         throws TorqueException, NoRowsException, TooManyRowsException
738     {
739         Criteria criteria = buildCriteria(pk);
740         List JavaDoc v = doSelect(criteria, con);
741         if (v.size() == 0)
742         {
743             throw new NoRowsException("Failed to select a row.");
744         }
745         else if (v.size() > 1)
746         {
747             throw new TooManyRowsException("Failed to select only one row.");
748         }
749         else
750         {
751             return (InboxAttachment)v.get(0);
752         }
753     }
754
755     /**
756      * Retrieve a multiple objects by pk
757      *
758      * @param pks List of primary keys
759      * @throws TorqueException Any exceptions caught during processing will be
760      * rethrown wrapped into a TorqueException.
761      */

762     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
763         throws TorqueException
764     {
765         Connection JavaDoc db = null;
766         List JavaDoc retVal = null;
767         try
768         {
769            db = Torque.getConnection(DATABASE_NAME);
770            retVal = retrieveByPKs(pks, db);
771         }
772         finally
773         {
774             Torque.closeConnection(db);
775         }
776         return(retVal);
777     }
778
779     /**
780      * Retrieve a multiple objects by pk
781      *
782      * @param pks List of primary keys
783      * @param dbcon the connection to use
784      * @throws TorqueException Any exceptions caught during processing will be
785      * rethrown wrapped into a TorqueException.
786      */

787     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
788         throws TorqueException
789     {
790         List JavaDoc objs = null;
791         if (pks == null || pks.size() == 0)
792         {
793             objs = new LinkedList JavaDoc();
794         }
795         else
796         {
797             Criteria criteria = new Criteria();
798               criteria.addIn( INBOX_ATTACHMENT_ID, pks );
799           objs = doSelect(criteria, dbcon);
800         }
801         return objs;
802     }
803
804  
805
806
807
808           
809                                               
810                 
811                 
812
813     /**
814      * selects a collection of InboxAttachment objects pre-filled with their
815      * InboxEvent objects.
816      *
817      * This method is protected by default in order to keep the public
818      * api reasonable. You can provide public methods for those you
819      * actually need in InboxAttachmentPeer.
820      *
821      * @throws TorqueException Any exceptions caught during processing will be
822      * rethrown wrapped into a TorqueException.
823      */

824     protected static List JavaDoc doSelectJoinInboxEvent(Criteria criteria)
825         throws TorqueException
826     {
827         setDbName(criteria);
828
829         InboxAttachmentPeer.addSelectColumns(criteria);
830         int offset = numColumns + 1;
831         InboxEventPeer.addSelectColumns(criteria);
832
833
834                         criteria.addJoin(InboxAttachmentPeer.INBOX_EVENT_ID,
835             InboxEventPeer.INBOX_EVENT_ID);
836         
837
838                                                                                                                                       
839         List JavaDoc rows = BasePeer.doSelect(criteria);
840         List JavaDoc results = new ArrayList JavaDoc();
841
842         for (int i = 0; i < rows.size(); i++)
843         {
844             Record row = (Record) rows.get(i);
845
846                             Class JavaDoc omClass = InboxAttachmentPeer.getOMClass();
847                     InboxAttachment obj1 = (InboxAttachment) InboxAttachmentPeer
848                 .row2Object(row, 1, omClass);
849                      omClass = InboxEventPeer.getOMClass();
850                     InboxEvent obj2 = (InboxEvent)InboxEventPeer
851                 .row2Object(row, offset, omClass);
852
853             boolean newObject = true;
854             for (int j = 0; j < results.size(); j++)
855             {
856                 InboxAttachment temp_obj1 = (InboxAttachment)results.get(j);
857                 InboxEvent temp_obj2 = (InboxEvent)temp_obj1.getInboxEvent();
858                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
859                 {
860                     newObject = false;
861                               temp_obj2.addInboxAttachment(obj1);
862                               break;
863                 }
864             }
865                       if (newObject)
866             {
867                 obj2.initInboxAttachments();
868                 obj2.addInboxAttachment(obj1);
869             }
870                       results.add(obj1);
871         }
872         return results;
873     }
874                     
875   
876     
877   
878       /**
879      * Returns the TableMap related to this peer. This method is not
880      * needed for general use but a specific application could have a need.
881      *
882      * @throws TorqueException Any exceptions caught during processing will be
883      * rethrown wrapped into a TorqueException.
884      */

885     protected static TableMap getTableMap()
886         throws TorqueException
887     {
888         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
889     }
890    
891     private static void setDbName(Criteria crit)
892     {
893         // Set the correct dbName if it has not been overridden
894
// crit.getDbName will return the same object if not set to
895
// another value so == check is okay and faster
896
if (crit.getDbName() == Torque.getDefaultDB())
897         {
898             crit.setDbName(DATABASE_NAME);
899         }
900     }
901 }
902
Popular Tags