KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

205     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
206         throws TorqueException
207     {
208                           // check for conversion from boolean to int
209
if (criteria.containsKey(ACTIVE))
210         {
211             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
212             if (possibleBoolean instanceof Boolean JavaDoc)
213             {
214                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
215             }
216          }
217                   // check for conversion from boolean to int
218
if (criteria.containsKey(LOCKED))
219         {
220             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
221             if (possibleBoolean instanceof Boolean JavaDoc)
222             {
223                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
224             }
225          }
226                   
227         setDbName(criteria);
228
229         if (con == null)
230         {
231             return BasePeer.doInsert(criteria);
232         }
233         else
234         {
235             return BasePeer.doInsert(criteria, con);
236         }
237     }
238
239     /**
240      * Add all the columns needed to create a new object.
241      *
242      * @param criteria object containing the columns to add.
243      * @throws TorqueException Any exceptions caught during processing will be
244      * rethrown wrapped into a TorqueException.
245      */

246     public static void addSelectColumns(Criteria criteria)
247             throws TorqueException
248     {
249           criteria.addSelectColumn(ISSUE_TYPE_ID);
250           criteria.addSelectColumn(OPTION_ID);
251           criteria.addSelectColumn(ACTIVE);
252           criteria.addSelectColumn(LOCKED);
253           criteria.addSelectColumn(PREFERRED_ORDER);
254           criteria.addSelectColumn(WEIGHT);
255       }
256
257     /**
258      * Create a new object of type cls from a resultset row starting
259      * from a specified offset. This is done so that you can select
260      * other rows than just those needed for this object. You may
261      * for example want to create two objects from the same row.
262      *
263      * @throws TorqueException Any exceptions caught during processing will be
264      * rethrown wrapped into a TorqueException.
265      */

266     public static RIssueTypeOption row2Object(Record row,
267                                              int offset,
268                                              Class JavaDoc cls)
269         throws TorqueException
270     {
271         try
272         {
273             RIssueTypeOption obj = (RIssueTypeOption) cls.newInstance();
274             RIssueTypeOptionPeer.populateObject(row, offset, obj);
275                   obj.setModified(false);
276               obj.setNew(false);
277
278             return obj;
279         }
280         catch (InstantiationException JavaDoc e)
281         {
282             throw new TorqueException(e);
283         }
284         catch (IllegalAccessException JavaDoc e)
285         {
286             throw new TorqueException(e);
287         }
288     }
289
290     /**
291      * Populates an object from a resultset row starting
292      * from a specified offset. This is done so that you can select
293      * other rows than just those needed for this object. You may
294      * for example want to create two objects from the same row.
295      *
296      * @throws TorqueException Any exceptions caught during processing will be
297      * rethrown wrapped into a TorqueException.
298      */

299     public static void populateObject(Record row,
300                                       int offset,
301                                       RIssueTypeOption obj)
302         throws TorqueException
303     {
304         try
305         {
306                 obj.setIssueTypeId(row.getValue(offset + 0).asIntegerObj());
307                   obj.setOptionId(row.getValue(offset + 1).asIntegerObj());
308                   obj.setActive(row.getValue(offset + 2).asBoolean());
309                   obj.setLocked(row.getValue(offset + 3).asBoolean());
310                   obj.setOrder(row.getValue(offset + 4).asInt());
311                   obj.setWeight(row.getValue(offset + 5).asInt());
312               }
313         catch (DataSetException e)
314         {
315             throw new TorqueException(e);
316         }
317     }
318
319     /**
320      * Method to do selects.
321      *
322      * @param criteria object used to create the SELECT statement.
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) throws TorqueException
328     {
329         return populateObjects(doSelectVillageRecords(criteria));
330     }
331
332     /**
333      * Method to do selects within a transaction.
334      *
335      * @param criteria object used to create the SELECT statement.
336      * @param con the connection to use
337      * @return List of selected Objects
338      * @throws TorqueException Any exceptions caught during processing will be
339      * rethrown wrapped into a TorqueException.
340      */

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

357     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
358         throws TorqueException
359     {
360         return BaseRIssueTypeOptionPeer
361             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
362     }
363
364     /**
365      * Grabs the raw Village records to be formed into objects.
366      * This method should be used for transactions
367      *
368      * @param criteria object used to create the SELECT statement.
369      * @param con the connection to use
370      * @throws TorqueException Any exceptions caught during processing will be
371      * rethrown wrapped into a TorqueException.
372      */

