KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This class was autogenerated by Torque on:
36  *
37  * [Wed May 04 09:10:56 CEST 2005]
38  *
39  */

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

55     public static MapBuilder getMapBuilder()
56         throws TorqueException
57     {
58         return getMapBuilder(CreamUserMapBuilder.CLASS_NAME);
59     }
60
61       /** the column name for the USER_ID field */
62     public static final String JavaDoc USER_ID;
63       /** the column name for the LOGIN_NAME field */
64     public static final String JavaDoc LOGIN_NAME;
65       /** the column name for the WELCOME field */
66     public static final String JavaDoc WELCOME;
67       /** the column name for the DEFAULT_LIST field */
68     public static final String JavaDoc DEFAULT_LIST;
69       /** the column name for the INBOX_FID field */
70     public static final String JavaDoc INBOX_FID;
71       /** the column name for the OUTBOX_FID field */
72     public static final String JavaDoc OUTBOX_FID;
73       /** the column name for the NEWS_SUBS_FID field */
74     public static final String JavaDoc NEWS_SUBS_FID;
75       /** the column name for the NEWSLETTER_FID field */
76     public static final String JavaDoc NEWSLETTER_FID;
77       /** the column name for the ONLINE_SUBS_FID field */
78     public static final String JavaDoc ONLINE_SUBS_FID;
79       /** the column name for the PRINT_SUBS_FID field */
80     public static final String JavaDoc PRINT_SUBS_FID;
81       /** the column name for the SERVICE_FID field */
82     public static final String JavaDoc SERVICE_FID;
83       /** the column name for the SHIPMENT_FID field */
84     public static final String JavaDoc SHIPMENT_FID;
85       /** the column name for the PAYMENT_FID field */
86     public static final String JavaDoc PAYMENT_FID;
87       /** the column name for the SORDER_FID field */
88     public static final String JavaDoc SORDER_FID;
89       /** the column name for the PROJECT_FID field */
90     public static final String JavaDoc PROJECT_FID;
91       /** the column name for the CUSTOMER_FID field */
92     public static final String JavaDoc CUSTOMER_FID;
93       /** the column name for the PRODUCT_FID field */
94     public static final String JavaDoc PRODUCT_FID;
95   
96     static
97     {
98           USER_ID = "CREAM_USER.USER_ID";
99           LOGIN_NAME = "CREAM_USER.LOGIN_NAME";
100           WELCOME = "CREAM_USER.WELCOME";
101           DEFAULT_LIST = "CREAM_USER.DEFAULT_LIST";
102           INBOX_FID = "CREAM_USER.INBOX_FID";
103           OUTBOX_FID = "CREAM_USER.OUTBOX_FID";
104           NEWS_SUBS_FID = "CREAM_USER.NEWS_SUBS_FID";
105           NEWSLETTER_FID = "CREAM_USER.NEWSLETTER_FID";
106           ONLINE_SUBS_FID = "CREAM_USER.ONLINE_SUBS_FID";
107           PRINT_SUBS_FID = "CREAM_USER.PRINT_SUBS_FID";
108           SERVICE_FID = "CREAM_USER.SERVICE_FID";
109           SHIPMENT_FID = "CREAM_USER.SHIPMENT_FID";
110           PAYMENT_FID = "CREAM_USER.PAYMENT_FID";
111           SORDER_FID = "CREAM_USER.SORDER_FID";
112           PROJECT_FID = "CREAM_USER.PROJECT_FID";
113           CUSTOMER_FID = "CREAM_USER.CUSTOMER_FID";
114           PRODUCT_FID = "CREAM_USER.PRODUCT_FID";
115           if (Torque.isInit())
116         {
117             try
118             {
119                 getMapBuilder(CreamUserMapBuilder.CLASS_NAME);
120             }
121             catch (Exception JavaDoc e)
122             {
123                 log.error("Could not initialize Peer", e);
124             }
125         }
126         else
127         {
128             Torque.registerMapBuilder(CreamUserMapBuilder.CLASS_NAME);
129         }
130     }
131  
132     /** number of columns for this peer */
133     public static final int numColumns = 17;
134
135     /** A class that can be returned by this peer. */
136     protected static final String JavaDoc CLASSNAME_DEFAULT =
137         "org.campware.cream.om.CreamUser";
138
139     /** A class that can be returned by this peer. */
140     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
141
142     /**
143      * Class object initialization method.
144      *
145      * @param className name of the class to initialize
146      * @return the initialized class
147      */

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

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

