KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > om > BaseProjectPeer


1 package org.campware.cream.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.campware.cream.om.map.*;
32
33
34   
35 /**
36  * This class was autogenerated by Torque on:
37  *
38  * [Wed May 04 09:10:56 CEST 2005]
39  *
40  */

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

56     public static MapBuilder getMapBuilder()
57         throws TorqueException
58     {
59         return getMapBuilder(ProjectMapBuilder.CLASS_NAME);
60     }
61
62       /** the column name for the PROJECT_ID field */
63     public static final String JavaDoc PROJECT_ID;
64       /** the column name for the PROJECT_CODE field */
65     public static final String JavaDoc PROJECT_CODE;
66       /** the column name for the STATUS field */
67     public static final String JavaDoc STATUS;
68       /** the column name for the PRIORITY field */
69     public static final String JavaDoc PRIORITY;
70       /** the column name for the PROJECT_CAT_ID field */
71     public static final String JavaDoc PROJECT_CAT_ID;
72       /** the column name for the PROJECT_NAME field */
73     public static final String JavaDoc PROJECT_NAME;
74       /** the column name for the START_DATE field */
75     public static final String JavaDoc START_DATE;
76       /** the column name for the END_DATE field */
77     public static final String JavaDoc END_DATE;
78       /** the column name for the EXPENSES field */
79     public static final String JavaDoc EXPENSES;
80       /** the column name for the REVENUES field */
81     public static final String JavaDoc REVENUES;
82       /** the column name for the CUSTOM_1 field */
83     public static final String JavaDoc CUSTOM_1;
84       /** the column name for the CUSTOM_2 field */
85     public static final String JavaDoc CUSTOM_2;
86       /** the column name for the CUSTOM_3 field */
87     public static final String JavaDoc CUSTOM_3;
88       /** the column name for the CUSTOM_4 field */
89     public static final String JavaDoc CUSTOM_4;
90       /** the column name for the CUSTOM_5 field */
91     public static final String JavaDoc CUSTOM_5;
92       /** the column name for the CUSTOM_6 field */
93     public static final String JavaDoc CUSTOM_6;
94       /** the column name for the NOTES field */
95     public static final String JavaDoc NOTES;
96       /** the column name for the CREATED field */
97     public static final String JavaDoc CREATED;
98       /** the column name for the MODIFIED field */
99     public static final String JavaDoc MODIFIED;
100       /** the column name for the CREATED_BY field */
101     public static final String JavaDoc CREATED_BY;
102       /** the column name for the MODIFIED_BY field */
103     public static final String JavaDoc MODIFIED_BY;
104   
105     static
106     {
107           PROJECT_ID = "PROJECT.PROJECT_ID";
108           PROJECT_CODE = "PROJECT.PROJECT_CODE";
109           STATUS = "PROJECT.STATUS";
110           PRIORITY = "PROJECT.PRIORITY";
111           PROJECT_CAT_ID = "PROJECT.PROJECT_CAT_ID";
112           PROJECT_NAME = "PROJECT.PROJECT_NAME";
113           START_DATE = "PROJECT.START_DATE";
114           END_DATE = "PROJECT.END_DATE";
115           EXPENSES = "PROJECT.EXPENSES";
116           REVENUES = "PROJECT.REVENUES";
117           CUSTOM_1 = "PROJECT.CUSTOM_1";
118           CUSTOM_2 = "PROJECT.CUSTOM_2";
119           CUSTOM_3 = "PROJECT.CUSTOM_3";
120           CUSTOM_4 = "PROJECT.CUSTOM_4";
121           CUSTOM_5 = "PROJECT.CUSTOM_5";
122           CUSTOM_6 = "PROJECT.CUSTOM_6";
123           NOTES = "PROJECT.NOTES";
124           CREATED = "PROJECT.CREATED";
125           MODIFIED = "PROJECT.MODIFIED";
126           CREATED_BY = "PROJECT.CREATED_BY";
127           MODIFIED_BY = "PROJECT.MODIFIED_BY";
128           if (Torque.isInit())
129         {
130             try
131             {
132                 getMapBuilder(ProjectMapBuilder.CLASS_NAME);
133             }
134             catch (Exception JavaDoc e)
135             {
136                 log.error("Could not initialize Peer", e);
137             }
138         }
139         else
140         {
141             Torque.registerMapBuilder(ProjectMapBuilder.CLASS_NAME);
142         }
143     }
144  
145     /** number of columns for this peer */
146     public static final int numColumns = 21;
147
148     /** A class that can be returned by this peer. */
149     protected static final String JavaDoc CLASSNAME_DEFAULT =
150         "org.campware.cream.om.Project";
151
152     /** A class that can be returned by this peer. */
153     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
154
155     /**
156      * Class object initialization method.
157      *
158      * @param className name of the class to initialize
159      * @return the initialized class
160      */