373     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
374         throws TorqueException
375     {
376         if (criteria.getSelectColumns().size() == 0)
377         {
378             addSelectColumns(criteria);
379         }
380
381                           // check for conversion from boolean to int
382
if (criteria.containsKey(ACTIVE))
383         {
384             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
385             if (possibleBoolean instanceof Boolean JavaDoc)
386             {
387                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
388             }
389          }
390                   // check for conversion from boolean to int
391
if (criteria.containsKey(LOCKED))
392         {
393             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
394             if (possibleBoolean instanceof Boolean JavaDoc)
395             {
396                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
397             }
398          }
399                   
400         setDbName(criteria);
401
402         // BasePeer returns a List of Value (Village) arrays. The array
403
// order follows the order columns were placed in the Select clause.
404
if (con == null)
405         {
406             return BasePeer.doSelect(criteria);
407         }
408         else
409         {
410             return BasePeer.doSelect(criteria, con);
411         }
412     }
413
414     /**
415      * The returned List will contain objects of the default type or
416      * objects that inherit from the default.
417      *
418      * @throws TorqueException Any exceptions caught during processing will be
419      * rethrown wrapped into a TorqueException.
420      */

421     public static List JavaDoc populateObjects(List JavaDoc records)
422         throws TorqueException
423     {
424         List JavaDoc results = new ArrayList JavaDoc(records.size());
425
426         // populate the object(s)
427
for (int i = 0; i < records.size(); i++)
428         {
429             Record row = (Record) records.get(i);
430               results.add(RIssueTypeOptionPeer.row2Object(row, 1,
431                 RIssueTypeOptionPeer.getOMClass()));
432           }
433         return results;
434     }
435  
436
437     /**
438      * The class that the Peer will make instances of.
439      * If the BO is abstract then you must implement this method
440      * in the BO.
441      *
442      * @throws TorqueException Any exceptions caught during processing will be
443      * rethrown wrapped into a TorqueException.
444      */

445     public static Class JavaDoc getOMClass()
446         throws TorqueException
447     {
448         return CLASS_DEFAULT;
449     }
450
451     /**
452      * Method to do updates.
453      *
454      * @param criteria object containing data that is used to create the UPDATE
455      * statement.
456      * @throws TorqueException Any exceptions caught during processing will be
457      * rethrown wrapped into a TorqueException.
458      */

459     public static void doUpdate(Criteria criteria) throws TorqueException
460     {
461          BaseRIssueTypeOptionPeer
462             .doUpdate(criteria, (Connection JavaDoc) null);
463     }
464
465     /**
466      * Method to do updates. This method is to be used during a transaction,
467      * otherwise use the doUpdate(Criteria) method. It will take care of
468      * the connection details internally.
469      *
470      * @param criteria object containing data that is used to create the UPDATE
471      * statement.
472      * @param con the connection to use
473      * @throws TorqueException Any exceptions caught during processing will be
474      * rethrown wrapped into a TorqueException.
475      */

476     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
477         throws TorqueException
478     {
479         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
480                    selectCriteria.put(ISSUE_TYPE_ID, criteria.remove(ISSUE_TYPE_ID));
481                        selectCriteria.put(OPTION_ID, criteria.remove(OPTION_ID));
482                   // check for conversion from boolean to int
483
if (criteria.containsKey(ACTIVE))
484         {
485             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
486             if (possibleBoolean instanceof Boolean JavaDoc)
487             {
488                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
489             }
490          }
491                       // check for conversion from boolean to int
492
if (criteria.containsKey(LOCKED))
493         {
494             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
495             if (possibleBoolean instanceof Boolean JavaDoc)
496             {
497                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
498             }
499          }
500                               
501         setDbName(criteria);
502
503         if (con == null)
504         {
505             BasePeer.doUpdate(selectCriteria, criteria);
506         }
507         else
508         {
509             BasePeer.doUpdate(selectCriteria, criteria, con);
510         }
511     }
512
513     /**
514      * Method to do deletes.
515      *
516      * @param criteria object containing data that is used DELETE from database.
517      * @throws TorqueException Any exceptions caught during processing will be
518      * rethrown wrapped into a TorqueException.
519      */

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

