KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.tigris.scarab.om;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.sql.Connection JavaDoc;
5 import java.sql.SQLException JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.LinkedList JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.apache.torque.NoRowsException;
13 import org.apache.torque.TooManyRowsException;
14 import org.apache.torque.Torque;
15 import org.apache.torque.TorqueException;
16 import org.apache.torque.map.MapBuilder;
17 import org.apache.torque.map.TableMap;
18 import org.apache.torque.om.DateKey;
19 import org.apache.torque.om.NumberKey;
20 import org.apache.torque.om.StringKey;
21 import org.apache.torque.om.ObjectKey;
22 import org.apache.torque.om.SimpleKey;
23 import org.apache.torque.util.BasePeer;
24 import org.apache.torque.util.Criteria;
25
26 import com.workingdogs.village.DataSetException;
27 import com.workingdogs.village.QueryDataSet;
28 import com.workingdogs.village.Record;
29
30 // Local classes
31
import org.tigris.scarab.om.map.*;
32
33
34   
35 /**
36  */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

416     public static Class JavaDoc getOMClass()
417         throws TorqueException
418     {
419         return CLASS_DEFAULT;
420     }
421
422     /**
423      * Method to do updates.
424      *
425      * @param criteria object containing data that is used to create the UPDATE
426      * statement.
427      * @throws TorqueException Any exceptions caught during processing will be
428      * rethrown wrapped into a TorqueException.
429      */

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

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

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

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

528     public static List JavaDoc doSelect(AttributeOption obj) throws TorqueException
529     {
530         return doSelect(buildSelectCriteria(obj));
531     }
532
533     /**
534      * Method to do inserts
535      *
536      * @throws TorqueException Any exceptions caught during processing will be
537      * rethrown wrapped into a TorqueException.
538      */

539     public static void doInsert(AttributeOption obj) throws TorqueException
540     {
541           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
542           obj.setNew(false);
543         obj.setModified(false);
544     }
545
546     /**
547      * @param obj the data object to update in the database.
548      * @throws TorqueException Any exceptions caught during processing will be
549      * rethrown wrapped into a TorqueException.
550      */

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

562     public static void doDelete(AttributeOption obj) throws TorqueException
563     {
564         doDelete(buildSelectCriteria(obj));
565     }
566
567     /**
568      * Method to do inserts. This method is to be used during a transaction,
569      * otherwise use the doInsert(AttributeOption) method. It will take
570      * care of the connection details internally.
571      *
572      * @param obj the data object to insert into the database.
573      * @param con the connection to use
574      * @throws TorqueException Any exceptions caught during processing will be
575      * rethrown wrapped into a TorqueException.
576      */

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

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

612     public static void doDelete(AttributeOption obj, Connection JavaDoc con)
613         throws TorqueException
614     {
615         doDelete(buildSelectCriteria(obj), con);
616     }
617
618     /**
619      * Method to do deletes.
620      *
621      * @param pk ObjectKey that is used DELETE from database.
622      * @throws TorqueException Any exceptions caught during processing will be
623      * rethrown wrapped into a TorqueException.
624      */

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

641     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
642         throws TorqueException
643     {
644         doDelete(buildCriteria(pk), con);
645     }
646
647     /** Build a Criteria object from an ObjectKey */
648     public static Criteria buildCriteria( ObjectKey pk )
649     {
650         Criteria criteria = new Criteria();
651               criteria.add(OPTION_ID, pk);
652           return criteria;
653      }
654
655     /** Build a Criteria object from the data object for this peer */
656     public static Criteria buildCriteria( AttributeOption obj )
657     {
658         Criteria criteria = new Criteria(DATABASE_NAME);
659               if (!obj.isNew())
660             criteria.add(OPTION_ID, obj.getOptionId());
661               criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
662               criteria.add(OPTION_NAME, obj.getName());
663               criteria.add(DELETED, obj.getDeleted());
664           return criteria;
665     }
666
667     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
668     public static Criteria buildSelectCriteria( AttributeOption obj )
669     {
670         Criteria criteria = new Criteria(DATABASE_NAME);
671               if (!obj.isNew())
672                     criteria.add(OPTION_ID, obj.getOptionId());
673                           criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
674                           criteria.add(OPTION_NAME, obj.getName());
675                           criteria.add(DELETED, obj.getDeleted());
676               return criteria;
677     }
678  
679     
680         /**
681      * Retrieve a single object by pk
682      *
683      * @param pk the primary key
684      * @throws TorqueException Any exceptions caught during processing will be
685      * rethrown wrapped into a TorqueException.
686      * @throws NoRowsException Primary key was not found in database.
687      * @throws TooManyRowsException Primary key was not found in database.
688      */