223     public static ObjectKey doInsert(Criteria criteria)
224         throws TorqueException
225     {
226         return BaseCreamUserPeer
227             .doInsert(criteria, (Connection JavaDoc) null);
228     }
229
230     /**
231      * Method to do inserts. This method is to be used during a transaction,
232      * otherwise use the doInsert(Criteria) method. It will take care of
233      * the connection details internally.
234      *
235      * @param criteria object used to create the INSERT statement.
236      * @param con the connection to use
237      * @throws TorqueException Any exceptions caught during processing will be
238      * rethrown wrapped into a TorqueException.
239      */

240     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
241         throws TorqueException
242     {
243                                                                                                         
244         setDbName(criteria);
245
246         if (con == null)
247         {
248             return BasePeer.doInsert(criteria);
249         }
250         else
251         {
252             return BasePeer.doInsert(criteria, con);
253         }
254     }
255
256     /**
257      * Add all the columns needed to create a new object.
258      *
259      * @param criteria object containing the columns to add.
260      * @throws TorqueException Any exceptions caught during processing will be
261      * rethrown wrapped into a TorqueException.
262      */

263     public static void addSelectColumns(Criteria criteria)
264             throws TorqueException
265     {
266           criteria.addSelectColumn(USER_ID);
267           criteria.addSelectColumn(LOGIN_NAME);
268           criteria.addSelectColumn(WELCOME);
269           criteria.addSelectColumn(DEFAULT_LIST);
270           criteria.addSelectColumn(INBOX_FID);
271           criteria.addSelectColumn(OUTBOX_FID);
272           criteria.addSelectColumn(NEWS_SUBS_FID);
273           criteria.addSelectColumn(NEWSLETTER_FID);
274           criteria.addSelectColumn(ONLINE_SUBS_FID);
275           criteria.addSelectColumn(PRINT_SUBS_FID);
276           criteria.addSelectColumn(SERVICE_FID);
277           criteria.addSelectColumn(SHIPMENT_FID);
278           criteria.addSelectColumn(PAYMENT_FID);
279           criteria.addSelectColumn(SORDER_FID);
280           criteria.addSelectColumn(PROJECT_FID);
281           criteria.addSelectColumn(CUSTOMER_FID);
282           criteria.addSelectColumn(PRODUCT_FID);
283       }
284
285     /**
286      * Create a new object of type cls from a resultset row starting
287      * from a specified offset. This is done so that you can select
288      * other rows than just those needed for this object. You may
289      * for example want to create two objects from the same row.
290      *
291      * @throws TorqueException Any exceptions caught during processing will be
292      * rethrown wrapped into a TorqueException.
293      */

294     public static CreamUser row2Object(Record row,
295                                              int offset,
296                                              Class JavaDoc cls)
297         throws TorqueException
298     {
299         try
300         {
301             CreamUser obj = (CreamUser) cls.newInstance();
302             CreamUserPeer.populateObject(row, offset, obj);
303                   obj.setModified(false);
304               obj.setNew(false);
305
306             return obj;
307         }
308         catch (InstantiationException JavaDoc e)
309         {
310             throw new TorqueException(e);
311         }
312         catch (IllegalAccessException JavaDoc e)
313         {
314             throw new TorqueException(e);
315         }
316     }
317
318     /**
319      * Populates an object from a resultset row starting
320      * from a specified offset. This is done so that you can select
321      * other rows than just those needed for this object. You may
322      * for example want to create two objects from the same row.
323      *
324      * @throws TorqueException Any exceptions caught during processing will be
325      * rethrown wrapped into a TorqueException.
326      */