536      public static void doDelete(Criteria criteria, Connection JavaDoc con)
537         throws TorqueException
538      {
539                           // check for conversion from boolean to int
540
if (criteria.containsKey(ACTIVE))
541         {
542             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
543             if (possibleBoolean instanceof Boolean JavaDoc)
544             {
545                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
546             }
547          }
548                   // check for conversion from boolean to int
549
if (criteria.containsKey(LOCKED))
550         {
551             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
552             if (possibleBoolean instanceof Boolean JavaDoc)
553             {
554                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
555             }
556          }
557                   
558         setDbName(criteria);
559
560         if (con == null)
561         {
562             BasePeer.doDelete(criteria);
563         }
564         else
565         {
566             BasePeer.doDelete(criteria, con);
567         }
568      }
569
570     /**
571      * Method to do selects
572      *
573      * @throws TorqueException Any exceptions caught during processing will be
574      * rethrown wrapped into a TorqueException.
575      */

576     public static List JavaDoc doSelect(RIssueTypeOption obj) throws TorqueException
577     {
578         return doSelect(buildSelectCriteria(obj));
579     }
580
581     /**
582      * Method to do inserts
583      *
584      * @throws TorqueException Any exceptions caught during processing will be
585      * rethrown wrapped into a TorqueException.
586      */

587     public static void doInsert(RIssueTypeOption obj) throws TorqueException
588     {
589           doInsert(buildCriteria(obj));
590           obj.setNew(false);
591         obj.setModified(false);
592     }
593
594     /**
595      * @param obj the data object to update in the database.
596      * @throws TorqueException Any exceptions caught during processing will be
597      * rethrown wrapped into a TorqueException.
598      */

599     public static void doUpdate(RIssueTypeOption obj) throws TorqueException
600     {
601         doUpdate(buildCriteria(obj));
602         obj.setModified(false);
603     }
604
605     /**
606      * @param obj the data object to delete in the database.
607      * @throws TorqueException Any exceptions caught during processing will be
608      * rethrown wrapped into a TorqueException.
609      */

610     public static void doDelete(RIssueTypeOption obj) throws TorqueException
611     {
612         doDelete(buildSelectCriteria(obj));
613     }
614
615     /**
616      * Method to do inserts. This method is to be used during a transaction,
617      * otherwise use the doInsert(RIssueTypeOption) method. It will take
618      * care of the connection details internally.
619      *
620      * @param obj the data object to insert into the database.
621      * @param con the connection to use
622      * @throws TorqueException Any exceptions caught during processing will be
623      * rethrown wrapped into a TorqueException.
624      */

625     public static void doInsert(RIssueTypeOption obj, Connection JavaDoc con)
626         throws TorqueException
627     {
628           doInsert(buildCriteria(obj), con);
629           obj.setNew(false);
630         obj.setModified(false);
631     }
632
633     /**
634      * Method to do update. This method is to be used during a transaction,
635      * otherwise use the doUpdate(RIssueTypeOption) method. It will take
636      * care of the connection details internally.
637      *
638      * @param obj the data object to update in the database.
639      * @param con the connection to use
640      * @throws TorqueException Any exceptions caught during processing will be
641      * rethrown wrapped into a TorqueException.
642      */

643     public static void doUpdate(RIssueTypeOption obj, Connection JavaDoc con)
644         throws TorqueException
645     {
646         doUpdate(buildCriteria(obj), con);
647         obj.setModified(false);
648     }
649
650     /**
651      * Method to delete. This method is to be used during a transaction,
652      * otherwise use the doDelete(RIssueTypeOption) method. It will take
653      * care of the connection details internally.
654      *
655      * @param obj the data object to delete in the database.
656      * @param con the connection to use
657      * @throws TorqueException Any exceptions caught during processing will be
658      * rethrown wrapped into a TorqueException.
659      */

660     public static void doDelete(RIssueTypeOption obj, Connection JavaDoc con)
661         throws TorqueException
662     {
663         doDelete(buildSelectCriteria(obj), con);
664     }
665
666     /**
667      * Method to do deletes.
668      *
669      * @param pk ObjectKey that is used DELETE from database.
670      * @throws TorqueException Any exceptions caught during processing will be
671      * rethrown wrapped into a TorqueException.
672      */

673     public static void doDelete(ObjectKey pk) throws TorqueException
674     {
675         BaseRIssueTypeOptionPeer
676            .doDelete(pk, (Connection JavaDoc) null);
677     }
678
679     /**
680      * Method to delete. This method is to be used during a transaction,
681      * otherwise use the doDelete(ObjectKey) method. It will take
682      * care of the connection details internally.
683      *
684      * @param pk the primary key for the object to delete in the database.
685      * @param con the connection to use
686      * @throws TorqueException Any exceptions caught during processing will be
687      * rethrown wrapped into a TorqueException.
688      */

