KickJava   Java API By Example, From Geeks To Geeks.

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


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 BaseScarabUserImplPeer
37     extends org.apache.fulcrum.security.impl.db.entity.TurbineUserPeer
38 {
39  
40     /** number of columns for this peer */
41     public static final int numColumns = 1;
42
43     /** A class that can be returned by this peer. */
44     protected static final String JavaDoc CLASSNAME_DEFAULT =
45         "org.tigris.scarab.om.ScarabUserImpl";
46
47     /** A class that can be returned by this peer. */
48     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
49
50     /**
51      * Class object initialization method.
52      *
53      * @param className name of the class to initialize
54      * @return the initialized class
55      */

56     private static Class JavaDoc initClass(String JavaDoc className)
57     {
58         Class JavaDoc c = null;
59         try
60         {
61             c = Class.forName(className);
62         }
63         catch (Throwable JavaDoc t)
64         {
65             log.error("A FATAL ERROR has occurred which should not "
66                 + "have happened under any circumstance. Please notify "
67                 + "the Torque developers <torque-dev@db.apache.org> "
68                 + "and give as many details as possible (including the error "
69                 + "stack trace).", t);
70
71             // Error objects should always be propogated.
72
if (t instanceof Error JavaDoc)
73             {
74                 throw (Error JavaDoc) t.fillInStackTrace();
75             }
76         }
77         return c;
78     }
79
80  
81
82     /**
83      * The class that the Peer will make instances of.
84      * If the BO is abstract then you must implement this method
85      * in the BO.
86      *
87      * @throws TorqueException Any exceptions caught during processing will be
88      * rethrown wrapped into a TorqueException.
89      */

90     public static Class JavaDoc getOMClass()
91         throws TorqueException
92     {
93         return CLASS_DEFAULT;
94     }
95
96  
97     
98         /**
99      * Retrieve a single object by pk
100      *
101      * @param pk the primary key
102      * @throws TorqueException Any exceptions caught during processing will be
103      * rethrown wrapped into a TorqueException.
104      * @throws NoRowsException Primary key was not found in database.
105      * @throws TooManyRowsException Primary key was not found in database.
106      */

107     public static ScarabUserImpl retrieveScarabUserImplByPK(Integer JavaDoc pk)
108         throws TorqueException, NoRowsException, TooManyRowsException
109     {
110         return retrieveScarabUserImplByPK(SimpleKey.keyFor(pk));
111     }
112
113     /**
114      * Retrieve a single object by pk
115      *
116      * @param pk the primary key
117      * @param con the connection to use
118      * @throws TorqueException Any exceptions caught during processing will be
119      * rethrown wrapped into a TorqueException.
120      * @throws NoRowsException Primary key was not found in database.
121      * @throws TooManyRowsException Primary key was not found in database.
122      */

123     public static ScarabUserImpl retrieveScarabUserImplByPK(Integer JavaDoc pk, Connection JavaDoc con)
124         throws TorqueException, NoRowsException, TooManyRowsException
125     {
126         return retrieveScarabUserImplByPK(SimpleKey.keyFor(pk), con);
127     }
128   
129     /**
130      * Retrieve a single object by pk
131      *
132      * @param pk the primary key
133      * @throws TorqueException Any exceptions caught during processing will be
134      * rethrown wrapped into a TorqueException.
135      * @throws NoRowsException Primary key was not found in database.
136      * @throws TooManyRowsException Primary key was not found in database.
137      */

138     public static ScarabUserImpl retrieveScarabUserImplByPK(ObjectKey pk)
139         throws TorqueException, NoRowsException, TooManyRowsException
140     {
141         Connection JavaDoc db = null;
142         ScarabUserImpl retVal = null;
143         try
144         {
145             db = Torque.getConnection(DATABASE_NAME);
146             retVal = retrieveScarabUserImplByPK(pk, db);
147         }
148         finally
149         {
150             Torque.closeConnection(db);
151         }
152         return(retVal);
153     }
154
155     /**
156      * Retrieve a single object by pk
157      *
158      * @param pk the primary key
159      * @param con the connection to use
160      * @throws TorqueException Any exceptions caught during processing will be
161      * rethrown wrapped into a TorqueException.
162      * @throws NoRowsException Primary key was not found in database.
163      * @throws TooManyRowsException Primary key was not found in database.
164      */

165     public static ScarabUserImpl retrieveScarabUserImplByPK(ObjectKey pk, Connection JavaDoc con)
166         throws TorqueException, NoRowsException, TooManyRowsException
167     {
168         Criteria criteria = buildCriteria(pk);
169         List JavaDoc v = doSelect(criteria, con);
170         if (v.size() == 0)
171         {
172             throw new NoRowsException("Failed to select a row.");
173         }
174         else if (v.size() > 1)
175         {
176             throw new TooManyRowsException("Failed to select only one row.");
177         }
178         else
179         {
180             return (ScarabUserImpl)v.get(0);
181         }
182     }
183
184     /**
185      * Retrieve a multiple objects by pk
186      *
187      * @param pks List of primary keys
188      * @throws TorqueException Any exceptions caught during processing will be
189      * rethrown wrapped into a TorqueException.
190      */

191     public static List JavaDoc retrieveScarabUserImplByPKs(List JavaDoc pks)
192         throws TorqueException
193     {
194         Connection JavaDoc db = null;
195         List JavaDoc retVal = null;
196         try
197         {
198            db = Torque.getConnection(DATABASE_NAME);
199            retVal = retrieveScarabUserImplByPKs(pks, db);
200         }
201         finally
202         {
203             Torque.closeConnection(db);
204         }
205         return(retVal);
206     }
207
208     /**
209      * Retrieve a multiple objects by pk
210      *
211      * @param pks List of primary keys
212      * @param dbcon the connection to use
213      * @throws TorqueException Any exceptions caught during processing will be
214      * rethrown wrapped into a TorqueException.
215      */

216     public static List JavaDoc retrieveScarabUserImplByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
217         throws TorqueException
218     {
219         List JavaDoc objs = null;
220         if (pks == null || pks.size() == 0)
221         {
222             objs = new LinkedList JavaDoc();
223         }
224         else
225         {
226             Criteria criteria = new Criteria();
227               criteria.addIn( USER_ID, pks );
228           objs = doSelect(criteria, dbcon);
229         }
230         return objs;
231     }
232
233  
234
235
236
237         
238   
239   
240     
241   
242    
243     private static void setDbName(Criteria crit)
244     {
245         // Set the correct dbName if it has not been overridden
246
// crit.getDbName will return the same object if not set to
247
// another value so == check is okay and faster
248
if (crit.getDbName() == Torque.getDefaultDB())
249         {
250             crit.setDbName(DATABASE_NAME);
251         }
252     }
253 }
254
Popular Tags