161     private static Class JavaDoc initClass(String JavaDoc className)
162     {
163         Class JavaDoc c = null;
164         try
165         {
166             c = Class.forName(className);
167         }
168         catch (Throwable JavaDoc t)
169         {
170             log.error("A FATAL ERROR has occurred which should not "
171                 + "have happened under any circumstance. Please notify "
172                 + "the Torque developers <torque-dev@db.apache.org> "
173                 + "and give as many details as possible (including the error "
174                 + "stack trace).", t);
175
176             // Error objects should always be propogated.
177
if (t instanceof Error JavaDoc)
178             {
179                 throw (Error JavaDoc) t.fillInStackTrace();
180             }
181         }
182         return c;
183     }
184
185     /**
186      * Get the list of objects for a ResultSet. Please not that your
187      * resultset MUST return columns in the right order. You can use
188      * getFieldNames() in BaseObject to get the correct sequence.
189      *
190      * @param results the ResultSet
191      * @return the list of objects
192      * @throws TorqueException Any exceptions caught during processing will be
193      * rethrown wrapped into a TorqueException.
194      */

195     public static List JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
196             throws TorqueException
197     {
198         try
199         {
200             QueryDataSet qds = null;
201             List JavaDoc rows = null;
202             try
203             {
204                 qds = new QueryDataSet(results);
205                 rows = getSelectResults(qds);
206             }
207             finally
208             {
209                 if (qds != null)
210                 {
211                     qds.close();
212                 }
213             }
214
215             return populateObjects(rows);
216         }
217         catch (SQLException JavaDoc e)
218         {
219             throw new TorqueException(e);
220         }
221         catch (DataSetException e)
222         {
223             throw new TorqueException(e);
224         }
225     }
226
227
228   
229     /**
230      * Method to do inserts.
231      *
232      * @param criteria object used to create the INSERT statement.
233      * @throws TorqueException Any exceptions caught during processing will be
234      * rethrown wrapped into a TorqueException.
235      */

236     public static ObjectKey doInsert(Criteria criteria)
237         throws TorqueException
238     {
239         return BaseProjectPeer
240             .doInsert(criteria, (Connection JavaDoc) null);
241     }
242
243     /**
244      * Method to do inserts. This method is to be used during a transaction,
245      * otherwise use the doInsert(Criteria) method. It will take care of
246      * the connection details internally.
247      *
248      * @param criteria object used to create the INSERT statement.
249      * @param con the connection to use
250      * @throws TorqueException Any exceptions caught during processing will be
251      * rethrown wrapped into a TorqueException.
252      */

253     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
254         throws TorqueException
255     {
256                                                                                                                                 
257         setDbName(criteria);
258
259         if (con == null)
260         {
261             return BasePeer.doInsert(criteria);
262         }
263         else
264         {
265             return BasePeer.doInsert(criteria, con);
266         }
267     }
268
269     /**
270      * Add all the columns needed to create a new object.
271      *
272      * @param criteria object containing the columns to add.
273      * @throws TorqueException Any exceptions caught during processing will be
274      * rethrown wrapped into a TorqueException.
275      */