689     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
690         throws TorqueException
691     {
692         doDelete(buildCriteria(pk), con);
693     }
694
695     /** Build a Criteria object from an ObjectKey */
696     public static Criteria buildCriteria( ObjectKey pk )
697     {
698         Criteria criteria = new Criteria();
699           SimpleKey[] keys = (SimpleKey[])pk.getValue();
700                     criteria.add(ISSUE_TYPE_ID, keys[0]);
701                       criteria.add(OPTION_ID, keys[1]);
702                     return criteria;
703      }
704
705     /** Build a Criteria object from the data object for this peer */
706     public static Criteria buildCriteria( RIssueTypeOption obj )
707     {
708         Criteria criteria = new Criteria(DATABASE_NAME);
709               criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId());
710               criteria.add(OPTION_ID, obj.getOptionId());
711               criteria.add(ACTIVE, obj.getActive());
712               criteria.add(LOCKED, obj.getLocked());
713               criteria.add(PREFERRED_ORDER, obj.getOrder());
714               criteria.add(WEIGHT, obj.getWeight());
715           return criteria;
716     }
717
718     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
719     public static Criteria buildSelectCriteria( RIssueTypeOption obj )
720     {
721         Criteria criteria = new Criteria(DATABASE_NAME);
722                       criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId());
723                           criteria.add(OPTION_ID, obj.getOptionId());
724                           criteria.add(ACTIVE, obj.getActive());
725                           criteria.add(LOCKED, obj.getLocked());
726                           criteria.add(PREFERRED_ORDER, obj.getOrder());
727                           criteria.add(WEIGHT, obj.getWeight());
728               return criteria;
729     }
730  
731     
732     
733     /**
734      * Retrieve a single object by pk
735      *
736      * @param pk the primary key
737      * @throws TorqueException Any exceptions caught during processing will be
738      * rethrown wrapped into a TorqueException.
739      * @throws NoRowsException Primary key was not found in database.
740      * @throws TooManyRowsException Primary key was not found in database.
741      */

742     public static RIssueTypeOption retrieveByPK(ObjectKey pk)
743         throws TorqueException, NoRowsException, TooManyRowsException
744     {
745         Connection JavaDoc db = null;
746         RIssueTypeOption retVal = null;
747         try
748         {
749             db = Torque.getConnection(DATABASE_NAME);
750             retVal = retrieveByPK(pk, db);
751         }
752         finally
753         {
754             Torque.closeConnection(db);
755         }
756         return(retVal);
757     }
758
759     /**
760      * Retrieve a single object by pk
761      *
762      * @param pk the primary key
763      * @param con the connection to use
764      * @throws TorqueException Any exceptions caught during processing will be
765      * rethrown wrapped into a TorqueException.
766      * @throws NoRowsException Primary key was not found in database.
767      * @throws TooManyRowsException Primary key was not found in database.
768      */

769     public static RIssueTypeOption retrieveByPK(ObjectKey pk, Connection JavaDoc con)
770         throws TorqueException, NoRowsException, TooManyRowsException
771     {
772         Criteria criteria = buildCriteria(pk);
773         List JavaDoc v = doSelect(criteria, con);
774         if (v.size() == 0)
775         {
776             throw new NoRowsException("Failed to select a row.");
777         }
778         else if (v.size() > 1)
779         {
780             throw new TooManyRowsException("Failed to select only one row.");
781         }
782         else
783         {
784             return (RIssueTypeOption)v.get(0);
785         }
786     }
787
788     /**
789      * Retrieve a multiple objects by pk
790      *
791      * @param pks List of primary keys
792      * @throws TorqueException Any exceptions caught during processing will be
793      * rethrown wrapped into a TorqueException.
794      */

795     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
796         throws TorqueException
797     {
798         Connection JavaDoc db = null;
799         List JavaDoc retVal = null;
800         try
801         {
802            db = Torque.getConnection(DATABASE_NAME);
803            retVal = retrieveByPKs(pks, db);
804         }
805         finally
806         {
807             Torque.closeConnection(db);
808         }
809         return(retVal);
810     }
811
812     /**
813      * Retrieve a multiple objects by pk
814      *
815      * @param pks List of primary keys
816      * @param dbcon the connection to use
817      * @throws TorqueException Any exceptions caught during processing will be
818      * rethrown wrapped into a TorqueException.
819      */

