KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > BaseIssueTemplateInfoPeer


1 package org.tigris.scarab.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.tigris.scarab.om.map.*;
32
33
34   
35   
36 /**
37  */

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

53     public static MapBuilder getMapBuilder()
54         throws TorqueException
55     {
56         return getMapBuilder(IssueTemplateInfoMapBuilder.CLASS_NAME);
57     }
58
59       /** the column name for the ISSUE_ID field */
60     public static final String JavaDoc ISSUE_ID;
61       /** the column name for the NAME field */
62     public static final String JavaDoc NAME;
63       /** the column name for the DESCRIPTION field */
64     public static final String JavaDoc DESCRIPTION;
65       /** the column name for the APPROVED field */
66     public static final String JavaDoc APPROVED;
67       /** the column name for the SCOPE_ID field */
68     public static final String JavaDoc SCOPE_ID;
69   
70     static
71     {
72           ISSUE_ID = "SCARAB_ISSUE_TEMPLATE_INFO.ISSUE_ID";
73           NAME = "SCARAB_ISSUE_TEMPLATE_INFO.NAME";
74           DESCRIPTION = "SCARAB_ISSUE_TEMPLATE_INFO.DESCRIPTION";
75           APPROVED = "SCARAB_ISSUE_TEMPLATE_INFO.APPROVED";
76           SCOPE_ID = "SCARAB_ISSUE_TEMPLATE_INFO.SCOPE_ID";
77           if (Torque.isInit())
78         {
79             try
80             {
81                 getMapBuilder(IssueTemplateInfoMapBuilder.CLASS_NAME);
82             }
83             catch (Exception JavaDoc e)
84             {
85                 log.error("Could not initialize Peer", e);
86             }
87         }
88         else
89         {
90             Torque.registerMapBuilder(IssueTemplateInfoMapBuilder.CLASS_NAME);
91         }
92     }
93  
94     /** number of columns for this peer */
95     public static final int numColumns = 5;
96
97     /** A class that can be returned by this peer. */
98     protected static final String JavaDoc CLASSNAME_DEFAULT =
99         "org.tigris.scarab.om.IssueTemplateInfo";
100
101     /** A class that can be returned by this peer. */
102     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
103
104     /**
105      * Class object initialization method.
106      *
107      * @param className name of the class to initialize
108      * @return the initialized class
109      */

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

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

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

