KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.tigris.scarab.om;
2
3
4 import java.math.BigDecimal JavaDoc;
5 import java.sql.Connection JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Collections JavaDoc;
8 import java.util.Date JavaDoc;
9 import java.util.List JavaDoc;
10
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.fulcrum.intake.Retrievable;
13 import org.apache.torque.TorqueException;
14 import org.apache.torque.om.BaseObject;
15 import org.apache.torque.om.ComboKey;
16 import org.apache.torque.om.DateKey;
17 import org.apache.torque.om.NumberKey;
18 import org.apache.torque.om.ObjectKey;
19 import org.apache.torque.om.SimpleKey;
20 import org.apache.torque.om.StringKey;
21 import org.apache.torque.om.Persistent;
22 import org.apache.torque.util.Criteria;
23 import org.apache.torque.util.Transaction;
24
25     
26   
27 /**
28  * You should not use this class directly. It should not even be
29  * extended all references should be to GlobalParameter
30  */

31 public abstract class BaseGlobalParameter extends BaseObject
32     implements org.apache.fulcrum.intake.Retrievable
33 {
34     /** The Peer class */
35     private static final GlobalParameterPeer peer =
36         new GlobalParameterPeer();
37
38         
39     /** The value for the parameterId field */
40     private Integer JavaDoc parameterId;
41       
42     /** The value for the name field */
43     private String JavaDoc name;
44       
45     /** The value for the value field */
46     private String JavaDoc value;
47       
48     /** The value for the moduleId field */
49     private Integer JavaDoc moduleId;
50   
51     
52     /**
53      * Get the ParameterId
54      *
55      * @return Integer
56      */

57     public Integer JavaDoc getParameterId()
58     {
59         return parameterId;
60     }
61
62                         
63     /**
64      * Set the value of ParameterId
65      *
66      * @param v new value
67      */

68     public void setParameterId(Integer JavaDoc v)
69     {
70     
71                   if (!ObjectUtils.equals(this.parameterId, v))
72               {
73             this.parameterId = v;
74             setModified(true);
75         }
76     
77           
78               }
79   
80     /**
81      * Get the Name
82      *
83      * @return String
84      */

85     public String JavaDoc getName()
86     {
87         return name;
88     }
89
90                         
91     /**
92      * Set the value of Name
93      *
94      * @param v new value
95      */

96     public void setName(String JavaDoc v)
97     {
98     
99                   if (!ObjectUtils.equals(this.name, v))
100               {
101             this.name = v;
102             setModified(true);
103         }
104     
105           
106               }
107   
108     /**
109      * Get the Value
110      *
111      * @return String
112      */

113     public String JavaDoc getValue()
114     {
115         return value;
116     }
117
118                         
119     /**
120      * Set the value of Value
121      *
122      * @param v new value
123      */

124     public void setValue(String JavaDoc v)
125     {
126     
127                   if (!ObjectUtils.equals(this.value, v))
128               {
129             this.value = v;
130             setModified(true);
131         }
132     
133           
134               }
135   
136     /**
137      * Get the ModuleId
138      *
139      * @return Integer
140      */

141     public Integer JavaDoc getModuleId()
142     {
143         return moduleId;
144     }
145
146                               
147     /**
148      * Set the value of ModuleId
149      *
150      * @param v new value
151      */

152     public void setModuleId(Integer JavaDoc v) throws TorqueException
153     {
154     
155                   if (!ObjectUtils.equals(this.moduleId, v))
156               {
157             this.moduleId = v;
158             setModified(true);
159         }
160     
161                                           
162                 if (aModule != null && !ObjectUtils.equals(aModule.getModuleId(), v))
163                 {
164             aModule = null;
165         }
166       
167               }
168   
169       
170             
171                   
172         private Module aModule;
173
174     /**
175      * Declares an association between this object and a Module object
176      *
177      * @param v Module
178      * @throws TorqueException
179      */

180     public void setModule(Module v) throws TorqueException
181     {
182             if (v == null)
183         {
184                   setModuleId((Integer JavaDoc) null);
185               }
186         else
187         {
188             setModuleId(v.getModuleId());
189         }
190             aModule = v;
191     }
192
193                         
194     /**
195      * Get the associated Module object
196      *
197      * @return the associated Module object
198      * @throws TorqueException
199      */

200     public Module getModule() throws TorqueException
201     {
202         if ( !ObjectUtils.equals(getModuleId(), null) )
203         {
204                 return ModuleManager.getInstance(SimpleKey.keyFor(getModuleId()));
205             }
206         return aModule;
207     }
208
209     /**
210      * Provides convenient way to set a relationship based on a
211      * ObjectKey, for example
212      * <code>bar.setFooKey(foo.getPrimaryKey())</code>
213      *
214          */

215     public void setModuleKey(ObjectKey key) throws TorqueException
216     {
217     
218                     setModuleId(new Integer JavaDoc(((NumberKey) key).intValue()));
219               }
220      
221                 
222     private static List JavaDoc fieldNames = null;
223
224     /**
225      * Generate a list of field names.
226      *
227      * @return a list of field names
228      */

229     public static synchronized List JavaDoc getFieldNames()
230     {
231         if (fieldNames == null)
232         {
233             fieldNames = new ArrayList JavaDoc();
234               fieldNames.add("ParameterId");
235               fieldNames.add("Name");
236               fieldNames.add("Value");
237               fieldNames.add("ModuleId");
238               fieldNames = Collections.unmodifiableList(fieldNames);
239         }
240         return fieldNames;
241     }
242
243     /**
244      * Retrieves a field from the object by name passed in as a String.
245      *
246      * @param name field name
247      * @return value
248      */

249     public Object JavaDoc getByName(String JavaDoc name)
250     {
251           if (name.equals("ParameterId"))
252         {
253                 return getParameterId();
254             }
255           if (name.equals("Name"))
256         {
257                 return getName();
258             }
259           if (name.equals("Value"))
260         {
261                 return getValue();
262             }
263           if (name.equals("ModuleId"))
264         {
265                 return getModuleId();
266             }
267           return null;
268     }
269     
270     /**
271      * Retrieves a field from the object by name passed in
272      * as a String. The String must be one of the static
273      * Strings defined in this Class' Peer.
274      *
275      * @param name peer name
276      * @return value
277      */

278     public Object JavaDoc getByPeerName(String JavaDoc name)
279     {
280           if (name.equals(GlobalParameterPeer.PARAMETER_ID))
281         {
282                 return getParameterId();
283             }
284           if (name.equals(GlobalParameterPeer.NAME))
285         {
286                 return getName();
287             }
288           if (name.equals(GlobalParameterPeer.VALUE))
289         {
290                 return getValue();
291             }
292           if (name.equals(GlobalParameterPeer.MODULE_ID))
293         {
294                 return getModuleId();
295             }
296           return null;
297     }
298
299     /**
300      * Retrieves a field from the object by Position as specified
301      * in the xml schema. Zero-based.
302      *
303      * @param pos position in xml schema
304      * @return value
305      */

306     public Object JavaDoc getByPosition(int pos)
307     {
308             if (pos == 0)
309         {
310                 return getParameterId();
311             }
312               if (pos == 1)
313         {
314                 return getName();
315             }
316               if (pos == 2)
317         {
318                 return getValue();
319             }
320               if (pos == 3)
321         {
322                 return getModuleId();
323             }
324               return null;
325     }
326      
327     /**
328      * Stores the object in the database. If the object is new,
329      * it inserts it; otherwise an update is performed.
330      *
331      * @throws Exception
332      */

333     public void save() throws Exception JavaDoc
334     {
335           save(GlobalParameterPeer.getMapBuilder()
336                 .getDatabaseMap().getName());
337       }
338
339     /**
340      * Stores the object in the database. If the object is new,
341      * it inserts it; otherwise an update is performed.
342        * Note: this code is here because the method body is
343      * auto-generated conditionally and therefore needs to be
344      * in this file instead of in the super class, BaseObject.
345        *
346      * @param dbName
347      * @throws TorqueException
348      */

349     public void save(String JavaDoc dbName) throws TorqueException
350     {
351         Connection JavaDoc con = null;
352           try
353         {
354             con = Transaction.begin(dbName);
355             save(con);
356             Transaction.commit(con);
357         }
358         catch(TorqueException e)
359         {
360             Transaction.safeRollback(con);
361             throw e;
362         }
363       }
364
365       /** flag to prevent endless save loop, if this object is referenced
366         by another object which falls in this transaction. */

367     private boolean alreadyInSave = false;
368       /**
369      * Stores the object in the database. If the object is new,
370      * it inserts it; otherwise an update is performed. This method
371      * is meant to be used as part of a transaction, otherwise use
372      * the save() method and the connection details will be handled
373      * internally
374      *
375      * @param con
376      * @throws TorqueException
377      */

378     public void save(Connection JavaDoc con) throws TorqueException
379     {
380           if (!alreadyInSave)
381         {
382             alreadyInSave = true;
383
384
385   
386             // If this object has been modified, then save it to the database.
387
if (isModified())
388             {
389                 if (isNew())
390                 {
391                     GlobalParameterPeer.doInsert((GlobalParameter)this, con);
392                     setNew(false);
393                 }
394                 else
395                 {
396                     GlobalParameterPeer.doUpdate((GlobalParameter)this, con);
397                 }
398
399                       if (isCacheOnSave())
400                 {
401                     GlobalParameterManager.putInstance(this);
402                 }
403               }
404
405                       alreadyInSave = false;
406         }
407       }
408
409     /**
410      * Specify whether to cache the object after saving to the db.
411      * This method returns false
412      */

413     protected boolean isCacheOnSave()
414     {
415         return true;
416     }
417
418                   
419       /**
420      * Set the PrimaryKey using ObjectKey.
421      *
422      * @param parameterId ObjectKey
423      */

424     public void setPrimaryKey(ObjectKey parameterId)
425          {
426             setParameterId(new Integer JavaDoc(((NumberKey)parameterId).intValue()));
427         }
428
429     /**
430      * Set the PrimaryKey using a String.
431      *
432      * @param key
433      */

434     public void setPrimaryKey(String JavaDoc key)
435     {
436             setParameterId(new Integer JavaDoc(key));
437         }
438
439   
440     /**
441      * returns an id that differentiates this object from others
442      * of its class.
443      */

444     public ObjectKey getPrimaryKey()
445     {
446           return SimpleKey.keyFor(getParameterId());
447       }
448  
449     /**
450      * get an id that differentiates this object from others
451      * of its class.
452      */

453     public String JavaDoc getQueryKey()
454     {
455         if (getPrimaryKey() == null)
456         {
457             return "";
458         }
459         else
460         {
461             return getPrimaryKey().toString();
462         }
463     }
464
465     /**
466      * set an id that differentiates this object from others
467      * of its class.
468      */

469     public void setQueryKey(String JavaDoc key)
470         throws TorqueException
471     {
472         setPrimaryKey(key);
473     }
474
475     /**
476      * Makes a copy of this object.
477      * It creates a new object filling in the simple attributes.
478        * It then fills all the association collections and sets the
479      * related objects to isNew=true.
480        */

481       public GlobalParameter copy() throws TorqueException
482     {
483         GlobalParameter copyObj = new GlobalParameter();
484             copyObj.setParameterId(parameterId);
485           copyObj.setName(name);
486           copyObj.setValue(value);
487           copyObj.setModuleId(moduleId);
488   
489                       copyObj.setParameterId((Integer JavaDoc)null);
490                               
491                 return copyObj;
492     }
493
494     /**
495      * returns a peer instance associated with this om. Since Peer classes
496      * are not to have any instance attributes, this method returns the
497      * same instance for all member of this class. The method could therefore
498      * be static, but this would prevent one from overriding the behavior.
499      */

500     public GlobalParameterPeer getPeer()
501     {
502         return peer;
503     }
504
505     public String JavaDoc toString()
506     {
507         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
508         str.append("GlobalParameter:\n");
509         str.append("ParameterId = ")
510                .append(getParameterId())
511              .append("\n");
512         str.append("Name = ")
513                .append(getName())
514              .append("\n");
515         str.append("Value = ")
516                .append(getValue())
517              .append("\n");
518         str.append("ModuleId = ")
519                .append(getModuleId())
520              .append("\n");
521         return(str.toString());
522     }
523 }
524
Popular Tags