KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
37  * This class was autogenerated by Torque on:
38  *
39  * [Wed May 04 09:10:56 CEST 2005]
40  *
41  */

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

57     public static MapBuilder getMapBuilder()
58         throws TorqueException
59     {
60         return getMapBuilder(NewsSubscriptionMapBuilder.CLASS_NAME);
61     }
62
63       /** the column name for the NEWS_SUBS_ID field */
64     public static final String JavaDoc NEWS_SUBS_ID;
65       /** the column name for the NEWS_SUBS_CODE field */
66     public static final String JavaDoc NEWS_SUBS_CODE;
67       /** the column name for the STATUS field */
68     public static final String JavaDoc STATUS;
69       /** the column name for the PRIORITY field */
70     public static final String JavaDoc PRIORITY;
71       /** the column name for the ISSUED_DATE field */
72     public static final String JavaDoc ISSUED_DATE;
73       /** the column name for the CLOSED_DATE field */
74     public static final String JavaDoc CLOSED_DATE;
75       /** the column name for the EMAIL field */
76     public static final String JavaDoc EMAIL;
77       /** the column name for the PROJECT_ID field */
78     public static final String JavaDoc PROJECT_ID;
79       /** the column name for the PRODUCT_ID field */
80     public static final String JavaDoc PRODUCT_ID;
81       /** the column name for the SUBJECT field */
82     public static final String JavaDoc SUBJECT;
83       /** the column name for the NOTES field */
84     public static final String JavaDoc NOTES;
85       /** the column name for the CREATED field */
86     public static final String JavaDoc CREATED;
87       /** the column name for the MODIFIED field */
88     public static final String JavaDoc MODIFIED;
89       /** the column name for the CREATED_BY field */
90     public static final String JavaDoc CREATED_BY;
91       /** the column name for the MODIFIED_BY field */
92     public static final String JavaDoc MODIFIED_BY;
93   
94     static
95     {
96           NEWS_SUBS_ID = "NEWS_SUBSCRIPTION.NEWS_SUBS_ID";
97           NEWS_SUBS_CODE = "NEWS_SUBSCRIPTION.NEWS_SUBS_CODE";
98           STATUS = "NEWS_SUBSCRIPTION.STATUS";
99           PRIORITY = "NEWS_SUBSCRIPTION.PRIORITY";
100           ISSUED_DATE = "NEWS_SUBSCRIPTION.ISSUED_DATE";
101           CLOSED_DATE = "NEWS_SUBSCRIPTION.CLOSED_DATE";
102           EMAIL = "NEWS_SUBSCRIPTION.EMAIL";
103           PROJECT_ID = "NEWS_SUBSCRIPTION.PROJECT_ID";
104           PRODUCT_ID = "NEWS_SUBSCRIPTION.PRODUCT_ID";
105           SUBJECT = "NEWS_SUBSCRIPTION.SUBJECT";
106           NOTES = "NEWS_SUBSCRIPTION.NOTES";
107           CREATED = "NEWS_SUBSCRIPTION.CREATED";
108           MODIFIED = "NEWS_SUBSCRIPTION.MODIFIED";
109           CREATED_BY = "NEWS_SUBSCRIPTION.CREATED_BY";
110           MODIFIED_BY = "NEWS_SUBSCRIPTION.MODIFIED_BY";
111           if (Torque.isInit())
112         {
113             try
114             {
115                 getMapBuilder(NewsSubscriptionMapBuilder.CLASS_NAME);
116             }
117             catch (Exception JavaDoc e)
118             {
119                 log.error("Could not initialize Peer", e);
120             }
121         }
122         else
123         {
124             Torque.registerMapBuilder(NewsSubscriptionMapBuilder.CLASS_NAME);
125         }
126     }
127  
128     /** number of columns for this peer */
129     public static final int numColumns = 15;
130
131     /** A class that can be returned by this peer. */
132     protected static final String JavaDoc CLASSNAME_DEFAULT =
133         "org.campware.cream.om.NewsSubscription";
134
135     /** A class that can be returned by this peer. */
136     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
137
138     /**
139      * Class object initialization method.
140      *
141      * @param className name of the class to initialize
142      * @return the initialized class
143      */

