View Javadoc

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