KickJava   Java API By Example, From Geeks To Geeks.

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


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  */

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

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

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

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

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

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

238     public static void addSelectColumns(Criteria criteria)
239             throws TorqueException
240     {
241           criteria.addSelectColumn(TRANSITION_ID);
242           criteria.addSelectColumn(ROLE_ID);
243           criteria.addSelectColumn(ATTRIBUTE_ID);
244           criteria.addSelectColumn(FROM_OPTION_ID);
245           criteria.addSelectColumn(TO_OPTION_ID);
246           criteria.addSelectColumn(DISABLED_IF_BLOCKED);
247       }
248
249     /**
250      * Create a new object of type cls from a resultset row starting
251      * from a specified offset. This is done so that you can select
252      * other rows than just those needed for this object. You may
253      * for example want to create two objects from the same row.
254      *
255      * @throws TorqueException Any exceptions caught during processing will be
256      * rethrown wrapped into a TorqueException.
257      */

258     public static Transition row2Object(Record row,
259                                              int offset,
260                                              Class JavaDoc cls)
261         throws TorqueException
262     {
263         try
264         {
265             Transition obj = (Transition) cls.newInstance();
266             TransitionPeer.populateObject(row, offset, obj);
267                   obj.setModified(false);
268               obj.setNew(false);
269
270             return obj;
271         }
272         catch (InstantiationException JavaDoc e)
273         {
274             throw new TorqueException(e);
275         }
276         catch (IllegalAccessException JavaDoc e)
277         {
278             throw new TorqueException(e);
279         }
280     }
281
282     /**
283      * Populates an object 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 void populateObject(Record row,
292                                       int offset,
293                                       Transition obj)
294         throws TorqueException
295     {
296         try
297         {
298                 obj.setTransitionId(row.getValue(offset + 0).asIntegerObj());
299                   obj.setRoleId(row.getValue(offset + 1).asIntegerObj());
300                   obj.setAttributeId(row.getValue(offset + 2).asIntegerObj());
301                   obj.setFromOptionId(row.getValue(offset + 3).asIntegerObj());
302                   obj.setToOptionId(row.getValue(offset + 4).asIntegerObj());
303                   obj.setDisabledIfBlocked(row.getValue(offset + 5).asBoolean());
304               }
305         catch (DataSetException e)
306         {
307             throw new TorqueException(e);
308         }
309     }
310
311     /**
312      * Method to do selects.
313      *
314      * @param criteria object used to create the SELECT statement.
315      * @return List of selected Objects
316      * @throws TorqueException Any exceptions caught during processing will be
317      * rethrown wrapped into a TorqueException.
318      */

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

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

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

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

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

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

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

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

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

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

540     public static List JavaDoc doSelect(Transition obj) throws TorqueException
541     {
542         return doSelect(buildSelectCriteria(obj));
543     }
544
545     /**
546      * Method to do inserts
547      *
548      * @throws TorqueException Any exceptions caught during processing will be
549      * rethrown wrapped into a TorqueException.
550      */

551     public static void doInsert(Transition obj) throws TorqueException
552     {
553           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
554           obj.setNew(false);
555         obj.setModified(false);
556     }
557
558     /**
559      * @param obj the data object to update in the database.
560      * @throws TorqueException Any exceptions caught during processing will be
561      * rethrown wrapped into a TorqueException.
562      */

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

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

589     public static void doInsert(Transition obj, Connection JavaDoc con)
590         throws TorqueException
591     {
592           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
593           obj.setNew(false);
594         obj.setModified(false);
595     }
596
597     /**
598      * Method to do update. This method is to be used during a transaction,
599      * otherwise use the doUpdate(Transition) method. It will take
600      * care of the connection details internally.
601      *
602      * @param obj the data object to update in the database.
603      * @param con the connection to use
604      * @throws TorqueException Any exceptions caught during processing will be
605      * rethrown wrapped into a TorqueException.
606      */

607     public static void doUpdate(Transition obj, Connection JavaDoc con)
608         throws TorqueException
609     {
610         doUpdate(buildCriteria(obj), con);
611         obj.setModified(false);
612     }
613
614     /**
615      * Method to delete. This method is to be used during a transaction,
616      * otherwise use the doDelete(Transition) method. It will take
617      * care of the connection details internally.
618      *
619      * @param obj the data object to delete in the database.
620      * @param con the connection to use
621      * @throws TorqueException Any exceptions caught during processing will be
622      * rethrown wrapped into a TorqueException.
623      */

