KickJava   Java API By Example, From Geeks To Geeks.

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


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 BaseNotificationPeer
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 = "NOTIFICATION";
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(NotificationMapBuilder.CLASS_NAME);
60     }
61
62       /** the column name for the NOTIFICATION_ID field */
63     public static final String JavaDoc NOTIFICATION_ID;
64       /** the column name for the NOTIFICATION_TYPE field */
65     public static final String JavaDoc NOTIFICATION_TYPE;
66       /** the column name for the LANGUAGE_ID field */
67     public static final String JavaDoc LANGUAGE_ID;
68       /** the column name for the EMAIL_FORMAT field */
69     public static final String JavaDoc EMAIL_FORMAT;
70       /** the column name for the SUBJECT field */
71     public static final String JavaDoc SUBJECT;
72       /** the column name for the BODY field */
73     public static final String JavaDoc BODY;
74   
75     static
76     {
77           NOTIFICATION_ID = "NOTIFICATION.NOTIFICATION_ID";
78           NOTIFICATION_TYPE = "NOTIFICATION.NOTIFICATION_TYPE";
79           LANGUAGE_ID = "NOTIFICATION.LANGUAGE_ID";
80           EMAIL_FORMAT = "NOTIFICATION.EMAIL_FORMAT";
81           SUBJECT = "NOTIFICATION.SUBJECT";
82           BODY = "NOTIFICATION.BODY";
83           if (Torque.isInit())
84         {
85             try
86             {
87                 getMapBuilder(NotificationMapBuilder.CLASS_NAME);
88             }
89             catch (Exception JavaDoc e)
90             {
91                 log.error("Could not initialize Peer", e);
92             }
93         }
94         else
95         {
96             Torque.registerMapBuilder(NotificationMapBuilder.CLASS_NAME);
97         }
98     }
99  
100     /** number of columns for this peer */
101     public static final int numColumns = 6;
102
103     /** A class that can be returned by this peer. */
104     protected static final String JavaDoc CLASSNAME_DEFAULT =
105         "org.campware.cream.om.Notification";
106
107     /** A class that can be returned by this peer. */
108     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
109
110     /**
111      * Class object initialization method.
112      *
113      * @param className name of the class to initialize
114      * @return the initialized class
115      */