276     public static void addSelectColumns(Criteria criteria)
277             throws TorqueException
278     {
279           criteria.addSelectColumn(PROJECT_ID);
280           criteria.addSelectColumn(PROJECT_CODE);
281           criteria.addSelectColumn(STATUS);
282           criteria.addSelectColumn(PRIORITY);
283           criteria.addSelectColumn(PROJECT_CAT_ID);
284           criteria.addSelectColumn(PROJECT_NAME);
285           criteria.addSelectColumn(START_DATE);
286           criteria.addSelectColumn(END_DATE);
287           criteria.addSelectColumn(EXPENSES);
288           criteria.addSelectColumn(REVENUES);
289           criteria.addSelectColumn(CUSTOM_1);
290           criteria.addSelectColumn(CUSTOM_2);
291           criteria.addSelectColumn(CUSTOM_3);
292           criteria.addSelectColumn(CUSTOM_4);
293           criteria.addSelectColumn(CUSTOM_5);
294           criteria.addSelectColumn(CUSTOM_6);
295           criteria.addSelectColumn(NOTES);
296           criteria.addSelectColumn(CREATED);
297           criteria.addSelectColumn(MODIFIED);
298           criteria.addSelectColumn(CREATED_BY);
299           criteria.addSelectColumn(MODIFIED_BY);
300       }
301
302     /**
303      * Create a new object of type cls from a resultset row starting
304      * from a specified offset. This is done so that you can select
305      * other rows than just those needed for this object. You may
306      * for example want to create two objects from the same row.
307      *
308      * @throws TorqueException Any exceptions caught during processing will be
309      * rethrown wrapped into a TorqueException.
310      */

311     public static Project row2Object(Record row,
312                                              int offset,
313                                              Class JavaDoc cls)
314         throws TorqueException
315     {
316         try
317         {
318             Project obj = (Project) cls.newInstance();
319             ProjectPeer.populateObject(row, offset, obj);
320                   obj.setModified(false);
321               obj.setNew(false);
322
323             return obj;
324         }
325         catch (InstantiationException JavaDoc e)
326         {
327             throw new TorqueException(e);
328         }
329         catch (IllegalAccessException JavaDoc e)
330         {
331             throw new TorqueException(e);
332         }
333     }
334
335     /**
336      * Populates an object from a resultset row starting
337      * from a specified offset. This is done so that you can select
338      * other rows than just those needed for this object. You may
339      * for example want to create two objects from the same row.
340      *
341      * @throws TorqueException Any exceptions caught during processing will be
342      * rethrown wrapped into a TorqueException.
343      */

344     public static void populateObject(Record row,
345                                       int offset,
346                                       Project obj)
347         throws TorqueException
348     {
349         try
350         {
351                 obj.setProjectId(row.getValue(offset + 0).asInt());
352                   obj.setProjectCode(row.getValue(offset + 1).asString());
353                   obj.setStatus(row.getValue(offset + 2).asInt());
354                   obj.setPriority(row.getValue(offset + 3).asInt());
355                   obj.setProjectCatId(row.getValue(offset + 4).asInt());
356                   obj.setProjectName(row.getValue(offset + 5).asString());
357                   obj.setStartDate(row.getValue(offset + 6).asUtilDate());
358                   obj.setEndDate(row.getValue(offset + 7).asUtilDate());
359                   obj.setExpenses(row.getValue(offset + 8).asBigDecimal());
360                   obj.setRevenues(row.getValue(offset + 9).asBigDecimal());
361                   obj.setCustom1(row.getValue(offset + 10).asString());
362                   obj.setCustom2(row.getValue(offset + 11).asString());
363                   obj.setCustom3(row.getValue(offset + 12).asString());
364                   obj.setCustom4(row.getValue(offset + 13).asString());
365                   obj.setCustom5(row.getValue(offset + 14).asString());
366                   obj.setCustom6(row.getValue(offset + 15).asString());
367                   obj.setNotes(row.getValue(offset + 16).asString());
368                   obj.setCreated(row.getValue(offset + 17).asUtilDate());
369                   obj.setModified(row.getValue(offset + 18).asUtilDate());
370                   obj.setCreatedBy(row.getValue(offset + 19).asString());
371                   obj.setModifiedBy(row.getValue(offset + 20).asString());
372               }
373         catch (DataSetException e)
374         {
375             throw new TorqueException(e);
376         }
377     }
378
379     /**
380      * Method to do selects.
381      *
382      * @param criteria object used to create the SELECT statement.
383      * @return List of selected Objects
384      * @throws TorqueException Any exceptions caught during processing will be
385      * rethrown wrapped into a TorqueException.
386      */

