1 package org.apache.jetspeed.om.apps.coffees;
2
3
4 import java.math.BigDecimal;
5 import java.sql.Connection;
6 import java.util.ArrayList;
7 import java.util.Collections;
8 import java.util.Date;
9 import java.util.List;
10
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.torque.TorqueException;
13 import org.apache.torque.om.BaseObject;
14 import org.apache.torque.om.ComboKey;
15 import org.apache.torque.om.DateKey;
16 import org.apache.torque.om.NumberKey;
17 import org.apache.torque.om.ObjectKey;
18 import org.apache.torque.om.SimpleKey;
19 import org.apache.torque.om.StringKey;
20 import org.apache.torque.om.Persistent;
21 import org.apache.torque.util.Criteria;
22 import org.apache.torque.util.Transaction;
23
24
25 /***
26 * This class was autogenerated by Torque on:
27 *
28 * [Thu Apr 22 23:12:36 EDT 2004]
29 *
30 * You should not use this class directly. It should not even be
31 * extended all references should be to Coffees
32 */
33 public abstract class BaseCoffees extends BaseObject
34 {
35 /*** The Peer class */
36 private static final CoffeesPeer peer =
37 new CoffeesPeer();
38
39
40 /*** The value for the coffeeId field */
41 private int coffeeId;
42
43 /*** The value for the coffeeName field */
44 private String coffeeName;
45
46 /*** The value for the supplierId field */
47 private int supplierId;
48
49 /*** The value for the price field */
50 private double price;
51
52 /*** The value for the sales field */
53 private int sales;
54
55 /*** The value for the total field */
56 private int total;
57
58
59 /***
60 * Get the CoffeeId
61 * @return int
62 */
63 public int getCoffeeId()
64 {
65 return coffeeId;
66 }
67
68
69 /***
70 * Set the value of CoffeeId
71 */
72 public void setCoffeeId(int v )
73 {
74
75 if (this.coffeeId != v)
76 {
77 this.coffeeId = v;
78 setModified(true);
79 }
80
81
82 }
83
84
85 /***
86 * Get the CoffeeName
87 * @return String
88 */
89 public String getCoffeeName()
90 {
91 return coffeeName;
92 }
93
94
95 /***
96 * Set the value of CoffeeName
97 */
98 public void setCoffeeName(String v )
99 {
100
101 if (!ObjectUtils.equals(this.coffeeName, v))
102 {
103 this.coffeeName = v;
104 setModified(true);
105 }
106
107
108 }
109
110
111 /***
112 * Get the SupplierId
113 * @return int
114 */
115 public int getSupplierId()
116 {
117 return supplierId;
118 }
119
120
121 /***
122 * Set the value of SupplierId
123 */
124 public void setSupplierId(int v )
125 {
126
127 if (this.supplierId != v)
128 {
129 this.supplierId = v;
130 setModified(true);
131 }
132
133
134 }
135
136
137 /***
138 * Get the Price
139 * @return double
140 */
141 public double getPrice()
142 {
143 return price;
144 }
145
146
147 /***
148 * Set the value of Price
149 */
150 public void setPrice(double v )
151 {
152
153 if (this.price != v)
154 {
155 this.price = v;
156 setModified(true);
157 }
158
159
160 }
161
162
163 /***
164 * Get the Sales
165 * @return int
166 */
167 public int getSales()
168 {
169 return sales;
170 }
171
172
173 /***
174 * Set the value of Sales
175 */
176 public void setSales(int v )
177 {
178
179 if (this.sales != v)
180 {
181 this.sales = v;
182 setModified(true);
183 }
184
185
186 }
187
188
189 /***
190 * Get the Total
191 * @return int
192 */
193 public int getTotal()
194 {
195 return total;
196 }
197
198
199 /***
200 * Set the value of Total
201 */
202 public void setTotal(int v )
203 {
204
205 if (this.total != v)
206 {
207 this.total = v;
208 setModified(true);
209 }
210
211
212 }
213
214
215
216
217 private static List fieldNames = null;
218
219 /***
220 * Generate a list of field names.
221 */
222 public static synchronized List getFieldNames()
223 {
224 if (fieldNames == null)
225 {
226 fieldNames = new ArrayList();
227 fieldNames.add("CoffeeId");
228 fieldNames.add("CoffeeName");
229 fieldNames.add("SupplierId");
230 fieldNames.add("Price");
231 fieldNames.add("Sales");
232 fieldNames.add("Total");
233 fieldNames = Collections.unmodifiableList(fieldNames);
234 }
235 return fieldNames;
236 }
237
238 /***
239 * Retrieves a field from the object by name passed in
240 * as a String.
241 */
242 public Object getByName(String name)
243 {
244 if (name.equals("CoffeeId"))
245 {
246 return new Integer(getCoffeeId());
247 }
248 if (name.equals("CoffeeName"))
249 {
250 return getCoffeeName();
251 }
252 if (name.equals("SupplierId"))
253 {
254 return new Integer(getSupplierId());
255 }
256 if (name.equals("Price"))
257 {
258 return new Double(getPrice());
259 }
260 if (name.equals("Sales"))
261 {
262 return new Integer(getSales());
263 }
264 if (name.equals("Total"))
265 {
266 return new Integer(getTotal());
267 }
268 return null;
269 }
270
271 /***
272 * Retrieves a field from the object by name passed in
273 * as a String. The String must be one of the static
274 * Strings defined in this Class' Peer.
275 */
276 public Object getByPeerName(String name)
277 {
278 if (name.equals(CoffeesPeer.COFFEE_ID ))
279 {
280 return new Integer(getCoffeeId());
281 }
282 if (name.equals(CoffeesPeer.COFFEE_NAME ))
283 {
284 return getCoffeeName();
285 }
286 if (name.equals(CoffeesPeer.SUPPLIER_ID ))
287 {
288 return new Integer(getSupplierId());
289 }
290 if (name.equals(CoffeesPeer.PRICE ))
291 {
292 return new Double(getPrice());
293 }
294 if (name.equals(CoffeesPeer.SALES ))
295 {
296 return new Integer(getSales());
297 }
298 if (name.equals(CoffeesPeer.TOTAL ))
299 {
300 return new Integer(getTotal());
301 }
302 return null;
303 }
304
305 /***
306 * Retrieves a field from the object by Position as specified
307 * in the xml schema. Zero-based.
308 */
309 public Object getByPosition(int pos)
310 {
311 if ( pos == 0 )
312 {
313 return new Integer(getCoffeeId());
314 }
315 if ( pos == 1 )
316 {
317 return getCoffeeName();
318 }
319 if ( pos == 2 )
320 {
321 return new Integer(getSupplierId());
322 }
323 if ( pos == 3 )
324 {
325 return new Double(getPrice());
326 }
327 if ( pos == 4 )
328 {
329 return new Integer(getSales());
330 }
331 if ( pos == 5 )
332 {
333 return new Integer(getTotal());
334 }
335 return null;
336 }
337
338 /***
339 * Stores the object in the database. If the object is new,
340 * it inserts it; otherwise an update is performed.
341 */
342 public void save() throws Exception
343 {
344 save(CoffeesPeer.getMapBuilder()
345 .getDatabaseMap().getName());
346 }
347
348 /***
349 * Stores the object in the database. If the object is new,
350 * it inserts it; otherwise an update is performed.
351 * Note: this code is here because the method body is
352 * auto-generated conditionally and therefore needs to be
353 * in this file instead of in the super class, BaseObject.
354 */
355 public void save(String dbName) throws TorqueException
356 {
357 Connection con = null;
358 try
359 {
360 con = Transaction.begin(dbName);
361 save(con);
362 Transaction.commit(con);
363 }
364 catch(TorqueException e)
365 {
366 Transaction.safeRollback(con);
367 throw e;
368 }
369 }
370
371 /*** flag to prevent endless save loop, if this object is referenced
372 by another object which falls in this transaction. */
373 private boolean alreadyInSave = false;
374 /***
375 * Stores the object in the database. If the object is new,
376 * it inserts it; otherwise an update is performed. This method
377 * is meant to be used as part of a transaction, otherwise use
378 * the save() method and the connection details will be handled
379 * internally
380 */
381 public void save(Connection con) throws TorqueException
382 {
383 if (!alreadyInSave)
384 {
385 alreadyInSave = true;
386
387
388
389
390 if (isModified())
391 {
392 if (isNew())
393 {
394 CoffeesPeer.doInsert((Coffees)this, con);
395 setNew(false);
396 }
397 else
398 {
399 CoffeesPeer.doUpdate((Coffees)this, con);
400 }
401
402 if (isCacheOnSave())
403 {
404 CoffeesManager.putInstance(this);
405 }
406 }
407
408 alreadyInSave = false;
409 }
410 }
411
412 /***
413 * Specify whether to cache the object after saving to the db.
414 * This method returns false
415 */
416 protected boolean isCacheOnSave()
417 {
418 return true;
419 }
420
421
422 /***
423 * Set the PrimaryKey using ObjectKey.
424 *
425 * @param ObjectKey coffeeId
426 */
427 public void setPrimaryKey(ObjectKey coffeeId)
428 {
429 setCoffeeId(((NumberKey)coffeeId).intValue());
430 }
431
432 /***
433 * Set the PrimaryKey using a String.
434 */
435 public void setPrimaryKey(String key)
436 {
437 setCoffeeId(Integer.parseInt(key));
438 }
439
440
441 /***
442 * returns an id that differentiates this object from others
443 * of its class.
444 */
445 public ObjectKey getPrimaryKey()
446 {
447 return SimpleKey.keyFor(getCoffeeId());
448 }
449
450
451 /***
452 * Makes a copy of this object.
453 * It creates a new object filling in the simple attributes.
454 * It then fills all the association collections.
455 */
456 public Coffees copy() throws TorqueException
457 {
458 Coffees copyObj = new Coffees();
459 copyObj.setCoffeeId(coffeeId);
460 copyObj.setCoffeeName(coffeeName);
461 copyObj.setSupplierId(supplierId);
462 copyObj.setPrice(price);
463 copyObj.setSales(sales);
464 copyObj.setTotal(total);
465
466 copyObj.setCoffeeId(0);
467
468 return copyObj;
469 }
470
471 /***
472 * returns a peer instance associated with this om. Since Peer classes
473 * are not to have any instance attributes, this method returns the
474 * same instance for all member of this class. The method could therefore
475 * be static, but this would prevent one from overriding the behavior.
476 */
477 public CoffeesPeer getPeer()
478 {
479 return peer;
480 }
481 }