KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > dbregistry > BasePortletDbEntryPeer


1 package org.apache.jetspeed.om.dbregistry;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.sql.Connection JavaDoc;
5 import java.sql.SQLException JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.LinkedList JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.apache.torque.NoRowsException;
13 import org.apache.torque.TooManyRowsException;
14 import org.apache.torque.Torque;
15 import org.apache.torque.TorqueException;
16 import org.apache.torque.map.MapBuilder;
17 import org.apache.torque.map.TableMap;
18 import org.apache.torque.om.DateKey;
19 import org.apache.torque.om.NumberKey;
20 import org.apache.torque.om.StringKey;
21 import org.apache.torque.om.ObjectKey;
22 import org.apache.torque.om.SimpleKey;
23 import org.apache.torque.util.BasePeer;
24 import org.apache.torque.util.Criteria;
25
26 import com.workingdogs.village.DataSetException;
27 import com.workingdogs.village.QueryDataSet;
28 import com.workingdogs.village.Record;
29
30 // Local classes
31
import org.apache.jetspeed.om.dbregistry.map.*;
32
33
34 /**
35  * This class was autogenerated by Torque on:
36  *
37  * [Thu Apr 22 15:30:48 PDT 2004]
38  *
39  */

40 public abstract class BasePortletDbEntryPeer
41     extends BasePeer
42 {
43
44     /** the default database name for this class */
45     public static final String JavaDoc DATABASE_NAME = "default";
46
47      /** the table name for this class */
48     public static final String JavaDoc TABLE_NAME = "PORTLET";
49
50     /**
51      * @return the map builder for this peer
52      * @throws TorqueException Any exceptions caught during processing will be
53      * rethrown wrapped into a TorqueException.
54      */

55     public static MapBuilder getMapBuilder()
56         throws TorqueException
57     {
58         return getMapBuilder(PortletDbEntryMapBuilder.CLASS_NAME);
59     }
60
61       /** the column name for the ID field */
62     public static final String JavaDoc ID;
63       /** the column name for the NAME field */
64     public static final String JavaDoc NAME;
65       /** the column name for the HIDDEN field */
66     public static final String JavaDoc HIDDEN;
67       /** the column name for the CLASSNAME field */
68     public static final String JavaDoc CLASSNAME;
69       /** the column name for the TYPE field */
70     public static final String JavaDoc TYPE;
71       /** the column name for the APPLICATION field */
72     public static final String JavaDoc APPLICATION;
73       /** the column name for the PARENT field */
74     public static final String JavaDoc PARENT;
75       /** the column name for the URL field */
76     public static final String JavaDoc URL;
77       /** the column name for the CACHEDONURL field */
78     public static final String JavaDoc CACHEDONURL;
79       /** the column name for the ROLE field */
80     public static final String JavaDoc ROLE;
81       /** the column name for the TITLE field */
82     public static final String JavaDoc TITLE;
83       /** the column name for the DESCRIPTION field */
84     public static final String JavaDoc DESCRIPTION;
85       /** the column name for the IMAGE field */
86     public static final String JavaDoc IMAGE;
87       /** the column name for the SECURITY field */
88     public static final String JavaDoc SECURITY;
89   
90     static
91     {
92           ID = "PORTLET.ID";
93           NAME = "PORTLET.NAME";
94           HIDDEN = "PORTLET.HIDDEN";
95           CLASSNAME = "PORTLET.CLASSNAME";
96           TYPE = "PORTLET.TYPE";
97           APPLICATION = "PORTLET.APPLICATION";
98           PARENT = "PORTLET.PARENT";
99           URL = "PORTLET.URL";
100           CACHEDONURL = "PORTLET.CACHEDONURL";
101           ROLE = "PORTLET.ROLE";
102           TITLE = "PORTLET.TITLE";
103           DESCRIPTION = "PORTLET.DESCRIPTION";
104           IMAGE = "PORTLET.IMAGE";
105           SECURITY = "PORTLET.SECURITY";
106           if (Torque.isInit())
107         {
108             try
109             {
110                 getMapBuilder();
111             }
112             catch (Exception JavaDoc e)
113             {
114                 log.error("Could not initialize Peer", e);
115             }
116         }
117         else
118         {
119             Torque.registerMapBuilder(PortletDbEntryMapBuilder.CLASS_NAME);
120         }
121     }
122  
123     /** number of columns for this peer */
124     public static final int numColumns = 14;
125
126     /** A class that can be returned by this peer. */
127     protected static final String JavaDoc CLASSNAME_DEFAULT =
128         "org.apache.jetspeed.om.dbregistry.PortletDbEntry";
129
130     /** A class that can be returned by this peer. */
131     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
132
133     /**
134      * Class object initialization method.
135      *
136      * @param className name of the class to initialize
137      * @return the initialized class
138      */

139     private static Class JavaDoc initClass(String JavaDoc className)
140     {
141         Class JavaDoc c = null;
142         try
143         {
144             c = Class.forName(className);
145         }
146         catch (Throwable JavaDoc t)
147         {
148             log.error("A FATAL ERROR has occurred which should not "
149                 + "have happened under any circumstance. Please notify "
150                 + "the Torque developers <turbine-torque-dev@jakarta.apache.org> "
151                 + "and give as many details as possible (including the error "
152                 + "stack trace).", t);
153
154             // Error objects should always be propogated.
155
if (t instanceof Error JavaDoc)
156             {
157                 throw (Error JavaDoc) t.fillInStackTrace();
158             }
159         }
160         return c;
161     }
162
163     /**
164      * Get the list of objects for a ResultSet. Please not that your
165      * resultset MUST return columns in the right order. You can use
166      * getFieldNames() in BaseObject to get the correct sequence.
167      *
168      * @param results the ResultSet
169      * @return the list of objects
170      * @throws TorqueException Any exceptions caught during processing will be
171      * rethrown wrapped into a TorqueException.
172      */

173     public static List JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
174             throws TorqueException
175     {
176         try
177         {
178             QueryDataSet qds = null;
179             List JavaDoc rows = null;
180             try
181             {
182                 qds = new QueryDataSet(results);
183                 rows = getSelectResults(qds);
184             }
185             finally
186             {
187                 if (qds != null)
188                 {
189                     qds.close();
190                 }
191             }
192
193             return populateObjects(rows);
194         }
195         catch (SQLException JavaDoc e)
196         {
197             throw new TorqueException(e);
198         }
199         catch (DataSetException e)
200         {
201             throw new TorqueException(e);
202         }
203     }
204
205
206   
207     /**
208      * Method to do inserts.
209      *
210      * @param criteria object used to create the INSERT statement.
211      * @throws TorqueException Any exceptions caught during processing will be
212      * rethrown wrapped into a TorqueException.
213      */

214     public static ObjectKey doInsert(Criteria criteria)
215         throws TorqueException
216     {
217         return BasePortletDbEntryPeer
218             .doInsert(criteria, (Connection JavaDoc) null);
219     }
220
221     /**
222      * Method to do inserts. This method is to be used during a transaction,
223      * otherwise use the doInsert(Criteria) method. It will take care of
224      * the connection details internally.
225      *
226      * @param criteria object used to create the INSERT statement.
227      * @param con the connection to use
228      * @throws TorqueException Any exceptions caught during processing will be
229      * rethrown wrapped into a TorqueException.
230      */

231     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
232         throws TorqueException
233     {
234                           // check for conversion from boolean to int
235
if (criteria.containsKey(HIDDEN))
236         {
237             Object JavaDoc possibleBoolean = criteria.get(HIDDEN);
238             if (possibleBoolean instanceof Boolean JavaDoc)
239             {
240                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
241                 {
242                     criteria.add(HIDDEN, 1);
243                 }
244                 else
245                 {
246                     criteria.add(HIDDEN, 0);
247                 }
248             }
249          }
250                               // check for conversion from boolean to int
251
if (criteria.containsKey(APPLICATION))
252         {
253             Object JavaDoc possibleBoolean = criteria.get(APPLICATION);
254             if (possibleBoolean instanceof Boolean JavaDoc)
255             {
256                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
257                 {
258                     criteria.add(APPLICATION, 1);
259                 }
260                 else
261                 {
262                     criteria.add(APPLICATION, 0);
263                 }
264             }
265          }
266                               // check for conversion from boolean to int
267
if (criteria.containsKey(CACHEDONURL))
268         {
269             Object JavaDoc possibleBoolean = criteria.get(CACHEDONURL);
270             if (possibleBoolean instanceof Boolean JavaDoc)
271             {
272                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
273                 {
274                     criteria.add(CACHEDONURL, 1);
275                 }
276                 else
277                 {
278                     criteria.add(CACHEDONURL, 0);
279                 }
280             }
281          }
282                                     
283         // Set the correct dbName if it has not been overridden
284
// criteria.getDbName will return the same object if not set to
285
// another value so == check is okay and faster
286
if (criteria.getDbName() == Torque.getDefaultDB())
287         {
288             criteria.setDbName(DATABASE_NAME);
289         }
290         if (con == null)
291         {
292             return BasePeer.doInsert(criteria);
293         }
294         else
295         {
296             return BasePeer.doInsert(criteria, con);
297         }
298     }
299
300     /**
301      * Add all the columns needed to create a new object.
302      *
303      * @param criteria object containing the columns to add.
304      * @throws TorqueException Any exceptions caught during processing will be
305      * rethrown wrapped into a TorqueException.
306      */

307     public static void addSelectColumns(Criteria criteria)
308             throws TorqueException
309     {
310           criteria.addSelectColumn(ID);
311           criteria.addSelectColumn(NAME);
312           criteria.addSelectColumn(HIDDEN);
313           criteria.addSelectColumn(CLASSNAME);
314           criteria.addSelectColumn(TYPE);
315           criteria.addSelectColumn(APPLICATION);
316           criteria.addSelectColumn(PARENT);
317           criteria.addSelectColumn(URL);
318           criteria.addSelectColumn(CACHEDONURL);
319           criteria.addSelectColumn(ROLE);
320           criteria.addSelectColumn(TITLE);
321           criteria.addSelectColumn(DESCRIPTION);
322           criteria.addSelectColumn(IMAGE);
323           criteria.addSelectColumn(SECURITY);
324       }
325
326     /**
327      * Create a new object of type cls from a resultset row starting
328      * from a specified offset. This is done so that you can select
329      * other rows than just those needed for this object. You may
330      * for example want to create two objects from the same row.
331      *
332      * @throws TorqueException Any exceptions caught during processing will be
333      * rethrown wrapped into a TorqueException.
334      */

335     public static PortletDbEntry row2Object(Record row,
336                                              int offset,
337                                              Class JavaDoc cls)
338         throws TorqueException
339     {
340         try
341         {
342             PortletDbEntry obj = (PortletDbEntry) cls.newInstance();
343             PortletDbEntryPeer.populateObject(row, offset, obj);
344                   obj.setModified(false);
345               obj.setNew(false);
346
347             return obj;
348         }
349         catch (InstantiationException JavaDoc e)
350         {
351             throw new TorqueException(e);
352         }
353         catch (IllegalAccessException JavaDoc e)
354         {
355             throw new TorqueException(e);
356         }
357     }
358
359     /**
360      * Populates an object from a resultset row starting
361      * from a specified offset. This is done so that you can select
362      * other rows than just those needed for this object. You may
363      * for example want to create two objects from the same row.
364      *
365      * @throws TorqueException Any exceptions caught during processing will be
366      * rethrown wrapped into a TorqueException.
367      */

368     public static void populateObject(Record row,
369                                       int offset,
370                                       PortletDbEntry obj)
371         throws TorqueException
372     {
373         try
374         {
375                 obj.setId(row.getValue(offset + 0).asLong());
376                   obj.setName(row.getValue(offset + 1).asString());
377                   obj.setHidden(row.getValue(offset + 2).asBoolean());
378                   obj.setClassname(row.getValue(offset + 3).asString());
379                   obj.setType(row.getValue(offset + 4).asString());
380                   obj.setApplication(row.getValue(offset + 5).asBoolean());
381                   obj.setParentRef(row.getValue(offset + 6).asLong());
382                   obj.setURL(row.getValue(offset + 7).asString());
383                   obj.setCachedonurl(row.getValue(offset + 8).asBoolean());
384                   obj.setRole(row.getValue(offset + 9).asString());
385                   obj.setTitle(row.getValue(offset + 10).asString());
386                   obj.setDescription(row.getValue(offset + 11).asString());
387                   obj.setImage(row.getValue(offset + 12).asString());
388                   obj.setSecurityRef(row.getValue(offset + 13).asString());
389               }
390         catch (DataSetException e)
391         {
392             throw new TorqueException(e);
393         }
394     }
395
396     /**
397      * Method to do selects.
398      *
399      * @param criteria object used to create the SELECT statement.
400      * @return List of selected Objects
401      * @throws TorqueException Any exceptions caught during processing will be
402      * rethrown wrapped into a TorqueException.
403      */

404     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
405     {
406         return populateObjects(doSelectVillageRecords(criteria));
407     }
408
409     /**
410      * Method to do selects within a transaction.
411      *
412      * @param criteria object used to create the SELECT statement.
413      * @param con the connection to use
414      * @return List of selected Objects
415      * @throws TorqueException Any exceptions caught during processing will be
416      * rethrown wrapped into a TorqueException.
417      */

418     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
419         throws TorqueException
420     {
421         return populateObjects(doSelectVillageRecords(criteria, con));
422     }
423
424     /**
425      * Grabs the raw Village records to be formed into objects.
426      * This method handles connections internally. The Record objects
427      * returned by this method should be considered readonly. Do not
428      * alter the data and call save(), your results may vary, but are
429      * certainly likely to result in hard to track MT bugs.
430      *
431      * @throws TorqueException Any exceptions caught during processing will be
432      * rethrown wrapped into a TorqueException.
433      */

434     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
435         throws TorqueException
436     {
437         return BasePortletDbEntryPeer
438             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
439     }
440
441     /**
442      * Grabs the raw Village records to be formed into objects.
443      * This method should be used for transactions
444      *
445      * @param con the connection to use
446      * @throws TorqueException Any exceptions caught during processing will be
447      * rethrown wrapped into a TorqueException.
448      */

449     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
450         throws TorqueException
451     {
452         if (criteria.getSelectColumns().size() == 0)
453         {
454             addSelectColumns(criteria);
455         }
456
457                           // check for conversion from boolean to int
458
if (criteria.containsKey(HIDDEN))
459         {
460             Object JavaDoc possibleBoolean = criteria.get(HIDDEN);
461             if (possibleBoolean instanceof Boolean JavaDoc)
462             {
463                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
464                 {
465                     criteria.add(HIDDEN, 1);
466                 }
467                 else
468                 {
469                     criteria.add(HIDDEN, 0);
470                 }
471             }
472          }
473                               // check for conversion from boolean to int
474
if (criteria.containsKey(APPLICATION))
475         {
476             Object JavaDoc possibleBoolean = criteria.get(APPLICATION);
477             if (possibleBoolean instanceof Boolean JavaDoc)
478             {
479                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
480                 {
481                     criteria.add(APPLICATION, 1);
482                 }
483                 else
484                 {
485                     criteria.add(APPLICATION, 0);
486                 }
487             }
488          }
489                               // check for conversion from boolean to int
490
if (criteria.containsKey(CACHEDONURL))
491         {
492             Object JavaDoc possibleBoolean = criteria.get(CACHEDONURL);
493             if (possibleBoolean instanceof Boolean JavaDoc)
494             {
495                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
496                 {
497                     criteria.add(CACHEDONURL, 1);
498                 }
499                 else
500                 {
501                     criteria.add(CACHEDONURL, 0);
502                 }
503             }
504          }
505                                     
506         // Set the correct dbName if it has not been overridden
507
// criteria.getDbName will return the same object if not set to
508
// another value so == check is okay and faster
509
if (criteria.getDbName() == Torque.getDefaultDB())
510         {
511             criteria.setDbName(DATABASE_NAME);
512         }
513         // BasePeer returns a List of Value (Village) arrays. The array
514
// order follows the order columns were placed in the Select clause.
515
if (con == null)
516         {
517             return BasePeer.doSelect(criteria);
518         }
519         else
520         {
521             return BasePeer.doSelect(criteria, con);
522         }
523     }
524
525     /**
526      * The returned List will contain objects of the default type or
527      * objects that inherit from the default.
528      *
529      * @throws TorqueException Any exceptions caught during processing will be
530      * rethrown wrapped into a TorqueException.
531      */

532     public static List JavaDoc populateObjects(List JavaDoc records)
533         throws TorqueException
534     {
535         List JavaDoc results = new ArrayList JavaDoc(records.size());
536
537         // populate the object(s)
538
for (int i = 0; i < records.size(); i++)
539         {
540             Record row = (Record) records.get(i);
541               results.add(PortletDbEntryPeer.row2Object(row, 1,
542                 PortletDbEntryPeer.getOMClass()));
543           }
544         return results;
545     }
546  
547
548     /**
549      * The class that the Peer will make instances of.
550      * If the BO is abstract then you must implement this method
551      * in the BO.
552      *
553      * @throws TorqueException Any exceptions caught during processing will be
554      * rethrown wrapped into a TorqueException.
555      */

556     public static Class JavaDoc getOMClass()
557         throws TorqueException
558     {
559         return CLASS_DEFAULT;
560     }
561
562     /**
563      * Method to do updates.
564      *
565      * @param criteria object containing data that is used to create the UPDATE
566      * statement.
567      * @throws TorqueException Any exceptions caught during processing will be
568      * rethrown wrapped into a TorqueException.
569      */

570     public static void doUpdate(Criteria criteria) throws TorqueException
571     {
572          BasePortletDbEntryPeer
573             .doUpdate(criteria, (Connection JavaDoc) null);
574     }
575
576     /**
577      * Method to do updates. This method is to be used during a transaction,
578      * otherwise use the doUpdate(Criteria) method. It will take care of
579      * the connection details internally.
580      *
581      * @param criteria object containing data that is used to create the UPDATE
582      * statement.
583      * @param con the connection to use
584      * @throws TorqueException Any exceptions caught during processing will be
585      * rethrown wrapped into a TorqueException.
586      */

587     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
588         throws TorqueException
589     {
590         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
591                    selectCriteria.put(ID, criteria.remove(ID));
592                             // check for conversion from boolean to int
593
if (criteria.containsKey(HIDDEN))
594         {
595             Object JavaDoc possibleBoolean = criteria.get(HIDDEN);
596             if (possibleBoolean instanceof Boolean JavaDoc)
597             {
598                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
599                 {
600                     criteria.add(HIDDEN, 1);
601                 }
602                 else
603                 {
604                     criteria.add(HIDDEN, 0);
605                 }
606             }
607          }
608                                           // check for conversion from boolean to int
609
if (criteria.containsKey(APPLICATION))
610         {
611             Object JavaDoc possibleBoolean = criteria.get(APPLICATION);
612             if (possibleBoolean instanceof Boolean JavaDoc)
613             {
614                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
615                 {
616                     criteria.add(APPLICATION, 1);
617                 }
618                 else
619                 {
620                     criteria.add(APPLICATION, 0);
621                 }
622             }
623          }
624                                           // check for conversion from boolean to int
625
if (criteria.containsKey(CACHEDONURL))
626         {
627             Object JavaDoc possibleBoolean = criteria.get(CACHEDONURL);
628             if (possibleBoolean instanceof Boolean JavaDoc)
629             {
630                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
631                 {
632                     criteria.add(CACHEDONURL, 1);
633                 }
634                 else
635                 {
636                     criteria.add(CACHEDONURL, 0);
637                 }
638             }
639          }
640                                                             
641         // Set the correct dbName if it has not been overridden
642
// criteria.getDbName will return the same object if not set to
643
// another value so == check is okay and faster
644
if (criteria.getDbName() == Torque.getDefaultDB())
645         {
646             criteria.setDbName(DATABASE_NAME);
647         }
648         if (con == null)
649         {
650             BasePeer.doUpdate(selectCriteria, criteria);
651         }
652         else
653         {
654             BasePeer.doUpdate(selectCriteria, criteria, con);
655         }
656     }
657
658     /**
659      * Method to do deletes.
660      *
661      * @param criteria object containing data that is used DELETE from database.
662      * @throws TorqueException Any exceptions caught during processing will be
663      * rethrown wrapped into a TorqueException.
664      */

665      public static void doDelete(Criteria criteria) throws TorqueException
666      {
667          BasePortletDbEntryPeer
668             .doDelete(criteria, (Connection JavaDoc) null);
669      }
670
671     /**
672      * Method to do deletes. This method is to be used during a transaction,
673      * otherwise use the doDelete(Criteria) method. It will take care of
674      * the connection details internally.
675      *
676      * @param criteria object containing data that is used DELETE from database.
677      * @param con the connection to use
678      * @throws TorqueException Any exceptions caught during processing will be
679      * rethrown wrapped into a TorqueException.
680      */

681      public static void doDelete(Criteria criteria, Connection JavaDoc con)
682         throws TorqueException
683      {
684                           // check for conversion from boolean to int
685
if (criteria.containsKey(HIDDEN))
686         {
687             Object JavaDoc possibleBoolean = criteria.get(HIDDEN);
688             if (possibleBoolean instanceof Boolean JavaDoc)
689             {
690                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
691                 {
692                     criteria.add(HIDDEN, 1);
693                 }
694                 else
695                 {
696                     criteria.add(HIDDEN, 0);
697                 }
698             }
699          }
700                               // check for conversion from boolean to int
701
if (criteria.containsKey(APPLICATION))
702         {
703             Object JavaDoc possibleBoolean = criteria.get(APPLICATION);
704             if (possibleBoolean instanceof Boolean JavaDoc)
705             {
706                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
707                 {
708                     criteria.add(APPLICATION, 1);
709                 }
710                 else
711                 {
712                     criteria.add(APPLICATION, 0);
713                 }
714             }
715          }
716                               // check for conversion from boolean to int
717
if (criteria.containsKey(CACHEDONURL))
718         {
719             Object JavaDoc possibleBoolean = criteria.get(CACHEDONURL);
720             if (possibleBoolean instanceof Boolean JavaDoc)
721             {
722                 if (((Boolean JavaDoc) possibleBoolean).booleanValue())
723                 {
724                     criteria.add(CACHEDONURL, 1);
725                 }
726                 else
727                 {
728                     criteria.add(CACHEDONURL, 0);
729                 }
730             }
731          }
732                                     
733         // Set the correct dbName if it has not been overridden
734
// criteria.getDbName will return the same object if not set to
735
// another value so == check is okay and faster
736
if (criteria.getDbName() == Torque.getDefaultDB())
737         {
738             criteria.setDbName(DATABASE_NAME);
739         }
740         if (con == null)
741         {
742             BasePeer.doDelete(criteria);
743         }
744         else
745         {
746             BasePeer.doDelete(criteria, con);
747         }
748      }
749
750     /**
751      * Method to do selects
752      *
753      * @throws TorqueException Any exceptions caught during processing will be
754      * rethrown wrapped into a TorqueException.
755      */

756     public static List JavaDoc doSelect(PortletDbEntry obj) throws TorqueException
757     {
758         return doSelect(buildCriteria(obj));
759     }
760
761     /**
762      * Method to do inserts
763      *
764      * @throws TorqueException Any exceptions caught during processing will be
765      * rethrown wrapped into a TorqueException.
766      */

767     public static void doInsert(PortletDbEntry obj) throws TorqueException
768     {
769           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
770           obj.setNew(false);
771         obj.setModified(false);
772     }
773
774     /**
775      * @param obj the data object to update in the database.
776      * @throws TorqueException Any exceptions caught during processing will be
777      * rethrown wrapped into a TorqueException.
778      */

779     public static void doUpdate(PortletDbEntry obj) throws TorqueException
780     {
781         doUpdate(buildCriteria(obj));
782         obj.setModified(false);
783     }
784
785     /**
786      * @param obj the data object to delete in the database.
787      * @throws TorqueException Any exceptions caught during processing will be
788      * rethrown wrapped into a TorqueException.
789      */

790     public static void doDelete(PortletDbEntry obj) throws TorqueException
791     {
792         doDelete(buildCriteria(obj));
793     }
794
795     /**
796      * Method to do inserts. This method is to be used during a transaction,
797      * otherwise use the doInsert(PortletDbEntry) method. It will take
798      * care of the connection details internally.
799      *
800      * @param obj the data object to insert into the database.
801      * @param con the connection to use
802      * @throws TorqueException Any exceptions caught during processing will be
803      * rethrown wrapped into a TorqueException.
804      */

805     public static void doInsert(PortletDbEntry obj, Connection JavaDoc con)
806         throws TorqueException
807     {
808           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
809           obj.setNew(false);
810         obj.setModified(false);
811     }
812
813     /**
814      * Method to do update. This method is to be used during a transaction,
815      * otherwise use the doUpdate(PortletDbEntry) method. It will take
816      * care of the connection details internally.
817      *
818      * @param obj the data object to update in the database.
819      * @param con the connection to use
820      * @throws TorqueException Any exceptions caught during processing will be
821      * rethrown wrapped into a TorqueException.
822      */

823     public static void doUpdate(PortletDbEntry obj, Connection JavaDoc con)
824         throws TorqueException
825     {
826         doUpdate(buildCriteria(obj), con);
827         obj.setModified(false);
828     }
829
830     /**
831      * Method to delete. This method is to be used during a transaction,
832      * otherwise use the doDelete(PortletDbEntry) method. It will take
833      * care of the connection details internally.
834      *
835      * @param obj the data object to delete in the database.
836      * @param con the connection to use
837      * @throws TorqueException Any exceptions caught during processing will be
838      * rethrown wrapped into a TorqueException.
839      */

840     public static void doDelete(PortletDbEntry obj, Connection JavaDoc con)
841         throws TorqueException
842     {
843         doDelete(buildCriteria(obj), con);
844     }
845
846     /**
847      * Method to do deletes.
848      *
849      * @param pk ObjectKey that is used DELETE from database.
850      * @throws TorqueException Any exceptions caught during processing will be
851      * rethrown wrapped into a TorqueException.
852      */

853     public static void doDelete(ObjectKey pk) throws TorqueException
854     {
855         BasePortletDbEntryPeer
856            .doDelete(pk, (Connection JavaDoc) null);
857     }
858
859     /**
860      * Method to delete. This method is to be used during a transaction,
861      * otherwise use the doDelete(ObjectKey) method. It will take
862      * care of the connection details internally.
863      *
864      * @param pk the primary key for the object to delete in the database.
865      * @param con the connection to use
866      * @throws TorqueException Any exceptions caught during processing will be
867      * rethrown wrapped into a TorqueException.
868      */

869     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
870         throws TorqueException
871     {
872         doDelete(buildCriteria(pk), con);
873     }
874
875     /** Build a Criteria object from an ObjectKey */
876     public static Criteria buildCriteria( ObjectKey pk )
877     {
878         Criteria criteria = new Criteria();
879               criteria.add(ID, pk);
880           return criteria;
881      }
882
883     /** Build a Criteria object from the data object for this peer */
884     public static Criteria buildCriteria( PortletDbEntry obj )
885     {
886         Criteria criteria = new Criteria(DATABASE_NAME);
887               if (!obj.isNew())
888                 criteria.add(ID, obj.getId());
889                   criteria.add(NAME, obj.getName());
890                   criteria.add(HIDDEN, obj.getHidden());
891                   criteria.add(CLASSNAME, obj.getClassname());
892                   criteria.add(TYPE, obj.getType());
893                   criteria.add(APPLICATION, obj.getApplication());
894                   criteria.add(PARENT, obj.getParentRef());
895                   criteria.add(URL, obj.getURL());
896                   criteria.add(CACHEDONURL, obj.getCachedonurl());
897                   criteria.add(ROLE, obj.getRole());
898                   criteria.add(TITLE, obj.getTitle());
899                   criteria.add(DESCRIPTION, obj.getDescription());
900                   criteria.add(IMAGE, obj.getImage());
901                   criteria.add(SECURITY, obj.getSecurityRef());
902           return criteria;
903     }
904  
905     
906         /**
907      * Retrieve a single object by pk
908      *
909      * @param pk the primary key
910      * @throws TorqueException Any exceptions caught during processing will be
911      * rethrown wrapped into a TorqueException.
912      * @throws NoRowsException Primary key was not found in database.
913      * @throws TooManyRowsException Primary key was not found in database.
914      */

915     public static PortletDbEntry retrieveByPK(long pk)
916         throws TorqueException, NoRowsException, TooManyRowsException
917     {
918         return retrieveByPK(SimpleKey.keyFor(pk));
919     }
920   
921     /**
922      * Retrieve a single object by pk
923      *
924      * @param pk the primary key
925      * @throws TorqueException Any exceptions caught during processing will be
926      * rethrown wrapped into a TorqueException.
927      * @throws NoRowsException Primary key was not found in database.
928      * @throws TooManyRowsException Primary key was not found in database.
929      */

930     public static PortletDbEntry retrieveByPK(ObjectKey pk)
931         throws TorqueException, NoRowsException, TooManyRowsException
932     {
933         Connection JavaDoc db = null;
934         PortletDbEntry retVal = null;
935         try
936         {
937             db = Torque.getConnection(DATABASE_NAME);
938             retVal = retrieveByPK(pk, db);
939         }
940         finally
941         {
942             Torque.closeConnection(db);
943         }
944         return(retVal);
945     }
946
947     /**
948      * Retrieve a single object by pk
949      *
950      * @param pk the primary key
951      * @param con the connection to use
952      * @throws TorqueException Any exceptions caught during processing will be
953      * rethrown wrapped into a TorqueException.
954      * @throws NoRowsException Primary key was not found in database.
955      * @throws TooManyRowsException Primary key was not found in database.
956      */

957     public static PortletDbEntry retrieveByPK(ObjectKey pk, Connection JavaDoc con)
958         throws TorqueException, NoRowsException, TooManyRowsException
959     {
960         Criteria criteria = buildCriteria(pk);
961         List JavaDoc v = doSelect(criteria, con);
962         if (v.size() == 0)
963         {
964             throw new NoRowsException("Failed to select a row.");
965         }
966         else if (v.size() > 1)
967         {
968             throw new TooManyRowsException("Failed to select only one row.");
969         }
970         else
971         {
972             return (PortletDbEntry)v.get(0);
973         }
974     }
975
976     /**
977      * Retrieve a multiple objects by pk
978      *
979      * @param pks List of primary keys
980      * @throws TorqueException Any exceptions caught during processing will be
981      * rethrown wrapped into a TorqueException.
982      */

983     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
984         throws TorqueException
985     {
986         Connection JavaDoc db = null;
987         List JavaDoc retVal = null;
988         try
989         {
990            db = Torque.getConnection(DATABASE_NAME);
991            retVal = retrieveByPKs(pks, db);
992         }
993         finally
994         {
995             Torque.closeConnection(db);
996         }
997         return(retVal);
998     }
999
1000    /**
1001     * Retrieve a multiple objects by pk
1002     *
1003     * @param pks List of primary keys
1004     * @param dbcon the connection to use
1005     * @throws TorqueException Any exceptions caught during processing will be
1006     * rethrown wrapped into a TorqueException.
1007     */

1008    public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
1009        throws TorqueException
1010    {
1011        List JavaDoc objs = null;
1012        if (pks == null || pks.size() == 0)
1013        {
1014            objs = new LinkedList JavaDoc();
1015        }
1016        else
1017        {
1018            Criteria criteria = new Criteria();
1019              criteria.addIn( ID, pks );
1020          objs = doSelect(criteria, dbcon);
1021        }
1022        return objs;
1023    }
1024
1025 
1026
1027
1028
1029        
1030  
1031  
1032    
1033  
1034      /**
1035     * Returns the TableMap related to this peer. This method is not
1036     * needed for general use but a specific application could have a need.
1037     *
1038     * @throws TorqueException Any exceptions caught during processing will be
1039     * rethrown wrapped into a TorqueException.
1040     */

1041    protected static TableMap getTableMap()
1042        throws TorqueException
1043    {
1044        return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1045    }
1046   }
1047
Popular Tags