387     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
388     {
389         return populateObjects(doSelectVillageRecords(criteria));
390     }
391
392     /**
393      * Method to do selects within a transaction.
394      *
395      * @param criteria object used to create the SELECT statement.
396      * @param con the connection to use
397      * @return List of selected Objects
398      * @throws TorqueException Any exceptions caught during processing will be
399      * rethrown wrapped into a TorqueException.
400      */

401     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
402         throws TorqueException
403     {
404         return populateObjects(doSelectVillageRecords(criteria, con));
405     }
406
407     /**
408      * Grabs the raw Village records to be formed into objects.
409      * This method handles connections internally. The Record objects
410      * returned by this method should be considered readonly. Do not
411      * alter the data and call save(), your results may vary, but are
412      * certainly likely to result in hard to track MT bugs.
413      *
414      * @throws TorqueException Any exceptions caught during processing will be
415      * rethrown wrapped into a TorqueException.
416      */

417     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
418         throws TorqueException
419     {
420         return BaseProjectPeer
421             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
422     }
423
424     /**
425      * Grabs the raw Village records to be formed into objects.
426      * This method should be used for transactions
427      *
428      * @param criteria object used to create the SELECT 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 List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
434         throws TorqueException
435     {
436         if (criteria.getSelectColumns().size() == 0)
437         {
438             addSelectColumns(criteria);
439         }
440
441                                                                                                                                 
442         setDbName(criteria);
443
444         // BasePeer returns a List of Value (Village) arrays. The array
445
// order follows the order columns were placed in the Select clause.
446
if (con == null)
447         {
448             return BasePeer.doSelect(criteria);
449         }
450         else
451         {
452             return BasePeer.doSelect(criteria, con);
453         }
454     }
455
456     /**
457      * The returned List will contain objects of the default type or
458      * objects that inherit from the default.
459      *
460      * @throws TorqueException Any exceptions caught during processing will be
461      * rethrown wrapped into a TorqueException.
462      */

463     public static List JavaDoc populateObjects(List JavaDoc records)
464         throws TorqueException
465     {
466         List JavaDoc results = new ArrayList JavaDoc(records.size());
467
468         // populate the object(s)
469
for (int i = 0; i < records.size(); i++)
470         {
471             Record row = (Record) records.get(i);
472               results.add(ProjectPeer.row2Object(row, 1,
473                 ProjectPeer.getOMClass()));
474           }
475         return results;
476     }
477  
478
479     /**
480      * The class that the Peer will make instances of.
481      * If the BO is abstract then you must implement this method
482      * in the BO.
483      *
484      * @throws TorqueException Any exceptions caught during processing will be
485      * rethrown wrapped into a TorqueException.
486      */

487     public static Class JavaDoc getOMClass()
488         throws TorqueException
489     {
490         return CLASS_DEFAULT;
491     }
492
493     /**
494      * Method to do updates.
495      *
496      * @param criteria object containing data that is used to create the UPDATE
497      * statement.
498      * @throws TorqueException Any exceptions caught during processing will be
499      * rethrown wrapped into a TorqueException.
500      */

501     public static void doUpdate(Criteria criteria) throws TorqueException
502     {
503          BaseProjectPeer
504             .doUpdate(criteria, (Connection JavaDoc) null);
505     }
506
507     /**
508      * Method to do updates. This method is to be used during a transaction,
509      * otherwise use the doUpdate(Criteria) method. It will take care of
510      * the connection details internally.
511      *
512      * @param criteria object containing data that is used to create the UPDATE
513      * statement.
514      * @param con the connection to use
515      * @throws TorqueException Any exceptions caught during processing will be
516      * rethrown wrapped into a TorqueException.
517      */

