KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

201     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
202         throws TorqueException
203     {
204                                 
205         setDbName(criteria);
206
207         if (con == null)
208         {
209             return BasePeer.doInsert(criteria);
210         }
211         else
212         {
213             return BasePeer.doInsert(criteria, con);
214         }
215     }
216
217     /**
218      * Add all the columns needed to create a new object.
219      *
220      * @param criteria object containing the columns to add.
221      * @throws TorqueException Any exceptions caught during processing will be
222      * rethrown wrapped into a TorqueException.
223      */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

564     public static void doUpdate(AttributeType obj, Connection JavaDoc con)
565         throws TorqueException
566     {
567         doUpdate(buildCriteria(obj), con);
568         obj.setModified(false);
569     }
570
571     /**
572      * Method to delete. This method is to be used during a transaction,
573      * otherwise use the doDelete(AttributeType) method. It will take
574      * care of the connection details internally.
575      *
576      * @param obj the data object to delete in the database.
577      * @param con the connection to use
578      * @throws TorqueException Any exceptions caught during processing will be
579      * rethrown wrapped into a TorqueException.
580      */

581     public static void doDelete(AttributeType obj, Connection JavaDoc con)
582         throws TorqueException
583     {
584         doDelete(buildSelectCriteria(obj), con);
585     }
586
587     /**
588      * Method to do deletes.
589      *
590      * @param pk ObjectKey that is used DELETE from database.
591      * @throws TorqueException Any exceptions caught during processing will be
592      * rethrown wrapped into a TorqueException.
593      */

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

610     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
611         throws TorqueException
612     {
613         doDelete(buildCriteria(pk), con);
614     }
615
616     /** Build a Criteria object from an ObjectKey */
617     public static Criteria buildCriteria( ObjectKey pk )
618     {
619         Criteria criteria = new Criteria();
620               criteria.add(ATTRIBUTE_TYPE_ID, pk);
621           return criteria;
622      }
623
624     /** Build a Criteria object from the data object for this peer */
625     public static Criteria buildCriteria( AttributeType obj )
626     {
627         Criteria criteria = new Criteria(DATABASE_NAME);
628               if (!obj.isNew())
629             criteria.add(ATTRIBUTE_TYPE_ID, obj.getAttributeTypeId());
630               criteria.add(ATTRIBUTE_CLASS_ID, obj.getClassId());
631               criteria.add(ATTRIBUTE_TYPE_NAME, obj.getName());
632               criteria.add(JAVA_CLASS_NAME, obj.getJavaClassName());
633               criteria.add(VALIDATION_KEY, obj.getValidationKey());
634           return criteria;
635     }
636
637     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
638     public static Criteria buildSelectCriteria( AttributeType obj )
639     {
640         Criteria criteria = new Criteria(DATABASE_NAME);
641               if (!obj.isNew())
642                     criteria.add(ATTRIBUTE_TYPE_ID, obj.getAttributeTypeId());
643                           criteria.add(ATTRIBUTE_CLASS_ID, obj.getClassId());
644                           criteria.add(ATTRIBUTE_TYPE_NAME, obj.getName());
645                           criteria.add(JAVA_CLASS_NAME, obj.getJavaClassName());
646                           criteria.add(VALIDATION_KEY, obj.getValidationKey());
647               return criteria;
648     }
649  
650     
651         /**
652      * Retrieve a single object by pk
653      *
654      * @param pk the primary key
655      * @throws TorqueException Any exceptions caught during processing will be
656      * rethrown wrapped into a TorqueException.
657      * @throws NoRowsException Primary key was not found in database.
658      * @throws TooManyRowsException Primary key was not found in database.
659      */

660     public static AttributeType retrieveByPK(Integer JavaDoc pk)
661         throws TorqueException, NoRowsException, TooManyRowsException
662     {
663         return retrieveByPK(SimpleKey.keyFor(pk));
664     }
665
666     /**
667      * Retrieve a single object by pk
668      *
669      * @param pk the primary key
670      * @param con the connection to use
671      * @throws TorqueException Any exceptions caught during processing will be
672      * rethrown wrapped into a TorqueException.
673      * @throws NoRowsException Primary key was not found in database.
674      * @throws TooManyRowsException Primary key was not found in database.
675      */

676     public static AttributeType retrieveByPK(Integer JavaDoc pk, Connection JavaDoc con)
677         throws TorqueException, NoRowsException, TooManyRowsException
678     {
679         return retrieveByPK(SimpleKey.keyFor(pk), con);
680     }
681   
682     /**
683      * Retrieve a single object by pk
684      *
685      * @param pk the primary key
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 AttributeType retrieveByPK(ObjectKey pk)
692         throws TorqueException, NoRowsException, TooManyRowsException
693     {
694         Connection JavaDoc db = null;
695         AttributeType retVal = null;
696         try
697         {
698             db = Torque.getConnection(DATABASE_NAME);
699             retVal = retrieveByPK(pk, db);
700         }
701         finally
702         {
703             Torque.closeConnection(db);
704         }
705         return(retVal);
706     }
707
708     /**
709      * Retrieve a single object by pk
710      *
711      * @param pk the primary key
712      * @param con the connection to use
713      * @throws TorqueException Any exceptions caught during processing will be
714      * rethrown wrapped into a TorqueException.
715      * @throws NoRowsException Primary key was not found in database.
716      * @throws TooManyRowsException Primary key was not found in database.
717      */

