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