518     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
519         throws TorqueException
520     {
521         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
522                    selectCriteria.put(PROJECT_ID, criteria.remove(PROJECT_ID));
523                                                                                                                                                                                                               
524         setDbName(criteria);
525
526         if (con == null)
527         {
528             BasePeer.doUpdate(selectCriteria, criteria);
529         }
530         else
531         {
532             BasePeer.doUpdate(selectCriteria, criteria, con);
533         }
534     }
535
536     /**
537      * Method to do deletes.
538      *
539      * @param criteria object containing data that is used DELETE from database.
540      * @throws TorqueException Any exceptions caught during processing will be
541      * rethrown wrapped into a TorqueException.
542      */

543      public static void doDelete(Criteria criteria) throws TorqueException
544      {
545          ProjectPeer
546             .doDelete(criteria, (Connection JavaDoc) null);
547      }
548
549     /**
550      * Method to do deletes. This method is to be used during a transaction,
551      * otherwise use the doDelete(Criteria) method. It will take care of
552      * the connection details internally.
553      *
554      * @param criteria object containing data that is used DELETE from database.
555      * @param con the connection to use
556      * @throws TorqueException Any exceptions caught during processing will be
557      * rethrown wrapped into a TorqueException.
558      */

559      public static void doDelete(Criteria criteria, Connection JavaDoc con)
560         throws TorqueException
561      {
562                                                                                                                                 
563         setDbName(criteria);
564
565         if (con == null)
566         {
567             BasePeer.doDelete(criteria);
568         }
569         else
570         {
571             BasePeer.doDelete(criteria, con);
572         }
573      }
574
575     /**
576      * Method to do selects
577      *
578      * @throws TorqueException Any exceptions caught during processing will be
579      * rethrown wrapped into a TorqueException.
580      */

581     public static List JavaDoc doSelect(Project obj) throws TorqueException
582     {
583         return doSelect(buildSelectCriteria(obj));
584     }
585
586     /**
587      * Method to do inserts
588      *
589      * @throws TorqueException Any exceptions caught during processing will be
590      * rethrown wrapped into a TorqueException.
591      */

592     public static void doInsert(Project obj) throws TorqueException
593     {
594           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
595           obj.setNew(false);
596         obj.setModified(false);
597     }
598
599     /**
600      * @param obj the data object to update in the database.
601      * @throws TorqueException Any exceptions caught during processing will be
602      * rethrown wrapped into a TorqueException.
603      */

604     public static void doUpdate(Project obj) throws TorqueException
605     {
606         doUpdate(buildCriteria(obj));
607         obj.setModified(false);
608     }
609
610     /**
611      * @param obj the data object to delete in the database.
612      * @throws TorqueException Any exceptions caught during processing will be
613      * rethrown wrapped into a TorqueException.
614      */

615     public static void doDelete(Project obj) throws TorqueException
616     {
617         doDelete(buildSelectCriteria(obj));
618     }
619
620     /**
621      * Method to do inserts. This method is to be used during a transaction,
622      * otherwise use the doInsert(Project) method. It will take
623      * care of the connection details internally.
624      *
625      * @param obj the data object to insert into the database.
626      * @param con the connection to use
627      * @throws TorqueException Any exceptions caught during processing will be
628      * rethrown wrapped into a TorqueException.
629      */

630     public static void doInsert(Project obj, Connection JavaDoc con)
631         throws TorqueException
632     {
633           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
634           obj.setNew(false);
635         obj.setModified(false);
636     }
637
638     /**
639      * Method to do update. This method is to be used during a transaction,
640      * otherwise use the doUpdate(Project) method. It will take
641      * care of the connection details internally.
642      *
643      * @param obj the data object to update in the database.
644      * @param con the connection to use
645      * @throws TorqueException Any exceptions caught during processing will be
646      * rethrown wrapped into a TorqueException.
647      */

