KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

194     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
195         throws TorqueException
196     {
197                           // check for conversion from boolean to int
198
if (criteria.containsKey(SEARCHABLE))
199         {
200             Object JavaDoc possibleBoolean = criteria.get(SEARCHABLE);
201             if (possibleBoolean instanceof Boolean JavaDoc)
202             {
203                 criteria.add(SEARCHABLE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
204             }
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(ATTACHMENT_TYPE_ID);
230           criteria.addSelectColumn(ATTACHMENT_TYPE_NAME);
231           criteria.addSelectColumn(SEARCHABLE);
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 AttachmentType row2Object(Record row,
244                                              int offset,
245                                              Class JavaDoc cls)
246         throws TorqueException
247     {
248         try
249         {
250             AttachmentType obj = (AttachmentType) cls.newInstance();
251             AttachmentTypePeer.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                                       AttachmentType obj)
279         throws TorqueException
280     {
281         try
282         {
283                 obj.setAttachmentTypeId(row.getValue(offset + 0).asIntegerObj());
284                   obj.setName(row.getValue(offset + 1).asString());
285                   obj.setSearchable(row.getValue(offset + 2).asBoolean());
286               }
287         catch (DataSetException e)
288         {
289             throw new TorqueException(e);
290         }
291     }
292
293     /**
294      * Method to do selects.
295      *
296      * @param criteria object used to create the SELECT statement.
297      * @return List of selected Objects
298      * @throws TorqueException Any exceptions caught during processing will be
299      * rethrown wrapped into a TorqueException.
300      */

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

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

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

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

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

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

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

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

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

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

522     public static List JavaDoc doSelect(AttachmentType obj) throws TorqueException
523     {
524         return doSelect(buildSelectCriteria(obj));
525     }
526
527     /**
528      * Method to do inserts
529      *
530      * @throws TorqueException Any exceptions caught during processing will be
531      * rethrown wrapped into a TorqueException.
532      */

533     public static void doInsert(AttachmentType obj) throws TorqueException
534     {
535           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
536           obj.setNew(false);
537         obj.setModified(false);
538     }
539
540     /**
541      * @param obj the data object to update in the database.
542      * @throws TorqueException Any exceptions caught during processing will be
543      * rethrown wrapped into a TorqueException.
544      */

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

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

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

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

606     public static void doDelete(AttachmentType obj, Connection JavaDoc con)
607         throws TorqueException
608     {
609         doDelete(buildSelectCriteria(obj), con);
610     }
611
612     /**
613      * Method to do deletes.
614      *
615      * @param pk ObjectKey that is used DELETE from database.
616      * @throws TorqueException Any exceptions caught during processing will be
617      * rethrown wrapped into a TorqueException.
618      */

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

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

681     public static AttachmentType retrieveByPK(Integer JavaDoc pk)
682         throws TorqueException, NoRowsException, TooManyRowsException
683     {
684         return retrieveByPK(SimpleKey.keyFor(pk));
685     }
686
687     /**
688      * Retrieve a single object by pk
689      *
690      * @param pk the primary key
691      * @param con the connection to use
692      * @throws TorqueException Any exceptions caught during processing will be
693      * rethrown wrapped into a TorqueException.
694      * @throws NoRowsException Primary key was not found in database.
695      * @throws TooManyRowsException Primary key was not found in database.
696      */

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

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

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

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

790     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
791         throws TorqueException
792     {
793         List JavaDoc objs = null;
794         if (pks == null || pks.size() == 0)
795         {
796             objs = new LinkedList JavaDoc();
797         }
798         else
799         {
800             Criteria criteria = new Criteria();
801               criteria.addIn( ATTACHMENT_TYPE_ID, pks );
802           objs = doSelect(criteria, dbcon);
803         }
804         return objs;
805     }
806
807  
808
809
810
811         
812   
813   
814     
815   
816       /**
817      * Returns the TableMap related to this peer. This method is not
818      * needed for general use but a specific application could have a need.
819      *
820      * @throws TorqueException Any exceptions caught during processing will be
821      * rethrown wrapped into a TorqueException.
822      */

823     protected static TableMap getTableMap()
824         throws TorqueException
825     {
826         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
827     }
828    
829     private static void setDbName(Criteria crit)
830     {
831         // Set the correct dbName if it has not been overridden
832
// crit.getDbName will return the same object if not set to
833
// another value so == check is okay and faster
834
if (crit.getDbName() == Torque.getDefaultDB())
835         {
836             crit.setDbName(DATABASE_NAME);
837         }
838     }
839 }
840
Popular Tags