202     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
203         throws TorqueException
204     {
205                                 // check for conversion from boolean to int
206
if (criteria.containsKey(APPROVED))
207         {
208             Object JavaDoc possibleBoolean = criteria.get(APPROVED);
209             if (possibleBoolean instanceof Boolean JavaDoc)
210             {
211                 criteria.add(APPROVED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
212             }
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(ISSUE_ID);
238           criteria.addSelectColumn(NAME);
239           criteria.addSelectColumn(DESCRIPTION);
240           criteria.addSelectColumn(APPROVED);
241           criteria.addSelectColumn(SCOPE_ID);
242       }
243
244     /**
245      * Create a new object of type cls from a resultset row starting
246      * from a specified offset. This is done so that you can select
247      * other rows than just those needed for this object. You may
248      * for example want to create two objects from the same row.
249      *
250      * @throws TorqueException Any exceptions caught during processing will be
251      * rethrown wrapped into a TorqueException.
252      */

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

286     public static void populateObject(Record row,
287                                       int offset,
288                                       IssueTemplateInfo obj)
289         throws TorqueException
290     {
291         try
292         {
293                 obj.setIssueId(row.getValue(offset + 0).asLongObj());
294                   obj.setName(row.getValue(offset + 1).asString());
295                   obj.setDescription(row.getValue(offset + 2).asString());
296                   obj.setApproved(row.getValue(offset + 3).asBoolean());
297                   obj.setScopeId(row.getValue(offset + 4).asIntegerObj());
298               }
299         catch (DataSetException e)
300         {
301             throw new TorqueException(e);
302         }
303     }
304
305     /**
306      * Method to do selects.
307      *
308      * @param criteria object used to create the SELECT statement.
309      * @return List of selected Objects
310      * @throws TorqueException Any exceptions caught during processing will be
311      * rethrown wrapped into a TorqueException.
312      */

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

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

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

359     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
360         throws TorqueException
361     {
362         if (criteria.getSelectColumns().size() == 0)
363         {
364             addSelectColumns(criteria);
365         }
366
367                                 // check for conversion from boolean to int
368
if (criteria.containsKey(APPROVED))
369         {
370             Object JavaDoc possibleBoolean = criteria.get(APPROVED);
371             if (possibleBoolean instanceof Boolean JavaDoc)
372             {
373                 criteria.add(APPROVED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
374             }
375          }
376             
377         setDbName(criteria);
378
379         // BasePeer returns a List of Value (Village) arrays. The array
380
// order follows the order columns were placed in the Select clause.
381
if (con == null)
382         {
383             return BasePeer.doSelect(criteria);
384         }
385         else
386         {
387             return BasePeer.doSelect(criteria, con);
388         }
389     }
390
391     /**
392      * The returned List will contain objects of the default type or
393      * objects that inherit from the default.
394      *
395      * @throws TorqueException Any exceptions caught during processing will be
396      * rethrown wrapped into a TorqueException.
397      */

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

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

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

453     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
454         throws TorqueException
455     {
456         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
457                    selectCriteria.put(ISSUE_ID, criteria.remove(ISSUE_ID));
458                                       // check for conversion from boolean to int
459
if (criteria.containsKey(APPROVED))
460         {
461             Object JavaDoc possibleBoolean = criteria.get(APPROVED);
462             if (possibleBoolean instanceof Boolean JavaDoc)
463             {
464                 criteria.add(APPROVED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
465             }
466          }
467                     
468         setDbName(criteria);
469
470         if (con == null)
471         {
472             BasePeer.doUpdate(selectCriteria, criteria);
473         }
474         else
475         {
476             BasePeer.doUpdate(selectCriteria, criteria, con);
477         }
478     }
479
480     /**
481      * Method to do deletes.
482      *
483      * @param criteria object containing data that is used DELETE from database.
484      * @throws TorqueException Any exceptions caught during processing will be
485      * rethrown wrapped into a TorqueException.
486      */

487      public static void doDelete(Criteria criteria) throws TorqueException
488      {
489          IssueTemplateInfoPeer
490             .doDelete(criteria, (Connection JavaDoc) null);
491      }
492
493     /**
494      * Method to do deletes. This method is to be used during a transaction,
495      * otherwise use the doDelete(Criteria) method. It will take care of
496      * the connection details internally.
497      *
498      * @param criteria object containing data that is used DELETE from database.
499      * @param con the connection to use
500      * @throws TorqueException Any exceptions caught during processing will be
501      * rethrown wrapped into a TorqueException.
502      */

503      public static void doDelete(Criteria criteria, Connection JavaDoc con)
504         throws TorqueException
505      {
506                                 // check for conversion from boolean to int
507
if (criteria.containsKey(APPROVED))
508         {
509             Object JavaDoc possibleBoolean = criteria.get(APPROVED);
510             if (possibleBoolean instanceof Boolean JavaDoc)
511             {
512                 criteria.add(APPROVED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
513             }
514          }
515             
516         setDbName(criteria);
517
518         if (con == null)
519         {
520             BasePeer.doDelete(criteria);
521         }
522         else
523         {
524             BasePeer.doDelete(criteria, con);
525         }
526      }
527
528     /**
529      * Method to do selects
530      *
531      * @throws TorqueException Any exceptions caught during processing will be
532      * rethrown wrapped into a TorqueException.
533      */

534     public static List JavaDoc doSelect(IssueTemplateInfo obj) throws TorqueException
535     {
536         return doSelect(buildSelectCriteria(obj));
537     }
538
539     /**
540      * Method to do inserts
541      *
542      * @throws TorqueException Any exceptions caught during processing will be
543      * rethrown wrapped into a TorqueException.
544      */

545     public static void doInsert(IssueTemplateInfo obj) throws TorqueException
546     {
547           doInsert(buildCriteria(obj));
548           obj.setNew(false);
549         obj.setModified(false);
550     }
551
552     /**
553      * @param obj the data object to update in the database.
554      * @throws TorqueException Any exceptions caught during processing will be
555      * rethrown wrapped into a TorqueException.
556      */

557     public static void doUpdate(IssueTemplateInfo obj) throws TorqueException
558     {
559         doUpdate(buildCriteria(obj));
560         obj.setModified(false);
561     }
562
563     /**
564      * @param obj the data object to delete in the database.
565      * @throws TorqueException Any exceptions caught during processing will be
566      * rethrown wrapped into a TorqueException.
567      */

568     public static void doDelete(IssueTemplateInfo obj) throws TorqueException
569     {
570         doDelete(buildSelectCriteria(obj));
571     }
572
573     /**
574      * Method to do inserts. This method is to be used during a transaction,
575      * otherwise use the doInsert(IssueTemplateInfo) method. It will take
576      * care of the connection details internally.
577      *
578      * @param obj the data object to insert into the database.
579      * @param con the connection to use
580      * @throws TorqueException Any exceptions caught during processing will be
581      * rethrown wrapped into a TorqueException.
582      */

583     public static void doInsert(IssueTemplateInfo obj, Connection JavaDoc con)
584         throws TorqueException
585     {
586           doInsert(buildCriteria(obj), con);
587           obj.setNew(false);
588         obj.setModified(false);
589     }
590
591     /**
592      * Method to do update. This method is to be used during a transaction,
593      * otherwise use the doUpdate(IssueTemplateInfo) method. It will take
594      * care of the connection details internally.
595      *
596      * @param obj the data object to update in 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 doUpdate(IssueTemplateInfo obj, Connection JavaDoc con)
602         throws TorqueException
603     {
604         doUpdate(buildCriteria(obj), con);
605         obj.setModified(false);
606     }
607
608     /**
609      * Method to delete. This method is to be used during a transaction,
610      * otherwise use the doDelete(IssueTemplateInfo) method. It will take
611      * care of the connection details internally.
612      *
613      * @param obj the data object to delete in the database.
614      * @param con the connection to use
615      * @throws TorqueException Any exceptions caught during processing will be
616      * rethrown wrapped into a TorqueException.
617      */

618     public static void doDelete(IssueTemplateInfo obj, Connection JavaDoc con)
619         throws TorqueException
620     {
621         doDelete(buildSelectCriteria(obj), con);
622     }
623
624     /**
625      * Method to do deletes.
626      *
627      * @param pk ObjectKey that is used DELETE from database.
628      * @throws TorqueException Any exceptions caught during processing will be
629      * rethrown wrapped into a TorqueException.
630      */

631     public static void doDelete(ObjectKey pk) throws TorqueException
632     {
633         BaseIssueTemplateInfoPeer
634            .doDelete(pk, (Connection JavaDoc) null);
635     }
636
637     /**
638      * Method to delete. This method is to be used during a transaction,
639      * otherwise use the doDelete(ObjectKey) method. It will take
640      * care of the connection details internally.
641      *
642      * @param pk the primary key for the object to delete in the database.
643      * @param con the connection to use
644      * @throws TorqueException Any exceptions caught during processing will be
645      * rethrown wrapped into a TorqueException.
646      */

647     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
648         throws TorqueException
649     {
650         doDelete(buildCriteria(pk), con);
651     }
652
653     /** Build a Criteria object from an ObjectKey */
654     public static Criteria buildCriteria( ObjectKey pk )
655     {
656         Criteria criteria = new Criteria();
657               criteria.add(ISSUE_ID, pk);
658           return criteria;
659      }
660
661     /** Build a Criteria object from the data object for this peer */
662     public static Criteria buildCriteria( IssueTemplateInfo obj )
663     {
664         Criteria criteria = new Criteria(DATABASE_NAME);
665               criteria.add(ISSUE_ID, obj.getIssueId());
666               criteria.add(NAME, obj.getName());
667               criteria.add(DESCRIPTION, obj.getDescription());
668               criteria.add(APPROVED, obj.getApproved());
669               criteria.add(SCOPE_ID, obj.getScopeId());
670           return criteria;
671     }
672
673     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
674     public static Criteria buildSelectCriteria( IssueTemplateInfo obj )
675     {
676         Criteria criteria = new Criteria(DATABASE_NAME);
677                       criteria.add(ISSUE_ID, obj.getIssueId());
678                           criteria.add(NAME, obj.getName());
679                           criteria.add(DESCRIPTION, obj.getDescription());
680                           criteria.add(APPROVED, obj.getApproved());
681                           criteria.add(SCOPE_ID, obj.getScopeId());
682               return criteria;
683     }
684  
685     
686         /**
687      * Retrieve a single object by pk
688      *
689      * @param pk the primary key
690      * @throws TorqueException Any exceptions caught during processing will be
691      * rethrown wrapped into a TorqueException.
692      * @throws NoRowsException Primary key was not found in database.
693      * @throws TooManyRowsException Primary key was not found in database.
694      */

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

711     public static IssueTemplateInfo retrieveByPK(Long JavaDoc pk, Connection JavaDoc con)
712         throws TorqueException, NoRowsException, TooManyRowsException
713     {
714         return retrieveByPK(SimpleKey.keyFor(pk), con);
715     }
716   
717     /**
718      * Retrieve a single object by pk
719      *
720      * @param pk the primary key
721      * @throws TorqueException Any exceptions caught during processing will be
722      * rethrown wrapped into a TorqueException.
723      * @throws NoRowsException Primary key was not found in database.
724      * @throws TooManyRowsException Primary key was not found in database.
725      */

726     public static IssueTemplateInfo retrieveByPK(ObjectKey pk)
727         throws TorqueException, NoRowsException, TooManyRowsException
728     {
729         Connection JavaDoc db = null;
730         IssueTemplateInfo retVal = null;
731         try
732         {
733             db = Torque.getConnection(DATABASE_NAME);
734             retVal = retrieveByPK(pk, db);
735         }
736         finally
737         {
738             Torque.closeConnection(db);
739         }
740         return(retVal);
741     }
742
743     /**
744      * Retrieve a single object by pk
745      *
746      * @param pk the primary key
747      * @param con the connection to use
748      * @throws TorqueException Any exceptions caught during processing will be
749      * rethrown wrapped into a TorqueException.
750      * @throws NoRowsException Primary key was not found in database.
751      * @throws TooManyRowsException Primary key was not found in database.
752      */

753     public static IssueTemplateInfo retrieveByPK(ObjectKey pk, Connection JavaDoc con)
754         throws TorqueException, NoRowsException, TooManyRowsException
755     {
756         Criteria criteria = buildCriteria(pk);
757         List JavaDoc v = doSelect(criteria, con);
758         if (v.size() == 0)
759         {
760             throw new NoRowsException("Failed to select a row.");
761         }
762         else if (v.size() > 1)
763         {
764             throw new TooManyRowsException("Failed to select only one row.");
765         }
766         else
767         {
768             return (IssueTemplateInfo)v.get(0);
769         }
770     }
771
772     /**
773      * Retrieve a multiple objects by pk
774      *
775      * @param pks List of primary keys
776      * @throws TorqueException Any exceptions caught during processing will be
777      * rethrown wrapped into a TorqueException.
778      */

779     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
780         throws TorqueException
781     {
782         Connection JavaDoc db = null;
783         List JavaDoc retVal = null;
784         try
785         {
786            db = Torque.getConnection(DATABASE_NAME);
787            retVal = retrieveByPKs(pks, db);
788         }
789         finally
790         {
791             Torque.closeConnection(db);
792         }
793         return(retVal);
794     }
795
796     /**
797      * Retrieve a multiple objects by pk
798      *
799      * @param pks List of primary keys
800      * @param dbcon the connection to use
801      * @throws TorqueException Any exceptions caught during processing will be
802      * rethrown wrapped into a TorqueException.
803      */

804     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
805         throws TorqueException
806     {
807         List JavaDoc objs = null;
808         if (pks == null || pks.size() == 0)
809         {
810             objs = new LinkedList JavaDoc();
811         }
812         else
813         {
814             Criteria criteria = new Criteria();
815               criteria.addIn( ISSUE_ID, pks );
816           objs = doSelect(criteria, dbcon);
817         }
818         return objs;
819     }
820
821  
822
823
824
825             
826                                               
827                 
828                 
829
830     /**
831      * selects a collection of IssueTemplateInfo objects pre-filled with their
832      * Issue objects.
833      *
834      * This method is protected by default in order to keep the public
835      * api reasonable. You can provide public methods for those you
836      * actually need in IssueTemplateInfoPeer.
837      *
838      * @throws TorqueException Any exceptions caught during processing will be
839      * rethrown wrapped into a TorqueException.
840      */

841     protected static List JavaDoc doSelectJoinIssue(Criteria criteria)
842         throws TorqueException
843     {
844         setDbName(criteria);
845
846         IssueTemplateInfoPeer.addSelectColumns(criteria);
847         int offset = numColumns + 1;
848         IssuePeer.addSelectColumns(criteria);
849
850
851                         criteria.addJoin(IssueTemplateInfoPeer.ISSUE_ID,
852             IssuePeer.ISSUE_ID);
853         
854
855                                                                                 // check for conversion from boolean to int
856
if (criteria.containsKey(APPROVED))
857         {
858             Object JavaDoc possibleBoolean = criteria.get(APPROVED);
859             if (possibleBoolean instanceof Boolean JavaDoc)
860             {
861                 criteria.add(APPROVED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
862             }
863          }
864                                     
865         List JavaDoc rows = BasePeer.doSelect(criteria);
866         List JavaDoc results = new ArrayList JavaDoc();
867
868         for (int i = 0; i < rows.size(); i++)
869         {
870             Record row = (Record) rows.get(i);
871
872                             Class JavaDoc omClass = IssueTemplateInfoPeer.getOMClass();
873                     IssueTemplateInfo obj1 = (IssueTemplateInfo) IssueTemplateInfoPeer
874                 .row2Object(row, 1, omClass);
875                      omClass = IssuePeer.getOMClass();
876                     Issue obj2 = (Issue)IssuePeer
877                 .row2Object(row, offset, omClass);
878
879             boolean newObject = true;
880             for (int j = 0; j < results.size(); j++)
881             {
882                 IssueTemplateInfo temp_obj1 = (IssueTemplateInfo)results.get(j);
883                 Issue temp_obj2 = (Issue)temp_obj1.getIssue();
884                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
885                 {
886                     newObject = false;
887                               temp_obj2.addIssueTemplateInfo(obj1);
888                               break;
889                 }
890             }
891                       if (newObject)
892             {
893                 obj2.initIssueTemplateInfos();
894                 obj2.addIssueTemplateInfo(obj1);
895             }
896                       results.add(obj1);
897         }
898         return results;
899     }
900                                                             
901                 
902                 
903
904     /**
905      * selects a collection of IssueTemplateInfo objects pre-filled with their
906      * Scope objects.
907      *
908      * This method is protected by default in order to keep the public
909      * api reasonable. You can provide public methods for those you
910      * actually need in IssueTemplateInfoPeer.
911      *
912      * @throws TorqueException Any exceptions caught during processing will be
913      * rethrown wrapped into a TorqueException.
914      */

915     protected static List JavaDoc doSelectJoinScope(Criteria criteria)
916         throws TorqueException
917     {
918         setDbName(criteria);
919
920         IssueTemplateInfoPeer.addSelectColumns(criteria);
921         int offset = numColumns + 1;
922         ScopePeer.addSelectColumns(criteria);
923
924
925                         criteria.addJoin(IssueTemplateInfoPeer.SCOPE_ID,
926             ScopePeer.SCOPE_ID);
927         
928
929                                                                                 // check for conversion from boolean to int
930
if (criteria.containsKey(APPROVED))
931         {
932             Object JavaDoc possibleBoolean = criteria.get(APPROVED);
933             if (possibleBoolean instanceof Boolean JavaDoc)
934             {
935                 criteria.add(APPROVED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
936             }
937          }
938                                     
939         List JavaDoc rows = BasePeer.doSelect(criteria);
940         List JavaDoc results = new ArrayList JavaDoc();
941
942         for (int i = 0; i < rows.size(); i++)
943         {
944             Record row = (Record) rows.get(i);
945
946                             Class JavaDoc omClass = IssueTemplateInfoPeer.getOMClass();
947                     IssueTemplateInfo obj1 = (IssueTemplateInfo) IssueTemplateInfoPeer
948                 .row2Object(row, 1, omClass);
949                      omClass = ScopePeer.getOMClass();
950                     Scope obj2 = (Scope)ScopePeer
951                 .row2Object(row, offset, omClass);
952
953             boolean newObject = true;
954             for (int j = 0; j < results.size(); j++)
955             {
956                 IssueTemplateInfo temp_obj1 = (IssueTemplateInfo)results.get(j);
957                 Scope temp_obj2 = (Scope)temp_obj1.getScope();
958                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
959                 {
960                     newObject = false;
961                               temp_obj2.addIssueTemplateInfo(obj1);
962                               break;
963                 }
964             }
965                       if (newObject)
966             {
967                 obj2.initIssueTemplateInfos();
968                 obj2.addIssueTemplateInfo(obj1);
969             }
970                       results.add(obj1);
971         }
972         return results;
973     }
974                     
975   
976     
977   
978       /**
979      * Returns the TableMap related to this peer. This method is not
980      * needed for general use but a specific application could have a need.
981      *
982      * @throws TorqueException Any exceptions caught during processing will be
983      * rethrown wrapped into a TorqueException.
984      */

985     protected static TableMap getTableMap()
986         throws TorqueException
987     {
988         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
989     }
990    
991     private static void setDbName(Criteria crit)
992     {
993         // Set the correct dbName if it has not been overridden
994
// crit.getDbName will return the same object if not set to
995
// another value so == check is okay and faster
996
if (crit.getDbName() == Torque.getDefaultDB())
997         {
998             crit.setDbName(DATABASE_NAME);
999         }
1000    }
1001}
1002
Popular Tags