648     public static void doUpdate(Project obj, Connection JavaDoc con)
649         throws TorqueException
650     {
651         doUpdate(buildCriteria(obj), con);
652         obj.setModified(false);
653     }
654
655     /**
656      * Method to delete. This method is to be used during a transaction,
657      * otherwise use the doDelete(Project) method. It will take
658      * care of the connection details internally.
659      *
660      * @param obj the data object to delete in the database.
661      * @param con the connection to use
662      * @throws TorqueException Any exceptions caught during processing will be
663      * rethrown wrapped into a TorqueException.
664      */

665     public static void doDelete(Project obj, Connection JavaDoc con)
666         throws TorqueException
667     {
668         doDelete(buildSelectCriteria(obj), con);
669     }
670
671     /**
672      * Method to do deletes.
673      *
674      * @param pk ObjectKey that is used DELETE from database.
675      * @throws TorqueException Any exceptions caught during processing will be
676      * rethrown wrapped into a TorqueException.
677      */

678     public static void doDelete(ObjectKey pk) throws TorqueException
679     {
680         BaseProjectPeer
681            .doDelete(pk, (Connection JavaDoc) null);
682     }
683
684     /**
685      * Method to delete. This method is to be used during a transaction,
686      * otherwise use the doDelete(ObjectKey) method. It will take
687      * care of the connection details internally.
688      *
689      * @param pk the primary key for the object to delete in the database.
690      * @param con the connection to use
691      * @throws TorqueException Any exceptions caught during processing will be
692      * rethrown wrapped into a TorqueException.
693      */

694     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
695         throws TorqueException
696     {
697         doDelete(buildCriteria(pk), con);
698     }
699
700     /** Build a Criteria object from an ObjectKey */
701     public static Criteria buildCriteria( ObjectKey pk )
702     {
703         Criteria criteria = new Criteria();
704               criteria.add(PROJECT_ID, pk);
705           return criteria;
706      }
707
708     /** Build a Criteria object from the data object for this peer */
709     public static Criteria buildCriteria( Project obj )
710     {
711         Criteria criteria = new Criteria(DATABASE_NAME);
712               if (!obj.isNew())
713             criteria.add(PROJECT_ID, obj.getProjectId());
714               criteria.add(PROJECT_CODE, obj.getProjectCode());
715               criteria.add(STATUS, obj.getStatus());
716               criteria.add(PRIORITY, obj.getPriority());
717               criteria.add(PROJECT_CAT_ID, obj.getProjectCatId());
718               criteria.add(PROJECT_NAME, obj.getProjectName());
719               criteria.add(START_DATE, obj.getStartDate());
720               criteria.add(END_DATE, obj.getEndDate());
721               criteria.add(EXPENSES, obj.getExpenses());
722               criteria.add(REVENUES, obj.getRevenues());
723               criteria.add(CUSTOM_1, obj.getCustom1());
724               criteria.add(CUSTOM_2, obj.getCustom2());
725               criteria.add(CUSTOM_3, obj.getCustom3());
726               criteria.add(CUSTOM_4, obj.getCustom4());
727               criteria.add(CUSTOM_5, obj.getCustom5());
728               criteria.add(CUSTOM_6, obj.getCustom6());
729               criteria.add(NOTES, obj.getNotes());
730               criteria.add(CREATED, obj.getCreated());
731               criteria.add(MODIFIED, obj.getModified());
732               criteria.add(CREATED_BY, obj.getCreatedBy());
733               criteria.add(MODIFIED_BY, obj.getModifiedBy());
734           return criteria;
735     }
736
737     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
738     public static Criteria buildSelectCriteria( Project obj )
739     {
740         Criteria criteria = new Criteria(DATABASE_NAME);
741               if (!obj.isNew())
742                     criteria.add(PROJECT_ID, obj.getProjectId());
743                           criteria.add(PROJECT_CODE, obj.getProjectCode());
744                           criteria.add(STATUS, obj.getStatus());
745                           criteria.add(PRIORITY, obj.getPriority());
746                           criteria.add(PROJECT_CAT_ID, obj.getProjectCatId());
747                           criteria.add(PROJECT_NAME, obj.getProjectName());
748                           criteria.add(START_DATE, obj.getStartDate());
749                           criteria.add(END_DATE, obj.getEndDate());
750                           criteria.add(EXPENSES, obj.getExpenses());
751                           criteria.add(REVENUES, obj.getRevenues());
752                           criteria.add(CUSTOM_1, obj.getCustom1());
753                           criteria.add(CUSTOM_2, obj.getCustom2());
754                           criteria.add(CUSTOM_3, obj.getCustom3());
755                           criteria.add(CUSTOM_4, obj.getCustom4());
756                           criteria.add(CUSTOM_5, obj.getCustom5());
757                           criteria.add(CUSTOM_6, obj.getCustom6());
758                           criteria.add(NOTES, obj.getNotes());
759                           criteria.add(CREATED, obj.getCreated());
760                           criteria.add(MODIFIED, obj.getModified());
761                           criteria.add(CREATED_BY, obj.getCreatedBy());
762                           criteria.add(MODIFIED_BY, obj.getModifiedBy());
763               return criteria;
764     }
765  
766     
767         /**
768      * Retrieve a single object by pk
769      *
770      * @param pk the primary key
771      * @throws TorqueException Any exceptions caught during processing will be
772      * rethrown wrapped into a TorqueException.
773      * @throws NoRowsException Primary key was not found in database.
774      * @throws TooManyRowsException Primary key was not found in database.
775      */