144     private static Class JavaDoc initClass(String JavaDoc className)
145     {
146         Class JavaDoc c = null;
147         try
148         {
149             c = Class.forName(className);
150         }
151         catch (Throwable JavaDoc t)
152         {
153             log.error("A FATAL ERROR has occurred which should not "
154                 + "have happened under any circumstance. Please notify "
155                 + "the Torque developers <torque-dev@db.apache.org> "
156                 + "and give as many details as possible (including the error "
157                 + "stack trace).", t);
158
159             // Error objects should always be propogated.
160
if (t instanceof Error JavaDoc)
161             {
162                 throw (Error JavaDoc) t.fillInStackTrace();
163             }
164         }
165         return c;
166     }
167
168     /**
169      * Get the list of objects for a ResultSet. Please not that your
170      * resultset MUST return columns in the right order. You can use
171      * getFieldNames() in BaseObject to get the correct sequence.
172      *
173      * @param results the ResultSet
174      * @return the list of objects
175      * @throws TorqueException Any exceptions caught during processing will be
176      * rethrown wrapped into a TorqueException.
177      */

178     public static List JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
179             throws TorqueException
180     {
181         try
182         {
183             QueryDataSet qds = null;
184             List JavaDoc rows = null;
185             try
186             {
187                 qds = new QueryDataSet(results);
188                 rows = getSelectResults(qds);
189             }
190             finally
191             {
192                 if (qds != null)
193                 {
194                     qds.close();
195                 }
196             }
197
198             return populateObjects(rows);
199         }
200         catch (SQLException JavaDoc e)
201         {
202             throw new TorqueException(e);
203         }
204         catch (DataSetException e)
205         {
206             throw new TorqueException(e);
207         }
208     }
209
210
211   
212     /**
213      * Method to do inserts.
214      *
215      * @param criteria object used to create the INSERT statement.
216      * @throws TorqueException Any exceptions caught during processing will be
217      * rethrown wrapped into a TorqueException.
218      */

219     public static ObjectKey doInsert(Criteria criteria)
220         throws TorqueException
221     {
222         return BaseNewsSubscriptionPeer
223             .doInsert(criteria, (Connection JavaDoc) null);
224     }
225
226     /**
227      * Method to do inserts. This method is to be used during a transaction,
228      * otherwise use the doInsert(Criteria) method. It will take care of
229      * the connection details internally.
230      *
231      * @param criteria object used to create the INSERT statement.
232      * @param con the connection to use
233      * @throws TorqueException Any exceptions caught during processing will be
234      * rethrown wrapped into a TorqueException.
235      */

236     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
237         throws TorqueException
238     {
239                                                                                             
240         setDbName(criteria);
241
242         if (con == null)
243         {
244             return BasePeer.doInsert(criteria);
245         }
246         else
247         {
248             return BasePeer.doInsert(criteria, con);
249         }
250     }
251
252     /**
253      * Add all the columns needed to create a new object.
254      *
255      * @param criteria object containing the columns to add.
256      * @throws TorqueException Any exceptions caught during processing will be
257      * rethrown wrapped into a TorqueException.
258      */