718     public static AttributeType retrieveByPK(ObjectKey pk, Connection JavaDoc con)
719         throws TorqueException, NoRowsException, TooManyRowsException
720     {
721         Criteria criteria = buildCriteria(pk);
722         List JavaDoc v = doSelect(criteria, con);
723         if (v.size() == 0)
724         {
725             throw new NoRowsException("Failed to select a row.");
726         }
727         else if (v.size() > 1)
728         {
729             throw new TooManyRowsException("Failed to select only one row.");
730         }
731         else
732         {
733             return (AttributeType)v.get(0);
734         }
735     }
736
737     /**
738      * Retrieve a multiple objects by pk
739      *
740      * @param pks List of primary keys
741      * @throws TorqueException Any exceptions caught during processing will be
742      * rethrown wrapped into a TorqueException.
743      */

744     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
745         throws TorqueException
746     {
747         Connection JavaDoc db = null;
748         List JavaDoc retVal = null;
749         try
750         {
751            db = Torque.getConnection(DATABASE_NAME);
752            retVal = retrieveByPKs(pks, db);
753         }
754         finally
755         {
756             Torque.closeConnection(db);
757         }
758         return(retVal);
759     }
760
761     /**
762      * Retrieve a multiple objects by pk
763      *
764      * @param pks List of primary keys
765      * @param dbcon the connection to use
766      * @throws TorqueException Any exceptions caught during processing will be
767      * rethrown wrapped into a TorqueException.
768      */

769     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
770         throws TorqueException
771     {
772         List JavaDoc objs = null;
773         if (pks == null || pks.size() == 0)
774         {
775             objs = new LinkedList JavaDoc();
776         }
777         else
778         {
779             Criteria criteria = new Criteria();
780               criteria.addIn( ATTRIBUTE_TYPE_ID, pks );
781           objs = doSelect(criteria, dbcon);
782         }
783         return objs;
784     }
785
786  
787
788
789
790           
791                                               
792                 
793                 
794
795     /**
796      * selects a collection of AttributeType objects pre-filled with their
797      * AttributeClass objects.
798      *
799      * This method is protected by default in order to keep the public
800      * api reasonable. You can provide public methods for those you
801      * actually need in AttributeTypePeer.
802      *
803      * @throws TorqueException Any exceptions caught during processing will be
804      * rethrown wrapped into a TorqueException.
805      */

806     protected static List JavaDoc doSelectJoinAttributeClass(Criteria criteria)
807         throws TorqueException
808     {
809         setDbName(criteria);
810
811         AttributeTypePeer.addSelectColumns(criteria);
812         int offset = numColumns + 1;
813         AttributeClassPeer.addSelectColumns(criteria);
814
815
816                         criteria.addJoin(AttributeTypePeer.ATTRIBUTE_CLASS_ID,
817             AttributeClassPeer.ATTRIBUTE_CLASS_ID);
818         
819
820                                                                                                   
821         List JavaDoc rows = BasePeer.doSelect(criteria);
822         List JavaDoc results = new ArrayList JavaDoc();
823
824         for (int i = 0; i < rows.size(); i++)
825         {
826             Record row = (Record) rows.get(i);
827
828                             Class JavaDoc omClass = AttributeTypePeer.getOMClass();
829                     AttributeType obj1 = (AttributeType) AttributeTypePeer
830                 .row2Object(row, 1, omClass);
831                      omClass = AttributeClassPeer.getOMClass();
832                     AttributeClass obj2 = (AttributeClass)AttributeClassPeer
833                 .row2Object(row, offset, omClass);
834
835             boolean newObject = true;
836             for (int j = 0; j < results.size(); j++)
837             {
838                 AttributeType temp_obj1 = (AttributeType)results.get(j);
839                 AttributeClass temp_obj2 = (AttributeClass)temp_obj1.getAttributeClass();
840                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
841                 {
842                     newObject = false;
843                               temp_obj2.addAttributeType(obj1);
844                               break;
845                 }
846             }
847                       if (newObject)
848             {
849                 obj2.initAttributeTypes();
850                 obj2.addAttributeType(obj1);
851             }
852                       results.add(obj1);
853         }
854         return results;
855     }
856                     
857   
858     
859   
860       /**
861      * Returns the TableMap related to this peer. This method is not
862      * needed for general use but a specific application could have a need.
863      *
864      * @throws TorqueException Any exceptions caught during processing will be
865      * rethrown wrapped into a TorqueException.
866      */

867     protected static TableMap getTableMap()
868         throws TorqueException
869     {
870         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
871     }
872    
873     private static void setDbName(Criteria crit)
874     {
875         // Set the correct dbName if it has not been overridden
876
// crit.getDbName will return the same object if not set to
877
// another value so == check is okay and faster
878
if (crit.getDbName() == Torque.getDefaultDB())
879         {
880             crit.setDbName(DATABASE_NAME);
881         }
882     }
883 }
884
Popular Tags