776     public static Project retrieveByPK(int pk)
777         throws TorqueException, NoRowsException, TooManyRowsException
778     {
779         return retrieveByPK(SimpleKey.keyFor(pk));
780     }
781
782     /**
783      * Retrieve a single object by pk
784      *
785      * @param pk the primary key
786      * @param con the connection to use
787      * @throws TorqueException Any exceptions caught during processing will be
788      * rethrown wrapped into a TorqueException.
789      * @throws NoRowsException Primary key was not found in database.
790      * @throws TooManyRowsException Primary key was not found in database.
791      */

792     public static Project retrieveByPK(int pk, Connection JavaDoc con)
793         throws TorqueException, NoRowsException, TooManyRowsException
794     {
795         return retrieveByPK(SimpleKey.keyFor(pk), con);
796     }
797   
798     /**
799      * Retrieve a single object by pk
800      *
801      * @param pk the primary key
802      * @throws TorqueException Any exceptions caught during processing will be
803      * rethrown wrapped into a TorqueException.
804      * @throws NoRowsException Primary key was not found in database.
805      * @throws TooManyRowsException Primary key was not found in database.
806      */

807     public static Project retrieveByPK(ObjectKey pk)
808         throws TorqueException, NoRowsException, TooManyRowsException
809     {
810         Connection JavaDoc db = null;
811         Project retVal = null;
812         try
813         {
814             db = Torque.getConnection(DATABASE_NAME);
815             retVal = retrieveByPK(pk, db);
816         }
817         finally
818         {
819             Torque.closeConnection(db);
820         }
821         return(retVal);
822     }
823
824     /**
825      * Retrieve a single object by pk
826      *
827      * @param pk the primary key
828      * @param con the connection to use
829      * @throws TorqueException Any exceptions caught during processing will be
830      * rethrown wrapped into a TorqueException.
831      * @throws NoRowsException Primary key was not found in database.
832      * @throws TooManyRowsException Primary key was not found in database.
833      */

834     public static Project retrieveByPK(ObjectKey pk, Connection JavaDoc con)
835         throws TorqueException, NoRowsException, TooManyRowsException
836     {
837         Criteria criteria = buildCriteria(pk);
838         List JavaDoc v = doSelect(criteria, con);
839         if (v.size() == 0)
840         {
841             throw new NoRowsException("Failed to select a row.");
842         }
843         else if (v.size() > 1)
844         {
845             throw new TooManyRowsException("Failed to select only one row.");
846         }
847         else
848         {
849             return (Project)v.get(0);
850         }
851     }
852
853     /**
854      * Retrieve a multiple objects by pk
855      *
856      * @param pks List of primary keys
857      * @throws TorqueException Any exceptions caught during processing will be
858      * rethrown wrapped into a TorqueException.
859      */