259     public static void addSelectColumns(Criteria criteria)
260             throws TorqueException
261     {
262           criteria.addSelectColumn(NEWS_SUBS_ID);
263           criteria.addSelectColumn(NEWS_SUBS_CODE);
264           criteria.addSelectColumn(STATUS);
265           criteria.addSelectColumn(PRIORITY);
266           criteria.addSelectColumn(ISSUED_DATE);
267           criteria.addSelectColumn(CLOSED_DATE);
268           criteria.addSelectColumn(EMAIL);
269           criteria.addSelectColumn(PROJECT_ID);
270           criteria.addSelectColumn(PRODUCT_ID);
271           criteria.addSelectColumn(SUBJECT);
272           criteria.addSelectColumn(NOTES);
273           criteria.addSelectColumn(CREATED);
274           criteria.addSelectColumn(MODIFIED);
275           criteria.addSelectColumn(CREATED_BY);
276           criteria.addSelectColumn(MODIFIED_BY);
277       }
278
279     /**
280      * Create a new object of type cls 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 NewsSubscription row2Object(Record row,
289                                              int offset,
290                                              Class JavaDoc cls)
291         throws TorqueException
292     {
293         try
294         {
295             NewsSubscription obj = (NewsSubscription) cls.newInstance();
296             NewsSubscriptionPeer.populateObject(row, offset, obj);
297                   obj.setModified(false);
298               obj.setNew(false);
299
300             return obj;
301         }
302         catch (InstantiationException JavaDoc e)
303         {
304             throw new TorqueException(e);
305         }
306         catch (IllegalAccessException JavaDoc e)
307         {
308             throw new TorqueException(e);
309         }
310     }
311
312     /**
313      * Populates an object from a resultset row starting
314      * from a specified offset. This is done so that you can select
315      * other rows than just those needed for this object. You may
316      * for example want to create two objects from the same row.
317      *
318      * @throws TorqueException Any exceptions caught during processing will be
319      * rethrown wrapped into a TorqueException.
320      */

321     public static void populateObject(Record row,
322                                       int offset,
323                                       NewsSubscription obj)
324         throws TorqueException
325     {
326         try
327         {
328                 obj.setNewsSubsId(row.getValue(offset + 0).asInt());
329                   obj.setNewsSubsCode(row.getValue(offset + 1).asString());
330                   obj.setStatus(row.getValue(offset + 2).asInt());
331                   obj.setPriority(row.getValue(offset + 3).asInt());
332                   obj.setIssuedDate(row.getValue(offset + 4).asUtilDate());
333                   obj.setClosedDate(row.getValue(offset + 5).asUtilDate());
334                   obj.setEmail(row.getValue(offset + 6).asString());
335                   obj.setProjectId(row.getValue(offset + 7).asInt());
336                   obj.setProductId(row.getValue(offset + 8).asInt());
337                   obj.setSubject(row.getValue(offset + 9).asString());
338                   obj.setNotes(row.getValue(offset + 10).asString());
339                   obj.setCreated(row.getValue(offset + 11).asUtilDate());
340                   obj.setModified(row.getValue(offset + 12).asUtilDate());
341                   obj.setCreatedBy(row.getValue(offset + 13).asString());
342                   obj.setModifiedBy(row.getValue(offset + 14).asString());
343               }
344         catch (DataSetException e)
345         {
346             throw new TorqueException(e);
347         }
348     }
349
350     /**
351      * Method to do selects.
352      *
353      * @param criteria object used to create the SELECT statement.
354      * @return List of selected Objects
355      * @throws TorqueException Any exceptions caught during processing will be
356      * rethrown wrapped into a TorqueException.
357      */

358     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
359     {
360         return populateObjects(doSelectVillageRecords(criteria));
361     }
362
363     /**
364      * Method to do selects within a transaction.
365      *
366      * @param criteria object used to create the SELECT statement.
367      * @param con the connection to use
368      * @return List of selected Objects
369      * @throws TorqueException Any exceptions caught during processing will be
370      * rethrown wrapped into a TorqueException.
371      */

372     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
373         throws TorqueException
374     {
375         return populateObjects(doSelectVillageRecords(criteria, con));
376     }
377
378     /**
379      * Grabs the raw Village records to be formed into objects.
380      * This method handles connections internally. The Record objects
381      * returned by this method should be considered readonly. Do not
382      * alter the data and call save(), your results may vary, but are
383      * certainly likely to result in hard to track MT bugs.
384      *
385      * @throws TorqueException Any exceptions caught during processing will be
386      * rethrown wrapped into a TorqueException.
387      */

388     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
389         throws TorqueException
390     {
391         return BaseNewsSubscriptionPeer
392             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
393     }
394
395     /**
396      * Grabs the raw Village records to be formed into objects.
397      * This method should be used for transactions
398      *
399      * @param criteria object used to create the SELECT statement.
400      * @param con the connection to use
401      * @throws TorqueException Any exceptions caught during processing will be
402      * rethrown wrapped into a TorqueException.
403      */

