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