689     public static AttributeOption retrieveByPK(Integer JavaDoc pk)
690         throws TorqueException, NoRowsException, TooManyRowsException
691     {
692         return retrieveByPK(SimpleKey.keyFor(pk));
693     }
694
695     /**
696      * Retrieve a single object by pk
697      *
698      * @param pk the primary key
699      * @param con the connection to use
700      * @throws TorqueException Any exceptions caught during processing will be
701      * rethrown wrapped into a TorqueException.
702      * @throws NoRowsException Primary key was not found in database.
703      * @throws TooManyRowsException Primary key was not found in database.
704      */

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

720     public static AttributeOption retrieveByPK(ObjectKey pk)
721         throws TorqueException, NoRowsException, TooManyRowsException
722     {
723         Connection JavaDoc db = null;
724         AttributeOption retVal = null;
725         try
726         {
727             db = Torque.getConnection(DATABASE_NAME);
728             retVal = retrieveByPK(pk, db);
729         }
730         finally
731         {
732             Torque.closeConnection(db);
733         }
734         return(retVal);
735     }
736
737     /**
738      * Retrieve a single object by pk
739      *
740      * @param pk the primary key
741      * @param con the connection to use
742      * @throws TorqueException Any exceptions caught during processing will be
743      * rethrown wrapped into a TorqueException.
744      * @throws NoRowsException Primary key was not found in database.
745      * @throws TooManyRowsException Primary key was not found in database.
746      */

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

773     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
774         throws TorqueException
775     {
776         Connection JavaDoc db = null;
777         List JavaDoc retVal = null;
778         try
779         {
780            db = Torque.getConnection(DATABASE_NAME);
781            retVal = retrieveByPKs(pks, db);
782         }
783         finally
784         {
785             Torque.closeConnection(db);
786         }
787         return(retVal);
788     }
789
790     /**
791      * Retrieve a multiple objects by pk
792      *
793      * @param pks List of primary keys
794      * @param dbcon the connection to use
795      * @throws TorqueException Any exceptions caught during processing will be
796      * rethrown wrapped into a TorqueException.
797      */

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

835     protected static List JavaDoc doSelectJoinAttribute(Criteria criteria)
836         throws TorqueException
837     {
838         setDbName(criteria);
839
840         AttributeOptionPeer.addSelectColumns(criteria);
841         int offset = numColumns + 1;
842         AttributePeer.addSelectColumns(criteria);
843
844
845                         criteria.addJoin(AttributeOptionPeer.ATTRIBUTE_ID,
846             AttributePeer.ATTRIBUTE_ID);
847         
848
849                                                                                 // check for conversion from boolean to int
850
if (criteria.containsKey(DELETED))
851         {
852             Object JavaDoc possibleBoolean = criteria.get(DELETED);
853             if (possibleBoolean instanceof Boolean JavaDoc)
854             {
855                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
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 = AttributeOptionPeer.getOMClass();
867                     AttributeOption obj1 = (AttributeOption) AttributeOptionPeer
868                 .row2Object(row, 1, omClass);
869                      omClass = AttributePeer.getOMClass();
870                     Attribute obj2 = (Attribute)AttributePeer
871                 .row2Object(row, offset, omClass);
872
873             boolean newObject = true;
874             for (int j = 0; j < results.size(); j++)
875             {
876                 AttributeOption temp_obj1 = (AttributeOption)results.get(j);
877                 Attribute temp_obj2 = (Attribute)temp_obj1.getAttribute();
878                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
879                 {
880                     newObject = false;
881                               temp_obj2.addAttributeOption(obj1);
882                               break;
883                 }
884             }
885                       if (newObject)
886             {
887                 obj2.initAttributeOptions();
888                 obj2.addAttributeOption(obj1);
889             }
890                       results.add(obj1);
891         }
892         return results;
893     }
894                     
895   
896     
897   
898       /**
899      * Returns the TableMap related to this peer. This method is not
900      * needed for general use but a specific application could have a need.
901      *
902      * @throws TorqueException Any exceptions caught during processing will be
903      * rethrown wrapped into a TorqueException.
904      */

905     protected static TableMap getTableMap()
906         throws TorqueException
907     {
908         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
909     }
910    
911     private static void setDbName(Criteria crit)
912     {
913         // Set the correct dbName if it has not been overridden
914
// crit.getDbName will return the same object if not set to
915
// another value so == check is okay and faster
916
if (crit.getDbName() == Torque.getDefaultDB())
917         {
918             crit.setDbName(DATABASE_NAME);
919         }
920     }
921 }
922
Popular Tags