404     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
405         throws TorqueException
406     {
407         if (criteria.getSelectColumns().size() == 0)
408         {
409             addSelectColumns(criteria);
410         }
411
412                                                                                             
413         setDbName(criteria);
414
415         // BasePeer returns a List of Value (Village) arrays. The array
416
// order follows the order columns were placed in the Select clause.
417
if (con == null)
418         {
419             return BasePeer.doSelect(criteria);
420         }
421         else
422         {
423             return BasePeer.doSelect(criteria, con);
424         }
425     }
426
427     /**
428      * The returned List will contain objects of the default type or
429      * objects that inherit from the default.
430      *
431      * @throws TorqueException Any exceptions caught during processing will be
432      * rethrown wrapped into a TorqueException.
433      */

434     public static List JavaDoc populateObjects(List JavaDoc records)
435         throws TorqueException
436     {
437         List JavaDoc results = new ArrayList JavaDoc(records.size());
438
439         // populate the object(s)
440
for (int i = 0; i < records.size(); i++)
441         {
442             Record row = (Record) records.get(i);
443               results.add(NewsSubscriptionPeer.row2Object(row, 1,
444                 NewsSubscriptionPeer.getOMClass()));
445           }
446         return results;
447     }
448  
449
450     /**
451      * The class that the Peer will make instances of.
452      * If the BO is abstract then you must implement this method
453      * in the BO.
454      *
455      * @throws TorqueException Any exceptions caught during processing will be
456      * rethrown wrapped into a TorqueException.
457      */

458     public static Class JavaDoc getOMClass()
459         throws TorqueException
460     {
461         return CLASS_DEFAULT;
462     }
463
464     /**
465      * Method to do updates.
466      *
467      * @param criteria object containing data that is used to create the UPDATE
468      * statement.
469      * @throws TorqueException Any exceptions caught during processing will be
470      * rethrown wrapped into a TorqueException.
471      */

472     public static void doUpdate(Criteria criteria) throws TorqueException
473     {
474          BaseNewsSubscriptionPeer
475             .doUpdate(criteria, (Connection JavaDoc) null);
476     }
477
478     /**
479      * Method to do updates. This method is to be used during a transaction,
480      * otherwise use the doUpdate(Criteria) method. It will take care of
481      * the connection details internally.
482      *
483      * @param criteria object containing data that is used to create the UPDATE
484      * statement.
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 doUpdate(Criteria criteria, Connection JavaDoc con)
490         throws TorqueException
491     {
492         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
493                    selectCriteria.put(NEWS_SUBS_ID, criteria.remove(NEWS_SUBS_ID));
494                                                                                                                                                   
495         setDbName(criteria);
496
497         if (con == null)
498         {
499             BasePeer.doUpdate(selectCriteria, criteria);
500         }
501         else
502         {
503             BasePeer.doUpdate(selectCriteria, criteria, con);
504         }
505     }
506
507     /**
508      * Method to do deletes.
509      *
510      * @param criteria object containing data that is used DELETE from database.
511      * @throws TorqueException Any exceptions caught during processing will be
512      * rethrown wrapped into a TorqueException.
513      */

514      public static void doDelete(Criteria criteria) throws TorqueException
515      {
516          NewsSubscriptionPeer
517             .doDelete(criteria, (Connection JavaDoc) null);
518      }
519
520     /**
521      * Method to do deletes. This method is to be used during a transaction,
522      * otherwise use the doDelete(Criteria) method. It will take care of
523      * the connection details internally.
524      *
525      * @param criteria object containing data that is used DELETE from database.
526      * @param con the connection to use
527      * @throws TorqueException Any exceptions caught during processing will be
528      * rethrown wrapped into a TorqueException.
529      */

530      public static void doDelete(Criteria criteria, Connection JavaDoc con)
531         throws TorqueException
532      {
533                                                                                             
534         setDbName(criteria);
535
536         if (con == null)
537         {
538             BasePeer.doDelete(criteria);
539         }
540         else
541         {
542             BasePeer.doDelete(criteria, con);
543         }
544      }
545
546     /**
547      * Method to do selects
548      *
549      * @throws TorqueException Any exceptions caught during processing will be
550      * rethrown wrapped into a TorqueException.
551      */