327     public static void populateObject(Record row,
328                                       int offset,
329                                       CreamUser obj)
330         throws TorqueException
331     {
332         try
333         {
334                 obj.setUserId(row.getValue(offset + 0).asInt());
335                   obj.setUserName(row.getValue(offset + 1).asString());
336                   obj.setWelcome(row.getValue(offset + 2).asString());
337                   obj.setDefaultList(row.getValue(offset + 3).asInt());
338                   obj.setInboxFid(row.getValue(offset + 4).asInt());
339                   obj.setOutboxFid(row.getValue(offset + 5).asInt());
340                   obj.setNewsSubsFid(row.getValue(offset + 6).asInt());
341                   obj.setNewsletterFid(row.getValue(offset + 7).asInt());
342                   obj.setOnlineSubsFid(row.getValue(offset + 8).asInt());
343                   obj.setPrintSubsFid(row.getValue(offset + 9).asInt());
344                   obj.setServiceFid(row.getValue(offset + 10).asInt());
345                   obj.setShipmentFid(row.getValue(offset + 11).asInt());
346                   obj.setPaymentFid(row.getValue(offset + 12).asInt());
347                   obj.setSorderFid(row.getValue(offset + 13).asInt());
348                   obj.setProjectFid(row.getValue(offset + 14).asInt());
349                   obj.setCustomerFid(row.getValue(offset + 15).asInt());
350                   obj.setProductFid(row.getValue(offset + 16).asInt());
351               }
352         catch (DataSetException e)
353         {
354             throw new TorqueException(e);
355         }
356     }
357
358     /**
359      * Method to do selects.
360      *
361      * @param criteria object used to create the SELECT statement.
362      * @return List of selected Objects
363      * @throws TorqueException Any exceptions caught during processing will be
364      * rethrown wrapped into a TorqueException.
365      */

366     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
367     {
368         return populateObjects(doSelectVillageRecords(criteria));
369     }
370
371     /**
372      * Method to do selects within a transaction.
373      *
374      * @param criteria object used to create the SELECT statement.
375      * @param con the connection to use
376      * @return List of selected Objects
377      * @throws TorqueException Any exceptions caught during processing will be
378      * rethrown wrapped into a TorqueException.
379      */

380     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
381         throws TorqueException
382     {
383         return populateObjects(doSelectVillageRecords(criteria, con));
384     }
385
386     /**
387      * Grabs the raw Village records to be formed into objects.
388      * This method handles connections internally. The Record objects
389      * returned by this method should be considered readonly. Do not
390      * alter the data and call save(), your results may vary, but are
391      * certainly likely to result in hard to track MT bugs.
392      *
393      * @throws TorqueException Any exceptions caught during processing will be
394      * rethrown wrapped into a TorqueException.
395      */

396     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
397         throws TorqueException
398     {
399         return BaseCreamUserPeer
400             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
401     }
402
403     /**
404      * Grabs the raw Village records to be formed into objects.
405      * This method should be used for transactions
406      *
407      * @param criteria object used to create the SELECT statement.
408      * @param con the connection to use
409      * @throws TorqueException Any exceptions caught during processing will be
410      * rethrown wrapped into a TorqueException.
411      */

412     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
413         throws TorqueException
414     {
415         if (criteria.getSelectColumns().size() == 0)
416         {
417             addSelectColumns(criteria);
418         }
419
420                                                                                                         
421         setDbName(criteria);
422
423         // BasePeer returns a List of Value (Village) arrays. The array
424
// order follows the order columns were placed in the Select clause.
425
if (con == null)
426         {
427             return BasePeer.doSelect(criteria);
428         }
429         else
430         {
431             return BasePeer.doSelect(criteria, con);
432         }
433     }
434
435     /**
436      * The returned List will contain objects of the default type or
437      * objects that inherit from the default.
438      *
439      * @throws TorqueException Any exceptions caught during processing will be
440      * rethrown wrapped into a TorqueException.
441      */

442     public static List JavaDoc populateObjects(List JavaDoc records)
443         throws TorqueException
444     {
445         List JavaDoc results = new ArrayList JavaDoc(records.size());
446
447         // populate the object(s)
448
for (int i = 0; i < records.size(); i++)
449         {
450             Record row = (Record) records.get(i);
451               results.add(CreamUserPeer.row2Object(row, 1,
452                 CreamUserPeer.getOMClass()));
453           }
454         return results;
455     }
456  
457
458     /**
459      * The class that the Peer will make instances of.
460      * If the BO is abstract then you must implement this method
461      * in the BO.
462      *
463      * @throws TorqueException Any exceptions caught during processing will be
464      * rethrown wrapped into a TorqueException.
465      */

466     public static Class JavaDoc getOMClass()
467         throws TorqueException
468     {
469         return CLASS_DEFAULT;
470     }
471
472     /**
473      * Method to do updates.
474      *
475      * @param criteria object containing data that is used to create the UPDATE
476      * statement.
477      * @throws TorqueException Any exceptions caught during processing will be
478      * rethrown wrapped into a TorqueException.
479      */