860     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
861         throws TorqueException
862     {
863         Connection JavaDoc db = null;
864         List JavaDoc retVal = null;
865         try
866         {
867            db = Torque.getConnection(DATABASE_NAME);
868            retVal = retrieveByPKs(pks, db);
869         }
870         finally
871         {
872             Torque.closeConnection(db);
873         }
874         return(retVal);
875     }
876
877     /**
878      * Retrieve a multiple objects by pk
879      *
880      * @param pks List of primary keys
881      * @param dbcon the connection to use
882      * @throws TorqueException Any exceptions caught during processing will be
883      * rethrown wrapped into a TorqueException.
884      */

885     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
886         throws TorqueException
887     {
888         List JavaDoc objs = null;
889         if (pks == null || pks.size() == 0)
890         {
891             objs = new LinkedList JavaDoc();
892         }
893         else
894         {
895             Criteria criteria = new Criteria();
896               criteria.addIn( PROJECT_ID, pks );
897           objs = doSelect(criteria, dbcon);
898         }
899         return objs;
900     }
901
902  
903
904
905
906           
907                                               
908                 
909                 
910
911     /**
912      * selects a collection of Project objects pre-filled with their
913      * ProjectCategory objects.
914      *
915      * This method is protected by default in order to keep the public
916      * api reasonable. You can provide public methods for those you
917      * actually need in ProjectPeer.
918      *
919      * @throws TorqueException Any exceptions caught during processing will be
920      * rethrown wrapped into a TorqueException.
921      */

922     protected static List JavaDoc doSelectJoinProjectCategory(Criteria criteria)
923         throws TorqueException
924     {
925         setDbName(criteria);
926
927         ProjectPeer.addSelectColumns(criteria);
928         int offset = numColumns + 1;
929         ProjectCategoryPeer.addSelectColumns(criteria);
930
931
932                         criteria.addJoin(ProjectPeer.PROJECT_CAT_ID,
933             ProjectCategoryPeer.PROJECT_CAT_ID);
934         
935
936                                                                                                                                                                                                                                                                                                                                                                                                   
937         List JavaDoc rows = BasePeer.doSelect(criteria);
938         List JavaDoc results = new ArrayList JavaDoc();
939
940         for (int i = 0; i < rows.size(); i++)
941         {
942             Record row = (Record) rows.get(i);
943
944                             Class JavaDoc omClass = ProjectPeer.getOMClass();
945                     Project obj1 = (Project) ProjectPeer
946                 .row2Object(row, 1, omClass);
947                      omClass = ProjectCategoryPeer.getOMClass();
948                     ProjectCategory obj2 = (ProjectCategory)ProjectCategoryPeer
949                 .row2Object(row, offset, omClass);
950
951             boolean newObject = true;
952             for (int j = 0; j < results.size(); j++)
953             {
954                 Project temp_obj1 = (Project)results.get(j);
955                 ProjectCategory temp_obj2 = (ProjectCategory)temp_obj1.getProjectCategory();
956                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
957                 {
958                     newObject = false;
959                               temp_obj2.addProject(obj1);
960                               break;
961                 }
962             }
963                       if (newObject)
964             {
965                 obj2.initProjects();
966                 obj2.addProject(obj1);
967             }
968                       results.add(obj1);
969         }
970         return results;
971     }
972                     
973   
974     
975   
976       /**
977      * Returns the TableMap related to this peer. This method is not
978      * needed for general use but a specific application could have a need.
979      *
980      * @throws TorqueException Any exceptions caught during processing will be
981      * rethrown wrapped into a TorqueException.
982      */

983     protected static TableMap getTableMap()
984         throws TorqueException
985     {
986         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
987     }
988    
989     private static void setDbName(Criteria crit)
990     {
991         // Set the correct dbName if it has not been overridden
992
// crit.getDbName will return the same object if not set to
993
// another value so == check is okay and faster
994
if (crit.getDbName() == Torque.getDefaultDB())
995         {
996             crit.setDbName(DATABASE_NAME);
997         }
998     }
999 }
1000
Popular Tags