552     public static List JavaDoc doSelect(NewsSubscription obj) throws TorqueException
553     {
554         return doSelect(buildSelectCriteria(obj));
555     }
556
557     /**
558      * Method to do inserts
559      *
560      * @throws TorqueException Any exceptions caught during processing will be
561      * rethrown wrapped into a TorqueException.
562      */

563     public static void doInsert(NewsSubscription obj) throws TorqueException
564     {
565           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
566           obj.setNew(false);
567         obj.setModified(false);
568     }
569
570     /**
571      * @param obj the data object to update in the database.
572      * @throws TorqueException Any exceptions caught during processing will be
573      * rethrown wrapped into a TorqueException.
574      */

575     public static void doUpdate(NewsSubscription obj) throws TorqueException
576     {
577         doUpdate(buildCriteria(obj));
578         obj.setModified(false);
579     }
580
581     /**
582      * @param obj the data object to delete in the database.
583      * @throws TorqueException Any exceptions caught during processing will be
584      * rethrown wrapped into a TorqueException.
585      */

586     public static void doDelete(NewsSubscription obj) throws TorqueException
587     {
588         doDelete(buildSelectCriteria(obj));
589     }
590
591     /**
592      * Method to do inserts. This method is to be used during a transaction,
593      * otherwise use the doInsert(NewsSubscription) method. It will take
594      * care of the connection details internally.
595      *
596      * @param obj the data object to insert into the database.
597      * @param con the connection to use
598      * @throws TorqueException Any exceptions caught during processing will be
599      * rethrown wrapped into a TorqueException.
600      */

601     public static void doInsert(NewsSubscription obj, Connection JavaDoc con)
602         throws TorqueException
603     {
604           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
605           obj.setNew(false);
606         obj.setModified(false);
607     }
608
609     /**
610      * Method to do update. This method is to be used during a transaction,
611      * otherwise use the doUpdate(NewsSubscription) method. It will take
612      * care of the connection details internally.
613      *
614      * @param obj the data object to update 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 doUpdate(NewsSubscription obj, Connection JavaDoc con)
620         throws TorqueException
621     {
622         doUpdate(buildCriteria(obj), con);
623         obj.setModified(false);
624     }
625
626     /**
627      * Method to delete. This method is to be used during a transaction,
628      * otherwise use the doDelete(NewsSubscription) method. It will take
629      * care of the connection details internally.
630      *
631      * @param obj the data object to delete in the database.
632      * @param con the connection to use
633      * @throws TorqueException Any exceptions caught during processing will be
634      * rethrown wrapped into a TorqueException.
635      */

636     public static void doDelete(NewsSubscription obj, Connection JavaDoc con)
637         throws TorqueException
638     {
639         doDelete(buildSelectCriteria(obj), con);
640     }
641
642     /**
643      * Method to do deletes.
644      *
645      * @param pk ObjectKey that is used DELETE from database.
646      * @throws TorqueException Any exceptions caught during processing will be
647      * rethrown wrapped into a TorqueException.
648      */

649     public static void doDelete(ObjectKey pk) throws TorqueException
650     {
651         BaseNewsSubscriptionPeer
652            .doDelete(pk, (Connection JavaDoc) null);
653     }
654
655     /**
656      * Method to delete. This method is to be used during a transaction,
657      * otherwise use the doDelete(ObjectKey) method. It will take
658      * care of the connection details internally.
659      *
660      * @param pk the primary key for the object to delete in the database.
661      * @param con the connection to use
662      * @throws TorqueException Any exceptions caught during processing will be
663      * rethrown wrapped into a TorqueException.
664      */