624     public static void doDelete(Transition obj, Connection JavaDoc con)
625         throws TorqueException
626     {
627         doDelete(buildSelectCriteria(obj), con);
628     }
629
630     /**
631      * Method to do deletes.
632      *
633      * @param pk ObjectKey that is used DELETE from database.
634      * @throws TorqueException Any exceptions caught during processing will be
635      * rethrown wrapped into a TorqueException.
636      */

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

653     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
654         throws TorqueException
655     {
656         doDelete(buildCriteria(pk), con);
657     }
658
659     /** Build a Criteria object from an ObjectKey */
660     public static Criteria buildCriteria( ObjectKey pk )
661     {
662         Criteria criteria = new Criteria();
663               criteria.add(TRANSITION_ID, pk);
664           return criteria;
665      }
666
667     /** Build a Criteria object from the data object for this peer */
668     public static Criteria buildCriteria( Transition obj )
669     {
670         Criteria criteria = new Criteria(DATABASE_NAME);
671               if (!obj.isNew())
672             criteria.add(TRANSITION_ID, obj.getTransitionId());
673               criteria.add(ROLE_ID, obj.getRoleId());
674               criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
675               criteria.add(FROM_OPTION_ID, obj.getFromOptionId());
676               criteria.add(TO_OPTION_ID, obj.getToOptionId());
677               criteria.add(DISABLED_IF_BLOCKED, obj.getDisabledIfBlocked());
678           return criteria;
679     }
680
681     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
682     public static Criteria buildSelectCriteria( Transition obj )
683     {
684         Criteria criteria = new Criteria(DATABASE_NAME);
685               if (!obj.isNew())
686                     criteria.add(TRANSITION_ID, obj.getTransitionId());
687                           criteria.add(ROLE_ID, obj.getRoleId());
688                           criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
689                           criteria.add(FROM_OPTION_ID, obj.getFromOptionId());
690                           criteria.add(TO_OPTION_ID, obj.getToOptionId());
691                           criteria.add(DISABLED_IF_BLOCKED, obj.getDisabledIfBlocked());
692               return criteria;
693     }
694  
695     
696         /**
697      * Retrieve a single object by pk
698      *
699      * @param pk the primary key
700      * @throws TorqueException Any exceptions caught during processing will be
701      * rethrown wrapped into a TorqueException.
702      * @throws NoRowsException Primary key was not found in database.
703      * @throws TooManyRowsException Primary key was not found in database.
704      */

705     public static Transition retrieveByPK(Integer JavaDoc pk)
706         throws TorqueException, NoRowsException, TooManyRowsException
707     {
708         return retrieveByPK(SimpleKey.keyFor(pk));
709     }
710
711     /**
712      * Retrieve a single object by pk
713      *
714      * @param pk the primary key
715      * @param con the connection to use
716      * @throws TorqueException Any exceptions caught during processing will be
717      * rethrown wrapped into a TorqueException.
718      * @throws NoRowsException Primary key was not found in database.
719      * @throws TooManyRowsException Primary key was not found in database.
720      */

721     public static Transition retrieveByPK(Integer JavaDoc pk, Connection JavaDoc con)
722         throws TorqueException, NoRowsException, TooManyRowsException
723     {
724         return retrieveByPK(SimpleKey.keyFor(pk), con);
725     }
726   
727     /**
728      * Retrieve a single object by pk
729      *
730      * @param pk the primary key
731      * @throws TorqueException Any exceptions caught during processing will be
732      * rethrown wrapped into a TorqueException.
733      * @throws NoRowsException Primary key was not found in database.
734      * @throws TooManyRowsException Primary key was not found in database.
735      */

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

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

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

814     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
815         throws TorqueException
816     {
817         List JavaDoc objs = null;
818         if (pks == null || pks.size() == 0)
819         {
820             objs = new LinkedList JavaDoc();
821         }
822         else
823         {
824             Criteria criteria = new Criteria();
825               criteria.addIn( TRANSITION_ID, pks );
826           objs = doSelect(criteria, dbcon);
827         }
828         return objs;
829     }
830
831  
832
833
834
835               
836                                               
837                 
838                 
839
840     /**
841      * selects a collection of Transition objects pre-filled with their
842      * Attribute objects.
843      *
844      * This method is protected by default in order to keep the public
845      * api reasonable. You can provide public methods for those you
846      * actually need in TransitionPeer.
847      *
848      * @throws TorqueException Any exceptions caught during processing will be
849      * rethrown wrapped into a TorqueException.
850      */

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

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

