KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1070    protected static List JavaDoc doSelectJoinAllExceptIssueRelatedByObservedId(Criteria criteria)
1071        throws TorqueException
1072    {
1073        setDbName(criteria);
1074
1075        addSelectColumns(criteria);
1076        int offset2 = numColumns + 1;
1077                                    
1078                                                  
1079                                                  
1080                    DependTypePeer.addSelectColumns(criteria);
1081        int offset3 = offset2 + DependTypePeer.numColumns;
1082                                                                                                                                              // check for conversion from boolean to int
1083
if (criteria.containsKey(DELETED))
1084        {
1085            Object JavaDoc possibleBoolean = criteria.get(DELETED);
1086            if (possibleBoolean instanceof Boolean JavaDoc)
1087            {
1088                criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1089            }
1090         }
1091                  
1092        List JavaDoc rows = BasePeer.doSelect(criteria);
1093        List JavaDoc results = new ArrayList JavaDoc();
1094
1095        for (int i = 0; i < rows.size(); i++)
1096        {
1097            Record row = (Record)rows.get(i);
1098
1099                            Class JavaDoc omClass = DependPeer.getOMClass();
1100                    Depend obj1 = (Depend)DependPeer
1101                .row2Object(row, 1, omClass);
1102                                                
1103                                                                  
1104                                                                  
1105                                                        
1106                            
1107              
1108                           omClass = DependTypePeer.getOMClass();
1109                          DependType obj2 = (DependType)DependTypePeer
1110                .row2Object( row, offset2, omClass);
1111
1112               boolean newObject = true;
1113            for (int j = 0; j < results.size(); j++)
1114            {
1115                Depend temp_obj1 = (Depend)results.get(j);
1116                DependType temp_obj2 = (DependType)temp_obj1.getDependType();
1117                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1118                {
1119                    newObject = false;
1120                                    temp_obj2.addDepend(obj1);
1121                                    break;
1122                }
1123            }
1124                            if (newObject)
1125            {
1126                obj2.initDepends();
1127                obj2.addDepend(obj1);
1128            }
1129                                                                results.add(obj1);
1130        }
1131        return results;
1132    }
1133        
1134        
1135                                            
1136                
1137
1138    /**
1139     * selects a collection of Depend objects pre-filled with
1140     * all related objects.
1141     *
1142     * This method is protected by default in order to keep the public
1143     * api reasonable. You can provide public methods for those you
1144     * actually need in DependPeer.
1145     *
1146     * @throws TorqueException Any exceptions caught during processing will be
1147     * rethrown wrapped into a TorqueException.
1148     */

1149    protected static List JavaDoc doSelectJoinAllExceptIssueRelatedByObserverId(Criteria criteria)
1150        throws TorqueException
1151    {
1152        setDbName(criteria);
1153
1154        addSelectColumns(criteria);
1155        int offset2 = numColumns + 1;
1156                                    
1157                                                  
1158                                                  
1159                    DependTypePeer.addSelectColumns(criteria);
1160        int offset3 = offset2 + DependTypePeer.numColumns;
1161                                                                                                                                              // check for conversion from boolean to int
1162
if (criteria.containsKey(DELETED))
1163        {
1164            Object JavaDoc possibleBoolean = criteria.get(DELETED);
1165            if (possibleBoolean instanceof Boolean JavaDoc)
1166            {
1167                criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1168            }
1169         }
1170                  
1171        List JavaDoc rows = BasePeer.doSelect(criteria);
1172        List JavaDoc results = new ArrayList JavaDoc();
1173
1174        for (int i = 0; i < rows.size(); i++)
1175        {
1176            Record row = (Record)rows.get(i);
1177
1178                            Class JavaDoc omClass = DependPeer.getOMClass();
1179                    Depend obj1 = (Depend)DependPeer
1180                .row2Object(row, 1, omClass);
1181                                                
1182                                                                  
1183                                                                  
1184                                                        
1185                            
1186              
1187                           omClass = DependTypePeer.getOMClass();
1188                          DependType obj2 = (DependType)DependTypePeer
1189                .row2Object( row, offset2, omClass);
1190
1191               boolean newObject = true;
1192            for (int j = 0; j < results.size(); j++)
1193            {
1194                Depend temp_obj1 = (Depend)results.get(j);
1195                DependType temp_obj2 = (DependType)temp_obj1.getDependType();
1196                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1197                {
1198                    newObject = false;
1199                                    temp_obj2.addDepend(obj1);
1200                                    break;
1201                }
1202            }
1203                            if (newObject)
1204            {
1205                obj2.initDepends();
1206                obj2.addDepend(obj1);
1207            }
1208                                                                results.add(obj1);
1209        }
1210        return results;
1211    }
1212        
1213        
1214                                  
1215                
1216
1217    /**
1218     * selects a collection of Depend objects pre-filled with
1219     * all related objects.
1220     *
1221     * This method is protected by default in order to keep the public
1222     * api reasonable. You can provide public methods for those you
1223     * actually need in DependPeer.
1224     *
1225     * @throws TorqueException Any exceptions caught during processing will be
1226     * rethrown wrapped into a TorqueException.
1227     */

