View Javadoc

1   package net.sourceforge.blogentis.om;
2   
3   import java.sql.Connection;
4   import java.sql.SQLException;
5   import java.util.ArrayList;
6   import java.util.LinkedList;
7   import java.util.List;
8   
9   import net.sourceforge.blogentis.om.map.CommentMapBuilder;
10  
11  import org.apache.torque.NoRowsException;
12  import org.apache.torque.TooManyRowsException;
13  import org.apache.torque.Torque;
14  import org.apache.torque.TorqueException;
15  import org.apache.torque.map.MapBuilder;
16  import org.apache.torque.map.TableMap;
17  import org.apache.torque.om.ObjectKey;
18  import org.apache.torque.om.SimpleKey;
19  import org.apache.torque.util.BasePeer;
20  import org.apache.torque.util.Criteria;
21  
22  import com.workingdogs.village.DataSetException;
23  import com.workingdogs.village.QueryDataSet;
24  import com.workingdogs.village.Record;
25  
26  
27    
28  /***
29   */
30  public abstract class BaseCommentPeer
31      extends BasePeer
32  {
33  
34      /*** the default database name for this class */
35      public static final String DATABASE_NAME = "blogentis";
36  
37       /*** the table name for this class */
38      public static final String TABLE_NAME = "Comment";
39  
40      /***
41       * @return the map builder for this peer
42       * @throws TorqueException Any exceptions caught during processing will be
43       *         rethrown wrapped into a TorqueException.
44       */
45      public static MapBuilder getMapBuilder()
46          throws TorqueException
47      {
48          return getMapBuilder(CommentMapBuilder.CLASS_NAME);
49      }
50  
51        /*** the column name for the COMMENT_ID field */
52      public static final String COMMENT_ID;
53        /*** the column name for the POST_ID field */
54      public static final String POST_ID;
55        /*** the column name for the POSTED_TIME field */
56      public static final String POSTED_TIME;
57        /*** the column name for the NAME field */
58      public static final String NAME;
59        /*** the column name for the URL field */
60      public static final String URL;
61        /*** the column name for the EMAIL field */
62      public static final String EMAIL;
63        /*** the column name for the TITLE field */
64      public static final String TITLE;
65        /*** the column name for the TEXT field */
66      public static final String TEXT;
67    
68      static
69      {
70            COMMENT_ID = "Comment.COMMENT_ID";
71            POST_ID = "Comment.POST_ID";
72            POSTED_TIME = "Comment.POSTED_TIME";
73            NAME = "Comment.NAME";
74            URL = "Comment.URL";
75            EMAIL = "Comment.EMAIL";
76            TITLE = "Comment.TITLE";
77            TEXT = "Comment.TEXT";
78            if (Torque.isInit())
79          {
80              try
81              {
82                  getMapBuilder(CommentMapBuilder.CLASS_NAME);
83              }
84              catch (Exception e)
85              {
86                  log.error("Could not initialize Peer", e);
87              }
88          }
89          else
90          {
91              Torque.registerMapBuilder(CommentMapBuilder.CLASS_NAME);
92          }
93      }
94   
95      /*** number of columns for this peer */
96      public static final int numColumns =  8;
97  
98      /*** A class that can be returned by this peer. */
99      protected static final String CLASSNAME_DEFAULT =
100         "net.sourceforge.blogentis.om.Comment";
101 
102     /*** A class that can be returned by this peer. */
103     protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
104 
105     /***
106      * Class object initialization method.
107      *
108      * @param className name of the class to initialize
109      * @return the initialized class
110      */
111     private static Class initClass(String className)
112     {
113         Class c = null;
114         try
115         {
116             c = Class.forName(className);
117         }
118         catch (Throwable t)
119         {
120             log.error("A FATAL ERROR has occurred which should not "
121                 + "have happened under any circumstance.  Please notify "
122                 + "the Torque developers <torque-dev@db.apache.org> "
123                 + "and give as many details as possible (including the error "
124                 + "stack trace).", t);
125 
126             // Error objects should always be propogated.
127             if (t instanceof Error)
128             {
129                 throw (Error) t.fillInStackTrace();
130             }
131         }
132         return c;
133     }
134 
135     /***
136      * Get the list of objects for a ResultSet.  Please not that your
137      * resultset MUST return columns in the right order.  You can use
138      * getFieldNames() in BaseObject to get the correct sequence.
139      *
140      * @param results the ResultSet
141      * @return the list of objects
142      * @throws TorqueException Any exceptions caught during processing will be
143      *         rethrown wrapped into a TorqueException.
144      */
145     public static List resultSet2Objects(java.sql.ResultSet results)
146             throws TorqueException
147     {
148         try
149         {
150             QueryDataSet qds = null;
151             List rows = null;
152             try
153             {
154                 qds = new QueryDataSet(results);
155                 rows = getSelectResults(qds);
156             }
157             finally
158             {
159                 if (qds != null)
160                 {
161                     qds.close();
162                 }
163             }
164 
165             return populateObjects(rows);
166         }
167         catch (SQLException e)
168         {
169             throw new TorqueException(e);
170         }
171         catch (DataSetException e)
172         {
173             throw new TorqueException(e);
174         }
175     }
176 
177 
178   
179     /***
180      * Method to do inserts.
181      *
182      * @param criteria object used to create the INSERT statement.
183      * @throws TorqueException Any exceptions caught during processing will be
184      *         rethrown wrapped into a TorqueException.
185      */
186     public static ObjectKey doInsert(Criteria criteria)
187         throws TorqueException
188     {
189         return BaseCommentPeer
190             .doInsert(criteria, (Connection) null);
191     }
192 
193     /***
194      * Method to do inserts.  This method is to be used during a transaction,
195      * otherwise use the doInsert(Criteria) method.  It will take care of
196      * the connection details internally.
197      *
198      * @param criteria object used to create the INSERT statement.
199      * @param con the connection to use
200      * @throws TorqueException Any exceptions caught during processing will be
201      *         rethrown wrapped into a TorqueException.
202      */
203     public static ObjectKey doInsert(Criteria criteria, Connection con)
204         throws TorqueException
205     {
206                                                   
207         // Set the correct dbName if it has not been overridden
208         // criteria.getDbName will return the same object if not set to
209         // another value so == check is okay and faster
210         if (criteria.getDbName() == Torque.getDefaultDB())
211         {
212             criteria.setDbName(DATABASE_NAME);
213         }
214         if (con == null)
215         {
216             return BasePeer.doInsert(criteria);
217         }
218         else
219         {
220             return BasePeer.doInsert(criteria, con);
221         }
222     }
223 
224     /***
225      * Add all the columns needed to create a new object.
226      *
227      * @param criteria object containing the columns to add.
228      * @throws TorqueException Any exceptions caught during processing will be
229      *         rethrown wrapped into a TorqueException.
230      */
231     public static void addSelectColumns(Criteria criteria)
232             throws TorqueException
233     {
234           criteria.addSelectColumn(COMMENT_ID);
235           criteria.addSelectColumn(POST_ID);
236           criteria.addSelectColumn(POSTED_TIME);
237           criteria.addSelectColumn(NAME);
238           criteria.addSelectColumn(URL);
239           criteria.addSelectColumn(EMAIL);
240           criteria.addSelectColumn(TITLE);
241           criteria.addSelectColumn(TEXT);
242       }
243 
244     /***
245      * Create a new object of type cls from a resultset row starting
246      * from a specified offset.  This is done so that you can select
247      * other rows than just those needed for this object.  You may
248      * for example want to create two objects from the same row.
249      *
250      * @throws TorqueException Any exceptions caught during processing will be
251      *         rethrown wrapped into a TorqueException.
252      */
253     public static Comment row2Object(Record row,
254                                              int offset,
255                                              Class cls)
256         throws TorqueException
257     {
258         try
259         {
260             Comment obj = (Comment) cls.newInstance();
261             CommentPeer.populateObject(row, offset, obj);
262                   obj.setModified(false);
263               obj.setNew(false);
264 
265             return obj;
266         }
267         catch (InstantiationException e)
268         {
269             throw new TorqueException(e);
270         }
271         catch (IllegalAccessException e)
272         {
273             throw new TorqueException(e);
274         }
275     }
276 
277     /***
278      * Populates an object from a resultset row starting
279      * from a specified offset.  This is done so that you can select
280      * other rows than just those needed for this object.  You may
281      * for example want to create two objects from the same row.
282      *
283      * @throws TorqueException Any exceptions caught during processing will be
284      *         rethrown wrapped into a TorqueException.
285      */
286     public static void populateObject(Record row,
287                                       int offset,
288                                       Comment obj)
289         throws TorqueException
290     {
291         try
292         {
293                 obj.setCommentId(row.getValue(offset + 0).asInt());
294                   obj.setPostId(row.getValue(offset + 1).asInt());
295                   obj.setPostedTime(row.getValue(offset + 2).asUtilDate());
296                   obj.setName(row.getValue(offset + 3).asString());
297                   obj.setUrl(row.getValue(offset + 4).asString());
298                   obj.setEmail(row.getValue(offset + 5).asString());
299                   obj.setTitle(row.getValue(offset + 6).asString());
300                   obj.setText(row.getValue(offset + 7).asString());
301               }
302         catch (DataSetException e)
303         {
304             throw new TorqueException(e);
305         }
306     }
307 
308     /***
309      * Method to do selects.
310      *
311      * @param criteria object used to create the SELECT statement.
312      * @return List of selected Objects
313      * @throws TorqueException Any exceptions caught during processing will be
314      *         rethrown wrapped into a TorqueException.
315      */
316     public static List doSelect(Criteria criteria) throws TorqueException
317     {
318         return populateObjects(doSelectVillageRecords(criteria));
319     }
320 
321     /***
322      * Method to do selects within a transaction.
323      *
324      * @param criteria object used to create the SELECT statement.
325      * @param con the connection to use
326      * @return List of selected Objects
327      * @throws TorqueException Any exceptions caught during processing will be
328      *         rethrown wrapped into a TorqueException.
329      */
330     public static List doSelect(Criteria criteria, Connection con)
331         throws TorqueException
332     {
333         return populateObjects(doSelectVillageRecords(criteria, con));
334     }
335 
336     /***
337      * Grabs the raw Village records to be formed into objects.
338      * This method handles connections internally.  The Record objects
339      * returned by this method should be considered readonly.  Do not
340      * alter the data and call save(), your results may vary, but are
341      * certainly likely to result in hard to track MT bugs.
342      *
343      * @throws TorqueException Any exceptions caught during processing will be
344      *         rethrown wrapped into a TorqueException.
345      */
346     public static List doSelectVillageRecords(Criteria criteria)
347         throws TorqueException
348     {
349         return BaseCommentPeer
350             .doSelectVillageRecords(criteria, (Connection) null);
351     }
352 
353     /***
354      * Grabs the raw Village records to be formed into objects.
355      * This method should be used for transactions
356      *
357      * @param con the connection to use
358      * @throws TorqueException Any exceptions caught during processing will be
359      *         rethrown wrapped into a TorqueException.
360      */
361     public static List doSelectVillageRecords(Criteria criteria, Connection con)
362         throws TorqueException
363     {
364         if (criteria.getSelectColumns().size() == 0)
365         {
366             addSelectColumns(criteria);
367         }
368 
369                                                   
370         // Set the correct dbName if it has not been overridden
371         // criteria.getDbName will return the same object if not set to
372         // another value so == check is okay and faster
373         if (criteria.getDbName() == Torque.getDefaultDB())
374         {
375             criteria.setDbName(DATABASE_NAME);
376         }
377         // BasePeer returns a List of Value (Village) arrays.  The array
378         // order follows the order columns were placed in the Select clause.
379         if (con == null)
380         {
381             return BasePeer.doSelect(criteria);
382         }
383         else
384         {
385             return BasePeer.doSelect(criteria, con);
386         }
387     }
388 
389     /***
390      * The returned List will contain objects of the default type or
391      * objects that inherit from the default.
392      *
393      * @throws TorqueException Any exceptions caught during processing will be
394      *         rethrown wrapped into a TorqueException.
395      */
396     public static List populateObjects(List records)
397         throws TorqueException
398     {
399         List results = new ArrayList(records.size());
400 
401         // populate the object(s)
402         for (int i = 0; i < records.size(); i++)
403         {
404             Record row = (Record) records.get(i);
405               results.add(CommentPeer.row2Object(row, 1,
406                 CommentPeer.getOMClass()));
407           }
408         return results;
409     }
410  
411 
412     /***
413      * The class that the Peer will make instances of.
414      * If the BO is abstract then you must implement this method
415      * in the BO.
416      *
417      * @throws TorqueException Any exceptions caught during processing will be
418      *         rethrown wrapped into a TorqueException.
419      */
420     public static Class getOMClass()
421         throws TorqueException
422     {
423         return CLASS_DEFAULT;
424     }
425 
426     /***
427      * Method to do updates.
428      *
429      * @param criteria object containing data that is used to create the UPDATE
430      *        statement.
431      * @throws TorqueException Any exceptions caught during processing will be
432      *         rethrown wrapped into a TorqueException.
433      */
434     public static void doUpdate(Criteria criteria) throws TorqueException
435     {
436          BaseCommentPeer
437             .doUpdate(criteria, (Connection) null);
438     }
439 
440     /***
441      * Method to do updates.  This method is to be used during a transaction,
442      * otherwise use the doUpdate(Criteria) method.  It will take care of
443      * the connection details internally.
444      *
445      * @param criteria object containing data that is used to create the UPDATE
446      *        statement.
447      * @param con the connection to use
448      * @throws TorqueException Any exceptions caught during processing will be
449      *         rethrown wrapped into a TorqueException.
450      */
451     public static void doUpdate(Criteria criteria, Connection con)
452         throws TorqueException
453     {
454         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
455                    selectCriteria.put(COMMENT_ID, criteria.remove(COMMENT_ID));
456                                                                             
457         // Set the correct dbName if it has not been overridden
458         // criteria.getDbName will return the same object if not set to
459         // another value so == check is okay and faster
460         if (criteria.getDbName() == Torque.getDefaultDB())
461         {
462             criteria.setDbName(DATABASE_NAME);
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          CommentPeer
484             .doDelete(criteria, (Connection) 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 con)
498         throws TorqueException
499      {
500                                                   
501         // Set the correct dbName if it has not been overridden
502         // criteria.getDbName will return the same object if not set to
503         // another value so == check is okay and faster
504         if (criteria.getDbName() == Torque.getDefaultDB())
505         {
506             criteria.setDbName(DATABASE_NAME);
507         }
508         if (con == null)
509         {
510             BasePeer.doDelete(criteria);
511         }
512         else
513         {
514             BasePeer.doDelete(criteria, con);
515         }
516      }
517 
518     /***
519      * Method to do selects
520      *
521      * @throws TorqueException Any exceptions caught during processing will be
522      *         rethrown wrapped into a TorqueException.
523      */
524     public static List doSelect(Comment obj) throws TorqueException
525     {
526         return doSelect(buildCriteria(obj));
527     }
528 
529     /***
530      * Method to do inserts
531      *
532      * @throws TorqueException Any exceptions caught during processing will be
533      *         rethrown wrapped into a TorqueException.
534      */
535     public static void doInsert(Comment obj) throws TorqueException
536     {
537           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
538           obj.setNew(false);
539         obj.setModified(false);
540     }
541 
542     /***
543      * @param obj the data object to update in the database.
544      * @throws TorqueException Any exceptions caught during processing will be
545      *         rethrown wrapped into a TorqueException.
546      */
547     public static void doUpdate(Comment obj) throws TorqueException
548     {
549         doUpdate(buildCriteria(obj));
550         obj.setModified(false);
551     }
552 
553     /***
554      * @param obj the data object to delete in the database.
555      * @throws TorqueException Any exceptions caught during processing will be
556      *         rethrown wrapped into a TorqueException.
557      */
558     public static void doDelete(Comment obj) throws TorqueException
559     {
560         doDelete(buildCriteria(obj));
561     }
562 
563     /***
564      * Method to do inserts.  This method is to be used during a transaction,
565      * otherwise use the doInsert(Comment) method.  It will take
566      * care of the connection details internally.
567      *
568      * @param obj the data object to insert into the database.
569      * @param con the connection to use
570      * @throws TorqueException Any exceptions caught during processing will be
571      *         rethrown wrapped into a TorqueException.
572      */
573     public static void doInsert(Comment obj, Connection con)
574         throws TorqueException
575     {
576           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
577           obj.setNew(false);
578         obj.setModified(false);
579     }
580 
581     /***
582      * Method to do update.  This method is to be used during a transaction,
583      * otherwise use the doUpdate(Comment) method.  It will take
584      * care of the connection details internally.
585      *
586      * @param obj the data object to update in the database.
587      * @param con the connection to use
588      * @throws TorqueException Any exceptions caught during processing will be
589      *         rethrown wrapped into a TorqueException.
590      */
591     public static void doUpdate(Comment obj, Connection con)
592         throws TorqueException
593     {
594         doUpdate(buildCriteria(obj), con);
595         obj.setModified(false);
596     }
597 
598     /***
599      * Method to delete.  This method is to be used during a transaction,
600      * otherwise use the doDelete(Comment) method.  It will take
601      * care of the connection details internally.
602      *
603      * @param obj the data object to delete in the database.
604      * @param con the connection to use
605      * @throws TorqueException Any exceptions caught during processing will be
606      *         rethrown wrapped into a TorqueException.
607      */
608     public static void doDelete(Comment obj, Connection con)
609         throws TorqueException
610     {
611         doDelete(buildCriteria(obj), con);
612     }
613 
614     /***
615      * Method to do deletes.
616      *
617      * @param pk ObjectKey that is used DELETE from database.
618      * @throws TorqueException Any exceptions caught during processing will be
619      *         rethrown wrapped into a TorqueException.
620      */
621     public static void doDelete(ObjectKey pk) throws TorqueException
622     {
623         BaseCommentPeer
624            .doDelete(pk, (Connection) null);
625     }
626 
627     /***
628      * Method to delete.  This method is to be used during a transaction,
629      * otherwise use the doDelete(ObjectKey) method.  It will take
630      * care of the connection details internally.
631      *
632      * @param pk the primary key for the object to delete in the database.
633      * @param con the connection to use
634      * @throws TorqueException Any exceptions caught during processing will be
635      *         rethrown wrapped into a TorqueException.
636      */
637     public static void doDelete(ObjectKey pk, Connection con)
638         throws TorqueException
639     {
640         doDelete(buildCriteria(pk), con);
641     }
642 
643     /*** Build a Criteria object from an ObjectKey */
644     public static Criteria buildCriteria( ObjectKey pk )
645     {
646         Criteria criteria = new Criteria();
647               criteria.add(COMMENT_ID, pk);
648           return criteria;
649      }
650 
651     /*** Build a Criteria object from the data object for this peer */
652     public static Criteria buildCriteria( Comment obj )
653     {
654         Criteria criteria = new Criteria(DATABASE_NAME);
655               if (!obj.isNew())
656                 criteria.add(COMMENT_ID, obj.getCommentId());
657                   criteria.add(POST_ID, obj.getPostId());
658                   criteria.add(POSTED_TIME, obj.getPostedTime());
659                   criteria.add(NAME, obj.getName());
660                   criteria.add(URL, obj.getUrl());
661                   criteria.add(EMAIL, obj.getEmail());
662                   criteria.add(TITLE, obj.getTitle());
663                   criteria.add(TEXT, obj.getText());
664           return criteria;
665     }
666  
667     
668         /***
669      * Retrieve a single object by pk
670      *
671      * @param pk the primary key
672      * @throws TorqueException Any exceptions caught during processing will be
673      *         rethrown wrapped into a TorqueException.
674      * @throws NoRowsException Primary key was not found in database.
675      * @throws TooManyRowsException Primary key was not found in database.
676      */
677     public static Comment retrieveByPK(int pk)
678         throws TorqueException, NoRowsException, TooManyRowsException
679     {
680         return retrieveByPK(SimpleKey.keyFor(pk));
681     }
682   
683     /***
684      * Retrieve a single object by pk
685      *
686      * @param pk the primary key
687      * @throws TorqueException Any exceptions caught during processing will be
688      *         rethrown wrapped into a TorqueException.
689      * @throws NoRowsException Primary key was not found in database.
690      * @throws TooManyRowsException Primary key was not found in database.
691      */
692     public static Comment retrieveByPK(ObjectKey pk)
693         throws TorqueException, NoRowsException, TooManyRowsException
694     {
695         Connection db = null;
696         Comment retVal = null;
697         try
698         {
699             db = Torque.getConnection(DATABASE_NAME);
700             retVal = retrieveByPK(pk, db);
701         }
702         finally
703         {
704             Torque.closeConnection(db);
705         }
706         return(retVal);
707     }
708 
709     /***
710      * Retrieve a single object by pk
711      *
712      * @param pk the primary key
713      * @param con the connection to use
714      * @throws TorqueException Any exceptions caught during processing will be
715      *         rethrown wrapped into a TorqueException.
716      * @throws NoRowsException Primary key was not found in database.
717      * @throws TooManyRowsException Primary key was not found in database.
718      */
719     public static Comment retrieveByPK(ObjectKey pk, Connection con)
720         throws TorqueException, NoRowsException, TooManyRowsException
721     {
722         Criteria criteria = buildCriteria(pk);
723         List v = doSelect(criteria, con);
724         if (v.size() == 0)
725         {
726             throw new NoRowsException("Failed to select a row.");
727         }
728         else if (v.size() > 1)
729         {
730             throw new TooManyRowsException("Failed to select only one row.");
731         }
732         else
733         {
734             return (Comment)v.get(0);
735         }
736     }
737 
738     /***
739      * Retrieve a multiple objects by pk
740      *
741      * @param pks List of primary keys
742      * @throws TorqueException Any exceptions caught during processing will be
743      *         rethrown wrapped into a TorqueException.
744      */
745     public static List retrieveByPKs(List pks)
746         throws TorqueException
747     {
748         Connection db = null;
749         List retVal = null;
750         try
751         {
752            db = Torque.getConnection(DATABASE_NAME);
753            retVal = retrieveByPKs(pks, db);
754         }
755         finally
756         {
757             Torque.closeConnection(db);
758         }
759         return(retVal);
760     }
761 
762     /***
763      * Retrieve a multiple objects by pk
764      *
765      * @param pks List of primary keys
766      * @param dbcon the connection to use
767      * @throws TorqueException Any exceptions caught during processing will be
768      *         rethrown wrapped into a TorqueException.
769      */
770     public static List retrieveByPKs( List pks, Connection dbcon )
771         throws TorqueException
772     {
773         List objs = null;
774         if (pks == null || pks.size() == 0)
775         {
776             objs = new LinkedList();
777         }
778         else
779         {
780             Criteria criteria = new Criteria();
781               criteria.addIn( COMMENT_ID, pks );
782           objs = doSelect(criteria, dbcon);
783         }
784         return objs;
785     }
786 
787  
788 
789 
790 
791           
792                                               
793                 
794                 
795 
796     /***
797      * selects a collection of Comment objects pre-filled with their
798      * Post objects.
799      *
800      * This method is protected by default in order to keep the public
801      * api reasonable.  You can provide public methods for those you
802      * actually need in CommentPeer.
803      *
804      * @throws TorqueException Any exceptions caught during processing will be
805      *         rethrown wrapped into a TorqueException.
806      */
807     protected static List doSelectJoinPost(Criteria c)
808         throws TorqueException
809     {
810         // Set the correct dbName if it has not been overridden
811         // c.getDbName will return the same object if not set to
812         // another value so == check is okay and faster
813         if (c.getDbName() == Torque.getDefaultDB())
814         {
815             c.setDbName(DATABASE_NAME);
816         }
817 
818         CommentPeer.addSelectColumns(c);
819         int offset = numColumns + 1;
820         PostPeer.addSelectColumns(c);
821 
822 
823                         c.addJoin(CommentPeer.POST_ID,
824             PostPeer.POST_ID);
825         
826 
827                                                                                                                                                         
828         List rows = BasePeer.doSelect(c);
829         List results = new ArrayList();
830 
831         for (int i = 0; i < rows.size(); i++)
832         {
833             Record row = (Record) rows.get(i);
834 
835                             Class omClass = CommentPeer.getOMClass();
836                     Comment obj1 = (Comment) CommentPeer
837                 .row2Object(row, 1, omClass);
838                      omClass = PostPeer.getOMClass();
839                     Post obj2 = (Post)PostPeer
840                 .row2Object(row, offset, omClass);
841 
842             boolean newObject = true;
843             for (int j = 0; j < results.size(); j++)
844             {
845                 Comment temp_obj1 = (Comment)results.get(j);
846                 Post temp_obj2 = (Post)temp_obj1.getPost();
847                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
848                 {
849                     newObject = false;
850                               temp_obj2.addComment(obj1);
851                               break;
852                 }
853             }
854             if (newObject)
855             {
856                           obj2.initComments();
857                 obj2.addComment(obj1);
858                       }
859             results.add(obj1);
860         }
861         return results;
862     }
863                     
864   
865     
866   
867       /***
868      * Returns the TableMap related to this peer.  This method is not
869      * needed for general use but a specific application could have a need.
870      *
871      * @throws TorqueException Any exceptions caught during processing will be
872      *         rethrown wrapped into a TorqueException.
873      */
874     protected static TableMap getTableMap()
875         throws TorqueException
876     {
877         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
878     }
879    }