116     private static Class JavaDoc initClass(String JavaDoc className)
117     {
118         Class JavaDoc c = null;
119         try
120         {
121             c = Class.forName(className);
122         }
123         catch (Throwable JavaDoc t)
124         {
125             log.error("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 JavaDoc)
133             {
134                 throw (Error JavaDoc) t.fillInStackTrace();
135             }
136         }
137         return c;
138     }
139
140     /**
141      * Get the list of objects for a ResultSet. Please not that your
142      * resultset MUST return columns in the right order. You can use
143      * getFieldNames() in BaseObject to get the correct sequence.
144      *
145      * @param results the ResultSet
146      * @return the list of objects
147      * @throws TorqueException Any exceptions caught during processing will be
148      * rethrown wrapped into a TorqueException.
149      */

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

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

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

231     public static void addSelectColumns(Criteria criteria)
232             throws TorqueException
233     {
234           criteria.addSelectColumn(NOTIFICATION_ID);
235           criteria.addSelectColumn(NOTIFICATION_TYPE);
236           criteria.addSelectColumn(LANGUAGE_ID);
237           criteria.addSelectColumn(EMAIL_FORMAT);
238           criteria.addSelectColumn(SUBJECT);
239           criteria.addSelectColumn(BODY);
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 Notification row2Object(Record row,
252                                              int offset,
253                                              Class JavaDoc cls)
254         throws TorqueException
255     {
256         try
257         {
258             Notification obj = (Notification) cls.newInstance();
259             NotificationPeer.populateObject(row, offset, obj);
260                   obj.setModified(false);
261               obj.setNew(false);
262
263             return obj;
264         }
265         catch (InstantiationException JavaDoc e)
266         {
267             throw new TorqueException(e);
268         }
269         catch (IllegalAccessException JavaDoc 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                                       Notification obj)
287         throws TorqueException
288     {
289         try
290         {
291                 obj.setNotificationId(row.getValue(offset + 0).asInt());
292                   obj.setNotificationType(row.getValue(offset + 1).asInt());
293                   obj.setLanguageId(row.getValue(offset + 2).asInt());
294                   obj.setEmailFormat(row.getValue(offset + 3).asInt());
295                   obj.setSubject(row.getValue(offset + 4).asString());
296                   obj.setBody(row.getValue(offset + 5).asString());
297               }
298         catch (DataSetException e)
299         {
300             throw new TorqueException(e);
301         }
302     }
303
304     /**
305      * Method to do selects.
306      *
307      * @param criteria object used to create the SELECT statement.
308      * @return List of selected Objects
309      * @throws TorqueException Any exceptions caught during processing will be
310      * rethrown wrapped into a TorqueException.
311      */

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

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

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

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

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

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

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

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

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

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

506     public static List JavaDoc doSelect(Notification obj) throws TorqueException
507     {
508         return doSelect(buildSelectCriteria(obj));
509     }
510
511     /**
512      * Method to do inserts
513      *
514      * @throws TorqueException Any exceptions caught during processing will be
515      * rethrown wrapped into a TorqueException.
516      */

517     public static void doInsert(Notification obj) throws TorqueException
518     {
519           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
520           obj.setNew(false);
521         obj.setModified(false);
522     }
523
524     /**
525      * @param obj the data object to update in the database.
526      * @throws TorqueException Any exceptions caught during processing will be
527      * rethrown wrapped into a TorqueException.
528      */

529     public static void doUpdate(Notification obj) throws TorqueException
530     {
531         doUpdate(buildCriteria(obj));
532         obj.setModified(false);
533     }
534
535     /**
536      * @param obj the data object to delete in the database.
537      * @throws TorqueException Any exceptions caught during processing will be
538      * rethrown wrapped into a TorqueException.
539      */

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

555     public static void doInsert(Notification obj, Connection JavaDoc con)
556         throws TorqueException
557     {
558           obj.setPrimaryKey(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(Notification) method. It will take
566      * care of the connection details internally.
567      *
568      * @param obj the data object to update in the database.
569      * @param con the connection to use
570      * @throws TorqueException Any exceptions caught during processing will be
571      * rethrown wrapped into a TorqueException.
572      */

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

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

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

619     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
620         throws TorqueException
621     {
622         doDelete(buildCriteria(pk), con);
623     }
624
625     /** Build a Criteria object from an ObjectKey */
626     public static Criteria buildCriteria( ObjectKey pk )
627     {
628         Criteria criteria = new Criteria();
629               criteria.add(NOTIFICATION_ID, pk);
630           return criteria;
631      }
632
633     /** Build a Criteria object from the data object for this peer */
634     public static Criteria buildCriteria( Notification obj )
635     {
636         Criteria criteria = new Criteria(DATABASE_NAME);
637               if (!obj.isNew())
638             criteria.add(NOTIFICATION_ID, obj.getNotificationId());
639               criteria.add(NOTIFICATION_TYPE, obj.getNotificationType());
640               criteria.add(LANGUAGE_ID, obj.getLanguageId());
641               criteria.add(EMAIL_FORMAT, obj.getEmailFormat());
642               criteria.add(SUBJECT, obj.getSubject());
643               criteria.add(BODY, obj.getBody());
644           return criteria;
645     }
646
647     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
648     public static Criteria buildSelectCriteria( Notification obj )
649     {
650         Criteria criteria = new Criteria(DATABASE_NAME);
651               if (!obj.isNew())
652                     criteria.add(NOTIFICATION_ID, obj.getNotificationId());
653                           criteria.add(NOTIFICATION_TYPE, obj.getNotificationType());
654                           criteria.add(LANGUAGE_ID, obj.getLanguageId());
655                           criteria.add(EMAIL_FORMAT, obj.getEmailFormat());
656                           criteria.add(SUBJECT, obj.getSubject());
657                           criteria.add(BODY, obj.getBody());
658               return criteria;
659     }
660  
661     
662         /**
663      * Retrieve a single object by pk
664      *
665      * @param pk the primary key
666      * @throws TorqueException Any exceptions caught during processing will be
667      * rethrown wrapped into a TorqueException.
668      * @throws NoRowsException Primary key was not found in database.
669      * @throws TooManyRowsException Primary key was not found in database.
670      */

671     public static Notification retrieveByPK(int pk)
672         throws TorqueException, NoRowsException, TooManyRowsException
673     {
674         return retrieveByPK(SimpleKey.keyFor(pk));
675     }
676
677     /**
678      * Retrieve a single object by pk
679      *
680      * @param pk the primary key
681      * @param con the connection to use
682      * @throws TorqueException Any exceptions caught during processing will be
683      * rethrown wrapped into a TorqueException.
684      * @throws NoRowsException Primary key was not found in database.
685      * @throws TooManyRowsException Primary key was not found in database.
686      */

687     public static Notification retrieveByPK(int pk, Connection JavaDoc con)
688         throws TorqueException, NoRowsException, TooManyRowsException
689     {
690         return retrieveByPK(SimpleKey.keyFor(pk), con);
691     }
692   
693     /**
694      * Retrieve a single object by pk
695      *
696      * @param pk the primary key
697      * @throws TorqueException Any exceptions caught during processing will be
698      * rethrown wrapped into a TorqueException.
699      * @throws NoRowsException Primary key was not found in database.
700      * @throws TooManyRowsException Primary key was not found in database.
701      */

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

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

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

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

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

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