480     public static void doUpdate(Criteria criteria) throws TorqueException
481     {
482          BaseCreamUserPeer
483             .doUpdate(criteria, (Connection JavaDoc) null);
484     }
485
486     /**
487      * Method to do updates. This method is to be used during a transaction,
488      * otherwise use the doUpdate(Criteria) method. It will take care of
489      * the connection details internally.
490      *
491      * @param criteria object containing data that is used to create the UPDATE
492      * statement.
493      * @param con the connection to use
494      * @throws TorqueException Any exceptions caught during processing will be
495      * rethrown wrapped into a TorqueException.
496      */

497     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
498         throws TorqueException
499     {
500         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
501                    selectCriteria.put(USER_ID, criteria.remove(USER_ID));
502                                                                                                                                                                       
503         setDbName(criteria);
504
505         if (con == null)
506         {
507             BasePeer.doUpdate(selectCriteria, criteria);
508         }
509         else
510         {
511             BasePeer.doUpdate(selectCriteria, criteria, con);
512         }
513     }
514
515     /**
516      * Method to do deletes.
517      *
518      * @param criteria object containing data that is used DELETE from database.
519      * @throws TorqueException Any exceptions caught during processing will be
520      * rethrown wrapped into a TorqueException.
521      */

522      public static void doDelete(Criteria criteria) throws TorqueException
523      {
524          CreamUserPeer
525             .doDelete(criteria, (Connection JavaDoc) null);
526      }
527
528     /**
529      * Method to do deletes. This method is to be used during a transaction,
530      * otherwise use the doDelete(Criteria) method. It will take care of
531      * the connection details internally.
532      *
533      * @param criteria object containing data that is used DELETE from database.
534      * @param con the connection to use
535      * @throws TorqueException Any exceptions caught during processing will be
536      * rethrown wrapped into a TorqueException.
537      */

538      public static void doDelete(Criteria criteria, Connection JavaDoc con)
539         throws TorqueException
540      {
541                                                                                                         
542         setDbName(criteria);
543
544         if (con == null)
545         {
546             BasePeer.doDelete(criteria);
547         }
548         else
549         {
550             BasePeer.doDelete(criteria, con);
551         }
552      }
553
554     /**
555      * Method to do selects
556      *
557      * @throws TorqueException Any exceptions caught during processing will be
558      * rethrown wrapped into a TorqueException.
559      */

560     public static List JavaDoc doSelect(CreamUser obj) throws TorqueException
561     {
562         return doSelect(buildSelectCriteria(obj));
563     }
564
565     /**
566      * Method to do inserts
567      *
568      * @throws TorqueException Any exceptions caught during processing will be
569      * rethrown wrapped into a TorqueException.
570      */

571     public static void doInsert(CreamUser obj) throws TorqueException
572     {
573           doInsert(buildCriteria(obj));
574           obj.setNew(false);
575         obj.setModified(false);
576     }
577
578     /**
579      * @param obj the data object to update in the database.
580      * @throws TorqueException Any exceptions caught during processing will be
581      * rethrown wrapped into a TorqueException.
582      */

583     public static void doUpdate(CreamUser obj) throws TorqueException
584     {
585         doUpdate(buildCriteria(obj));
586         obj.setModified(false);
587     }
588
589     /**
590      * @param obj the data object to delete in the database.
591      * @throws TorqueException Any exceptions caught during processing will be
592      * rethrown wrapped into a TorqueException.
593      */

594     public static void doDelete(CreamUser obj) throws TorqueException
595     {
596         doDelete(buildSelectCriteria(obj));
597     }
598
599     /**
600      * Method to do inserts. This method is to be used during a transaction,
601      * otherwise use the doInsert(CreamUser) method. It will take
602      * care of the connection details internally.
603      *
604      * @param obj the data object to insert into the database.
605      * @param con the connection to use
606      * @throws TorqueException Any exceptions caught during processing will be
607      * rethrown wrapped into a TorqueException.
608      */

609     public static void doInsert(CreamUser obj, Connection JavaDoc con)
610         throws TorqueException
611     {
612           doInsert(buildCriteria(obj), con);
613           obj.setNew(false);
614         obj.setModified(false);
615     }
616
617     /**
618      * Method to do update. This method is to be used during a transaction,
619      * otherwise use the doUpdate(CreamUser) method. It will take
620      * care of the connection details internally.
621      *
622      * @param obj the data object to update in the database.
623      * @param con the connection to use
624      * @throws TorqueException Any exceptions caught during processing will be
625      * rethrown wrapped into a TorqueException.
626      */

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

