KickJava   Java API By Example, From Geeks To Geeks.

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


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 BaseROptionOptionPeer
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_R_OPTION_OPTION";
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(ROptionOptionMapBuilder.CLASS_NAME);
58     }
59
60       /** the column name for the OPTION1_ID field */
61     public static final String JavaDoc OPTION1_ID;
62       /** the column name for the OPTION2_ID field */
63     public static final String JavaDoc OPTION2_ID;
64       /** the column name for the RELATIONSHIP_ID field */
65     public static final String JavaDoc RELATIONSHIP_ID;
66       /** the column name for the WEIGHT field */
67     public static final String JavaDoc WEIGHT;
68       /** the column name for the PREFERRED_ORDER field */
69     public static final String JavaDoc PREFERRED_ORDER;
70   
71     static
72     {
73           OPTION1_ID = "SCARAB_R_OPTION_OPTION.OPTION1_ID";
74           OPTION2_ID = "SCARAB_R_OPTION_OPTION.OPTION2_ID";
75           RELATIONSHIP_ID = "SCARAB_R_OPTION_OPTION.RELATIONSHIP_ID";
76           WEIGHT = "SCARAB_R_OPTION_OPTION.WEIGHT";
77           PREFERRED_ORDER = "SCARAB_R_OPTION_OPTION.PREFERRED_ORDER";
78           if (Torque.isInit())
79         {
80             try
81             {
82                 getMapBuilder(ROptionOptionMapBuilder.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(ROptionOptionMapBuilder.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.ROptionOption";
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 BaseROptionOptionPeer
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                                 
207         setDbName(criteria);
208
209         if (con == null)
210         {
211             return BasePeer.doInsert(criteria);
212         }
213         else
214         {
215             return BasePeer.doInsert(criteria, con);
216         }
217     }
218
219     /**
220      * Add all the columns needed to create a new object.
221      *
222      * @param criteria object containing the columns to add.
223      * @throws TorqueException Any exceptions caught during processing will be
224      * rethrown wrapped into a TorqueException.
225      */

226     public static void addSelectColumns(Criteria criteria)
227             throws TorqueException
228     {
229           criteria.addSelectColumn(OPTION1_ID);
230           criteria.addSelectColumn(OPTION2_ID);
231           criteria.addSelectColumn(RELATIONSHIP_ID);
232           criteria.addSelectColumn(WEIGHT);
233           criteria.addSelectColumn(PREFERRED_ORDER);
234       }
235
236     /**
237      * Create a new object of type cls from a resultset row starting
238      * from a specified offset. This is done so that you can select
239      * other rows than just those needed for this object. You may
240      * for example want to create two objects from the same row.
241      *
242      * @throws TorqueException Any exceptions caught during processing will be
243      * rethrown wrapped into a TorqueException.
244      */

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

278     public static void populateObject(Record row,
279                                       int offset,
280                                       ROptionOption obj)
281         throws TorqueException
282     {
283         try
284         {
285                 obj.setOption1Id(row.getValue(offset + 0).asIntegerObj());
286                   obj.setOption2Id(row.getValue(offset + 1).asIntegerObj());
287                   obj.setRelationshipId(row.getValue(offset + 2).asIntegerObj());
288                   obj.setWeight(row.getValue(offset + 3).asInt());
289                   obj.setPreferredOrder(row.getValue(offset + 4).asInt());
290               }
291         catch (DataSetException e)
292         {
293             throw new TorqueException(e);
294         }
295     }
296
297     /**
298      * Method to do selects.
299      *
300      * @param criteria object used to create the SELECT statement.
301      * @return List of selected Objects
302      * @throws TorqueException Any exceptions caught during processing will be
303      * rethrown wrapped into a TorqueException.
304      */

305     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
306     {
307         return populateObjects(doSelectVillageRecords(criteria));
308     }
309
310     /**
311      * Method to do selects within a transaction.
312      *
313      * @param criteria object used to create the SELECT statement.
314      * @param con the connection to use
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, Connection JavaDoc con)
320         throws TorqueException
321     {
322         return populateObjects(doSelectVillageRecords(criteria, con));
323     }
324
325     /**
326      * Grabs the raw Village records to be formed into objects.
327      * This method handles connections internally. The Record objects
328      * returned by this method should be considered readonly. Do not
329      * alter the data and call save(), your results may vary, but are
330      * certainly likely to result in hard to track MT bugs.
331      *
332      * @throws TorqueException Any exceptions caught during processing will be
333      * rethrown wrapped into a TorqueException.
334      */

335     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
336         throws TorqueException
337     {
338         return BaseROptionOptionPeer
339             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
340     }
341
342     /**
343      * Grabs the raw Village records to be formed into objects.
344      * This method should be used for transactions
345      *
346      * @param criteria object used to create the SELECT statement.
347      * @param con the connection to use
348      * @throws TorqueException Any exceptions caught during processing will be
349      * rethrown wrapped into a TorqueException.
350      */

351     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
352         throws TorqueException
353     {
354         if (criteria.getSelectColumns().size() == 0)
355         {
356             addSelectColumns(criteria);
357         }
358
359                                 
360         setDbName(criteria);
361
362         // BasePeer returns a List of Value (Village) arrays. The array
363
// order follows the order columns were placed in the Select clause.
364
if (con == null)
365         {
366             return BasePeer.doSelect(criteria);
367         }
368         else
369         {
370             return BasePeer.doSelect(criteria, con);
371         }
372     }
373
374     /**
375      * The returned List will contain objects of the default type or
376      * objects that inherit from the default.
377      *
378      * @throws TorqueException Any exceptions caught during processing will be
379      * rethrown wrapped into a TorqueException.
380      */

381     public static List JavaDoc populateObjects(List JavaDoc records)
382         throws TorqueException
383     {
384         List JavaDoc results = new ArrayList JavaDoc(records.size());
385
386         // populate the object(s)
387
for (int i = 0; i < records.size(); i++)
388         {
389             Record row = (Record) records.get(i);
390               results.add(ROptionOptionPeer.row2Object(row, 1,
391                 ROptionOptionPeer.getOMClass()));
392           }
393         return results;
394     }
395  
396
397     /**
398      * The class that the Peer will make instances of.
399      * If the BO is abstract then you must implement this method
400      * in the BO.
401      *
402      * @throws TorqueException Any exceptions caught during processing will be
403      * rethrown wrapped into a TorqueException.
404      */

405     public static Class JavaDoc getOMClass()
406         throws TorqueException
407     {
408         return CLASS_DEFAULT;
409     }
410
411     /**
412      * Method to do updates.
413      *
414      * @param criteria object containing data that is used to create the UPDATE
415      * statement.
416      * @throws TorqueException Any exceptions caught during processing will be
417      * rethrown wrapped into a TorqueException.
418      */

419     public static void doUpdate(Criteria criteria) throws TorqueException
420     {
421          BaseROptionOptionPeer
422             .doUpdate(criteria, (Connection JavaDoc) null);
423     }
424
425     /**
426      * Method to do updates. This method is to be used during a transaction,
427      * otherwise use the doUpdate(Criteria) method. It will take care of
428      * the connection details internally.
429      *
430      * @param criteria object containing data that is used to create the UPDATE
431      * statement.
432      * @param con the connection to use
433      * @throws TorqueException Any exceptions caught during processing will be
434      * rethrown wrapped into a TorqueException.
435      */

436     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
437         throws TorqueException
438     {
439         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
440                    selectCriteria.put(OPTION1_ID, criteria.remove(OPTION1_ID));
441                        selectCriteria.put(OPTION2_ID, criteria.remove(OPTION2_ID));
442                                     
443         setDbName(criteria);
444
445         if (con == null)
446         {
447             BasePeer.doUpdate(selectCriteria, criteria);
448         }
449         else
450         {
451             BasePeer.doUpdate(selectCriteria, criteria, con);
452         }
453     }
454
455     /**
456      * Method to do deletes.
457      *
458      * @param criteria object containing data that is used DELETE from database.
459      * @throws TorqueException Any exceptions caught during processing will be
460      * rethrown wrapped into a TorqueException.
461      */

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

478      public static void doDelete(Criteria criteria, Connection JavaDoc con)
479         throws TorqueException
480      {
481                                 
482         setDbName(criteria);
483
484         if (con == null)
485         {
486             BasePeer.doDelete(criteria);
487         }
488         else
489         {
490             BasePeer.doDelete(criteria, con);
491         }
492      }
493
494     /**
495      * Method to do selects
496      *
497      * @throws TorqueException Any exceptions caught during processing will be
498      * rethrown wrapped into a TorqueException.
499      */

500     public static List JavaDoc doSelect(ROptionOption obj) throws TorqueException
501     {
502         return doSelect(buildSelectCriteria(obj));
503     }
504
505     /**
506      * Method to do inserts
507      *
508      * @throws TorqueException Any exceptions caught during processing will be
509      * rethrown wrapped into a TorqueException.
510      */

511     public static void doInsert(ROptionOption obj) throws TorqueException
512     {
513           doInsert(buildCriteria(obj));
514           obj.setNew(false);
515         obj.setModified(false);
516     }
517
518     /**
519      * @param obj the data object to update in the database.
520      * @throws TorqueException Any exceptions caught during processing will be
521      * rethrown wrapped into a TorqueException.
522      */

523     public static void doUpdate(ROptionOption obj) throws TorqueException
524     {
525         doUpdate(buildCriteria(obj));
526         obj.setModified(false);
527     }
528
529     /**
530      * @param obj the data object to delete in the database.
531      * @throws TorqueException Any exceptions caught during processing will be
532      * rethrown wrapped into a TorqueException.
533      */

534     public static void doDelete(ROptionOption obj) throws TorqueException
535     {
536         doDelete(buildSelectCriteria(obj));
537     }
538
539     /**
540      * Method to do inserts. This method is to be used during a transaction,
541      * otherwise use the doInsert(ROptionOption) method. It will take
542      * care of the connection details internally.
543      *
544      * @param obj the data object to insert into the database.
545      * @param con the connection to use
546      * @throws TorqueException Any exceptions caught during processing will be
547      * rethrown wrapped into a TorqueException.
548      */

549     public static void doInsert(ROptionOption obj, Connection JavaDoc con)
550         throws TorqueException
551     {
552           doInsert(buildCriteria(obj), con);
553           obj.setNew(false);
554         obj.setModified(false);
555     }
556
557     /**
558      * Method to do update. This method is to be used during a transaction,
559      * otherwise use the doUpdate(ROptionOption) method. It will take
560      * care of the connection details internally.
561      *
562      * @param obj the data object to update in the database.
563      * @param con the connection to use
564      * @throws TorqueException Any exceptions caught during processing will be
565      * rethrown wrapped into a TorqueException.
566      */

567     public static void doUpdate(ROptionOption obj, Connection JavaDoc con)
568         throws TorqueException
569     {
570         doUpdate(buildCriteria(obj), con);
571         obj.setModified(false);
572     }
573
574     /**
575      * Method to delete. This method is to be used during a transaction,
576      * otherwise use the doDelete(ROptionOption) method. It will take
577      * care of the connection details internally.
578      *
579      * @param obj the data object to delete in 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 doDelete(ROptionOption obj, Connection JavaDoc con)
585         throws TorqueException
586     {
587         doDelete(buildSelectCriteria(obj), con);
588     }
589
590     /**
591      * Method to do deletes.
592      *
593      * @param pk ObjectKey that is used DELETE from database.
594      * @throws TorqueException Any exceptions caught during processing will be
595      * rethrown wrapped into a TorqueException.
596      */

597     public static void doDelete(ObjectKey pk) throws TorqueException
598     {
599         BaseROptionOptionPeer
600            .doDelete(pk, (Connection JavaDoc) null);
601     }
602
603     /**
604      * Method to delete. This method is to be used during a transaction,
605      * otherwise use the doDelete(ObjectKey) method. It will take
606      * care of the connection details internally.
607      *
608      * @param pk the primary key for the object to delete in the database.
609      * @param con the connection to use
610      * @throws TorqueException Any exceptions caught during processing will be
611      * rethrown wrapped into a TorqueException.
612      */

613     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
614         throws TorqueException
615     {
616         doDelete(buildCriteria(pk), con);
617     }
618
619     /** Build a Criteria object from an ObjectKey */
620     public static Criteria buildCriteria( ObjectKey pk )
621     {
622         Criteria criteria = new Criteria();
623           SimpleKey[] keys = (SimpleKey[])pk.getValue();
624                     criteria.add(OPTION1_ID, keys[0]);
625                       criteria.add(OPTION2_ID, keys[1]);
626                     return criteria;
627      }
628
629     /** Build a Criteria object from the data object for this peer */
630     public static Criteria buildCriteria( ROptionOption obj )
631     {
632         Criteria criteria = new Criteria(DATABASE_NAME);
633               criteria.add(OPTION1_ID, obj.getOption1Id());
634               criteria.add(OPTION2_ID, obj.getOption2Id());
635               criteria.add(RELATIONSHIP_ID, obj.getRelationshipId());
636               criteria.add(WEIGHT, obj.getWeight());
637               criteria.add(PREFERRED_ORDER, obj.getPreferredOrder());
638           return criteria;
639     }
640
641     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
642     public static Criteria buildSelectCriteria( ROptionOption obj )
643     {
644         Criteria criteria = new Criteria(DATABASE_NAME);
645                       criteria.add(OPTION1_ID, obj.getOption1Id());
646                           criteria.add(OPTION2_ID, obj.getOption2Id());
647                           criteria.add(RELATIONSHIP_ID, obj.getRelationshipId());
648                           criteria.add(WEIGHT, obj.getWeight());
649                           criteria.add(PREFERRED_ORDER, obj.getPreferredOrder());
650               return criteria;
651     }
652  
653     
654     
655     /**
656      * Retrieve a single object by pk
657      *
658      * @param pk the primary key
659      * @throws TorqueException Any exceptions caught during processing will be
660      * rethrown wrapped into a TorqueException.
661      * @throws NoRowsException Primary key was not found in database.
662      * @throws TooManyRowsException Primary key was not found in database.
663      */

664     public static ROptionOption retrieveByPK(ObjectKey pk)
665         throws TorqueException, NoRowsException, TooManyRowsException
666     {
667         Connection JavaDoc db = null;
668         ROptionOption retVal = null;
669         try
670         {
671             db = Torque.getConnection(DATABASE_NAME);
672             retVal = retrieveByPK(pk, db);
673         }
674         finally
675         {
676             Torque.closeConnection(db);
677         }
678         return(retVal);
679     }
680
681     /**
682      * Retrieve a single object by pk
683      *
684      * @param pk the primary key
685      * @param con the connection to use
686      * @throws TorqueException Any exceptions caught during processing will be
687      * rethrown wrapped into a TorqueException.
688      * @throws NoRowsException Primary key was not found in database.
689      * @throws TooManyRowsException Primary key was not found in database.
690      */

691     public static ROptionOption retrieveByPK(ObjectKey pk, Connection JavaDoc con)
692         throws TorqueException, NoRowsException, TooManyRowsException
693     {
694         Criteria criteria = buildCriteria(pk);
695         List JavaDoc v = doSelect(criteria, con);
696         if (v.size() == 0)
697         {
698             throw new NoRowsException("Failed to select a row.");
699         }
700         else if (v.size() > 1)
701         {
702             throw new TooManyRowsException("Failed to select only one row.");
703         }
704         else
705         {
706             return (ROptionOption)v.get(0);
707         }
708     }
709
710     /**
711      * Retrieve a multiple objects by pk
712      *
713      * @param pks List of primary keys
714      * @throws TorqueException Any exceptions caught during processing will be
715      * rethrown wrapped into a TorqueException.
716      */

717     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
718         throws TorqueException
719     {
720         Connection JavaDoc db = null;
721         List JavaDoc retVal = null;
722         try
723         {
724            db = Torque.getConnection(DATABASE_NAME);
725            retVal = retrieveByPKs(pks, db);
726         }
727         finally
728         {
729             Torque.closeConnection(db);
730         }
731         return(retVal);
732     }
733
734     /**
735      * Retrieve a multiple objects by pk
736      *
737      * @param pks List of primary keys
738      * @param dbcon the connection to use
739      * @throws TorqueException Any exceptions caught during processing will be
740      * rethrown wrapped into a TorqueException.
741      */

742     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
743         throws TorqueException
744     {
745         List JavaDoc objs = null;
746         if (pks == null || pks.size() == 0)
747         {
748             objs = new LinkedList JavaDoc();
749         }
750         else
751         {
752             Criteria criteria = new Criteria();
753               Iterator JavaDoc iter = pks.iterator();
754             while (iter.hasNext())
755             {
756                 ObjectKey pk = (ObjectKey)iter.next();
757                 SimpleKey[] keys = (SimpleKey[])pk.getValue();
758                             Criteria.Criterion c0 = criteria.getNewCriterion(
759                         OPTION1_ID, keys[0], Criteria.EQUAL);
760                                     Criteria.Criterion c1 = criteria.getNewCriterion(
761                         OPTION2_ID, keys[1], Criteria.EQUAL);
762                                     c0.and(c1);
763                           criteria.or(c0);
764             }
765           objs = doSelect(criteria, dbcon);
766         }
767         return objs;
768     }
769
770  
771     /**
772      * retrieve object using using pk values.
773      *
774        * @param option1_id Integer
775        * @param option2_id Integer
776        */

777     public static ROptionOption retrieveByPK(
778        Integer JavaDoc option1_id
779           , Integer JavaDoc option2_id
780               ) throws TorqueException
781     {
782         Connection JavaDoc db = null;
783         ROptionOption retVal = null;
784         try
785         {
786            db = Torque.getConnection(DATABASE_NAME);
787            retVal = retrieveByPK(
788          option1_id
789           , option2_id
790                      , db);
791         }
792         finally
793         {
794             Torque.closeConnection(db);
795         }
796         return(retVal);
797     }
798
799       /**
800      * retrieve object using using pk values.
801      *
802        * @param option1_id Integer
803        * @param option2_id Integer
804        * @param con Connection
805      */

806     public static ROptionOption retrieveByPK(
807        Integer JavaDoc option1_id
808           , Integer JavaDoc option2_id
809              ,Connection JavaDoc con) throws TorqueException
810     {
811
812         Criteria criteria = new Criteria(5);
813           criteria.add(OPTION1_ID, option1_id);
814           criteria.add(OPTION2_ID, option2_id);
815           List JavaDoc v = doSelect(criteria, con);
816         if (v.size() != 1)
817         {
818             throw new TorqueException("Failed to select one and only one row.");
819         }
820         else
821         {
822             return (ROptionOption) v.get(0);
823         }
824     }
825
826
827
828               
829                                                         
830                 
831                 
832
833     /**
834      * selects a collection of ROptionOption objects pre-filled with their
835      * AttributeOption 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 ROptionOptionPeer.
840      *
841      * @throws TorqueException Any exceptions caught during processing will be
842      * rethrown wrapped into a TorqueException.
843      */

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

909     protected static List JavaDoc doSelectJoinAttributeOptionRelatedByOption2Id(Criteria criteria)
910         throws TorqueException
911     {
912         setDbName(criteria);
913
914         ROptionOptionPeer.addSelectColumns(criteria);
915         int offset = numColumns + 1;
916         AttributeOptionPeer.addSelectColumns(criteria);
917
918
919                         criteria.addJoin(ROptionOptionPeer.OPTION2_ID,
920             AttributeOptionPeer.OPTION_ID);
921         
922
923                                                                                                   
924         List JavaDoc rows = BasePeer.doSelect(criteria);
925         List JavaDoc results = new ArrayList JavaDoc();
926
927         for (int i = 0; i < rows.size(); i++)
928         {
929             Record row = (Record) rows.get(i);
930
931                             Class JavaDoc omClass = ROptionOptionPeer.getOMClass();
932                     ROptionOption obj1 = (ROptionOption) ROptionOptionPeer
933                 .row2Object(row, 1, omClass);
934                      omClass = AttributeOptionPeer.getOMClass();
935                     AttributeOption obj2 = (AttributeOption)AttributeOptionPeer
936                 .row2Object(row, offset, omClass);
937
938             boolean newObject = true;
939             for (int j = 0; j < results.size(); j++)
940             {
941                 ROptionOption temp_obj1 = (ROptionOption)results.get(j);
942                 AttributeOption temp_obj2 = (AttributeOption)temp_obj1.getAttributeOptionRelatedByOption2Id();
943                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
944                 {
945                     newObject = false;
946                               temp_obj2.addROptionOptionRelatedByOption2Id(obj1);
947                               break;
948                 }
949             }
950                       if (newObject)
951             {
952                 obj2.initROptionOptionsRelatedByOption2Id();
953                 obj2.addROptionOptionRelatedByOption2Id(obj1);
954             }
955                       results.add(obj1);
956         }
957         return results;
958     }
959                                                             
960                 
961                 
962
963     /**
964      * selects a collection of ROptionOption objects pre-filled with their
965      * OptionRelationship objects.
966      *
967      * This method is protected by default in order to keep the public
968      * api reasonable. You can provide public methods for those you
969      * actually need in ROptionOptionPeer.
970      *
971      * @throws TorqueException Any exceptions caught during processing will be
972      * rethrown wrapped into a TorqueException.
973      */

974     protected static List JavaDoc doSelectJoinOptionRelationship(Criteria criteria)
975         throws TorqueException
976     {
977         setDbName(criteria);
978
979         ROptionOptionPeer.addSelectColumns(criteria);
980         int offset = numColumns + 1;
981         OptionRelationshipPeer.addSelectColumns(criteria);
982
983
984                         criteria.addJoin(ROptionOptionPeer.RELATIONSHIP_ID,
985             OptionRelationshipPeer.RELATIONSHIP_ID);
986         
987
988                                                                                                   
989         List JavaDoc rows = BasePeer.doSelect(criteria);
990         List JavaDoc results = new ArrayList JavaDoc();
991
992         for (int i = 0; i < rows.size(); i++)
993         {
994             Record row = (Record) rows.get(i);
995
996                             Class JavaDoc omClass = ROptionOptionPeer.getOMClass();
997                     ROptionOption obj1 = (ROptionOption) ROptionOptionPeer
998                 .row2Object(row, 1, omClass);
999                      omClass = OptionRelationshipPeer.getOMClass();
1000                    OptionRelationship obj2 = (OptionRelationship)OptionRelationshipPeer
1001                .row2Object(row, offset, omClass);
1002
1003            boolean newObject = true;
1004            for (int j = 0; j < results.size(); j++)
1005            {
1006                ROptionOption temp_obj1 = (ROptionOption)results.get(j);
1007                OptionRelationship temp_obj2 = (OptionRelationship)temp_obj1.getOptionRelationship();
1008                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1009                {
1010                    newObject = false;
1011                              temp_obj2.addROptionOption(obj1);
1012                              break;
1013                }
1014            }
1015                      if (newObject)
1016            {
1017                obj2.initROptionOptions();
1018                obj2.addROptionOption(obj1);
1019            }
1020                      results.add(obj1);
1021        }
1022        return results;
1023    }
1024                    
1025  
1026                                    
1027          
1028        
1029                                            
1030                
1031
1032    /**
1033     * selects a collection of ROptionOption objects pre-filled with
1034     * all related objects.
1035     *
1036     * This method is protected by default in order to keep the public
1037     * api reasonable. You can provide public methods for those you
1038     * actually need in ROptionOptionPeer.
1039     *
1040     * @throws TorqueException Any exceptions caught during processing will be
1041     * rethrown wrapped into a TorqueException.
1042     */

1043    protected static List JavaDoc doSelectJoinAllExceptAttributeOptionRelatedByOption1Id(Criteria criteria)
1044        throws TorqueException
1045    {
1046        setDbName(criteria);
1047
1048        addSelectColumns(criteria);
1049        int offset2 = numColumns + 1;
1050                                    
1051                                                  
1052                                                  
1053                    OptionRelationshipPeer.addSelectColumns(criteria);
1054        int offset3 = offset2 + OptionRelationshipPeer.numColumns;
1055                                                                                                                                              
1056        List JavaDoc rows = BasePeer.doSelect(criteria);
1057        List JavaDoc results = new ArrayList JavaDoc();
1058
1059        for (int i = 0; i < rows.size(); i++)
1060        {
1061            Record row = (Record)rows.get(i);
1062
1063                            Class JavaDoc omClass = ROptionOptionPeer.getOMClass();
1064                    ROptionOption obj1 = (ROptionOption)ROptionOptionPeer
1065                .row2Object(row, 1, omClass);
1066                                                
1067                                                                  
1068                                                                  
1069                                                        
1070                            
1071              
1072                           omClass = OptionRelationshipPeer.getOMClass();
1073                          OptionRelationship obj2 = (OptionRelationship)OptionRelationshipPeer
1074                .row2Object( row, offset2, omClass);
1075
1076               boolean newObject = true;
1077            for (int j = 0; j < results.size(); j++)
1078            {
1079                ROptionOption temp_obj1 = (ROptionOption)results.get(j);
1080                OptionRelationship temp_obj2 = (OptionRelationship)temp_obj1.getOptionRelationship();
1081                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1082                {
1083                    newObject = false;
1084                                    temp_obj2.addROptionOption(obj1);
1085                                    break;
1086                }
1087            }
1088                            if (newObject)
1089            {
1090                obj2.initROptionOptions();
1091                obj2.addROptionOption(obj1);
1092            }
1093                                                                results.add(obj1);
1094        }
1095        return results;
1096    }
1097        
1098        
1099                                            
1100                
1101
1102    /**
1103     * selects a collection of ROptionOption objects pre-filled with
1104     * all related objects.
1105     *
1106     * This method is protected by default in order to keep the public
1107     * api reasonable. You can provide public methods for those you
1108     * actually need in ROptionOptionPeer.
1109     *
1110     * @throws TorqueException Any exceptions caught during processing will be
1111     * rethrown wrapped into a TorqueException.
1112     */

1113    protected static List JavaDoc doSelectJoinAllExceptAttributeOptionRelatedByOption2Id(Criteria criteria)
1114        throws TorqueException
1115    {
1116        setDbName(criteria);
1117
1118        addSelectColumns(criteria);
1119        int offset2 = numColumns + 1;
1120                                    
1121                                                  
1122                                                  
1123                    OptionRelationshipPeer.addSelectColumns(criteria);
1124        int offset3 = offset2 + OptionRelationshipPeer.numColumns;
1125                                                                                                                                              
1126        List JavaDoc rows = BasePeer.doSelect(criteria);
1127        List JavaDoc results = new ArrayList JavaDoc();
1128
1129        for (int i = 0; i < rows.size(); i++)
1130        {
1131            Record row = (Record)rows.get(i);
1132
1133                            Class JavaDoc omClass = ROptionOptionPeer.getOMClass();
1134                    ROptionOption obj1 = (ROptionOption)ROptionOptionPeer
1135                .row2Object(row, 1, omClass);
1136                                                
1137                                                                  
1138                                                                  
1139                                                        
1140                            
1141              
1142                           omClass = OptionRelationshipPeer.getOMClass();
1143                          OptionRelationship obj2 = (OptionRelationship)OptionRelationshipPeer
1144                .row2Object( row, offset2, omClass);
1145
1146               boolean newObject = true;
1147            for (int j = 0; j < results.size(); j++)
1148            {
1149                ROptionOption temp_obj1 = (ROptionOption)results.get(j);
1150                OptionRelationship temp_obj2 = (OptionRelationship)temp_obj1.getOptionRelationship();
1151                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1152                {
1153                    newObject = false;
1154                                    temp_obj2.addROptionOption(obj1);
1155                                    break;
1156                }
1157            }
1158                            if (newObject)
1159            {
1160                obj2.initROptionOptions();
1161                obj2.addROptionOption(obj1);
1162            }
1163                                                                results.add(obj1);
1164        }
1165        return results;
1166    }
1167        
1168        
1169                                  
1170                
1171
1172    /**
1173     * selects a collection of ROptionOption objects pre-filled with
1174     * all related objects.
1175     *
1176     * This method is protected by default in order to keep the public
1177     * api reasonable. You can provide public methods for those you
1178     * actually need in ROptionOptionPeer.
1179     *
1180     * @throws TorqueException Any exceptions caught during processing will be
1181     * rethrown wrapped into a TorqueException.
1182     */

1183    protected static List JavaDoc doSelectJoinAllExceptOptionRelationship(Criteria criteria)
1184        throws TorqueException
1185    {
1186        setDbName(criteria);
1187
1188        addSelectColumns(criteria);
1189        int offset2 = numColumns + 1;
1190                                    
1191                    AttributeOptionPeer.addSelectColumns(criteria);
1192        int offset3 = offset2 + AttributeOptionPeer.numColumns;
1193                                                                
1194                    AttributeOptionPeer.addSelectColumns(criteria);
1195        int offset4 = offset3 + AttributeOptionPeer.numColumns;
1196                                                                
1197                                                                                                                                
1198        List JavaDoc rows = BasePeer.doSelect(criteria);
1199        List JavaDoc results = new ArrayList JavaDoc();
1200
1201        for (int i = 0; i < rows.size(); i++)
1202        {
1203            Record row = (Record)rows.get(i);
1204
1205                            Class JavaDoc omClass = ROptionOptionPeer.getOMClass();
1206                    ROptionOption obj1 = (ROptionOption)ROptionOptionPeer
1207                .row2Object(row, 1, omClass);
1208                                                
1209                                                                        
1210                            
1211              
1212                           omClass = AttributeOptionPeer.getOMClass();
1213                          AttributeOption obj2 = (AttributeOption)AttributeOptionPeer
1214                .row2Object( row, offset2, omClass);
1215
1216               boolean newObject = true;
1217            for (int j = 0; j < results.size(); j++)
1218            {
1219                ROptionOption temp_obj1 = (ROptionOption)results.get(j);
1220                AttributeOption temp_obj2 = (AttributeOption)temp_obj1.getAttributeOptionRelatedByOption1Id();
1221                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1222                {
1223                    newObject = false;
1224                                    temp_obj2.addROptionOptionRelatedByOption1Id(obj1);
1225                                    break;
1226                }
1227            }
1228                            if (newObject)
1229            {
1230                obj2.initROptionOptionsRelatedByOption1Id();
1231                obj2.addROptionOptionRelatedByOption1Id(obj1);
1232            }
1233                                                                                    
1234                                                                        
1235                            
1236              
1237                           omClass = AttributeOptionPeer.getOMClass();
1238                          AttributeOption obj3 = (AttributeOption)AttributeOptionPeer
1239                .row2Object( row, offset3, omClass);
1240
1241               newObject = true;
1242            for (int j = 0; j < results.size(); j++)
1243            {
1244                ROptionOption temp_obj1 = (ROptionOption)results.get(j);
1245                AttributeOption temp_obj3 = (AttributeOption)temp_obj1.getAttributeOptionRelatedByOption2Id();
1246                if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey()))
1247                {
1248                    newObject = false;
1249                                    temp_obj3.addROptionOptionRelatedByOption2Id(obj1);
1250                                    break;
1251                }
1252            }
1253                            if (newObject)
1254            {
1255                obj3.initROptionOptionsRelatedByOption2Id();
1256                obj3.addROptionOptionRelatedByOption2Id(obj1);
1257            }
1258                                                                                    
1259                                              results.add(obj1);
1260        }
1261        return results;
1262    }
1263                    
1264  
1265      /**
1266     * Returns the TableMap related to this peer. This method is not
1267     * needed for general use but a specific application could have a need.
1268     *
1269     * @throws TorqueException Any exceptions caught during processing will be
1270     * rethrown wrapped into a TorqueException.
1271     */

1272    protected static TableMap getTableMap()
1273        throws TorqueException
1274    {
1275        return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1276    }
1277   
1278    private static void setDbName(Criteria crit)
1279    {
1280        // Set the correct dbName if it has not been overridden
1281
// crit.getDbName will return the same object if not set to
1282
// another value so == check is okay and faster
1283
if (crit.getDbName() == Torque.getDefaultDB())
1284        {
1285            crit.setDbName(DATABASE_NAME);
1286        }
1287    }
1288}
1289
Popular Tags