665     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
666         throws TorqueException
667     {
668         doDelete(buildCriteria(pk), con);
669     }
670
671     /** Build a Criteria object from an ObjectKey */
672     public static Criteria buildCriteria( ObjectKey pk )
673     {
674         Criteria criteria = new Criteria();
675               criteria.add(NEWS_SUBS_ID, pk);
676           return criteria;
677      }
678
679     /** Build a Criteria object from the data object for this peer */
680     public static Criteria buildCriteria( NewsSubscription obj )
681     {
682         Criteria criteria = new Criteria(DATABASE_NAME);
683               if (!obj.isNew())
684             criteria.add(NEWS_SUBS_ID, obj.getNewsSubsId());
685               criteria.add(NEWS_SUBS_CODE, obj.getNewsSubsCode());
686               criteria.add(STATUS, obj.getStatus());
687               criteria.add(PRIORITY, obj.getPriority());
688               criteria.add(ISSUED_DATE, obj.getIssuedDate());
689               criteria.add(CLOSED_DATE, obj.getClosedDate());
690               criteria.add(EMAIL, obj.getEmail());
691               criteria.add(PROJECT_ID, obj.getProjectId());
692               criteria.add(PRODUCT_ID, obj.getProductId());
693               criteria.add(SUBJECT, obj.getSubject());
694               criteria.add(NOTES, obj.getNotes());
695               criteria.add(CREATED, obj.getCreated());
696               criteria.add(MODIFIED, obj.getModified());
697               criteria.add(CREATED_BY, obj.getCreatedBy());
698               criteria.add(MODIFIED_BY, obj.getModifiedBy());
699           return criteria;
700     }
701
702     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
703     public static Criteria buildSelectCriteria( NewsSubscription obj )
704     {
705         Criteria criteria = new Criteria(DATABASE_NAME);
706               if (!obj.isNew())
707                     criteria.add(NEWS_SUBS_ID, obj.getNewsSubsId());
708                           criteria.add(NEWS_SUBS_CODE, obj.getNewsSubsCode());
709                           criteria.add(STATUS, obj.getStatus());
710                           criteria.add(PRIORITY, obj.getPriority());
711                           criteria.add(ISSUED_DATE, obj.getIssuedDate());
712                           criteria.add(CLOSED_DATE, obj.getClosedDate());
713                           criteria.add(EMAIL, obj.getEmail());
714                           criteria.add(PROJECT_ID, obj.getProjectId());
715                           criteria.add(PRODUCT_ID, obj.getProductId());
716                           criteria.add(SUBJECT, obj.getSubject());
717                           criteria.add(NOTES, obj.getNotes());
718                           criteria.add(CREATED, obj.getCreated());
719                           criteria.add(MODIFIED, obj.getModified());
720                           criteria.add(CREATED_BY, obj.getCreatedBy());
721                           criteria.add(MODIFIED_BY, obj.getModifiedBy());
722               return criteria;
723     }
724  
725     
726         /**
727      * Retrieve a single object by pk
728      *
729      * @param pk the primary key
730      * @throws TorqueException Any exceptions caught during processing will be
731      * rethrown wrapped into a TorqueException.
732      * @throws NoRowsException Primary key was not found in database.
733      * @throws TooManyRowsException Primary key was not found in database.
734      */

735     public static NewsSubscription retrieveByPK(int pk)
736         throws TorqueException, NoRowsException, TooManyRowsException
737     {
738         return retrieveByPK(SimpleKey.keyFor(pk));
739     }
740
741     /**
742      * Retrieve a single object by pk
743      *
744      * @param pk the primary key
745      * @param con the connection to use
746      * @throws TorqueException Any exceptions caught during processing will be
747      * rethrown wrapped into a TorqueException.
748      * @throws NoRowsException Primary key was not found in database.
749      * @throws TooManyRowsException Primary key was not found in database.
750      */

751     public static NewsSubscription retrieveByPK(int pk, Connection JavaDoc con)
752         throws TorqueException, NoRowsException, TooManyRowsException
753     {
754         return retrieveByPK(SimpleKey.keyFor(pk), con);
755     }
756   
757     /**
758      * Retrieve a single object by pk
759      *
760      * @param pk the primary key
761      * @throws TorqueException Any exceptions caught during processing will be
762      * rethrown wrapped into a TorqueException.
763      * @throws NoRowsException Primary key was not found in database.
764      * @throws TooManyRowsException Primary key was not found in database.
765      */

