View Javadoc

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