KickJava   Java API By Example, From Geeks To Geeks.

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


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  * You should not use this class directly. It should not even be
28  * extended all references should be to Modification
29  */

30 public abstract class BaseModification extends BaseObject
31     implements org.apache.fulcrum.intake.Retrievable
32 {
33     /** The Peer class */
34     private static final ModificationPeer peer =
35         new ModificationPeer();
36
37         
38     /** The value for the tableId field */
39     private Integer JavaDoc tableId;
40       
41     /** The value for the columnId field */
42     private Integer JavaDoc columnId;
43       
44     /** The value for the modifiedBy field */
45     private Integer JavaDoc modifiedBy;
46       
47     /** The value for the createdBy field */
48     private Integer JavaDoc createdBy;
49       
50     /** The value for the modifiedDate field */
51     private Date JavaDoc modifiedDate;
52       
53     /** The value for the createdDate field */
54     private Date JavaDoc createdDate;
55   
56     
57     /**
58      * Get the TableId
59      *
60      * @return Integer
61      */

62     public Integer JavaDoc getTableId()
63     {
64         return tableId;
65     }
66
67                         
68     /**
69      * Set the value of TableId
70      *
71      * @param v new value
72      */

73     public void setTableId(Integer JavaDoc v)
74     {
75     
76                   if (!ObjectUtils.equals(this.tableId, v))
77               {
78             this.tableId = v;
79             setModified(true);
80         }
81     
82           
83               }
84   
85     /**
86      * Get the ColumnId
87      *
88      * @return Integer
89      */

90     public Integer JavaDoc getColumnId()
91     {
92         return columnId;
93     }
94
95                         
96     /**
97      * Set the value of ColumnId
98      *
99      * @param v new value
100      */

101     public void setColumnId(Integer JavaDoc v)
102     {
103     
104                   if (!ObjectUtils.equals(this.columnId, v))
105               {
106             this.columnId = v;
107             setModified(true);
108         }
109     
110           
111               }
112   
113     /**
114      * Get the ModifiedBy
115      *
116      * @return Integer
117      */

118     public Integer JavaDoc getModifiedBy()
119     {
120         return modifiedBy;
121     }
122
123                         
124     /**
125      * Set the value of ModifiedBy
126      *
127      * @param v new value
128      */

129     public void setModifiedBy(Integer JavaDoc v)
130     {
131     
132                   if (!ObjectUtils.equals(this.modifiedBy, v))
133               {
134             this.modifiedBy = v;
135             setModified(true);
136         }
137     
138           
139               }
140   
141     /**
142      * Get the CreatedBy
143      *
144      * @return Integer
145      */

146     public Integer JavaDoc getCreatedBy()
147     {
148         return createdBy;
149     }
150
151                         
152     /**
153      * Set the value of CreatedBy
154      *
155      * @param v new value
156      */

157     public void setCreatedBy(Integer JavaDoc v)
158     {
159     
160                   if (!ObjectUtils.equals(this.createdBy, v))
161               {
162             this.createdBy = v;
163             setModified(true);
164         }
165     
166           
167               }
168   
169     /**
170      * Get the ModifiedDate
171      *
172      * @return Date
173      */

174     public Date JavaDoc getModifiedDate()
175     {
176         return modifiedDate;
177     }
178
179                         
180     /**
181      * Set the value of ModifiedDate
182      *
183      * @param v new value
184      */

185     public void setModifiedDate(Date JavaDoc v)
186     {
187     
188                   if (!ObjectUtils.equals(this.modifiedDate, v))
189               {
190             this.modifiedDate = v;
191             setModified(true);
192         }
193     
194           
195               }
196   
197     /**
198      * Get the CreatedDate
199      *
200      * @return Date
201      */

202     public Date JavaDoc getCreatedDate()
203     {
204         return createdDate;
205     }
206
207                         
208     /**
209      * Set the value of CreatedDate
210      *
211      * @param v new value
212      */

213     public void setCreatedDate(Date JavaDoc v)
214     {
215     
216                   if (!ObjectUtils.equals(this.createdDate, v))
217               {
218             this.createdDate = v;
219             setModified(true);
220         }
221     
222           
223               }
224   
225          
226                 
227     private static List JavaDoc fieldNames = null;
228
229     /**
230      * Generate a list of field names.
231      *
232      * @return a list of field names
233      */

234     public static synchronized List JavaDoc getFieldNames()
235     {
236         if (fieldNames == null)
237         {
238             fieldNames = new ArrayList JavaDoc();
239               fieldNames.add("TableId");
240               fieldNames.add("ColumnId");
241               fieldNames.add("ModifiedBy");
242               fieldNames.add("CreatedBy");
243               fieldNames.add("ModifiedDate");
244               fieldNames.add("CreatedDate");
245               fieldNames = Collections.unmodifiableList(fieldNames);
246         }
247         return fieldNames;
248     }
249
250     /**
251      * Retrieves a field from the object by name passed in as a String.
252      *
253      * @param name field name
254      * @return value
255      */

256     public Object JavaDoc getByName(String JavaDoc name)
257     {
258           if (name.equals("TableId"))
259         {
260                 return getTableId();
261             }
262           if (name.equals("ColumnId"))
263         {
264                 return getColumnId();
265             }
266           if (name.equals("ModifiedBy"))
267         {
268                 return getModifiedBy();
269             }
270           if (name.equals("CreatedBy"))
271         {
272                 return getCreatedBy();
273             }
274           if (name.equals("ModifiedDate"))
275         {
276                 return getModifiedDate();
277             }
278           if (name.equals("CreatedDate"))
279         {
280                 return getCreatedDate();
281             }
282           return null;
283     }
284     
285     /**
286      * Retrieves a field from the object by name passed in
287      * as a String. The String must be one of the static
288      * Strings defined in this Class' Peer.
289      *
290      * @param name peer name
291      * @return value
292      */

293     public Object JavaDoc getByPeerName(String JavaDoc name)
294     {
295           if (name.equals(ModificationPeer.TABLE_ID))
296         {
297                 return getTableId();
298             }
299           if (name.equals(ModificationPeer.COLUMN_ID))
300         {
301                 return getColumnId();
302             }
303           if (name.equals(ModificationPeer.MODIFIED_BY))
304         {
305                 return getModifiedBy();
306             }
307           if (name.equals(ModificationPeer.CREATED_BY))
308         {
309                 return getCreatedBy();
310             }
311           if (name.equals(ModificationPeer.MODIFIED_DATE))
312         {
313                 return getModifiedDate();
314             }
315           if (name.equals(ModificationPeer.CREATED_DATE))
316         {
317                 return getCreatedDate();
318             }
319           return null;
320     }
321
322     /**
323      * Retrieves a field from the object by Position as specified
324      * in the xml schema. Zero-based.
325      *
326      * @param pos position in xml schema
327      * @return value
328      */

329     public Object JavaDoc getByPosition(int pos)
330     {
331             if (pos == 0)
332         {
333                 return getTableId();
334             }
335               if (pos == 1)
336         {
337                 return getColumnId();
338             }
339               if (pos == 2)
340         {
341                 return getModifiedBy();
342             }
343               if (pos == 3)
344         {
345                 return getCreatedBy();
346             }
347               if (pos == 4)
348         {
349                 return getModifiedDate();
350             }
351               if (pos == 5)
352         {
353                 return getCreatedDate();
354             }
355               return null;
356     }
357      
358     /**
359      * Stores the object in the database. If the object is new,
360      * it inserts it; otherwise an update is performed.
361      *
362      * @throws Exception
363      */

364     public void save() throws Exception JavaDoc
365     {
366           save(ModificationPeer.getMapBuilder()
367                 .getDatabaseMap().getName());
368       }
369
370     /**
371      * Stores the object in the database. If the object is new,
372      * it inserts it; otherwise an update is performed.
373        * Note: this code is here because the method body is
374      * auto-generated conditionally and therefore needs to be
375      * in this file instead of in the super class, BaseObject.
376        *
377      * @param dbName
378      * @throws TorqueException
379      */

380     public void save(String JavaDoc dbName) throws TorqueException
381     {
382         Connection JavaDoc con = null;
383           try
384         {
385             con = Transaction.begin(dbName);
386             save(con);
387             Transaction.commit(con);
388         }
389         catch(TorqueException e)
390         {
391             Transaction.safeRollback(con);
392             throw e;
393         }
394       }
395
396       /** flag to prevent endless save loop, if this object is referenced
397         by another object which falls in this transaction. */

398     private boolean alreadyInSave = false;
399       /**
400      * Stores the object in the database. If the object is new,
401      * it inserts it; otherwise an update is performed. This method
402      * is meant to be used as part of a transaction, otherwise use
403      * the save() method and the connection details will be handled
404      * internally
405      *
406      * @param con
407      * @throws TorqueException
408      */

409     public void save(Connection JavaDoc con) throws TorqueException
410     {
411           if (!alreadyInSave)
412         {
413             alreadyInSave = true;
414
415
416   
417             // If this object has been modified, then save it to the database.
418
if (isModified())
419             {
420                 if (isNew())
421                 {
422                     ModificationPeer.doInsert((Modification)this, con);
423                     setNew(false);
424                 }
425                 else
426                 {
427                     ModificationPeer.doUpdate((Modification)this, con);
428                 }
429
430                       if (isCacheOnSave())
431                 {
432                     ModificationManager.putInstance(this);
433                 }
434               }
435
436                       alreadyInSave = false;
437         }
438       }
439
440     /**
441      * Specify whether to cache the object after saving to the db.
442      * This method returns false
443      */

444     protected boolean isCacheOnSave()
445     {
446         return true;
447     }
448
449                                   
450   
451     private final SimpleKey[] pks = new SimpleKey[2];
452     private final ComboKey comboPK = new ComboKey(pks);
453
454     /**
455      * Set the PrimaryKey with an ObjectKey
456      *
457      * @param key
458      */

459     public void setPrimaryKey(ObjectKey key) throws TorqueException
460     {
461         SimpleKey[] keys = (SimpleKey[]) key.getValue();
462         SimpleKey tmpKey = null;
463                       setTableId(new Integer JavaDoc(((NumberKey)keys[0]).intValue()));
464                         setColumnId(new Integer JavaDoc(((NumberKey)keys[1]).intValue()));
465               }
466
467     /**
468      * Set the PrimaryKey using SimpleKeys.
469      *
470          * @param tableId Integer
471          * @param columnId Integer
472          */

473     public void setPrimaryKey( Integer JavaDoc tableId, Integer JavaDoc columnId)
474          
475     {
476             setTableId(tableId);
477             setColumnId(columnId);
478         }
479
480     /**
481      * Set the PrimaryKey using a String.
482      */

483     public void setPrimaryKey(String JavaDoc key) throws TorqueException
484     {
485         setPrimaryKey(new ComboKey(key));
486     }
487   
488     /**
489      * returns an id that differentiates this object from others
490      * of its class.
491      */

492     public ObjectKey getPrimaryKey()
493     {
494               pks[0] = SimpleKey.keyFor(getTableId());
495                   pks[1] = SimpleKey.keyFor(getColumnId());
496                   return comboPK;
497       }
498  
499     /**
500      * get an id that differentiates this object from others
501      * of its class.
502      */

503     public String JavaDoc getQueryKey()
504     {
505         if (getPrimaryKey() == null)
506         {
507             return "";
508         }
509         else
510         {
511             return getPrimaryKey().toString();
512         }
513     }
514
515     /**
516      * set an id that differentiates this object from others
517      * of its class.
518      */

519     public void setQueryKey(String JavaDoc key)
520         throws TorqueException
521     {
522         setPrimaryKey(key);
523     }
524
525     /**
526      * Makes a copy of this object.
527      * It creates a new object filling in the simple attributes.
528        * It then fills all the association collections and sets the
529      * related objects to isNew=true.
530        */

531       public Modification copy() throws TorqueException
532     {
533         Modification copyObj = new Modification();
534             copyObj.setTableId(tableId);
535           copyObj.setColumnId(columnId);
536           copyObj.setModifiedBy(modifiedBy);
537           copyObj.setCreatedBy(createdBy);
538           copyObj.setModifiedDate(modifiedDate);
539           copyObj.setCreatedDate(createdDate);
540   
541                       copyObj.setTableId((Integer JavaDoc)null);
542                                 copyObj.setColumnId((Integer JavaDoc)null);
543                                     
544                 return copyObj;
545     }
546
547     /**
548      * returns a peer instance associated with this om. Since Peer classes
549      * are not to have any instance attributes, this method returns the
550      * same instance for all member of this class. The method could therefore
551      * be static, but this would prevent one from overriding the behavior.
552      */

553     public ModificationPeer getPeer()
554     {
555         return peer;
556     }
557
558     public String JavaDoc toString()
559     {
560         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
561         str.append("Modification:\n");
562         str.append("TableId = ")
563                .append(getTableId())
564              .append("\n");
565         str.append("ColumnId = ")
566                .append(getColumnId())
567              .append("\n");
568         str.append("ModifiedBy = ")
569                .append(getModifiedBy())
570              .append("\n");
571         str.append("CreatedBy = ")
572                .append(getCreatedBy())
573              .append("\n");
574         str.append("ModifiedDate = ")
575                .append(getModifiedDate())
576              .append("\n");
577         str.append("CreatedDate = ")
578                .append(getCreatedDate())
579              .append("\n");
580         return(str.toString());
581     }
582 }
583
Popular Tags