644     public static void doDelete(CreamUser obj, Connection JavaDoc con)
645         throws TorqueException
646     {
647         doDelete(buildSelectCriteria(obj), con);
648     }
649
650     /**
651      * Method to do deletes.
652      *
653      * @param pk ObjectKey that is used DELETE from database.
654      * @throws TorqueException Any exceptions caught during processing will be
655      * rethrown wrapped into a TorqueException.
656      */

657     public static void doDelete(ObjectKey pk) throws TorqueException
658     {
659         BaseCreamUserPeer
660            .doDelete(pk, (Connection JavaDoc) null);
661     }
662
663     /**
664      * Method to delete. This method is to be used during a transaction,
665      * otherwise use the doDelete(ObjectKey) method. It will take
666      * care of the connection details internally.
667      *
668      * @param pk the primary key for the object to delete in the database.
669      * @param con the connection to use
670      * @throws TorqueException Any exceptions caught during processing will be
671      * rethrown wrapped into a TorqueException.
672      */

673     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
674         throws TorqueException
675     {
676         doDelete(buildCriteria(pk), con);
677     }
678
679     /** Build a Criteria object from an ObjectKey */
680     public static Criteria buildCriteria( ObjectKey pk )
681     {
682         Criteria criteria = new Criteria();
683               criteria.add(USER_ID, pk);
684           return criteria;
685      }
686
687     /** Build a Criteria object from the data object for this peer */
688     public static Criteria buildCriteria( CreamUser obj )
689     {
690         Criteria criteria = new Criteria(DATABASE_NAME);
691               criteria.add(USER_ID, obj.getUserId());
692               criteria.add(LOGIN_NAME, obj.getUserName());
693               criteria.add(WELCOME, obj.getWelcome());
694               criteria.add(DEFAULT_LIST, obj.getDefaultList());
695               criteria.add(INBOX_FID, obj.getInboxFid());
696               criteria.add(OUTBOX_FID, obj.getOutboxFid());
697               criteria.add(NEWS_SUBS_FID, obj.getNewsSubsFid());
698               criteria.add(NEWSLETTER_FID, obj.getNewsletterFid());
699               criteria.add(ONLINE_SUBS_FID, obj.getOnlineSubsFid());
700               criteria.add(PRINT_SUBS_FID, obj.getPrintSubsFid());
701               criteria.add(SERVICE_FID, obj.getServiceFid());
702               criteria.add(SHIPMENT_FID, obj.getShipmentFid());
703               criteria.add(PAYMENT_FID, obj.getPaymentFid());
704               criteria.add(SORDER_FID, obj.getSorderFid());
705               criteria.add(PROJECT_FID, obj.getProjectFid());
706               criteria.add(CUSTOMER_FID, obj.getCustomerFid());
707               criteria.add(PRODUCT_FID, obj.getProductFid());
708           return criteria;
709     }
710
711     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
712     public static Criteria buildSelectCriteria( CreamUser obj )
713     {
714         Criteria criteria = new Criteria(DATABASE_NAME);
715                       criteria.add(USER_ID, obj.getUserId());
716                           criteria.add(LOGIN_NAME, obj.getUserName());
717                           criteria.add(WELCOME, obj.getWelcome());
718                           criteria.add(DEFAULT_LIST, obj.getDefaultList());
719                           criteria.add(INBOX_FID, obj.getInboxFid());
720                           criteria.add(OUTBOX_FID, obj.getOutboxFid());
721                           criteria.add(NEWS_SUBS_FID, obj.getNewsSubsFid());
722                           criteria.add(NEWSLETTER_FID, obj.getNewsletterFid());
723                           criteria.add(ONLINE_SUBS_FID, obj.getOnlineSubsFid());
724                           criteria.add(PRINT_SUBS_FID, obj.getPrintSubsFid());
725                           criteria.add(SERVICE_FID, obj.getServiceFid());
726                           criteria.add(SHIPMENT_FID, obj.getShipmentFid());
727                           criteria.add(PAYMENT_FID, obj.getPaymentFid());
728                           criteria.add(SORDER_FID, obj.getSorderFid());
729                           criteria.add(PROJECT_FID, obj.getProjectFid());
730                           criteria.add(CUSTOMER_FID, obj.getCustomerFid());
731                           criteria.add(PRODUCT_FID, obj.getProductFid());
732               return criteria;
733     }
734  
735     
736         /**
737      * Retrieve a single object by pk
738      *
739      * @param pk the primary key
740      * @throws TorqueException Any exceptions caught during processing will be
741      * rethrown wrapped into a TorqueException.
742      * @throws NoRowsException Primary key was not found in database.
743      * @throws TooManyRowsException Primary key was not found in database.
744      */

