KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

210     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
211         throws TorqueException
212     {
213                                       // check for conversion from boolean to int
214
if (criteria.containsKey(DEDUPE))
215         {
216             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
217             if (possibleBoolean instanceof Boolean JavaDoc)
218             {
219                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
220             }
221          }
222                   // check for conversion from boolean to int
223
if (criteria.containsKey(DELETED))
224         {
225             Object JavaDoc possibleBoolean = criteria.get(DELETED);
226             if (possibleBoolean instanceof Boolean JavaDoc)
227             {
228                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
229             }
230          }
231                   // check for conversion from boolean to int
232
if (criteria.containsKey(LOCKED))
233         {
234             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
235             if (possibleBoolean instanceof Boolean JavaDoc)
236             {
237                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
238             }
239          }
240                   // check for conversion from boolean to int
241
if (criteria.containsKey(ISDEFAULT))
242         {
243             Object JavaDoc possibleBoolean = criteria.get(ISDEFAULT);
244             if (possibleBoolean instanceof Boolean JavaDoc)
245             {
246                 criteria.add(ISDEFAULT, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
247             }
248          }
249       
250         setDbName(criteria);
251
252         if (con == null)
253         {
254             return BasePeer.doInsert(criteria);
255         }
256         else
257         {
258             return BasePeer.doInsert(criteria, con);
259         }
260     }
261
262     /**
263      * Add all the columns needed to create a new object.
264      *
265      * @param criteria object containing the columns to add.
266      * @throws TorqueException Any exceptions caught during processing will be
267      * rethrown wrapped into a TorqueException.
268      */

269     public static void addSelectColumns(Criteria criteria)
270             throws TorqueException
271     {
272           criteria.addSelectColumn(ISSUE_TYPE_ID);
273           criteria.addSelectColumn(NAME);
274           criteria.addSelectColumn(DESCRIPTION);
275           criteria.addSelectColumn(PARENT_ID);
276           criteria.addSelectColumn(DEDUPE);
277           criteria.addSelectColumn(DELETED);
278           criteria.addSelectColumn(LOCKED);
279           criteria.addSelectColumn(ISDEFAULT);
280       }
281
282     /**
283      * Create a new object of type cls from a resultset row starting
284      * from a specified offset. This is done so that you can select
285      * other rows than just those needed for this object. You may
286      * for example want to create two objects from the same row.
287      *
288      * @throws TorqueException Any exceptions caught during processing will be
289      * rethrown wrapped into a TorqueException.
290      */

291     public static IssueType row2Object(Record row,
292                                              int offset,
293                                              Class JavaDoc cls)
294         throws TorqueException
295     {
296         try
297         {
298             IssueType obj = (IssueType) cls.newInstance();
299             IssueTypePeer.populateObject(row, offset, obj);
300                   obj.setModified(false);
301               obj.setNew(false);
302
303             return obj;
304         }
305         catch (InstantiationException JavaDoc e)
306         {
307             throw new TorqueException(e);
308         }
309         catch (IllegalAccessException JavaDoc e)
310         {
311             throw new TorqueException(e);
312         }
313     }
314
315     /**
316      * Populates an object from a resultset row starting
317      * from a specified offset. This is done so that you can select
318      * other rows than just those needed for this object. You may
319      * for example want to create two objects from the same row.
320      *
321      * @throws TorqueException Any exceptions caught during processing will be
322      * rethrown wrapped into a TorqueException.
323      */

324     public static void populateObject(Record row,
325                                       int offset,
326                                       IssueType obj)
327         throws TorqueException
328     {
329         try
330         {
331                 obj.setIssueTypeId(row.getValue(offset + 0).asIntegerObj());
332                   obj.setName(row.getValue(offset + 1).asString());
333                   obj.setDescription(row.getValue(offset + 2).asString());
334                   obj.setParentId(row.getValue(offset + 3).asIntegerObj());
335                   obj.setDedupe(row.getValue(offset + 4).asBoolean());
336                   obj.setDeleted(row.getValue(offset + 5).asBoolean());
337                   obj.setLocked(row.getValue(offset + 6).asBoolean());
338                   obj.setIsdefault(row.getValue(offset + 7).asBoolean());
339               }
340         catch (DataSetException e)
341         {
342             throw new TorqueException(e);
343         }
344     }
345
346     /**
347      * Method to do selects.
348      *
349      * @param criteria object used to create the SELECT statement.
350      * @return List of selected Objects
351      * @throws TorqueException Any exceptions caught during processing will be
352      * rethrown wrapped into a TorqueException.
353      */

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

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

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

400     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
401         throws TorqueException
402     {
403         if (criteria.getSelectColumns().size() == 0)
404         {
405             addSelectColumns(criteria);
406         }
407
408                                       // check for conversion from boolean to int
409
if (criteria.containsKey(DEDUPE))
410         {
411             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
412             if (possibleBoolean instanceof Boolean JavaDoc)
413             {
414                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
415             }
416          }
417                   // check for conversion from boolean to int
418
if (criteria.containsKey(DELETED))
419         {
420             Object JavaDoc possibleBoolean = criteria.get(DELETED);
421             if (possibleBoolean instanceof Boolean JavaDoc)
422             {
423                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
424             }
425          }
426                   // check for conversion from boolean to int
427
if (criteria.containsKey(LOCKED))
428         {
429             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
430             if (possibleBoolean instanceof Boolean JavaDoc)
431             {
432                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
433             }
434          }
435                   // check for conversion from boolean to int
436
if (criteria.containsKey(ISDEFAULT))
437         {
438             Object JavaDoc possibleBoolean = criteria.get(ISDEFAULT);
439             if (possibleBoolean instanceof Boolean JavaDoc)
440             {
441                 criteria.add(ISDEFAULT, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
442             }
443          }
444       
445         setDbName(criteria);
446
447         // BasePeer returns a List of Value (Village) arrays. The array
448
// order follows the order columns were placed in the Select clause.
449
if (con == null)
450         {
451             return BasePeer.doSelect(criteria);
452         }
453         else
454         {
455             return BasePeer.doSelect(criteria, con);
456         }
457     }
458
459     /**
460      * The returned List will contain objects of the default type or
461      * objects that inherit from the default.
462      *
463      * @throws TorqueException Any exceptions caught during processing will be
464      * rethrown wrapped into a TorqueException.
465      */

466     public static List JavaDoc populateObjects(List JavaDoc records)
467         throws TorqueException
468     {
469         List JavaDoc results = new ArrayList JavaDoc(records.size());
470
471         // populate the object(s)
472
for (int i = 0; i < records.size(); i++)
473         {
474             Record row = (Record) records.get(i);
475               results.add(IssueTypePeer.row2Object(row, 1,
476                 IssueTypePeer.getOMClass()));
477           }
478         return results;
479     }
480  
481
482     /**
483      * The class that the Peer will make instances of.
484      * If the BO is abstract then you must implement this method
485      * in the BO.
486      *
487      * @throws TorqueException Any exceptions caught during processing will be
488      * rethrown wrapped into a TorqueException.
489      */

490     public static Class JavaDoc getOMClass()
491         throws TorqueException
492     {
493         return CLASS_DEFAULT;
494     }
495
496     /**
497      * Method to do updates.
498      *
499      * @param criteria object containing data that is used to create the UPDATE
500      * statement.
501      * @throws TorqueException Any exceptions caught during processing will be
502      * rethrown wrapped into a TorqueException.
503      */

504     public static void doUpdate(Criteria criteria) throws TorqueException
505     {
506          BaseIssueTypePeer
507             .doUpdate(criteria, (Connection JavaDoc) null);
508     }
509
510     /**
511      * Method to do updates. This method is to be used during a transaction,
512      * otherwise use the doUpdate(Criteria) method. It will take care of
513      * the connection details internally.
514      *
515      * @param criteria object containing data that is used to create the UPDATE
516      * statement.
517      * @param con the connection to use
518      * @throws TorqueException Any exceptions caught during processing will be
519      * rethrown wrapped into a TorqueException.
520      */

521     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
522         throws TorqueException
523     {
524         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
525                    selectCriteria.put(ISSUE_TYPE_ID, criteria.remove(ISSUE_TYPE_ID));
526                                                 // check for conversion from boolean to int
527
if (criteria.containsKey(DEDUPE))
528         {
529             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
530             if (possibleBoolean instanceof Boolean JavaDoc)
531             {
532                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
533             }
534          }
535                       // check for conversion from boolean to int
536
if (criteria.containsKey(DELETED))
537         {
538             Object JavaDoc possibleBoolean = criteria.get(DELETED);
539             if (possibleBoolean instanceof Boolean JavaDoc)
540             {
541                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
542             }
543          }
544                       // check for conversion from boolean to int
545
if (criteria.containsKey(LOCKED))
546         {
547             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
548             if (possibleBoolean instanceof Boolean JavaDoc)
549             {
550                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
551             }
552          }
553                       // check for conversion from boolean to int
554
if (criteria.containsKey(ISDEFAULT))
555         {
556             Object JavaDoc possibleBoolean = criteria.get(ISDEFAULT);
557             if (possibleBoolean instanceof Boolean JavaDoc)
558             {
559                 criteria.add(ISDEFAULT, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
560             }
561          }
562           
563         setDbName(criteria);
564
565         if (con == null)
566         {
567             BasePeer.doUpdate(selectCriteria, criteria);
568         }
569         else
570         {
571             BasePeer.doUpdate(selectCriteria, criteria, con);
572         }
573     }
574
575     /**
576      * Method to do deletes.
577      *
578      * @param criteria object containing data that is used DELETE from database.
579      * @throws TorqueException Any exceptions caught during processing will be
580      * rethrown wrapped into a TorqueException.
581      */

582      public static void doDelete(Criteria criteria) throws TorqueException
583      {
584          IssueTypePeer
585             .doDelete(criteria, (Connection JavaDoc) null);
586      }
587
588     /**
589      * Method to do deletes. This method is to be used during a transaction,
590      * otherwise use the doDelete(Criteria) method. It will take care of
591      * the connection details internally.
592      *
593      * @param criteria object containing data that is used DELETE from database.
594      * @param con the connection to use
595      * @throws TorqueException Any exceptions caught during processing will be
596      * rethrown wrapped into a TorqueException.
597      */

598      public static void doDelete(Criteria criteria, Connection JavaDoc con)
599         throws TorqueException
600      {
601                                       // check for conversion from boolean to int
602
if (criteria.containsKey(DEDUPE))
603         {
604             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
605             if (possibleBoolean instanceof Boolean JavaDoc)
606             {
607                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
608             }
609          }
610                   // check for conversion from boolean to int
611
if (criteria.containsKey(DELETED))
612         {
613             Object JavaDoc possibleBoolean = criteria.get(DELETED);
614             if (possibleBoolean instanceof Boolean JavaDoc)
615             {
616                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
617             }
618          }
619                   // check for conversion from boolean to int
620
if (criteria.containsKey(LOCKED))
621         {
622             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
623             if (possibleBoolean instanceof Boolean JavaDoc)
624             {
625                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
626             }
627          }
628                   // check for conversion from boolean to int
629
if (criteria.containsKey(ISDEFAULT))
630         {
631             Object JavaDoc possibleBoolean = criteria.get(ISDEFAULT);
632             if (possibleBoolean instanceof Boolean JavaDoc)
633             {
634                 criteria.add(ISDEFAULT, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
635             }
636          }
637       
638         setDbName(criteria);
639
640         if (con == null)
641         {
642             BasePeer.doDelete(criteria);
643         }
644         else
645         {
646             BasePeer.doDelete(criteria, con);
647         }
648      }
649
650     /**
651      * Method to do selects
652      *
653      * @throws TorqueException Any exceptions caught during processing will be
654      * rethrown wrapped into a TorqueException.
655      */

656     public static List JavaDoc doSelect(IssueType obj) throws TorqueException
657     {
658         return doSelect(buildSelectCriteria(obj));
659     }
660
661     /**
662      * Method to do inserts
663      *
664      * @throws TorqueException Any exceptions caught during processing will be
665      * rethrown wrapped into a TorqueException.
666      */

667     public static void doInsert(IssueType obj) throws TorqueException
668     {
669           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
670           obj.setNew(false);
671         obj.setModified(false);
672     }
673
674     /**
675      * @param obj the data object to update in the database.
676      * @throws TorqueException Any exceptions caught during processing will be
677      * rethrown wrapped into a TorqueException.
678      */

679     public static void doUpdate(IssueType obj) throws TorqueException
680     {
681         doUpdate(buildCriteria(obj));
682         obj.setModified(false);
683     }
684
685     /**
686      * @param obj the data object to delete in the database.
687      * @throws TorqueException Any exceptions caught during processing will be
688      * rethrown wrapped into a TorqueException.
689      */

690     public static void doDelete(IssueType obj) throws TorqueException
691     {
692         doDelete(buildSelectCriteria(obj));
693     }
694
695     /**
696      * Method to do inserts. This method is to be used during a transaction,
697      * otherwise use the doInsert(IssueType) method. It will take
698      * care of the connection details internally.
699      *
700      * @param obj the data object to insert into the database.
701      * @param con the connection to use
702      * @throws TorqueException Any exceptions caught during processing will be
703      * rethrown wrapped into a TorqueException.
704      */

705     public static void doInsert(IssueType obj, Connection JavaDoc con)
706         throws TorqueException
707     {
708           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
709           obj.setNew(false);
710         obj.setModified(false);
711     }
712
713     /**
714      * Method to do update. This method is to be used during a transaction,
715      * otherwise use the doUpdate(IssueType) method. It will take
716      * care of the connection details internally.
717      *
718      * @param obj the data object to update in the database.
719      * @param con the connection to use
720      * @throws TorqueException Any exceptions caught during processing will be
721      * rethrown wrapped into a TorqueException.
722      */

723     public static void doUpdate(IssueType obj, Connection JavaDoc con)
724         throws TorqueException
725     {
726         doUpdate(buildCriteria(obj), con);
727         obj.setModified(false);
728     }
729
730     /**
731      * Method to delete. This method is to be used during a transaction,
732      * otherwise use the doDelete(IssueType) method. It will take
733      * care of the connection details internally.
734      *
735      * @param obj the data object to delete in the database.
736      * @param con the connection to use
737      * @throws TorqueException Any exceptions caught during processing will be
738      * rethrown wrapped into a TorqueException.
739      */

740     public static void doDelete(IssueType obj, Connection JavaDoc con)
741         throws TorqueException
742     {
743         doDelete(buildSelectCriteria(obj), con);
744     }
745
746     /**
747      * Method to do deletes.
748      *
749      * @param pk ObjectKey that is used DELETE from database.
750      * @throws TorqueException Any exceptions caught during processing will be
751      * rethrown wrapped into a TorqueException.
752      */

753     public static void doDelete(ObjectKey pk) throws TorqueException
754     {
755         BaseIssueTypePeer
756            .doDelete(pk, (Connection JavaDoc) null);
757     }
758
759     /**
760      * Method to delete. This method is to be used during a transaction,
761      * otherwise use the doDelete(ObjectKey) method. It will take
762      * care of the connection details internally.
763      *
764      * @param pk the primary key for the object to delete in the database.
765      * @param con the connection to use
766      * @throws TorqueException Any exceptions caught during processing will be
767      * rethrown wrapped into a TorqueException.
768      */

769     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
770         throws TorqueException
771     {
772         doDelete(buildCriteria(pk), con);
773     }
774
775     /** Build a Criteria object from an ObjectKey */
776     public static Criteria buildCriteria( ObjectKey pk )
777     {
778         Criteria criteria = new Criteria();
779               criteria.add(ISSUE_TYPE_ID, pk);
780           return criteria;
781      }
782
783     /** Build a Criteria object from the data object for this peer */
784     public static Criteria buildCriteria( IssueType obj )
785     {
786         Criteria criteria = new Criteria(DATABASE_NAME);
787               if (!obj.isNew())
788             criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId());
789               criteria.add(NAME, obj.getName());
790               criteria.add(DESCRIPTION, obj.getDescription());
791               criteria.add(PARENT_ID, obj.getParentId());
792               criteria.add(DEDUPE, obj.getDedupe());
793               criteria.add(DELETED, obj.getDeleted());
794               criteria.add(LOCKED, obj.getLocked());
795               criteria.add(ISDEFAULT, obj.getIsdefault());
796           return criteria;
797     }
798
799     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
800     public static Criteria buildSelectCriteria( IssueType obj )
801     {
802         Criteria criteria = new Criteria(DATABASE_NAME);
803               if (!obj.isNew())
804                     criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId());
805                           criteria.add(NAME, obj.getName());
806                           criteria.add(DESCRIPTION, obj.getDescription());
807                           criteria.add(PARENT_ID, obj.getParentId());
808                           criteria.add(DEDUPE, obj.getDedupe());
809                           criteria.add(DELETED, obj.getDeleted());
810                           criteria.add(LOCKED, obj.getLocked());
811                           criteria.add(ISDEFAULT, obj.getIsdefault());
812               return criteria;
813     }
814  
815     
816         /**
817      * Retrieve a single object by pk
818      *
819      * @param pk the primary key
820      * @throws TorqueException Any exceptions caught during processing will be
821      * rethrown wrapped into a TorqueException.
822      * @throws NoRowsException Primary key was not found in database.
823      * @throws TooManyRowsException Primary key was not found in database.
824      */

825     public static IssueType retrieveByPK(Integer JavaDoc pk)
826         throws TorqueException, NoRowsException, TooManyRowsException
827     {
828         return retrieveByPK(SimpleKey.keyFor(pk));
829     }
830
831     /**
832      * Retrieve a single object by pk
833      *
834      * @param pk the primary key
835      * @param con the connection to use
836      * @throws TorqueException Any exceptions caught during processing will be
837      * rethrown wrapped into a TorqueException.
838      * @throws NoRowsException Primary key was not found in database.
839      * @throws TooManyRowsException Primary key was not found in database.
840      */

841     public static IssueType retrieveByPK(Integer JavaDoc pk, Connection JavaDoc con)
842         throws TorqueException, NoRowsException, TooManyRowsException
843     {
844         return retrieveByPK(SimpleKey.keyFor(pk), con);
845     }
846   
847     /**
848      * Retrieve a single object by pk
849      *
850      * @param pk the primary key
851      * @throws TorqueException Any exceptions caught during processing will be
852      * rethrown wrapped into a TorqueException.
853      * @throws NoRowsException Primary key was not found in database.
854      * @throws TooManyRowsException Primary key was not found in database.
855      */

856     public static IssueType retrieveByPK(ObjectKey pk)
857         throws TorqueException, NoRowsException, TooManyRowsException
858     {
859         Connection JavaDoc db = null;
860         IssueType retVal = null;
861         try
862         {
863             db = Torque.getConnection(DATABASE_NAME);
864             retVal = retrieveByPK(pk, db);
865         }
866         finally
867         {
868             Torque.closeConnection(db);
869         }
870         return(retVal);
871     }
872
873     /**
874      * Retrieve a single object by pk
875      *
876      * @param pk the primary key
877      * @param con the connection to use
878      * @throws TorqueException Any exceptions caught during processing will be
879      * rethrown wrapped into a TorqueException.
880      * @throws NoRowsException Primary key was not found in database.
881      * @throws TooManyRowsException Primary key was not found in database.
882      */

883     public static IssueType retrieveByPK(ObjectKey pk, Connection JavaDoc con)
884         throws TorqueException, NoRowsException, TooManyRowsException
885     {
886         Criteria criteria = buildCriteria(pk);
887         List JavaDoc v = doSelect(criteria, con);
888         if (v.size() == 0)
889         {
890             throw new NoRowsException("Failed to select a row.");
891         }
892         else if (v.size() > 1)
893         {
894             throw new TooManyRowsException("Failed to select only one row.");
895         }
896         else
897         {
898             return (IssueType)v.get(0);
899         }
900     }
901
902     /**
903      * Retrieve a multiple objects by pk
904      *
905      * @param pks List of primary keys
906      * @throws TorqueException Any exceptions caught during processing will be
907      * rethrown wrapped into a TorqueException.
908      */

909     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
910         throws TorqueException
911     {
912         Connection JavaDoc db = null;
913         List JavaDoc retVal = null;
914         try
915         {
916            db = Torque.getConnection(DATABASE_NAME);
917            retVal = retrieveByPKs(pks, db);
918         }
919         finally
920         {
921             Torque.closeConnection(db);
922         }
923         return(retVal);
924     }
925
926     /**
927      * Retrieve a multiple objects by pk
928      *
929      * @param pks List of primary keys
930      * @param dbcon the connection to use
931      * @throws TorqueException Any exceptions caught during processing will be
932      * rethrown wrapped into a TorqueException.
933      */

934     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
935         throws TorqueException
936     {
937         List JavaDoc objs = null;
938         if (pks == null || pks.size() == 0)
939         {
940             objs = new LinkedList JavaDoc();
941         }
942         else
943         {
944             Criteria criteria = new Criteria();
945               criteria.addIn( ISSUE_TYPE_ID, pks );
946           objs = doSelect(criteria, dbcon);
947         }
948         return objs;
949     }
950
951  
952
953
954
955           
956                                 
957   
958     
959   
960       /**
961      * Returns the TableMap related to this peer. This method is not
962      * needed for general use but a specific application could have a need.
963      *
964      * @throws TorqueException Any exceptions caught during processing will be
965      * rethrown wrapped into a TorqueException.
966      */

967     protected static TableMap getTableMap()
968         throws TorqueException
969     {
970         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
971     }
972    
973     private static void setDbName(Criteria crit)
974     {
975         // Set the correct dbName if it has not been overridden
976
// crit.getDbName will return the same object if not set to
977
// another value so == check is okay and faster
978
if (crit.getDbName() == Torque.getDefaultDB())
979         {
980             crit.setDbName(DATABASE_NAME);
981         }
982     }
983 }
984
Popular Tags