766     public static NewsSubscription retrieveByPK(ObjectKey pk)
767         throws TorqueException, NoRowsException, TooManyRowsException
768     {
769         Connection JavaDoc db = null;
770         NewsSubscription retVal = null;
771         try
772         {
773             db = Torque.getConnection(DATABASE_NAME);
774             retVal = retrieveByPK(pk, db);
775         }
776         finally
777         {
778             Torque.closeConnection(db);
779         }
780         return(retVal);
781     }
782
783     /**
784      * Retrieve a single object by pk
785      *
786      * @param pk the primary key
787      * @param con the connection to use
788      * @throws TorqueException Any exceptions caught during processing will be
789      * rethrown wrapped into a TorqueException.
790      * @throws NoRowsException Primary key was not found in database.
791      * @throws TooManyRowsException Primary key was not found in database.
792      */

793     public static NewsSubscription retrieveByPK(ObjectKey pk, Connection JavaDoc con)
794         throws TorqueException, NoRowsException, TooManyRowsException
795     {
796         Criteria criteria = buildCriteria(pk);
797         List JavaDoc v = doSelect(criteria, con);
798         if (v.size() == 0)
799         {
800             throw new NoRowsException("Failed to select a row.");
801         }
802         else if (v.size() > 1)
803         {
804             throw new TooManyRowsException("Failed to select only one row.");
805         }
806         else
807         {
808             return (NewsSubscription)v.get(0);
809         }
810     }
811
812     /**
813      * Retrieve a multiple objects by pk
814      *
815      * @param pks List of primary keys
816      * @throws TorqueException Any exceptions caught during processing will be
817      * rethrown wrapped into a TorqueException.
818      */

819     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
820         throws TorqueException
821     {
822         Connection JavaDoc db = null;
823         List JavaDoc retVal = null;
824         try
825         {
826            db = Torque.getConnection(DATABASE_NAME);
827            retVal = retrieveByPKs(pks, db);
828         }
829         finally
830         {
831             Torque.closeConnection(db);
832         }
833         return(retVal);
834     }
835
836     /**
837      * Retrieve a multiple objects by pk
838      *
839      * @param pks List of primary keys
840      * @param dbcon the connection to use
841      * @throws TorqueException Any exceptions caught during processing will be
842      * rethrown wrapped into a TorqueException.
843      */

844     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
845         throws TorqueException
846     {
847         List JavaDoc objs = null;
848         if (pks == null || pks.size() == 0)
849         {
850             objs = new LinkedList JavaDoc();
851         }
852         else
853         {
854             Criteria criteria = new Criteria();
855               criteria.addIn( NEWS_SUBS_ID, pks );
856           objs = doSelect(criteria, dbcon);
857         }
858         return objs;
859     }
860
861  
862
863
864
865             
866                                               
867                 
868                 
869
870     /**
871      * selects a collection of NewsSubscription objects pre-filled with their
872      * Project objects.
873      *
874      * This method is protected by default in order to keep the public
875      * api reasonable. You can provide public methods for those you
876      * actually need in NewsSubscriptionPeer.
877      *
878      * @throws TorqueException Any exceptions caught during processing will be
879      * rethrown wrapped into a TorqueException.
880      */

