View Javadoc

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  // Local classes
31  import org.apache.jetspeed.om.dbregistry.map.*;
32  
33  
34    
35    
36  /***
37   * This class was autogenerated by Torque on:
38   *
39   * [Thu Apr 22 23:12:36 EDT 2004]
40   *
41   */
42  public abstract class BasePortletMediatypePeer
43      extends BasePeer
44  {
45  
46      /*** the default database name for this class */
47      public static final String DATABASE_NAME = "default";
48  
49       /*** the table name for this class */
50      public static final String TABLE_NAME = "PORTLET_MEDIATYPE";
51  
52      /***
53       * @return the map builder for this peer
54       * @throws TorqueException Any exceptions caught during processing will be
55       *         rethrown wrapped into a TorqueException.
56       */
57      public static MapBuilder getMapBuilder()
58          throws TorqueException
59      {
60          return getMapBuilder(PortletMediatypeMapBuilder.CLASS_NAME);
61      }
62  
63        /*** the column name for the ID field */
64      public static final String ID;
65        /*** the column name for the MEDIA_ID field */
66      public static final String MEDIA_ID;
67    
68      static
69      {
70            ID = "PORTLET_MEDIATYPE.ID";
71            MEDIA_ID = "PORTLET_MEDIATYPE.MEDIA_ID";
72            if (Torque.isInit())
73          {
74              try
75              {
76                  getMapBuilder();
77              }
78              catch (Exception e)
79              {
80                  log.error("Could not initialize Peer", e);
81              }
82          }
83          else
84          {
85              Torque.registerMapBuilder(PortletMediatypeMapBuilder.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.jetspeed.om.dbregistry.PortletMediatype";
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 <turbine-torque-dev@jakarta.apache.org> "
117                 + "and give as many details as possible (including the error "
118                 + "stack trace).", t);
119 
120             // Error objects should always be propogated.
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 BasePortletMediatypePeer
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               
201         // Set the correct dbName if it has not been overridden
202         // criteria.getDbName will return the same object if not set to
203         // another value so == check is okay and faster
204         if (criteria.getDbName() == Torque.getDefaultDB())
205         {
206             criteria.setDbName(DATABASE_NAME);
207         }
208         if (con == null)
209         {
210             return BasePeer.doInsert(criteria);
211         }
212         else
213         {
214             return BasePeer.doInsert(criteria, con);
215         }
216     }
217 
218     /***
219      * Add all the columns needed to create a new object.
220      *
221      * @param criteria object containing the columns to add.
222      * @throws TorqueException Any exceptions caught during processing will be
223      *         rethrown wrapped into a TorqueException.
224      */
225     public static void addSelectColumns(Criteria criteria)
226             throws TorqueException
227     {
228           criteria.addSelectColumn(ID);
229           criteria.addSelectColumn(MEDIA_ID);
230       }
231 
232     /***
233      * Create a new object of type cls from a resultset row starting
234      * from a specified offset.  This is done so that you can select
235      * other rows than just those needed for this object.  You may
236      * for example want to create two objects from the same row.
237      *
238      * @throws TorqueException Any exceptions caught during processing will be
239      *         rethrown wrapped into a TorqueException.
240      */
241     public static PortletMediatype row2Object(Record row,
242                                              int offset,
243                                              Class cls)
244         throws TorqueException
245     {
246         try
247         {
248             PortletMediatype obj = (PortletMediatype) cls.newInstance();
249             PortletMediatypePeer.populateObject(row, offset, obj);
250                   obj.setModified(false);
251               obj.setNew(false);
252 
253             return obj;
254         }
255         catch (InstantiationException e)
256         {
257             throw new TorqueException(e);
258         }
259         catch (IllegalAccessException e)
260         {
261             throw new TorqueException(e);
262         }
263     }
264 
265     /***
266      * Populates an object from a resultset row starting
267      * from a specified offset.  This is done so that you can select
268      * other rows than just those needed for this object.  You may
269      * for example want to create two objects from the same row.
270      *
271      * @throws TorqueException Any exceptions caught during processing will be
272      *         rethrown wrapped into a TorqueException.
273      */
274     public static void populateObject(Record row,
275                                       int offset,
276                                       PortletMediatype obj)
277         throws TorqueException
278     {
279         try
280         {
281                 obj.setId(row.getValue(offset + 0).asLong());
282                   obj.setMediaId(row.getValue(offset + 1).asLong());
283               }
284         catch (DataSetException e)
285         {
286             throw new TorqueException(e);
287         }
288     }
289 
290     /***
291      * Method to do selects.
292      *
293      * @param criteria object used to create the SELECT statement.
294      * @return List of selected Objects
295      * @throws TorqueException Any exceptions caught during processing will be
296      *         rethrown wrapped into a TorqueException.
297      */
298     public static List doSelect(Criteria criteria) throws TorqueException
299     {
300         return populateObjects(doSelectVillageRecords(criteria));
301     }
302 
303     /***
304      * Method to do selects within a transaction.
305      *
306      * @param criteria object used to create the SELECT statement.
307      * @param con the connection to use
308      * @return List of selected Objects
309      * @throws TorqueException Any exceptions caught during processing will be
310      *         rethrown wrapped into a TorqueException.
311      */
312     public static List doSelect(Criteria criteria, Connection con)
313         throws TorqueException
314     {
315         return populateObjects(doSelectVillageRecords(criteria, con));
316     }
317 
318     /***
319      * Grabs the raw Village records to be formed into objects.
320      * This method handles connections internally.  The Record objects
321      * returned by this method should be considered readonly.  Do not
322      * alter the data and call save(), your results may vary, but are
323      * certainly likely to result in hard to track MT bugs.
324      *
325      * @throws TorqueException Any exceptions caught during processing will be
326      *         rethrown wrapped into a TorqueException.
327      */
328     public static List doSelectVillageRecords(Criteria criteria)
329         throws TorqueException
330     {
331         return BasePortletMediatypePeer
332             .doSelectVillageRecords(criteria, (Connection) null);
333     }
334 
335     /***
336      * Grabs the raw Village records to be formed into objects.
337      * This method should be used for transactions
338      *
339      * @param con the connection to use
340      * @throws TorqueException Any exceptions caught during processing will be
341      *         rethrown wrapped into a TorqueException.
342      */
343     public static List doSelectVillageRecords(Criteria criteria, Connection con)
344         throws TorqueException
345     {
346         if (criteria.getSelectColumns().size() == 0)
347         {
348             addSelectColumns(criteria);
349         }
350 
351               
352         // Set the correct dbName if it has not been overridden
353         // criteria.getDbName will return the same object if not set to
354         // another value so == check is okay and faster
355         if (criteria.getDbName() == Torque.getDefaultDB())
356         {
357             criteria.setDbName(DATABASE_NAME);
358         }
359         // BasePeer returns a List of Value (Village) arrays.  The array
360         // order follows the order columns were placed in the Select clause.
361         if (con == null)
362         {
363             return BasePeer.doSelect(criteria);
364         }
365         else
366         {
367             return BasePeer.doSelect(criteria, con);
368         }
369     }
370 
371     /***
372      * The returned List will contain objects of the default type or
373      * objects that inherit from the default.
374      *
375      * @throws TorqueException Any exceptions caught during processing will be
376      *         rethrown wrapped into a TorqueException.
377      */
378     public static List populateObjects(List records)
379         throws TorqueException
380     {
381         List results = new ArrayList(records.size());
382 
383         // populate the object(s)
384         for (int i = 0; i < records.size(); i++)
385         {
386             Record row = (Record) records.get(i);
387               results.add(PortletMediatypePeer.row2Object(row, 1,
388                 PortletMediatypePeer.getOMClass()));
389           }
390         return results;
391     }
392  
393 
394     /***
395      * The class that the Peer will make instances of.
396      * If the BO is abstract then you must implement this method
397      * in the BO.
398      *
399      * @throws TorqueException Any exceptions caught during processing will be
400      *         rethrown wrapped into a TorqueException.
401      */
402     public static Class getOMClass()
403         throws TorqueException
404     {
405         return CLASS_DEFAULT;
406     }
407 
408     /***
409      * Method to do updates.
410      *
411      * @param criteria object containing data that is used to create the UPDATE
412      *        statement.
413      * @throws TorqueException Any exceptions caught during processing will be
414      *         rethrown wrapped into a TorqueException.
415      */
416     public static void doUpdate(Criteria criteria) throws TorqueException
417     {
418          BasePortletMediatypePeer
419             .doUpdate(criteria, (Connection) null);
420     }
421 
422     /***
423      * Method to do updates.  This method is to be used during a transaction,
424      * otherwise use the doUpdate(Criteria) method.  It will take care of
425      * the connection details internally.
426      *
427      * @param criteria object containing data that is used to create the UPDATE
428      *        statement.
429      * @param con the connection to use
430      * @throws TorqueException Any exceptions caught during processing will be
431      *         rethrown wrapped into a TorqueException.
432      */
433     public static void doUpdate(Criteria criteria, Connection con)
434         throws TorqueException
435     {
436         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
437                       
438         // Set the correct dbName if it has not been overridden
439         // criteria.getDbName will return the same object if not set to
440         // another value so == check is okay and faster
441         if (criteria.getDbName() == Torque.getDefaultDB())
442         {
443             criteria.setDbName(DATABASE_NAME);
444         }
445         if (con == null)
446         {
447             BasePeer.doUpdate(selectCriteria, criteria);
448         }
449         else
450         {
451             BasePeer.doUpdate(selectCriteria, criteria, con);
452         }
453     }
454 
455     /***
456      * Method to do deletes.
457      *
458      * @param criteria object containing data that is used DELETE from database.
459      * @throws TorqueException Any exceptions caught during processing will be
460      *         rethrown wrapped into a TorqueException.
461      */
462      public static void doDelete(Criteria criteria) throws TorqueException
463      {
464          BasePortletMediatypePeer
465             .doDelete(criteria, (Connection) null);
466      }
467 
468     /***
469      * Method to do deletes.  This method is to be used during a transaction,
470      * otherwise use the doDelete(Criteria) method.  It will take care of
471      * the connection details internally.
472      *
473      * @param criteria object containing data that is used DELETE from database.
474      * @param con the connection to use
475      * @throws TorqueException Any exceptions caught during processing will be
476      *         rethrown wrapped into a TorqueException.
477      */
478      public static void doDelete(Criteria criteria, Connection con)
479         throws TorqueException
480      {
481               
482         // Set the correct dbName if it has not been overridden
483         // criteria.getDbName will return the same object if not set to
484         // another value so == check is okay and faster
485         if (criteria.getDbName() == Torque.getDefaultDB())
486         {
487             criteria.setDbName(DATABASE_NAME);
488         }
489         if (con == null)
490         {
491             BasePeer.doDelete(criteria);
492         }
493         else
494         {
495             BasePeer.doDelete(criteria, con);
496         }
497      }
498 
499     /***
500      * Method to do selects
501      *
502      * @throws TorqueException Any exceptions caught during processing will be
503      *         rethrown wrapped into a TorqueException.
504      */
505     public static List doSelect(PortletMediatype obj) throws TorqueException
506     {
507         return doSelect(buildCriteria(obj));
508     }
509 
510     /***
511      * Method to do inserts
512      *
513      * @throws TorqueException Any exceptions caught during processing will be
514      *         rethrown wrapped into a TorqueException.
515      */
516     public static void doInsert(PortletMediatype obj) throws TorqueException
517     {
518           doInsert(buildCriteria(obj));
519           obj.setNew(false);
520         obj.setModified(false);
521     }
522 
523     /***
524      * @param obj the data object to update in the database.
525      * @throws TorqueException Any exceptions caught during processing will be
526      *         rethrown wrapped into a TorqueException.
527      */
528     public static void doUpdate(PortletMediatype obj) throws TorqueException
529     {
530         doUpdate(buildCriteria(obj));
531         obj.setModified(false);
532     }
533 
534     /***
535      * @param obj the data object to delete in the database.
536      * @throws TorqueException Any exceptions caught during processing will be
537      *         rethrown wrapped into a TorqueException.
538      */
539     public static void doDelete(PortletMediatype obj) throws TorqueException
540     {
541         doDelete(buildCriteria(obj));
542     }
543 
544     /***
545      * Method to do inserts.  This method is to be used during a transaction,
546      * otherwise use the doInsert(PortletMediatype) method.  It will take
547      * care of the connection details internally.
548      *
549      * @param obj the data object to insert into the database.
550      * @param con the connection to use
551      * @throws TorqueException Any exceptions caught during processing will be
552      *         rethrown wrapped into a TorqueException.
553      */
554     public static void doInsert(PortletMediatype obj, Connection con)
555         throws TorqueException
556     {
557           doInsert(buildCriteria(obj), con);
558           obj.setNew(false);
559         obj.setModified(false);
560     }
561 
562     /***
563      * Method to do update.  This method is to be used during a transaction,
564      * otherwise use the doUpdate(PortletMediatype) method.  It will take
565      * care of the connection details internally.
566      *
567      * @param obj the data object to update in the database.
568      * @param con the connection to use
569      * @throws TorqueException Any exceptions caught during processing will be
570      *         rethrown wrapped into a TorqueException.
571      */
572     public static void doUpdate(PortletMediatype obj, Connection con)
573         throws TorqueException
574     {
575         doUpdate(buildCriteria(obj), con);
576         obj.setModified(false);
577     }
578 
579     /***
580      * Method to delete.  This method is to be used during a transaction,
581      * otherwise use the doDelete(PortletMediatype) method.  It will take
582      * care of the connection details internally.
583      *
584      * @param obj the data object to delete in the database.
585      * @param con the connection to use
586      * @throws TorqueException Any exceptions caught during processing will be
587      *         rethrown wrapped into a TorqueException.
588      */
589     public static void doDelete(PortletMediatype obj, Connection con)
590         throws TorqueException
591     {
592         doDelete(buildCriteria(obj), con);
593     }
594 
595     /***
596      * Method to do deletes.
597      *
598      * @param pk ObjectKey that is used DELETE from database.
599      * @throws TorqueException Any exceptions caught during processing will be
600      *         rethrown wrapped into a TorqueException.
601      */
602     public static void doDelete(ObjectKey pk) throws TorqueException
603     {
604         BasePortletMediatypePeer
605            .doDelete(pk, (Connection) null);
606     }
607 
608     /***
609      * Method to delete.  This method is to be used during a transaction,
610      * otherwise use the doDelete(ObjectKey) method.  It will take
611      * care of the connection details internally.
612      *
613      * @param pk the primary key for the object to delete in the database.
614      * @param con the connection to use
615      * @throws TorqueException Any exceptions caught during processing will be
616      *         rethrown wrapped into a TorqueException.
617      */
618     public static void doDelete(ObjectKey pk, Connection con)
619         throws TorqueException
620     {
621         doDelete(buildCriteria(pk), con);
622     }
623 
624     /*** Build a Criteria object from an ObjectKey */
625     public static Criteria buildCriteria( ObjectKey pk )
626     {
627         Criteria criteria = new Criteria();
628           SimpleKey[] keys = (SimpleKey[])pk.getValue();
629                   return criteria;
630      }
631 
632     /*** Build a Criteria object from the data object for this peer */
633     public static Criteria buildCriteria( PortletMediatype obj )
634     {
635         Criteria criteria = new Criteria(DATABASE_NAME);
636                   criteria.add(ID, obj.getId());
637                   criteria.add(MEDIA_ID, obj.getMediaId());
638           return criteria;
639     }
640  
641  
642 
643 
644 
645             
646                                               
647                 
648                 
649 
650     /***
651      * selects a collection of PortletMediatype objects pre-filled with their
652      * PortletDbEntry objects.
653      *
654      * This method is protected by default in order to keep the public
655      * api reasonable.  You can provide public methods for those you
656      * actually need in PortletMediatypePeer.
657      *
658      * @throws TorqueException Any exceptions caught during processing will be
659      *         rethrown wrapped into a TorqueException.
660      */
661     protected static List doSelectJoinPortletDbEntry(Criteria c)
662         throws TorqueException
663     {
664         // Set the correct dbName if it has not been overridden
665         // c.getDbName will return the same object if not set to
666         // another value so == check is okay and faster
667         if (c.getDbName() == Torque.getDefaultDB())
668         {
669             c.setDbName(DATABASE_NAME);
670         }
671 
672         PortletMediatypePeer.addSelectColumns(c);
673         int offset = numColumns + 1;
674         PortletDbEntryPeer.addSelectColumns(c);
675 
676 
677                         c.addJoin(PortletMediatypePeer.ID,
678             PortletDbEntryPeer.ID);
679         
680 
681                                             
682         List rows = BasePeer.doSelect(c);
683         List results = new ArrayList();
684 
685         for (int i = 0; i < rows.size(); i++)
686         {
687             Record row = (Record) rows.get(i);
688 
689                             Class omClass = PortletMediatypePeer.getOMClass();
690                     PortletMediatype obj1 = (PortletMediatype) PortletMediatypePeer
691                 .row2Object(row, 1, omClass);
692                      omClass = PortletDbEntryPeer.getOMClass();
693                     PortletDbEntry obj2 = (PortletDbEntry)PortletDbEntryPeer
694                 .row2Object(row, offset, omClass);
695 
696             boolean newObject = true;
697             for (int j = 0; j < results.size(); j++)
698             {
699                 PortletMediatype temp_obj1 = (PortletMediatype)results.get(j);
700                 PortletDbEntry temp_obj2 = (PortletDbEntry)temp_obj1.getPortletDbEntry();
701                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
702                 {
703                     newObject = false;
704                     temp_obj2.addPortletMediatype(obj1);
705                     break;
706                 }
707             }
708             if (newObject)
709             {
710                 obj2.initPortletMediatypes();
711                 obj2.addPortletMediatype(obj1);
712             }
713             results.add(obj1);
714         }
715         return results;
716     }
717                                                             
718                 
719                 
720 
721     /***
722      * selects a collection of PortletMediatype objects pre-filled with their
723      * Mediatype objects.
724      *
725      * This method is protected by default in order to keep the public
726      * api reasonable.  You can provide public methods for those you
727      * actually need in PortletMediatypePeer.
728      *
729      * @throws TorqueException Any exceptions caught during processing will be
730      *         rethrown wrapped into a TorqueException.
731      */
732     protected static List doSelectJoinMediatype(Criteria c)
733         throws TorqueException
734     {
735         // Set the correct dbName if it has not been overridden
736         // c.getDbName will return the same object if not set to
737         // another value so == check is okay and faster
738         if (c.getDbName() == Torque.getDefaultDB())
739         {
740             c.setDbName(DATABASE_NAME);
741         }
742 
743         PortletMediatypePeer.addSelectColumns(c);
744         int offset = numColumns + 1;
745         MediatypePeer.addSelectColumns(c);
746 
747 
748                         c.addJoin(PortletMediatypePeer.MEDIA_ID,
749             MediatypePeer.ID);
750         
751 
752                                             
753         List rows = BasePeer.doSelect(c);
754         List results = new ArrayList();
755 
756         for (int i = 0; i < rows.size(); i++)
757         {
758             Record row = (Record) rows.get(i);
759 
760                             Class omClass = PortletMediatypePeer.getOMClass();
761                     PortletMediatype obj1 = (PortletMediatype) PortletMediatypePeer
762                 .row2Object(row, 1, omClass);
763                      omClass = MediatypePeer.getOMClass();
764                     Mediatype obj2 = (Mediatype)MediatypePeer
765                 .row2Object(row, offset, omClass);
766 
767             boolean newObject = true;
768             for (int j = 0; j < results.size(); j++)
769             {
770                 PortletMediatype temp_obj1 = (PortletMediatype)results.get(j);
771                 Mediatype temp_obj2 = (Mediatype)temp_obj1.getMediatype();
772                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
773                 {
774                     newObject = false;
775                     temp_obj2.addPortletMediatype(obj1);
776                     break;
777                 }
778             }
779             if (newObject)
780             {
781                 obj2.initPortletMediatypes();
782                 obj2.addPortletMediatype(obj1);
783             }
784             results.add(obj1);
785         }
786         return results;
787     }
788                     
789   
790     
791   
792       /***
793      * Returns the TableMap related to this peer.  This method is not
794      * needed for general use but a specific application could have a need.
795      *
796      * @throws TorqueException Any exceptions caught during processing will be
797      *         rethrown wrapped into a TorqueException.
798      */
799     protected static TableMap getTableMap()
800         throws TorqueException
801     {
802         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
803     }
804    }