999     protected static List JavaDoc doSelectJoinAttributeOptionRelatedByToOptionId(Criteria criteria)
1000        throws TorqueException
1001    {
1002        setDbName(criteria);
1003
1004        TransitionPeer.addSelectColumns(criteria);
1005        int offset = numColumns + 1;
1006        AttributeOptionPeer.addSelectColumns(criteria);
1007
1008
1009                        criteria.addJoin(TransitionPeer.TO_OPTION_ID,
1010            AttributeOptionPeer.OPTION_ID);
1011        
1012
1013                                                                                                                    // check for conversion from boolean to int
1014
if (criteria.containsKey(DISABLED_IF_BLOCKED))
1015        {
1016            Object JavaDoc possibleBoolean = criteria.get(DISABLED_IF_BLOCKED);
1017            if (possibleBoolean instanceof Boolean JavaDoc)
1018            {
1019                criteria.add(DISABLED_IF_BLOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1020            }
1021         }
1022                  
1023        List JavaDoc rows = BasePeer.doSelect(criteria);
1024        List JavaDoc results = new ArrayList JavaDoc();
1025
1026        for (int i = 0; i < rows.size(); i++)
1027        {
1028            Record row = (Record) rows.get(i);
1029
1030                            Class JavaDoc omClass = TransitionPeer.getOMClass();
1031                    Transition obj1 = (Transition) TransitionPeer
1032                .row2Object(row, 1, omClass);
1033                     omClass = AttributeOptionPeer.getOMClass();
1034                    AttributeOption obj2 = (AttributeOption)AttributeOptionPeer
1035                .row2Object(row, offset, omClass);
1036
1037            boolean newObject = true;
1038            for (int j = 0; j < results.size(); j++)
1039            {
1040                Transition temp_obj1 = (Transition)results.get(j);
1041                AttributeOption temp_obj2 = (AttributeOption)temp_obj1.getAttributeOptionRelatedByToOptionId();
1042                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1043                {
1044                    newObject = false;
1045                              temp_obj2.addTransitionRelatedByToOptionId(obj1);
1046                              break;
1047                }
1048            }
1049                      if (newObject)
1050            {
1051                obj2.initTransitionsRelatedByToOptionId();
1052                obj2.addTransitionRelatedByToOptionId(obj1);
1053            }
1054                      results.add(obj1);
1055        }
1056        return results;
1057    }
1058                    
1059  
1060                                    
1061          
1062        
1063                                  
1064                
1065
1066    /**
1067     * selects a collection of Transition objects pre-filled with
1068     * all related objects.
1069     *
1070     * This method is protected by default in order to keep the public
1071     * api reasonable. You can provide public methods for those you
1072     * actually need in TransitionPeer.
1073     *
1074     * @throws TorqueException Any exceptions caught during processing will be
1075     * rethrown wrapped into a TorqueException.
1076     */

1077    protected static List JavaDoc doSelectJoinAllExceptAttribute(Criteria criteria)
1078        throws TorqueException
1079    {
1080        setDbName(criteria);
1081
1082        addSelectColumns(criteria);
1083        int offset2 = numColumns + 1;
1084                                    
1085                                                  
1086                    AttributeOptionPeer.addSelectColumns(criteria);
1087        int offset3 = offset2 + AttributeOptionPeer.numColumns;
1088                                                                
1089                    AttributeOptionPeer.addSelectColumns(criteria);
1090        int offset4 = offset3 + AttributeOptionPeer.numColumns;
1091                                                                                                                                                                // check for conversion from boolean to int
1092
if (criteria.containsKey(DISABLED_IF_BLOCKED))
1093        {
1094            Object JavaDoc possibleBoolean = criteria.get(DISABLED_IF_BLOCKED);
1095            if (possibleBoolean instanceof Boolean JavaDoc)
1096            {
1097                criteria.add(DISABLED_IF_BLOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1098            }
1099         }
1100                  
1101        List JavaDoc rows = BasePeer.doSelect(criteria);
1102        List JavaDoc results = new ArrayList JavaDoc();
1103
1104        for (int i = 0; i < rows.size(); i++)
1105        {
1106            Record row = (Record)rows.get(i);
1107
1108                            Class JavaDoc omClass = TransitionPeer.getOMClass();
1109                    Transition obj1 = (Transition)TransitionPeer
1110                .row2Object(row, 1, omClass);
1111                                                
1112                                                                  
1113                                                                        
1114                            
1115              
1116                           omClass = AttributeOptionPeer.getOMClass();
1117                          AttributeOption obj2 = (AttributeOption)AttributeOptionPeer
1118                .row2Object( row, offset2, omClass);
1119
1120               boolean newObject = true;
1121            for (int j = 0; j < results.size(); j++)
1122            {
1123                Transition temp_obj1 = (Transition)results.get(j);
1124                AttributeOption temp_obj2 = (AttributeOption)temp_obj1.getAttributeOptionRelatedByFromOptionId();
1125                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1126                {
1127                    newObject = false;
1128                                    temp_obj2.addTransitionRelatedByFromOptionId(obj1);
1129                                    break;
1130                }
1131            }
1132                            if (newObject)
1133            {
1134                obj2.initTransitionsRelatedByFromOptionId();
1135                obj2.addTransitionRelatedByFromOptionId(obj1);
1136            }
1137                                                                                    
1138                                                                        
1139                            
1140              
1141                           omClass = AttributeOptionPeer.getOMClass();
1142                          AttributeOption obj3 = (AttributeOption)AttributeOptionPeer
1143                .row2Object( row, offset3, omClass);
1144
1145               newObject = true;
1146            for (int j = 0; j < results.size(); j++)
1147            {
1148                Transition temp_obj1 = (Transition)results.get(j);
1149                AttributeOption temp_obj3 = (AttributeOption)temp_obj1.getAttributeOptionRelatedByToOptionId();
1150                if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey()))
1151                {
1152                    newObject = false;
1153                                    temp_obj3.addTransitionRelatedByToOptionId(obj1);
1154                                    break;
1155                }
1156            }
1157                            if (newObject)
1158            {
1159                obj3.initTransitionsRelatedByToOptionId();
1160                obj3.addTransitionRelatedByToOptionId(obj1);
1161            }
1162                                                                results.add(obj1);
1163        }
1164        return results;
1165    }
1166        
1167        
1168                                            
1169                
1170
1171    /**
1172     * selects a collection of Transition objects pre-filled with
1173     * all related objects.
1174     *
1175     * This method is protected by default in order to keep the public
1176     * api reasonable. You can provide public methods for those you
1177     * actually need in TransitionPeer.
1178     *
1179     * @throws TorqueException Any exceptions caught during processing will be
1180     * rethrown wrapped into a TorqueException.
1181     */

