1 package org.apache.jetspeed.om.dbregistry;
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.jetspeed.om.dbregistry.map.*;
32
33
34
35 /***
36 * This class was autogenerated by Torque on:
37 *
38 * [Thu Apr 22 23:12:36 EDT 2004]
39 *
40 */
41 public abstract class BasePortletParameterPeer
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 = "PORTLET_PARAMETER";
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(PortletParameterMapBuilder.CLASS_NAME);
60 }
61
62 /*** the column name for the ID field */
63 public static final String ID;
64 /*** the column name for the NAME field */
65 public static final String NAME;
66 /*** the column name for the VALUE field */
67 public static final String VALUE;
68 /*** the column name for the TYPE field */
69 public static final String TYPE;
70 /*** the column name for the HIDDEN field */
71 public static final String HIDDEN;
72 /*** the column name for the ROLE field */
73 public static final String ROLE;
74 /*** the column name for the CACHEDONVALUE field */
75 public static final String CACHEDONVALUE;
76 /*** the column name for the CACHEDONNAME field */
77 public static final String CACHEDONNAME;
78 /*** the column name for the TITLE field */
79 public static final String TITLE;
80 /*** the column name for the DESCRIPTION field */
81 public static final String DESCRIPTION;
82 /*** the column name for the IMAGE field */
83 public static final String IMAGE;
84 /*** the column name for the PORTLET_ID field */
85 public static final String PORTLET_ID;
86 /*** the column name for the SECURITY field */
87 public static final String SECURITY;
88
89 static
90 {
91 ID = "PORTLET_PARAMETER.ID";
92 NAME = "PORTLET_PARAMETER.NAME";
93 VALUE = "PORTLET_PARAMETER.VALUE";
94 TYPE = "PORTLET_PARAMETER.TYPE";
95 HIDDEN = "PORTLET_PARAMETER.HIDDEN";
96 ROLE = "PORTLET_PARAMETER.ROLE";
97 CACHEDONVALUE = "PORTLET_PARAMETER.CACHEDONVALUE";
98 CACHEDONNAME = "PORTLET_PARAMETER.CACHEDONNAME";
99 TITLE = "PORTLET_PARAMETER.TITLE";
100 DESCRIPTION = "PORTLET_PARAMETER.DESCRIPTION";
101 IMAGE = "PORTLET_PARAMETER.IMAGE";
102 PORTLET_ID = "PORTLET_PARAMETER.PORTLET_ID";
103 SECURITY = "PORTLET_PARAMETER.SECURITY";
104 if (Torque.isInit())
105 {
106 try
107 {
108 getMapBuilder();
109 }
110 catch (Exception e)
111 {
112 log.error("Could not initialize Peer", e);
113 }
114 }
115 else
116 {
117 Torque.registerMapBuilder(PortletParameterMapBuilder.CLASS_NAME);
118 }
119 }
120
121 /*** number of columns for this peer */
122 public static final int numColumns = 13;
123
124 /*** A class that can be returned by this peer. */
125 protected static final String CLASSNAME_DEFAULT =
126 "org.apache.jetspeed.om.dbregistry.PortletParameter";
127
128 /*** A class that can be returned by this peer. */
129 protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
130
131 /***
132 * Class object initialization method.
133 *
134 * @param className name of the class to initialize
135 * @return the initialized class
136 */
137 private static Class initClass(String className)
138 {
139 Class c = null;
140 try
141 {
142 c = Class.forName(className);
143 }
144 catch (Throwable t)
145 {
146 log.error("A FATAL ERROR has occurred which should not "
147 + "have happened under any circumstance. Please notify "
148 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> "
149 + "and give as many details as possible (including the error "
150 + "stack trace).", t);
151
152
153 if (t instanceof Error)
154 {
155 throw (Error) t.fillInStackTrace();
156 }
157 }
158 return c;
159 }
160
161 /***
162 * Get the list of objects for a ResultSet. Please not that your
163 * resultset MUST return columns in the right order. You can use
164 * getFieldNames() in BaseObject to get the correct sequence.
165 *
166 * @param results the ResultSet
167 * @return the list of objects
168 * @throws TorqueException Any exceptions caught during processing will be
169 * rethrown wrapped into a TorqueException.
170 */
171 public static List resultSet2Objects(java.sql.ResultSet results)
172 throws TorqueException
173 {
174 try
175 {
176 QueryDataSet qds = null;
177 List rows = null;
178 try
179 {
180 qds = new QueryDataSet(results);
181 rows = getSelectResults(qds);
182 }
183 finally
184 {
185 if (qds != null)
186 {
187 qds.close();
188 }
189 }
190
191 return populateObjects(rows);
192 }
193 catch (SQLException e)
194 {
195 throw new TorqueException(e);
196 }
197 catch (DataSetException e)
198 {
199 throw new TorqueException(e);
200 }
201 }
202
203
204
205 /***
206 * Method to do inserts.
207 *
208 * @param criteria object used to create the INSERT statement.
209 * @throws TorqueException Any exceptions caught during processing will be
210 * rethrown wrapped into a TorqueException.
211 */
212 public static ObjectKey doInsert(Criteria criteria)
213 throws TorqueException
214 {
215 return BasePortletParameterPeer
216 .doInsert(criteria, (Connection) null);
217 }
218
219 /***
220 * Method to do inserts. This method is to be used during a transaction,
221 * otherwise use the doInsert(Criteria) method. It will take care of
222 * the connection details internally.
223 *
224 * @param criteria object used to create the INSERT statement.
225 * @param con the connection to use
226 * @throws TorqueException Any exceptions caught during processing will be
227 * rethrown wrapped into a TorqueException.
228 */
229 public static ObjectKey doInsert(Criteria criteria, Connection con)
230 throws TorqueException
231 {
232
233 if (criteria.containsKey(HIDDEN))
234 {
235 Object possibleBoolean = criteria.get(HIDDEN);
236 if (possibleBoolean instanceof Boolean)
237 {
238 if (((Boolean) possibleBoolean).booleanValue())
239 {
240 criteria.add(HIDDEN, 1);
241 }
242 else
243 {
244 criteria.add(HIDDEN, 0);
245 }
246 }
247 }
248
249 if (criteria.containsKey(CACHEDONVALUE))
250 {
251 Object possibleBoolean = criteria.get(CACHEDONVALUE);
252 if (possibleBoolean instanceof Boolean)
253 {
254 if (((Boolean) possibleBoolean).booleanValue())
255 {
256 criteria.add(CACHEDONVALUE, 1);
257 }
258 else
259 {
260 criteria.add(CACHEDONVALUE, 0);
261 }
262 }
263 }
264
265 if (criteria.containsKey(CACHEDONNAME))
266 {
267 Object possibleBoolean = criteria.get(CACHEDONNAME);
268 if (possibleBoolean instanceof Boolean)
269 {
270 if (((Boolean) possibleBoolean).booleanValue())
271 {
272 criteria.add(CACHEDONNAME, 1);
273 }
274 else
275 {
276 criteria.add(CACHEDONNAME, 0);
277 }
278 }
279 }
280
281
282
283
284 if (criteria.getDbName() == Torque.getDefaultDB())
285 {
286 criteria.setDbName(DATABASE_NAME);
287 }
288 if (con == null)
289 {
290 return BasePeer.doInsert(criteria);
291 }
292 else
293 {
294 return BasePeer.doInsert(criteria, con);
295 }
296 }
297
298 /***
299 * Add all the columns needed to create a new object.
300 *
301 * @param criteria object containing the columns to add.
302 * @throws TorqueException Any exceptions caught during processing will be
303 * rethrown wrapped into a TorqueException.
304 */
305 public static void addSelectColumns(Criteria criteria)
306 throws TorqueException
307 {
308 criteria.addSelectColumn(ID);
309 criteria.addSelectColumn(NAME);
310 criteria.addSelectColumn(VALUE);
311 criteria.addSelectColumn(TYPE);
312 criteria.addSelectColumn(HIDDEN);
313 criteria.addSelectColumn(ROLE);
314 criteria.addSelectColumn(CACHEDONVALUE);
315 criteria.addSelectColumn(CACHEDONNAME);
316 criteria.addSelectColumn(TITLE);
317 criteria.addSelectColumn(DESCRIPTION);
318 criteria.addSelectColumn(IMAGE);
319 criteria.addSelectColumn(PORTLET_ID);
320 criteria.addSelectColumn(SECURITY);
321 }
322
323 /***
324 * Create a new object of type cls from a resultset row starting
325 * from a specified offset. This is done so that you can select
326 * other rows than just those needed for this object. You may
327 * for example want to create two objects from the same row.
328 *
329 * @throws TorqueException Any exceptions caught during processing will be
330 * rethrown wrapped into a TorqueException.
331 */
332 public static PortletParameter row2Object(Record row,
333 int offset,
334 Class cls)
335 throws TorqueException
336 {
337 try
338 {
339 PortletParameter obj = (PortletParameter) cls.newInstance();
340 PortletParameterPeer.populateObject(row, offset, obj);
341 obj.setModified(false);
342 obj.setNew(false);
343
344 return obj;
345 }
346 catch (InstantiationException e)
347 {
348 throw new TorqueException(e);
349 }
350 catch (IllegalAccessException e)
351 {
352 throw new TorqueException(e);
353 }
354 }
355
356 /***
357 * Populates an object from a resultset row starting
358 * from a specified offset. This is done so that you can select
359 * other rows than just those needed for this object. You may
360 * for example want to create two objects from the same row.
361 *
362 * @throws TorqueException Any exceptions caught during processing will be
363 * rethrown wrapped into a TorqueException.
364 */
365 public static void populateObject(Record row,
366 int offset,
367 PortletParameter obj)
368 throws TorqueException
369 {
370 try
371 {
372 obj.setId(row.getValue(offset + 0).asLong());
373 obj.setName(row.getValue(offset + 1).asString());
374 obj.setValue(row.getValue(offset + 2).asString());
375 obj.setType(row.getValue(offset + 3).asString());
376 obj.setHidden(row.getValue(offset + 4).asBoolean());
377 obj.setRole(row.getValue(offset + 5).asString());
378 obj.setCachedonvalue(row.getValue(offset + 6).asBoolean());
379 obj.setCachedonname(row.getValue(offset + 7).asBoolean());
380 obj.setTitle(row.getValue(offset + 8).asString());
381 obj.setDescription(row.getValue(offset + 9).asString());
382 obj.setImage(row.getValue(offset + 10).asString());
383 obj.setPortletId(row.getValue(offset + 11).asLong());
384 obj.setSecurityRef(row.getValue(offset + 12).asString());
385 }
386 catch (DataSetException e)
387 {
388 throw new TorqueException(e);
389 }
390 }
391
392 /***
393 * Method to do selects.
394 *
395 * @param criteria object used to create the SELECT statement.
396 * @return List of selected Objects
397 * @throws TorqueException Any exceptions caught during processing will be
398 * rethrown wrapped into a TorqueException.
399 */
400 public static List doSelect(Criteria criteria) throws TorqueException
401 {
402 return populateObjects(doSelectVillageRecords(criteria));
403 }
404
405 /***
406 * Method to do selects within a transaction.
407 *
408 * @param criteria object used to create the SELECT statement.
409 * @param con the connection to use
410 * @return List of selected Objects
411 * @throws TorqueException Any exceptions caught during processing will be
412 * rethrown wrapped into a TorqueException.
413 */
414 public static List doSelect(Criteria criteria, Connection con)
415 throws TorqueException
416 {
417 return populateObjects(doSelectVillageRecords(criteria, con));
418 }
419
420 /***
421 * Grabs the raw Village records to be formed into objects.
422 * This method handles connections internally. The Record objects
423 * returned by this method should be considered readonly. Do not
424 * alter the data and call save(), your results may vary, but are
425 * certainly likely to result in hard to track MT bugs.
426 *
427 * @throws TorqueException Any exceptions caught during processing will be
428 * rethrown wrapped into a TorqueException.
429 */
430 public static List doSelectVillageRecords(Criteria criteria)
431 throws TorqueException
432 {
433 return BasePortletParameterPeer
434 .doSelectVillageRecords(criteria, (Connection) null);
435 }
436
437 /***
438 * Grabs the raw Village records to be formed into objects.
439 * This method should be used for transactions
440 *
441 * @param con the connection to use
442 * @throws TorqueException Any exceptions caught during processing will be
443 * rethrown wrapped into a TorqueException.
444 */
445 public static List doSelectVillageRecords(Criteria criteria, Connection con)
446 throws TorqueException
447 {
448 if (criteria.getSelectColumns().size() == 0)
449 {
450 addSelectColumns(criteria);
451 }
452
453
454 if (criteria.containsKey(HIDDEN))
455 {
456 Object possibleBoolean = criteria.get(HIDDEN);
457 if (possibleBoolean instanceof Boolean)
458 {
459 if (((Boolean) possibleBoolean).booleanValue())
460 {
461 criteria.add(HIDDEN, 1);
462 }
463 else
464 {
465 criteria.add(HIDDEN, 0);
466 }
467 }
468 }
469
470 if (criteria.containsKey(CACHEDONVALUE))
471 {
472 Object possibleBoolean = criteria.get(CACHEDONVALUE);
473 if (possibleBoolean instanceof Boolean)
474 {
475 if (((Boolean) possibleBoolean).booleanValue())
476 {
477 criteria.add(CACHEDONVALUE, 1);
478 }
479 else
480 {
481 criteria.add(CACHEDONVALUE, 0);
482 }
483 }
484 }
485
486 if (criteria.containsKey(CACHEDONNAME))
487 {
488 Object possibleBoolean = criteria.get(CACHEDONNAME);
489 if (possibleBoolean instanceof Boolean)
490 {
491 if (((Boolean) possibleBoolean).booleanValue())
492 {
493 criteria.add(CACHEDONNAME, 1);
494 }
495 else
496 {
497 criteria.add(CACHEDONNAME, 0);
498 }
499 }
500 }
501
502
503
504
505 if (criteria.getDbName() == Torque.getDefaultDB())
506 {
507 criteria.setDbName(DATABASE_NAME);
508 }
509
510
511 if (con == null)
512 {
513 return BasePeer.doSelect(criteria);
514 }
515 else
516 {
517 return BasePeer.doSelect(criteria, con);
518 }
519 }
520
521 /***
522 * The returned List will contain objects of the default type or
523 * objects that inherit from the default.
524 *
525 * @throws TorqueException Any exceptions caught during processing will be
526 * rethrown wrapped into a TorqueException.
527 */
528 public static List populateObjects(List records)
529 throws TorqueException
530 {
531 List results = new ArrayList(records.size());
532
533
534 for (int i = 0; i < records.size(); i++)
535 {
536 Record row = (Record) records.get(i);
537 results.add(PortletParameterPeer.row2Object(row, 1,
538 PortletParameterPeer.getOMClass()));
539 }
540 return results;
541 }
542
543
544 /***
545 * The class that the Peer will make instances of.
546 * If the BO is abstract then you must implement this method
547 * in the BO.
548 *
549 * @throws TorqueException Any exceptions caught during processing will be
550 * rethrown wrapped into a TorqueException.
551 */
552 public static Class getOMClass()
553 throws TorqueException
554 {
555 return CLASS_DEFAULT;
556 }
557
558 /***
559 * Method to do updates.
560 *
561 * @param criteria object containing data that is used to create the UPDATE
562 * statement.
563 * @throws TorqueException Any exceptions caught during processing will be
564 * rethrown wrapped into a TorqueException.
565 */
566 public static void doUpdate(Criteria criteria) throws TorqueException
567 {
568 BasePortletParameterPeer
569 .doUpdate(criteria, (Connection) null);
570 }
571
572 /***
573 * Method to do updates. This method is to be used during a transaction,
574 * otherwise use the doUpdate(Criteria) method. It will take care of
575 * the connection details internally.
576 *
577 * @param criteria object containing data that is used to create the UPDATE
578 * statement.
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 doUpdate(Criteria criteria, Connection con)
584 throws TorqueException
585 {
586 Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
587 selectCriteria.put(ID, criteria.remove(ID));
588
589 if (criteria.containsKey(HIDDEN))
590 {
591 Object possibleBoolean = criteria.get(HIDDEN);
592 if (possibleBoolean instanceof Boolean)
593 {
594 if (((Boolean) possibleBoolean).booleanValue())
595 {
596 criteria.add(HIDDEN, 1);
597 }
598 else
599 {
600 criteria.add(HIDDEN, 0);
601 }
602 }
603 }
604
605 if (criteria.containsKey(CACHEDONVALUE))
606 {
607 Object possibleBoolean = criteria.get(CACHEDONVALUE);
608 if (possibleBoolean instanceof Boolean)
609 {
610 if (((Boolean) possibleBoolean).booleanValue())
611 {
612 criteria.add(CACHEDONVALUE, 1);
613 }
614 else
615 {
616 criteria.add(CACHEDONVALUE, 0);
617 }
618 }
619 }
620
621 if (criteria.containsKey(CACHEDONNAME))
622 {
623 Object possibleBoolean = criteria.get(CACHEDONNAME);
624 if (possibleBoolean instanceof Boolean)
625 {
626 if (((Boolean) possibleBoolean).booleanValue())
627 {
628 criteria.add(CACHEDONNAME, 1);
629 }
630 else
631 {
632 criteria.add(CACHEDONNAME, 0);
633 }
634 }
635 }
636
637
638
639
640 if (criteria.getDbName() == Torque.getDefaultDB())
641 {
642 criteria.setDbName(DATABASE_NAME);
643 }
644 if (con == null)
645 {
646 BasePeer.doUpdate(selectCriteria, criteria);
647 }
648 else
649 {
650 BasePeer.doUpdate(selectCriteria, criteria, con);
651 }
652 }
653
654 /***
655 * Method to do deletes.
656 *
657 * @param criteria object containing data that is used DELETE from database.
658 * @throws TorqueException Any exceptions caught during processing will be
659 * rethrown wrapped into a TorqueException.
660 */
661 public static void doDelete(Criteria criteria) throws TorqueException
662 {
663 BasePortletParameterPeer
664 .doDelete(criteria, (Connection) null);
665 }
666
667 /***
668 * Method to do deletes. This method is to be used during a transaction,
669 * otherwise use the doDelete(Criteria) method. It will take care of
670 * the connection details internally.
671 *
672 * @param criteria object containing data that is used DELETE from database.
673 * @param con the connection to use
674 * @throws TorqueException Any exceptions caught during processing will be
675 * rethrown wrapped into a TorqueException.
676 */
677 public static void doDelete(Criteria criteria, Connection con)
678 throws TorqueException
679 {
680
681 if (criteria.containsKey(HIDDEN))
682 {
683 Object possibleBoolean = criteria.get(HIDDEN);
684 if (possibleBoolean instanceof Boolean)
685 {
686 if (((Boolean) possibleBoolean).booleanValue())
687 {
688 criteria.add(HIDDEN, 1);
689 }
690 else
691 {
692 criteria.add(HIDDEN, 0);
693 }
694 }
695 }
696
697 if (criteria.containsKey(CACHEDONVALUE))
698 {
699 Object possibleBoolean = criteria.get(CACHEDONVALUE);
700 if (possibleBoolean instanceof Boolean)
701 {
702 if (((Boolean) possibleBoolean).booleanValue())
703 {
704 criteria.add(CACHEDONVALUE, 1);
705 }
706 else
707 {
708 criteria.add(CACHEDONVALUE, 0);
709 }
710 }
711 }
712
713 if (criteria.containsKey(CACHEDONNAME))
714 {
715 Object possibleBoolean = criteria.get(CACHEDONNAME);
716 if (possibleBoolean instanceof Boolean)
717 {
718 if (((Boolean) possibleBoolean).booleanValue())
719 {
720 criteria.add(CACHEDONNAME, 1);
721 }
722 else
723 {
724 criteria.add(CACHEDONNAME, 0);
725 }
726 }
727 }
728
729
730
731
732 if (criteria.getDbName() == Torque.getDefaultDB())
733 {
734 criteria.setDbName(DATABASE_NAME);
735 }
736 if (con == null)
737 {
738 BasePeer.doDelete(criteria);
739 }
740 else
741 {
742 BasePeer.doDelete(criteria, con);
743 }
744 }
745
746 /***
747 * Method to do selects
748 *
749 * @throws TorqueException Any exceptions caught during processing will be
750 * rethrown wrapped into a TorqueException.
751 */
752 public static List doSelect(PortletParameter obj) throws TorqueException
753 {
754 return doSelect(buildCriteria(obj));
755 }
756
757 /***
758 * Method to do inserts
759 *
760 * @throws TorqueException Any exceptions caught during processing will be
761 * rethrown wrapped into a TorqueException.
762 */
763 public static void doInsert(PortletParameter obj) throws TorqueException
764 {
765 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
766 obj.setNew(false);
767 obj.setModified(false);
768 }
769
770 /***
771 * @param obj the data object to update in the database.
772 * @throws TorqueException Any exceptions caught during processing will be
773 * rethrown wrapped into a TorqueException.
774 */
775 public static void doUpdate(PortletParameter obj) throws TorqueException
776 {
777 doUpdate(buildCriteria(obj));
778 obj.setModified(false);
779 }
780
781 /***
782 * @param obj the data object to delete in the database.
783 * @throws TorqueException Any exceptions caught during processing will be
784 * rethrown wrapped into a TorqueException.
785 */
786 public static void doDelete(PortletParameter obj) throws TorqueException
787 {
788 doDelete(buildCriteria(obj));
789 }
790
791 /***
792 * Method to do inserts. This method is to be used during a transaction,
793 * otherwise use the doInsert(PortletParameter) method. It will take
794 * care of the connection details internally.
795 *
796 * @param obj the data object to insert into the database.
797 * @param con the connection to use
798 * @throws TorqueException Any exceptions caught during processing will be
799 * rethrown wrapped into a TorqueException.
800 */
801 public static void doInsert(PortletParameter obj, Connection con)
802 throws TorqueException
803 {
804 obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
805 obj.setNew(false);
806 obj.setModified(false);
807 }
808
809 /***
810 * Method to do update. This method is to be used during a transaction,
811 * otherwise use the doUpdate(PortletParameter) method. It will take
812 * care of the connection details internally.
813 *
814 * @param obj the data object to update in the database.
815 * @param con the connection to use
816 * @throws TorqueException Any exceptions caught during processing will be
817 * rethrown wrapped into a TorqueException.
818 */
819 public static void doUpdate(PortletParameter obj, Connection con)
820 throws TorqueException
821 {
822 doUpdate(buildCriteria(obj), con);
823 obj.setModified(false);
824 }
825
826 /***
827 * Method to delete. This method is to be used during a transaction,
828 * otherwise use the doDelete(PortletParameter) method. It will take
829 * care of the connection details internally.
830 *
831 * @param obj the data object to delete in the database.
832 * @param con the connection to use
833 * @throws TorqueException Any exceptions caught during processing will be
834 * rethrown wrapped into a TorqueException.
835 */
836 public static void doDelete(PortletParameter obj, Connection con)
837 throws TorqueException
838 {
839 doDelete(buildCriteria(obj), con);
840 }
841
842 /***
843 * Method to do deletes.
844 *
845 * @param pk ObjectKey that is used DELETE from database.
846 * @throws TorqueException Any exceptions caught during processing will be
847 * rethrown wrapped into a TorqueException.
848 */
849 public static void doDelete(ObjectKey pk) throws TorqueException
850 {
851 BasePortletParameterPeer
852 .doDelete(pk, (Connection) null);
853 }
854
855 /***
856 * Method to delete. This method is to be used during a transaction,
857 * otherwise use the doDelete(ObjectKey) method. It will take
858 * care of the connection details internally.
859 *
860 * @param pk the primary key for the object to delete in the database.
861 * @param con the connection to use
862 * @throws TorqueException Any exceptions caught during processing will be
863 * rethrown wrapped into a TorqueException.
864 */
865 public static void doDelete(ObjectKey pk, Connection con)
866 throws TorqueException
867 {
868 doDelete(buildCriteria(pk), con);
869 }
870
871 /*** Build a Criteria object from an ObjectKey */
872 public static Criteria buildCriteria( ObjectKey pk )
873 {
874 Criteria criteria = new Criteria();
875 criteria.add(ID, pk);
876 return criteria;
877 }
878
879 /*** Build a Criteria object from the data object for this peer */
880 public static Criteria buildCriteria( PortletParameter obj )
881 {
882 Criteria criteria = new Criteria(DATABASE_NAME);
883 if (!obj.isNew())
884 criteria.add(ID, obj.getId());
885 criteria.add(NAME, obj.getName());
886 criteria.add(VALUE, obj.getValue());
887 criteria.add(TYPE, obj.getType());
888 criteria.add(HIDDEN, obj.getHidden());
889 criteria.add(ROLE, obj.getRole());
890 criteria.add(CACHEDONVALUE, obj.getCachedonvalue());
891 criteria.add(CACHEDONNAME, obj.getCachedonname());
892 criteria.add(TITLE, obj.getTitle());
893 criteria.add(DESCRIPTION, obj.getDescription());
894 criteria.add(IMAGE, obj.getImage());
895 criteria.add(PORTLET_ID, obj.getPortletId());
896 criteria.add(SECURITY, obj.getSecurityRef());
897 return criteria;
898 }
899
900
901 /***
902 * Retrieve a single object by pk
903 *
904 * @param pk the primary key
905 * @throws TorqueException Any exceptions caught during processing will be
906 * rethrown wrapped into a TorqueException.
907 * @throws NoRowsException Primary key was not found in database.
908 * @throws TooManyRowsException Primary key was not found in database.
909 */
910 public static PortletParameter retrieveByPK(long pk)
911 throws TorqueException, NoRowsException, TooManyRowsException
912 {
913 return retrieveByPK(SimpleKey.keyFor(pk));
914 }
915
916 /***
917 * Retrieve a single object by pk
918 *
919 * @param pk the primary key
920 * @throws TorqueException Any exceptions caught during processing will be
921 * rethrown wrapped into a TorqueException.
922 * @throws NoRowsException Primary key was not found in database.
923 * @throws TooManyRowsException Primary key was not found in database.
924 */
925 public static PortletParameter retrieveByPK(ObjectKey pk)
926 throws TorqueException, NoRowsException, TooManyRowsException
927 {
928 Connection db = null;
929 PortletParameter retVal = null;
930 try
931 {
932 db = Torque.getConnection(DATABASE_NAME);
933 retVal = retrieveByPK(pk, db);
934 }
935 finally
936 {
937 Torque.closeConnection(db);
938 }
939 return(retVal);
940 }
941
942 /***
943 * Retrieve a single object by pk
944 *
945 * @param pk the primary key
946 * @param con the connection to use
947 * @throws TorqueException Any exceptions caught during processing will be
948 * rethrown wrapped into a TorqueException.
949 * @throws NoRowsException Primary key was not found in database.
950 * @throws TooManyRowsException Primary key was not found in database.
951 */
952 public static PortletParameter retrieveByPK(ObjectKey pk, Connection con)
953 throws TorqueException, NoRowsException, TooManyRowsException
954 {
955 Criteria criteria = buildCriteria(pk);
956 List v = doSelect(criteria, con);
957 if (v.size() == 0)
958 {
959 throw new NoRowsException("Failed to select a row.");
960 }
961 else if (v.size() > 1)
962 {
963 throw new TooManyRowsException("Failed to select only one row.");
964 }
965 else
966 {
967 return (PortletParameter)v.get(0);
968 }
969 }
970
971 /***
972 * Retrieve a multiple objects by pk
973 *
974 * @param pks List of primary keys
975 * @throws TorqueException Any exceptions caught during processing will be
976 * rethrown wrapped into a TorqueException.
977 */
978 public static List retrieveByPKs(List pks)
979 throws TorqueException
980 {
981 Connection db = null;
982 List retVal = null;
983 try
984 {
985 db = Torque.getConnection(DATABASE_NAME);
986 retVal = retrieveByPKs(pks, db);
987 }
988 finally
989 {
990 Torque.closeConnection(db);
991 }
992 return(retVal);
993 }
994
995 /***
996 * Retrieve a multiple objects by pk
997 *
998 * @param pks List of primary keys
999 * @param dbcon the connection to use
1000 * @throws TorqueException Any exceptions caught during processing will be
1001 * rethrown wrapped into a TorqueException.
1002 */
1003 public static List retrieveByPKs( List pks, Connection dbcon )
1004 throws TorqueException
1005 {
1006 List objs = null;
1007 if (pks == null || pks.size() == 0)
1008 {
1009 objs = new LinkedList();
1010 }
1011 else
1012 {
1013 Criteria criteria = new Criteria();
1014 criteria.addIn( ID, pks );
1015 objs = doSelect(criteria, dbcon);
1016 }
1017 return objs;
1018 }
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029 /***
1030 * selects a collection of PortletParameter objects pre-filled with their
1031 * PortletDbEntry objects.
1032 *
1033 * This method is protected by default in order to keep the public
1034 * api reasonable. You can provide public methods for those you
1035 * actually need in PortletParameterPeer.
1036 *
1037 * @throws TorqueException Any exceptions caught during processing will be
1038 * rethrown wrapped into a TorqueException.
1039 */
1040 protected static List doSelectJoinPortletDbEntry(Criteria c)
1041 throws TorqueException
1042 {
1043
1044
1045
1046 if (c.getDbName() == Torque.getDefaultDB())
1047 {
1048 c.setDbName(DATABASE_NAME);
1049 }
1050
1051 PortletParameterPeer.addSelectColumns(c);
1052 int offset = numColumns + 1;
1053 PortletDbEntryPeer.addSelectColumns(c);
1054
1055
1056 c.addJoin(PortletParameterPeer.PORTLET_ID,
1057 PortletDbEntryPeer.ID);
1058
1059
1060
1061 if (c.containsKey(HIDDEN))
1062 {
1063 Object possibleBoolean = c.get(HIDDEN);
1064 if (possibleBoolean instanceof Boolean)
1065 {
1066 if (((Boolean) possibleBoolean).booleanValue())
1067 {
1068 c.add(HIDDEN, 1);
1069 }
1070 else
1071 {
1072 c.add(HIDDEN, 0);
1073 }
1074 }
1075 }
1076
1077 if (c.containsKey(CACHEDONVALUE))
1078 {
1079 Object possibleBoolean = c.get(CACHEDONVALUE);
1080 if (possibleBoolean instanceof Boolean)
1081 {
1082 if (((Boolean) possibleBoolean).booleanValue())
1083 {
1084 c.add(CACHEDONVALUE, 1);
1085 }
1086 else
1087 {
1088 c.add(CACHEDONVALUE, 0);
1089 }
1090 }
1091 }
1092
1093 if (c.containsKey(CACHEDONNAME))
1094 {
1095 Object possibleBoolean = c.get(CACHEDONNAME);
1096 if (possibleBoolean instanceof Boolean)
1097 {
1098 if (((Boolean) possibleBoolean).booleanValue())
1099 {
1100 c.add(CACHEDONNAME, 1);
1101 }
1102 else
1103 {
1104 c.add(CACHEDONNAME, 0);
1105 }
1106 }
1107 }
1108
1109 List rows = BasePeer.doSelect(c);
1110 List results = new ArrayList();
1111
1112 for (int i = 0; i < rows.size(); i++)
1113 {
1114 Record row = (Record) rows.get(i);
1115
1116 Class omClass = PortletParameterPeer.getOMClass();
1117 PortletParameter obj1 = (PortletParameter) PortletParameterPeer
1118 .row2Object(row, 1, omClass);
1119 omClass = PortletDbEntryPeer.getOMClass();
1120 PortletDbEntry obj2 = (PortletDbEntry)PortletDbEntryPeer
1121 .row2Object(row, offset, omClass);
1122
1123 boolean newObject = true;
1124 for (int j = 0; j < results.size(); j++)
1125 {
1126 PortletParameter temp_obj1 = (PortletParameter)results.get(j);
1127 PortletDbEntry temp_obj2 = (PortletDbEntry)temp_obj1.getPortletDbEntry();
1128 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1129 {
1130 newObject = false;
1131 temp_obj2.addPortletParameter(obj1);
1132 break;
1133 }
1134 }
1135 if (newObject)
1136 {
1137 obj2.initPortletParameters();
1138 obj2.addPortletParameter(obj1);
1139 }
1140 results.add(obj1);
1141 }
1142 return results;
1143 }
1144
1145
1146
1147
1148 /***
1149 * Returns the TableMap related to this peer. This method is not
1150 * needed for general use but a specific application could have a need.
1151 *
1152 * @throws TorqueException Any exceptions caught during processing will be
1153 * rethrown wrapped into a TorqueException.
1154 */
1155 protected static TableMap getTableMap()
1156 throws TorqueException
1157 {
1158 return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1159 }
1160 }