745     public static CreamUser retrieveByPK(int pk)
746         throws TorqueException, NoRowsException, TooManyRowsException
747     {
748         return retrieveByPK(SimpleKey.keyFor(pk));
749     }
750
751     /**
752      * Retrieve a single object by pk
753      *
754      * @param pk the primary key
755      * @param con the connection to use
756      * @throws TorqueException Any exceptions caught during processing will be
757      * rethrown wrapped into a TorqueException.
758      * @throws NoRowsException Primary key was not found in database.
759      * @throws TooManyRowsException Primary key was not found in database.
760      */

761     public static CreamUser retrieveByPK(int pk, Connection JavaDoc con)
762         throws TorqueException, NoRowsException, TooManyRowsException
763     {
764         return retrieveByPK(SimpleKey.keyFor(pk), con);
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 CreamUser retrieveByPK(ObjectKey pk)
777         throws TorqueException, NoRowsException, TooManyRowsException
778     {
779         Connection JavaDoc db = null;
780         CreamUser retVal = null;
781         try
782         {
783             db = Torque.getConnection(DATABASE_NAME);
784             retVal = retrieveByPK(pk, db);
785         }
786         finally
787         {
788             Torque.closeConnection(db);
789         }
790         return(retVal);
791     }
792
793     /**
794      * Retrieve a single object by pk
795      *
796      * @param pk the primary key
797      * @param con the connection to use
798      * @throws TorqueException Any exceptions caught during processing will be
799      * rethrown wrapped into a TorqueException.
800      * @throws NoRowsException Primary key was not found in database.
801      * @throws TooManyRowsException Primary key was not found in database.
802      */

803     public static CreamUser retrieveByPK(ObjectKey pk, Connection JavaDoc con)
804         throws TorqueException, NoRowsException, TooManyRowsException
805     {
806         Criteria criteria = buildCriteria(pk);
807         List JavaDoc v = doSelect(criteria, con);
808         if (v.size() == 0)
809         {
810             throw new NoRowsException("Failed to select a row.");
811         }
812         else if (v.size() > 1)
813         {
814             throw new TooManyRowsException("Failed to select only one row.");
815         }
816         else
817         {
818             return (CreamUser)v.get(0);
819         }
820     }
821
822     /**
823      * Retrieve a multiple objects by pk
824      *
825      * @param pks List of primary keys
826      * @throws TorqueException Any exceptions caught during processing will be
827      * rethrown wrapped into a TorqueException.
828      */

829     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
830         throws TorqueException
831     {
832         Connection JavaDoc db = null;
833         List JavaDoc retVal = null;
834         try
835         {
836            db = Torque.getConnection(DATABASE_NAME);
837            retVal = retrieveByPKs(pks, db);
838         }
839         finally
840         {
841             Torque.closeConnection(db);
842         }
843         return(retVal);
844     }
845
846     /**
847      * Retrieve a multiple objects by pk
848      *
849      * @param pks List of primary keys
850      * @param dbcon the connection to use
851      * @throws TorqueException Any exceptions caught during processing will be
852      * rethrown wrapped into a TorqueException.
853      */

854     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
855         throws TorqueException
856     {
857         List JavaDoc objs = null;
858         if (pks == null || pks.size() == 0)
859         {
860             objs = new LinkedList JavaDoc();
861         }
862         else
863         {
864             Criteria criteria = new Criteria();
865               criteria.addIn( USER_ID, pks );
866           objs = doSelect(criteria, dbcon);
867         }
868         return objs;
869     }
870
871  
872
873
874
875         
876   
877   
878     
879   
880       /**
881      * Returns the TableMap related to this peer. This method is not
882      * needed for general use but a specific application could have a need.
883      *
884      * @throws TorqueException Any exceptions caught during processing will be
885      * rethrown wrapped into a TorqueException.
886      */

887     protected static TableMap getTableMap()
888         throws TorqueException
889     {
890         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
891     }
892    
893     private static void setDbName(Criteria crit)
894     {
895         // Set the correct dbName if it has not been overridden
896
// crit.getDbName will return the same object if not set to
897
// another value so == check is okay and faster
898
if (crit.getDbName() == Torque.getDefaultDB())
899         {
900             crit.setDbName(DATABASE_NAME);
901         }
902     }
903 }
904
Popular Tags