1182    protected static List JavaDoc doSelectJoinAllExceptAttributeOptionRelatedByFromOptionId(Criteria criteria)
1183        throws TorqueException
1184    {
1185        setDbName(criteria);
1186
1187        addSelectColumns(criteria);
1188        int offset2 = numColumns + 1;
1189                                    
1190                    AttributePeer.addSelectColumns(criteria);
1191        int offset3 = offset2 + AttributePeer.numColumns;
1192                                                                
1193                                                  
1194                                                                                                                                                  // check for conversion from boolean to int
1195
if (criteria.containsKey(DISABLED_IF_BLOCKED))
1196        {
1197            Object JavaDoc possibleBoolean = criteria.get(DISABLED_IF_BLOCKED);
1198            if (possibleBoolean instanceof Boolean JavaDoc)
1199            {
1200                criteria.add(DISABLED_IF_BLOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1201            }
1202         }
1203                  
1204        List JavaDoc rows = BasePeer.doSelect(criteria);
1205        List JavaDoc results = new ArrayList JavaDoc();
1206
1207        for (int i = 0; i < rows.size(); i++)
1208        {
1209            Record row = (Record)rows.get(i);
1210
1211                            Class JavaDoc omClass = TransitionPeer.getOMClass();
1212                    Transition obj1 = (Transition)TransitionPeer
1213                .row2Object(row, 1, omClass);
1214                                                
1215                                                        
1216                            
1217              
1218                           omClass = AttributePeer.getOMClass();
1219                          Attribute obj2 = (Attribute)AttributePeer
1220                .row2Object( row, offset2, omClass);
1221
1222               boolean newObject = true;
1223            for (int j = 0; j < results.size(); j++)
1224            {
1225                Transition temp_obj1 = (Transition)results.get(j);
1226                Attribute temp_obj2 = (Attribute)temp_obj1.getAttribute();
1227                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1228                {
1229                    newObject = false;
1230                                    temp_obj2.addTransition(obj1);
1231                                    break;
1232                }
1233            }
1234                            if (newObject)
1235            {
1236                obj2.initTransitions();
1237                obj2.addTransition(obj1);
1238            }
1239                                                                                    
1240                                                                  
1241                                              results.add(obj1);
1242        }
1243        return results;
1244    }
1245        
1246        
1247                                            
1248                
1249
1250    /**
1251     * selects a collection of Transition objects pre-filled with
1252     * all related objects.
1253     *
1254     * This method is protected by default in order to keep the public
1255     * api reasonable. You can provide public methods for those you
1256     * actually need in TransitionPeer.
1257     *
1258     * @throws TorqueException Any exceptions caught during processing will be
1259     * rethrown wrapped into a TorqueException.
1260     */

1261    protected static List JavaDoc doSelectJoinAllExceptAttributeOptionRelatedByToOptionId(Criteria criteria)
1262        throws TorqueException
1263    {
1264        setDbName(criteria);
1265
1266        addSelectColumns(criteria);
1267        int offset2 = numColumns + 1;
1268                                    
1269                    AttributePeer.addSelectColumns(criteria);
1270        int offset3 = offset2 + AttributePeer.numColumns;
1271                                                                
1272                                                  
1273                                                                                                                                                  // check for conversion from boolean to int
1274
if (criteria.containsKey(DISABLED_IF_BLOCKED))
1275        {
1276            Object JavaDoc possibleBoolean = criteria.get(DISABLED_IF_BLOCKED);
1277            if (possibleBoolean instanceof Boolean JavaDoc)
1278            {
1279                criteria.add(DISABLED_IF_BLOCKED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1280            }
1281         }
1282                  
1283        List JavaDoc rows = BasePeer.doSelect(criteria);
1284        List JavaDoc results = new ArrayList JavaDoc();
1285
1286        for (int i = 0; i < rows.size(); i++)
1287        {
1288            Record row = (Record)rows.get(i);
1289
1290                            Class JavaDoc omClass = TransitionPeer.getOMClass();
1291                    Transition obj1 = (Transition)TransitionPeer
1292                .row2Object(row, 1, omClass);
1293                                                
1294                                                        
1295                            
1296              
1297                           omClass = AttributePeer.getOMClass();
1298                          Attribute obj2 = (Attribute)AttributePeer
1299                .row2Object( row, offset2, omClass);
1300
1301               boolean newObject = true;
1302            for (int j = 0; j < results.size(); j++)
1303            {
1304                Transition temp_obj1 = (Transition)results.get(j);
1305                Attribute temp_obj2 = (Attribute)temp_obj1.getAttribute();
1306                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1307                {
1308                    newObject = false;
1309                                    temp_obj2.addTransition(obj1);
1310                                    break;
1311                }
1312            }
1313                            if (newObject)
1314            {
1315                obj2.initTransitions();
1316                obj2.addTransition(obj1);
1317            }
1318                                                                                    
1319                                                                  
1320                                              results.add(obj1);
1321        }
1322        return results;
1323    }
1324                    
1325  
1326      /**
1327     * Returns the TableMap related to this peer. This method is not
1328     * needed for general use but a specific application could have a need.
1329     *
1330     * @throws TorqueException Any exceptions caught during processing will be
1331     * rethrown wrapped into a TorqueException.
1332     */

1333    protected static TableMap getTableMap()
1334        throws TorqueException
1335    {
1336        return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1337    }
1338   
1339    private static void setDbName(Criteria crit)
1340    {
1341        // Set the correct dbName if it has not been overridden
1342
// crit.getDbName will return the same object if not set to
1343
// another value so == check is okay and faster
1344
if (crit.getDbName() == Torque.getDefaultDB())
1345        {
1346            crit.setDbName(DATABASE_NAME);
1347        }
1348    }
1349}
1350
Popular Tags