820     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
821         throws TorqueException
822     {
823         List JavaDoc objs = null;
824         if (pks == null || pks.size() == 0)
825         {
826             objs = new LinkedList JavaDoc();
827         }
828         else
829         {
830             Criteria criteria = new Criteria();
831               Iterator JavaDoc iter = pks.iterator();
832             while (iter.hasNext())
833             {
834                 ObjectKey pk = (ObjectKey)iter.next();
835                 SimpleKey[] keys = (SimpleKey[])pk.getValue();
836                             Criteria.Criterion c0 = criteria.getNewCriterion(
837                         ISSUE_TYPE_ID, keys[0], Criteria.EQUAL);
838                                     Criteria.Criterion c1 = criteria.getNewCriterion(
839                         OPTION_ID, keys[1], Criteria.EQUAL);
840                                     c0.and(c1);
841                           criteria.or(c0);
842             }
843           objs = doSelect(criteria, dbcon);
844         }
845         return objs;
846     }
847
848  
849     /**
850      * retrieve object using using pk values.
851      *
852        * @param issue_type_id Integer
853        * @param option_id Integer
854        */

855     public static RIssueTypeOption retrieveByPK(
856        Integer JavaDoc issue_type_id
857           , Integer JavaDoc option_id
858               ) throws TorqueException
859     {
860         Connection JavaDoc db = null;
861         RIssueTypeOption retVal = null;
862         try
863         {
864            db = Torque.getConnection(DATABASE_NAME);
865            retVal = retrieveByPK(
866          issue_type_id
867           , option_id
868                      , db);
869         }
870         finally
871         {
872             Torque.closeConnection(db);
873         }
874         return(retVal);
875     }
876
877       /**
878      * retrieve object using using pk values.
879      *
880        * @param issue_type_id Integer
881        * @param option_id Integer
882        * @param con Connection
883      */

884     public static RIssueTypeOption retrieveByPK(
885        Integer JavaDoc issue_type_id
886           , Integer JavaDoc option_id
887              ,Connection JavaDoc con) throws TorqueException
888     {
889
890         Criteria criteria = new Criteria(5);
891           criteria.add(ISSUE_TYPE_ID, issue_type_id);
892           criteria.add(OPTION_ID, option_id);
893           List JavaDoc v = doSelect(criteria, con);
894         if (v.size() != 1)
895         {
896             throw new TorqueException("Failed to select one and only one row.");
897         }
898         else
899         {
900             return (RIssueTypeOption) v.get(0);
901         }
902     }
903
904
905
906             
907                                               
908                 
909                 
910
911     /**
912      * selects a collection of RIssueTypeOption objects pre-filled with their
913      * AttributeOption objects.
914      *
915      * This method is protected by default in order to keep the public
916      * api reasonable. You can provide public methods for those you
917      * actually need in RIssueTypeOptionPeer.
918      *
919      * @throws TorqueException Any exceptions caught during processing will be
920      * rethrown wrapped into a TorqueException.
921      */

922     protected static List JavaDoc doSelectJoinAttributeOption(Criteria criteria)
923         throws TorqueException
924     {
925         setDbName(criteria);
926
927         RIssueTypeOptionPeer.addSelectColumns(criteria);
928         int offset = numColumns + 1;
929         AttributeOptionPeer.addSelectColumns(criteria);
930
931
932                         criteria.addJoin(RIssueTypeOptionPeer.OPTION_ID,
933             AttributeOptionPeer.OPTION_ID);
934         
935
936                                                               // check for conversion from boolean to int
937
if (criteria.containsKey(ACTIVE))
938         {
939             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
940             if (possibleBoolean instanceof Boolean JavaDoc)
941             {
942                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
943             }
944          }
945                                     // check for conversion from boolean to int
946
if (criteria.containsKey(LOCKED))
947         {
948             Object JavaDoc possibleBoolean = criteria.get(LOCKED);
949             if (possibleBoolean instanceof Boolean JavaDoc)
950             {
951                 criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
952             }
953          }
954                                                       
955         List JavaDoc rows = BasePeer.doSelect(criteria);
956         List JavaDoc results = new ArrayList JavaDoc();
957
958         for (int i = 0; i < rows.size(); i++)
959         {
960             Record row = (Record) rows.get(i);
961
962                             Class JavaDoc omClass = RIssueTypeOptionPeer.getOMClass();
963                     RIssueTypeOption obj1 = (RIssueTypeOption) RIssueTypeOptionPeer
964                 .row2Object(row, 1, omClass);
965                      omClass = AttributeOptionPeer.getOMClass();
966                     AttributeOption obj2 = (AttributeOption)AttributeOptionPeer
967                 .row2Object(row, offset, omClass);
968
969             boolean newObject = true;
970             for (int j = 0; j < results.size(); j++)
971             {
972                 RIssueTypeOption temp_obj1 = (RIssueTypeOption)results.get(j);
973                 AttributeOption temp_obj2 = (AttributeOption)temp_obj1.getAttributeOption();
974                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
975                 {
976                     newObject = false;
977                               temp_obj2.addRIssueTypeOption(obj1);
978                               break;
979                 }
980             }
981                       if (newObject)
982             {
983                 obj2.initRIssueTypeOptions();
984                 obj2.addRIssueTypeOption(obj1);
985             }
986                       results.add(obj1);
987         }
988         return results;
989     }
990                                                             
991                 
992                 
993
994     /**
995      * selects a collection of RIssueTypeOption objects pre-filled with their
996      * IssueType objects.
997      *
998      * This method is protected by default in order to keep the public
999      * api reasonable. You can provide public methods for those you
1000     * actually need in RIssueTypeOptionPeer.
1001     *
1002     * @throws TorqueException Any exceptions caught during processing will be
1003     * rethrown wrapped into a TorqueException.
1004     */

