KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > BaseModificationPeer


1 package org.tigris.scarab.om;
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.tigris.scarab.om.map.*;
32
33
34 /**
35  */

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

51     public static MapBuilder getMapBuilder()
52         throws TorqueException
53     {
54         return getMapBuilder(ModificationMapBuilder.CLASS_NAME);
55     }
56
57       /** the column name for the TABLE_ID field */
58     public static final String JavaDoc TABLE_ID;
59       /** the column name for the COLUMN_ID field */
60     public static final String JavaDoc COLUMN_ID;
61       /** the column name for the MODIFIED_BY field */
62     public static final String JavaDoc MODIFIED_BY;
63       /** the column name for the CREATED_BY field */
64     public static final String JavaDoc CREATED_BY;
65       /** the column name for the MODIFIED_DATE field */
66     public static final String JavaDoc MODIFIED_DATE;
67       /** the column name for the CREATED_DATE field */
68     public static final String JavaDoc CREATED_DATE;
69   
70     static
71     {
72           TABLE_ID = "SCARAB_MODIFICATION.TABLE_ID";
73           COLUMN_ID = "SCARAB_MODIFICATION.COLUMN_ID";
74           MODIFIED_BY = "SCARAB_MODIFICATION.MODIFIED_BY";
75           CREATED_BY = "SCARAB_MODIFICATION.CREATED_BY";
76           MODIFIED_DATE = "SCARAB_MODIFICATION.MODIFIED_DATE";
77           CREATED_DATE = "SCARAB_MODIFICATION.CREATED_DATE";
78           if (Torque.isInit())
79         {
80             try
81             {
82                 getMapBuilder(ModificationMapBuilder.CLASS_NAME);
83             }
84             catch (Exception JavaDoc e)
85             {
86                 log.error("Could not initialize Peer", e);
87             }
88         }
89         else
90         {
91             Torque.registerMapBuilder(ModificationMapBuilder.CLASS_NAME);
92         }
93     }
94  
95     /** number of columns for this peer */
96     public static final int numColumns = 6;
97
98     /** A class that can be returned by this peer. */
99     protected static final String JavaDoc CLASSNAME_DEFAULT =
100         "org.tigris.scarab.om.Modification";
101
102     /** A class that can be returned by this peer. */
103     protected static final Class JavaDoc 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 JavaDoc initClass(String JavaDoc className)
112     {
113         Class JavaDoc c = null;
114         try
115         {
116             c = Class.forName(className);
117         }
118         catch (Throwable JavaDoc 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 JavaDoc)
128             {
129                 throw (Error JavaDoc) 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 JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
146             throws TorqueException
147     {
148         try
149         {
150             QueryDataSet qds = null;
151             List JavaDoc 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 JavaDoc 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 BaseModificationPeer
190             .doInsert(criteria, (Connection JavaDoc) 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 JavaDoc con)
204         throws TorqueException
205     {
206                                       
207         setDbName(criteria);
208
209         if (con == null)
210         {
211             return BasePeer.doInsert(criteria);
212         }
213         else
214         {
215             return BasePeer.doInsert(criteria, con);
216         }
217     }
218
219     /**
220      * Add all the columns needed to create a new object.
221      *
222      * @param criteria object containing the columns to add.
223      * @throws TorqueException Any exceptions caught during processing will be
224      * rethrown wrapped into a TorqueException.
225      */

226     public static void addSelectColumns(Criteria criteria)
227             throws TorqueException
228     {
229           criteria.addSelectColumn(TABLE_ID);
230           criteria.addSelectColumn(COLUMN_ID);
231           criteria.addSelectColumn(MODIFIED_BY);
232           criteria.addSelectColumn(CREATED_BY);
233           criteria.addSelectColumn(MODIFIED_DATE);
234           criteria.addSelectColumn(CREATED_DATE);
235       }
236
237     /**
238      * Create a new object of type cls from a resultset row starting
239      * from a specified offset. This is done so that you can select
240      * other rows than just those needed for this object. You may
241      * for example want to create two objects from the same row.
242      *
243      * @throws TorqueException Any exceptions caught during processing will be
244      * rethrown wrapped into a TorqueException.
245      */

246     public static Modification row2Object(Record row,
247                                              int offset,
248                                              Class JavaDoc cls)
249         throws TorqueException
250     {
251         try
252         {
253             Modification obj = (Modification) cls.newInstance();
254             ModificationPeer.populateObject(row, offset, obj);
255                   obj.setModified(false);
256               obj.setNew(false);
257
258             return obj;
259         }
260         catch (InstantiationException JavaDoc e)
261         {
262             throw new TorqueException(e);
263         }
264         catch (IllegalAccessException JavaDoc e)
265         {
266             throw new TorqueException(e);
267         }
268     }
269
270     /**
271      * Populates an object from a resultset row starting
272      * from a specified offset. This is done so that you can select
273      * other rows than just those needed for this object. You may
274      * for example want to create two objects from the same row.
275      *
276      * @throws TorqueException Any exceptions caught during processing will be
277      * rethrown wrapped into a TorqueException.
278      */

279     public static void populateObject(Record row,
280                                       int offset,
281                                       Modification obj)
282         throws TorqueException
283     {
284         try
285         {
286                 obj.setTableId(row.getValue(offset + 0).asIntegerObj());
287                   obj.setColumnId(row.getValue(offset + 1).asIntegerObj());
288                   obj.setModifiedBy(row.getValue(offset + 2).asIntegerObj());
289                   obj.setCreatedBy(row.getValue(offset + 3).asIntegerObj());
290                   obj.setModifiedDate(row.getValue(offset + 4).asUtilDate());
291                   obj.setCreatedDate(row.getValue(offset + 5).asUtilDate());
292               }
293         catch (DataSetException e)
294         {
295             throw new TorqueException(e);
296         }
297     }
298
299     /**
300      * Method to do selects.
301      *
302      * @param criteria object used to create the SELECT statement.
303      * @return List of selected Objects
304      * @throws TorqueException Any exceptions caught during processing will be
305      * rethrown wrapped into a TorqueException.
306      */

307     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
308     {
309         return populateObjects(doSelectVillageRecords(criteria));
310     }
311
312     /**
313      * Method to do selects within a transaction.
314      *
315      * @param criteria object used to create the SELECT statement.
316      * @param con the connection to use
317      * @return List of selected Objects
318      * @throws TorqueException Any exceptions caught during processing will be
319      * rethrown wrapped into a TorqueException.
320      */

321     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
322         throws TorqueException
323     {
324         return populateObjects(doSelectVillageRecords(criteria, con));
325     }
326
327     /**
328      * Grabs the raw Village records to be formed into objects.
329      * This method handles connections internally. The Record objects
330      * returned by this method should be considered readonly. Do not
331      * alter the data and call save(), your results may vary, but are
332      * certainly likely to result in hard to track MT bugs.
333      *
334      * @throws TorqueException Any exceptions caught during processing will be
335      * rethrown wrapped into a TorqueException.
336      */

337     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
338         throws TorqueException
339     {
340         return BaseModificationPeer
341             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
342     }
343
344     /**
345      * Grabs the raw Village records to be formed into objects.
346      * This method should be used for transactions
347      *
348      * @param criteria object used to create the SELECT statement.
349      * @param con the connection to use
350      * @throws TorqueException Any exceptions caught during processing will be
351      * rethrown wrapped into a TorqueException.
352      */

353     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
354         throws TorqueException
355     {
356         if (criteria.getSelectColumns().size() == 0)
357         {
358             addSelectColumns(criteria);
359         }
360
361                                       
362         setDbName(criteria);
363
364         // BasePeer returns a List of Value (Village) arrays. The array
365
// order follows the order columns were placed in the Select clause.
366
if (con == null)
367         {
368             return BasePeer.doSelect(criteria);
369         }
370         else
371         {
372             return BasePeer.doSelect(criteria, con);
373         }
374     }
375
376     /**
377      * The returned List will contain objects of the default type or
378      * objects that inherit from the default.
379      *
380      * @throws TorqueException Any exceptions caught during processing will be
381      * rethrown wrapped into a TorqueException.
382      */

383     public static List JavaDoc populateObjects(List JavaDoc records)
384         throws TorqueException
385     {
386         List JavaDoc results = new ArrayList JavaDoc(records.size());
387
388         // populate the object(s)
389
for (int i = 0; i < records.size(); i++)
390         {
391             Record row = (Record) records.get(i);
392               results.add(ModificationPeer.row2Object(row, 1,
393                 ModificationPeer.getOMClass()));
394           }
395         return results;
396     }
397  
398
399     /**
400      * The class that the Peer will make instances of.
401      * If the BO is abstract then you must implement this method
402      * in the BO.
403      *
404      * @throws TorqueException Any exceptions caught during processing will be
405      * rethrown wrapped into a TorqueException.
406      */

407     public static Class JavaDoc getOMClass()
408         throws TorqueException
409     {
410         return CLASS_DEFAULT;
411     }
412
413     /**
414      * Method to do updates.
415      *
416      * @param criteria object containing data that is used to create the UPDATE
417      * statement.
418      * @throws TorqueException Any exceptions caught during processing will be
419      * rethrown wrapped into a TorqueException.
420      */

421     public static void doUpdate(Criteria criteria) throws TorqueException
422     {
423          BaseModificationPeer
424             .doUpdate(criteria, (Connection JavaDoc) null);
425     }
426
427     /**
428      * Method to do updates. This method is to be used during a transaction,
429      * otherwise use the doUpdate(Criteria) method. It will take care of
430      * the connection details internally.
431      *
432      * @param criteria object containing data that is used to create the UPDATE
433      * statement.
434      * @param con the connection to use
435      * @throws TorqueException Any exceptions caught during processing will be
436      * rethrown wrapped into a TorqueException.
437      */

438     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
439         throws TorqueException
440     {
441         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
442                    selectCriteria.put(TABLE_ID, criteria.remove(TABLE_ID));
443                        selectCriteria.put(COLUMN_ID, criteria.remove(COLUMN_ID));
444                                               
445         setDbName(criteria);
446
447         if (con == null)
448         {
449             BasePeer.doUpdate(selectCriteria, criteria);
450         }
451         else
452         {
453             BasePeer.doUpdate(selectCriteria, criteria, con);
454         }
455     }
456
457     /**
458      * Method to do deletes.
459      *
460      * @param criteria object containing data that is used DELETE from database.
461      * @throws TorqueException Any exceptions caught during processing will be
462      * rethrown wrapped into a TorqueException.
463      */

464      public static void doDelete(Criteria criteria) throws TorqueException
465      {
466          ModificationPeer
467             .doDelete(criteria, (Connection JavaDoc) null);
468      }
469
470     /**
471      * Method to do deletes. This method is to be used during a transaction,
472      * otherwise use the doDelete(Criteria) method. It will take care of
473      * the connection details internally.
474      *
475      * @param criteria object containing data that is used DELETE from database.
476      * @param con the connection to use
477      * @throws TorqueException Any exceptions caught during processing will be
478      * rethrown wrapped into a TorqueException.
479      */

480      public static void doDelete(Criteria criteria, Connection JavaDoc con)
481         throws TorqueException
482      {
483                                       
484         setDbName(criteria);
485
486         if (con == null)
487         {
488             BasePeer.doDelete(criteria);
489         }
490         else
491         {
492             BasePeer.doDelete(criteria, con);
493         }
494      }
495
496     /**
497      * Method to do selects
498      *
499      * @throws TorqueException Any exceptions caught during processing will be
500      * rethrown wrapped into a TorqueException.
501      */

502     public static List JavaDoc doSelect(Modification obj) throws TorqueException
503     {
504         return doSelect(buildSelectCriteria(obj));
505     }
506
507     /**
508      * Method to do inserts
509      *
510      * @throws TorqueException Any exceptions caught during processing will be
511      * rethrown wrapped into a TorqueException.
512      */

513     public static void doInsert(Modification obj) throws TorqueException
514     {
515           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
516           obj.setNew(false);
517         obj.setModified(false);
518     }
519
520     /**
521      * @param obj the data object to update in the database.
522      * @throws TorqueException Any exceptions caught during processing will be
523      * rethrown wrapped into a TorqueException.
524      */

525     public static void doUpdate(Modification obj) throws TorqueException
526     {
527         doUpdate(buildCriteria(obj));
528         obj.setModified(false);
529     }
530
531     /**
532      * @param obj the data object to delete in the database.
533      * @throws TorqueException Any exceptions caught during processing will be
534      * rethrown wrapped into a TorqueException.
535      */

536     public static void doDelete(Modification obj) throws TorqueException
537     {
538         doDelete(buildSelectCriteria(obj));
539     }
540
541     /**
542      * Method to do inserts. This method is to be used during a transaction,
543      * otherwise use the doInsert(Modification) method. It will take
544      * care of the connection details internally.
545      *
546      * @param obj the data object to insert into the database.
547      * @param con the connection to use
548      * @throws TorqueException Any exceptions caught during processing will be
549      * rethrown wrapped into a TorqueException.
550      */

551     public static void doInsert(Modification obj, Connection JavaDoc con)
552         throws TorqueException
553     {
554           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
555           obj.setNew(false);
556         obj.setModified(false);
557     }
558
559     /**
560      * Method to do update. This method is to be used during a transaction,
561      * otherwise use the doUpdate(Modification) method. It will take
562      * care of the connection details internally.
563      *
564      * @param obj the data object to update in the database.
565      * @param con the connection to use
566      * @throws TorqueException Any exceptions caught during processing will be
567      * rethrown wrapped into a TorqueException.
568      */

569     public static void doUpdate(Modification obj, Connection JavaDoc con)
570         throws TorqueException
571     {
572         doUpdate(buildCriteria(obj), con);
573         obj.setModified(false);
574     }
575
576     /**
577      * Method to delete. This method is to be used during a transaction,
578      * otherwise use the doDelete(Modification) method. It will take
579      * care of the connection details internally.
580      *
581      * @param obj the data object to delete in the database.
582      * @param con the connection to use
583      * @throws TorqueException Any exceptions caught during processing will be
584      * rethrown wrapped into a TorqueException.
585      */

586     public static void doDelete(Modification obj, Connection JavaDoc con)
587         throws TorqueException
588     {
589         doDelete(buildSelectCriteria(obj), con);
590     }
591
592     /**
593      * Method to do deletes.
594      *
595      * @param pk ObjectKey that is used DELETE from database.
596      * @throws TorqueException Any exceptions caught during processing will be
597      * rethrown wrapped into a TorqueException.
598      */

599     public static void doDelete(ObjectKey pk) throws TorqueException
600     {
601         BaseModificationPeer
602            .doDelete(pk, (Connection JavaDoc) null);
603     }
604
605     /**
606      * Method to delete. This method is to be used during a transaction,
607      * otherwise use the doDelete(ObjectKey) method. It will take
608      * care of the connection details internally.
609      *
610      * @param pk the primary key for the object to delete in the database.
611      * @param con the connection to use
612      * @throws TorqueException Any exceptions caught during processing will be
613      * rethrown wrapped into a TorqueException.
614      */

615     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
616         throws TorqueException
617     {
618         doDelete(buildCriteria(pk), con);
619     }
620
621     /** Build a Criteria object from an ObjectKey */
622     public static Criteria buildCriteria( ObjectKey pk )
623     {
624         Criteria criteria = new Criteria();
625           SimpleKey[] keys = (SimpleKey[])pk.getValue();
626                     criteria.add(TABLE_ID, keys[0]);
627                       criteria.add(COLUMN_ID, keys[1]);
628                     return criteria;
629      }
630
631     /** Build a Criteria object from the data object for this peer */
632     public static Criteria buildCriteria( Modification obj )
633     {
634         Criteria criteria = new Criteria(DATABASE_NAME);
635               if (!obj.isNew())
636             criteria.add(TABLE_ID, obj.getTableId());
637               if (!obj.isNew())
638             criteria.add(COLUMN_ID, obj.getColumnId());
639               criteria.add(MODIFIED_BY, obj.getModifiedBy());
640               criteria.add(CREATED_BY, obj.getCreatedBy());
641               criteria.add(MODIFIED_DATE, obj.getModifiedDate());
642               criteria.add(CREATED_DATE, obj.getCreatedDate());
643           return criteria;
644     }
645
646     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
647     public static Criteria buildSelectCriteria( Modification obj )
648     {
649         Criteria criteria = new Criteria(DATABASE_NAME);
650               if (!obj.isNew())
651                     criteria.add(TABLE_ID, obj.getTableId());
652                   if (!obj.isNew())
653                     criteria.add(COLUMN_ID, obj.getColumnId());
654                           criteria.add(MODIFIED_BY, obj.getModifiedBy());
655                           criteria.add(CREATED_BY, obj.getCreatedBy());
656                           criteria.add(MODIFIED_DATE, obj.getModifiedDate());
657                           criteria.add(CREATED_DATE, obj.getCreatedDate());
658               return criteria;
659     }
660  
661     
662     
663     /**
664      * Retrieve a single object by pk
665      *
666      * @param pk the primary key
667      * @throws TorqueException Any exceptions caught during processing will be
668      * rethrown wrapped into a TorqueException.
669      * @throws NoRowsException Primary key was not found in database.
670      * @throws TooManyRowsException Primary key was not found in database.
671      */

672     public static Modification retrieveByPK(ObjectKey pk)
673         throws TorqueException, NoRowsException, TooManyRowsException
674     {
675         Connection JavaDoc db = null;
676         Modification retVal = null;
677         try
678         {
679             db = Torque.getConnection(DATABASE_NAME);
680             retVal = retrieveByPK(pk, db);
681         }
682         finally
683         {
684             Torque.closeConnection(db);
685         }
686         return(retVal);
687     }
688
689     /**
690      * Retrieve a single object by pk
691      *
692      * @param pk the primary key
693      * @param con the connection to use
694      * @throws TorqueException Any exceptions caught during processing will be
695      * rethrown wrapped into a TorqueException.
696      * @throws NoRowsException Primary key was not found in database.
697      * @throws TooManyRowsException Primary key was not found in database.
698      */

699     public static Modification retrieveByPK(ObjectKey pk, Connection JavaDoc con)
700         throws TorqueException, NoRowsException, TooManyRowsException
701     {
702         Criteria criteria = buildCriteria(pk);
703         List JavaDoc v = doSelect(criteria, con);
704         if (v.size() == 0)
705         {
706             throw new NoRowsException("Failed to select a row.");
707         }
708         else if (v.size() > 1)
709         {
710             throw new TooManyRowsException("Failed to select only one row.");
711         }
712         else
713         {
714             return (Modification)v.get(0);
715         }
716     }
717
718     /**
719      * Retrieve a multiple objects by pk
720      *
721      * @param pks List of primary keys
722      * @throws TorqueException Any exceptions caught during processing will be
723      * rethrown wrapped into a TorqueException.
724      */

725     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
726         throws TorqueException
727     {
728         Connection JavaDoc db = null;
729         List JavaDoc retVal = null;
730         try
731         {
732            db = Torque.getConnection(DATABASE_NAME);
733            retVal = retrieveByPKs(pks, db);
734         }
735         finally
736         {
737             Torque.closeConnection(db);
738         }
739         return(retVal);
740     }
741
742     /**
743      * Retrieve a multiple objects by pk
744      *
745      * @param pks List of primary keys
746      * @param dbcon the connection to use
747      * @throws TorqueException Any exceptions caught during processing will be
748      * rethrown wrapped into a TorqueException.
749      */

750     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
751         throws TorqueException
752     {
753         List JavaDoc objs = null;
754         if (pks == null || pks.size() == 0)
755         {
756             objs = new LinkedList JavaDoc();
757         }
758         else
759         {
760             Criteria criteria = new Criteria();
761               Iterator JavaDoc iter = pks.iterator();
762             while (iter.hasNext())
763             {
764                 ObjectKey pk = (ObjectKey)iter.next();
765                 SimpleKey[] keys = (SimpleKey[])pk.getValue();
766                             Criteria.Criterion c0 = criteria.getNewCriterion(
767                         TABLE_ID, keys[0], Criteria.EQUAL);
768                                     Criteria.Criterion c1 = criteria.getNewCriterion(
769                         COLUMN_ID, keys[1], Criteria.EQUAL);
770                                     c0.and(c1);
771                           criteria.or(c0);
772             }
773           objs = doSelect(criteria, dbcon);
774         }
775         return objs;
776     }
777
778  
779     /**
780      * retrieve object using using pk values.
781      *
782        * @param table_id Integer
783        * @param column_id Integer
784        */

785     public static Modification retrieveByPK(
786        Integer JavaDoc table_id
787           , Integer JavaDoc column_id
788               ) throws TorqueException
789     {
790         Connection JavaDoc db = null;
791         Modification retVal = null;
792         try
793         {
794            db = Torque.getConnection(DATABASE_NAME);
795            retVal = retrieveByPK(
796          table_id
797           , column_id
798                      , db);
799         }
800         finally
801         {
802             Torque.closeConnection(db);
803         }
804         return(retVal);
805     }
806
807       /**
808      * retrieve object using using pk values.
809      *
810        * @param table_id Integer
811        * @param column_id Integer
812        * @param con Connection
813      */

814     public static Modification retrieveByPK(
815        Integer JavaDoc table_id
816           , Integer JavaDoc column_id
817              ,Connection JavaDoc con) throws TorqueException
818     {
819
820         Criteria criteria = new Criteria(5);
821           criteria.add(TABLE_ID, table_id);
822           criteria.add(COLUMN_ID, column_id);
823           List JavaDoc v = doSelect(criteria, con);
824         if (v.size() != 1)
825         {
826             throw new TorqueException("Failed to select one and only one row.");
827         }
828         else
829         {
830             return (Modification) v.get(0);
831         }
832     }
833
834
835
836         
837   
838   
839     
840   
841       /**
842      * Returns the TableMap related to this peer. This method is not
843      * needed for general use but a specific application could have a need.
844      *
845      * @throws TorqueException Any exceptions caught during processing will be
846      * rethrown wrapped into a TorqueException.
847      */

848     protected static TableMap getTableMap()
849         throws TorqueException
850     {
851         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
852     }
853    
854     private static void setDbName(Criteria crit)
855     {
856         // Set the correct dbName if it has not been overridden
857
// crit.getDbName will return the same object if not set to
858
// another value so == check is okay and faster
859
if (crit.getDbName() == Torque.getDefaultDB())
860         {
861             crit.setDbName(DATABASE_NAME);
862         }
863     }
864 }
865
Popular Tags