881     protected static List JavaDoc doSelectJoinProject(Criteria criteria)
882         throws TorqueException
883     {
884         setDbName(criteria);
885
886         NewsSubscriptionPeer.addSelectColumns(criteria);
887         int offset = numColumns + 1;
888         ProjectPeer.addSelectColumns(criteria);
889
890
891                         criteria.addJoin(NewsSubscriptionPeer.PROJECT_ID,
892             ProjectPeer.PROJECT_ID);
893         
894
895                                                                                                                                                                                                                                                                                       
896         List JavaDoc rows = BasePeer.doSelect(criteria);
897         List JavaDoc results = new ArrayList JavaDoc();
898
899         for (int i = 0; i < rows.size(); i++)
900         {
901             Record row = (Record) rows.get(i);
902
903                             Class JavaDoc omClass = NewsSubscriptionPeer.getOMClass();
904                     NewsSubscription obj1 = (NewsSubscription) NewsSubscriptionPeer
905                 .row2Object(row, 1, omClass);
906                      omClass = ProjectPeer.getOMClass();
907                     Project obj2 = (Project)ProjectPeer
908                 .row2Object(row, offset, omClass);
909
910             boolean newObject = true;
911             for (int j = 0; j < results.size(); j++)
912             {
913                 NewsSubscription temp_obj1 = (NewsSubscription)results.get(j);
914                 Project temp_obj2 = (Project)temp_obj1.getProject();
915                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
916                 {
917                     newObject = false;
918                               temp_obj2.addNewsSubscription(obj1);
919                               break;
920                 }
921             }
922                       if (newObject)
923             {
924                 obj2.initNewsSubscriptions();
925                 obj2.addNewsSubscription(obj1);
926             }
927                       results.add(obj1);
928         }
929         return results;
930     }
931                                                             
932                 
933                 
934
935     /**
936      * selects a collection of NewsSubscription objects pre-filled with their
937      * Product objects.
938      *
939      * This method is protected by default in order to keep the public
940      * api reasonable. You can provide public methods for those you
941      * actually need in NewsSubscriptionPeer.
942      *
943      * @throws TorqueException Any exceptions caught during processing will be
944      * rethrown wrapped into a TorqueException.
945      */

946     protected static List JavaDoc doSelectJoinProduct(Criteria criteria)
947         throws TorqueException
948     {
949         setDbName(criteria);
950
951         NewsSubscriptionPeer.addSelectColumns(criteria);
952         int offset = numColumns + 1;
953         ProductPeer.addSelectColumns(criteria);
954
955
956                         criteria.addJoin(NewsSubscriptionPeer.PRODUCT_ID,
957             ProductPeer.PRODUCT_ID);
958         
959
960                                                                                                                                                                                                                                                                                       
961         List JavaDoc rows = BasePeer.doSelect(criteria);
962         List JavaDoc results = new ArrayList JavaDoc();
963
964         for (int i = 0; i < rows.size(); i++)
965         {
966             Record row = (Record) rows.get(i);
967
968                             Class JavaDoc omClass = NewsSubscriptionPeer.getOMClass();
969                     NewsSubscription obj1 = (NewsSubscription) NewsSubscriptionPeer
970                 .row2Object(row, 1, omClass);
971                      omClass = ProductPeer.getOMClass();
972                     Product obj2 = (Product)ProductPeer
973                 .row2Object(row, offset, omClass);
974
975             boolean newObject = true;
976             for (int j = 0; j < results.size(); j++)
977             {
978                 NewsSubscription temp_obj1 = (NewsSubscription)results.get(j);
979                 Product temp_obj2 = (Product)temp_obj1.getProduct();
980                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
981                 {
982                     newObject = false;
983                               temp_obj2.addNewsSubscription(obj1);
984                               break;
985                 }
986             }
987                       if (newObject)
988             {
989                 obj2.initNewsSubscriptions();
990                 obj2.addNewsSubscription(obj1);
991             }
992                       results.add(obj1);
993         }
994         return results;
995     }
996                     
997   
998     
999   
1000      /**
1001     * Returns the TableMap related to this peer. This method is not
1002     * needed for general use but a specific application could have a need.
1003     *
1004     * @throws TorqueException Any exceptions caught during processing will be
1005     * rethrown wrapped into a TorqueException.
1006     */

1007    protected static TableMap getTableMap()
1008        throws TorqueException
1009    {
1010        return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1011    }
1012   
1013    private static void setDbName(Criteria crit)
1014    {
1015        // Set the correct dbName if it has not been overridden
1016
// crit.getDbName will return the same object if not set to
1017
// another value so == check is okay and faster
1018
if (crit.getDbName() == Torque.getDefaultDB())
1019        {
1020            crit.setDbName(DATABASE_NAME);
1021        }
1022    }
1023}
1024
Popular Tags