1005    protected static List JavaDoc doSelectJoinIssueType(Criteria criteria)
1006        throws TorqueException
1007    {
1008        setDbName(criteria);
1009
1010        RIssueTypeOptionPeer.addSelectColumns(criteria);
1011        int offset = numColumns + 1;
1012        IssueTypePeer.addSelectColumns(criteria);
1013
1014
1015                        criteria.addJoin(RIssueTypeOptionPeer.ISSUE_TYPE_ID,
1016            IssueTypePeer.ISSUE_TYPE_ID);
1017        
1018
1019                                                              // check for conversion from boolean to int
1020
if (criteria.containsKey(ACTIVE))
1021        {
1022            Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
1023            if (possibleBoolean instanceof Boolean JavaDoc)
1024            {
1025                criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1026            }
1027         }
1028                                    // check for conversion from boolean to int
1029
if (criteria.containsKey(LOCKED))
1030        {
1031            Object JavaDoc possibleBoolean = criteria.get(LOCKED);
1032            if (possibleBoolean instanceof Boolean JavaDoc)
1033            {
1034                criteria.add(LOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1035            }
1036         }
1037                                                      
1038        List JavaDoc rows = BasePeer.doSelect(criteria);
1039        List JavaDoc results = new ArrayList JavaDoc();
1040
1041        for (int i = 0; i < rows.size(); i++)
1042        {
1043            Record row = (Record) rows.get(i);
1044
1045                            Class JavaDoc omClass = RIssueTypeOptionPeer.getOMClass();
1046                    RIssueTypeOption obj1 = (RIssueTypeOption) RIssueTypeOptionPeer
1047                .row2Object(row, 1, omClass);
1048                     omClass = IssueTypePeer.getOMClass();
1049                    IssueType obj2 = (IssueType)IssueTypePeer
1050                .row2Object(row, offset, omClass);
1051
1052            boolean newObject = true;
1053            for (int j = 0; j < results.size(); j++)
1054            {
1055                RIssueTypeOption temp_obj1 = (RIssueTypeOption)results.get(j);
1056                IssueType temp_obj2 = (IssueType)temp_obj1.getIssueType();
1057                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1058                {
1059                    newObject = false;
1060                              temp_obj2.addRIssueTypeOption(obj1);
1061                              break;
1062                }
1063            }
1064                      if (newObject)
1065            {
1066                obj2.initRIssueTypeOptions();
1067                obj2.addRIssueTypeOption(obj1);
1068            }
1069                      results.add(obj1);
1070        }
1071        return results;
1072    }
1073                    
1074  
1075    
1076  
1077      /**
1078     * Returns the TableMap related to this peer. This method is not
1079     * needed for general use but a specific application could have a need.
1080     *
1081     * @throws TorqueException Any exceptions caught during processing will be
1082     * rethrown wrapped into a TorqueException.
1083     */

1084    protected static TableMap getTableMap()
1085        throws TorqueException
1086    {
1087        return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1088    }
1089   
1090    private static void setDbName(Criteria crit)
1091    {
1092        // Set the correct dbName if it has not been overridden
1093
// crit.getDbName will return the same object if not set to
1094
// another value so == check is okay and faster
1095
if (crit.getDbName() == Torque.getDefaultDB())
1096        {
1097            crit.setDbName(DATABASE_NAME);
1098        }
1099    }
1100}
1101
Popular Tags