1228    protected static List JavaDoc doSelectJoinAllExceptDependType(Criteria criteria)
1229        throws TorqueException
1230    {
1231        setDbName(criteria);
1232
1233        addSelectColumns(criteria);
1234        int offset2 = numColumns + 1;
1235                                    
1236                    IssuePeer.addSelectColumns(criteria);
1237        int offset3 = offset2 + IssuePeer.numColumns;
1238                                                                
1239                    IssuePeer.addSelectColumns(criteria);
1240        int offset4 = offset3 + IssuePeer.numColumns;
1241                                                                
1242                                                                                                                                // check for conversion from boolean to int
1243
if (criteria.containsKey(DELETED))
1244        {
1245            Object JavaDoc possibleBoolean = criteria.get(DELETED);
1246            if (possibleBoolean instanceof Boolean JavaDoc)
1247            {
1248                criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1249            }
1250         }
1251                  
1252        List JavaDoc rows = BasePeer.doSelect(criteria);
1253        List JavaDoc results = new ArrayList JavaDoc();
1254
1255        for (int i = 0; i < rows.size(); i++)
1256        {
1257            Record row = (Record)rows.get(i);
1258
1259                            Class JavaDoc omClass = DependPeer.getOMClass();
1260                    Depend obj1 = (Depend)DependPeer
1261                .row2Object(row, 1, omClass);
1262                                                
1263                                                                        
1264                            
1265              
1266                           omClass = IssuePeer.getOMClass();
1267                          Issue obj2 = (Issue)IssuePeer
1268                .row2Object( row, offset2, omClass);
1269
1270               boolean newObject = true;
1271            for (int j = 0; j < results.size(); j++)
1272            {
1273                Depend temp_obj1 = (Depend)results.get(j);
1274                Issue temp_obj2 = (Issue)temp_obj1.getIssueRelatedByObservedId();
1275                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1276                {
1277                    newObject = false;
1278                                    temp_obj2.addDependRelatedByObservedId(obj1);
1279                                    break;
1280                }
1281            }
1282                            if (newObject)
1283            {
1284                obj2.initDependsRelatedByObservedId();
1285                obj2.addDependRelatedByObservedId(obj1);
1286            }
1287                                                                                    
1288                                                                        
1289                            
1290              
1291                           omClass = IssuePeer.getOMClass();
1292                          Issue obj3 = (Issue)IssuePeer
1293                .row2Object( row, offset3, omClass);
1294
1295               newObject = true;
1296            for (int j = 0; j < results.size(); j++)
1297            {
1298                Depend temp_obj1 = (Depend)results.get(j);
1299                Issue temp_obj3 = (Issue)temp_obj1.getIssueRelatedByObserverId();
1300                if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey()))
1301                {
1302                    newObject = false;
1303                                    temp_obj3.addDependRelatedByObserverId(obj1);
1304                                    break;
1305                }
1306            }
1307                            if (newObject)
1308            {
1309                obj3.initDependsRelatedByObserverId();
1310                obj3.addDependRelatedByObserverId(obj1);
1311            }
1312                                                                                    
1313                                              results.add(obj1);
1314        }
1315        return results;
1316    }
1317                    
1318  
1319      /**
1320     * Returns the TableMap related to this peer. This method is not
1321     * needed for general use but a specific application could have a need.
1322     *
1323     * @throws TorqueException Any exceptions caught during processing will be
1324     * rethrown wrapped into a TorqueException.
1325     */

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