KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > dbregistry > BaseMediatype


1 package org.apache.jetspeed.om.dbregistry;
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.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 15:30:48 PDT 2004]
29  *
30  * You should not use this class directly. It should not even be
31  * extended all references should be to Mediatype
32  */

33 public abstract class BaseMediatype extends BaseObject
34 {
35     /** The Peer class */
36     private static final MediatypePeer peer =
37         new MediatypePeer();
38
39       
40     /** The value for the id field */
41     private long id;
42       
43     /** The value for the name field */
44     private String JavaDoc name;
45                                                                 
46     /** The value for the hidden field */
47     private boolean hidden=false;
48       
49     /** The value for the mimetype field */
50     private String JavaDoc mimetype;
51       
52     /** The value for the role field */
53     private String JavaDoc role;
54       
55     /** The value for the title field */
56     private String JavaDoc title;
57       
58     /** The value for the description field */
59     private String JavaDoc description;
60       
61     /** The value for the image field */
62     private String JavaDoc image;
63   
64   
65     /**
66      * Get the Id
67      * @return long
68      */

69     public long getId()
70     {
71         return id;
72     }
73
74                                               
75     /**
76      * Set the value of Id
77      */

78     public void setId(long v ) throws TorqueException
79     {
80     
81                   if (this.id != v)
82               {
83             this.id = v;
84             setModified(true);
85         }
86     
87           
88                                   
89         // update associated PortletMediatype
90
if (collPortletMediatypes != null )
91         {
92             for (int i = 0; i < collPortletMediatypes.size(); i++)
93             {
94                 ((PortletMediatype)collPortletMediatypes.get(i))
95                         .setMediaId(v);
96             }
97         }
98                       }
99
100   
101     /**
102      * Get the Name
103      * @return String
104      */

105     public String JavaDoc getName()
106     {
107         return name;
108     }
109
110                         
111     /**
112      * Set the value of Name
113      */

114     public void setName(String JavaDoc v )
115     {
116     
117                   if (!ObjectUtils.equals(this.name, v))
118               {
119             this.name = v;
120             setModified(true);
121         }
122     
123           
124               }
125
126   
127     /**
128      * Get the Hidden
129      * @return boolean
130      */

131     public boolean getHidden()
132     {
133         return hidden;
134     }
135
136                         
137     /**
138      * Set the value of Hidden
139      */

140     public void setHidden(boolean v )
141     {
142     
143                   if (this.hidden != v)
144               {
145             this.hidden = v;
146             setModified(true);
147         }
148     
149           
150               }
151
152   
153     /**
154      * Get the Mimetype
155      * @return String
156      */

157     public String JavaDoc getMimetype()
158     {
159         return mimetype;
160     }
161
162                         
163     /**
164      * Set the value of Mimetype
165      */

166     public void setMimetype(String JavaDoc v )
167     {
168     
169                   if (!ObjectUtils.equals(this.mimetype, v))
170               {
171             this.mimetype = v;
172             setModified(true);
173         }
174     
175           
176               }
177
178   
179     /**
180      * Get the Role
181      * @return String
182      */

183     public String JavaDoc getRole()
184     {
185         return role;
186     }
187
188                         
189     /**
190      * Set the value of Role
191      */

192     public void setRole(String JavaDoc v )
193     {
194     
195                   if (!ObjectUtils.equals(this.role, v))
196               {
197             this.role = v;
198             setModified(true);
199         }
200     
201           
202               }
203
204   
205     /**
206      * Get the Title
207      * @return String
208      */

209     public String JavaDoc getTitle()
210     {
211         return title;
212     }
213
214                         
215     /**
216      * Set the value of Title
217      */

218     public void setTitle(String JavaDoc v )
219     {
220     
221                   if (!ObjectUtils.equals(this.title, v))
222               {
223             this.title = v;
224             setModified(true);
225         }
226     
227           
228               }
229
230   
231     /**
232      * Get the Description
233      * @return String
234      */

235     public String JavaDoc getDescription()
236     {
237         return description;
238     }
239
240                         
241     /**
242      * Set the value of Description
243      */

244     public void setDescription(String JavaDoc v )
245     {
246     
247                   if (!ObjectUtils.equals(this.description, v))
248               {
249             this.description = v;
250             setModified(true);
251         }
252     
253           
254               }
255
256   
257     /**
258      * Get the Image
259      * @return String
260      */

261     public String JavaDoc getImage()
262     {
263         return image;
264     }
265
266                         
267     /**
268      * Set the value of Image
269      */

270     public void setImage(String JavaDoc v )
271     {
272     
273                   if (!ObjectUtils.equals(this.image, v))
274               {
275             this.image = v;
276             setModified(true);
277         }
278     
279           
280               }
281
282   
283          
284                                 
285             
286     /**
287      * Collection to store aggregation of collPortletMediatypes
288      */

289     protected List JavaDoc collPortletMediatypes;
290
291     /**
292      * Temporary storage of collPortletMediatypes to save a possible db hit in
293      * the event objects are add to the collection, but the
294      * complete collection is never requested.
295      */

296     protected void initPortletMediatypes()
297     {
298         if (collPortletMediatypes == null)
299         {
300             collPortletMediatypes = new ArrayList JavaDoc();
301         }
302     }
303
304             
305     /**
306      * Method called to associate a PortletMediatype object to this object
307      * through the PortletMediatype foreign key attribute
308      *
309      * @param PortletMediatype l
310      */

311     public void addPortletMediatype(PortletMediatype l) throws TorqueException
312     {
313         getPortletMediatypes().add(l);
314         l.setMediatype((Mediatype)this);
315     }
316
317     /**
318      * The criteria used to select the current contents of collPortletMediatypes
319      */

320     private Criteria lastPortletMediatypesCriteria = null;
321
322     /**
323      * If this collection has already been initialized, returns
324      * the collection. Otherwise returns the results of
325      * getPortletMediatypes(new Criteria())
326      */

327     public List JavaDoc getPortletMediatypes() throws TorqueException
328     {
329         if (collPortletMediatypes == null)
330         {
331             collPortletMediatypes = getPortletMediatypes(new Criteria(10));
332         }
333         return collPortletMediatypes;
334     }
335
336     /**
337      * If this collection has already been initialized with
338      * an identical criteria, it returns the collection.
339      * Otherwise if this Mediatype has previously
340      * been saved, it will retrieve related PortletMediatypes from storage.
341      * If this Mediatype is new, it will return
342      * an empty collection or the current collection, the criteria
343      * is ignored on a new object.
344      */

345     public List JavaDoc getPortletMediatypes(Criteria criteria) throws TorqueException
346     {
347         if (collPortletMediatypes == null)
348         {
349             if (isNew())
350             {
351                collPortletMediatypes = new ArrayList JavaDoc();
352             }
353             else
354             {
355                       criteria.add(PortletMediatypePeer.MEDIA_ID, getId() );
356                       collPortletMediatypes = PortletMediatypePeer.doSelect(criteria);
357             }
358         }
359         else
360         {
361             // criteria has no effect for a new object
362
if (!isNew())
363             {
364                 // the following code is to determine if a new query is
365
// called for. If the criteria is the same as the last
366
// one, just return the collection.
367
criteria.add(PortletMediatypePeer.MEDIA_ID, getId() );
368                       if (!lastPortletMediatypesCriteria.equals(criteria))
369                 {
370                     collPortletMediatypes = PortletMediatypePeer.doSelect(criteria);
371                 }
372             }
373         }
374         lastPortletMediatypesCriteria = criteria;
375
376         return collPortletMediatypes;
377     }
378
379     /**
380      * If this collection has already been initialized, returns
381      * the collection. Otherwise returns the results of
382      * getPortletMediatypes(new Criteria(),Connection)
383      * This method takes in the Connection also as input so that
384      * referenced objects can also be obtained using a Connection
385      * that is taken as input
386      */

387     public List JavaDoc getPortletMediatypes(Connection JavaDoc con) throws TorqueException
388     {
389         if (collPortletMediatypes == null)
390         {
391             collPortletMediatypes = getPortletMediatypes(new Criteria(10),con);
392         }
393         return collPortletMediatypes;
394     }
395
396     /**
397      * If this collection has already been initialized with
398      * an identical criteria, it returns the collection.
399      * Otherwise if this Mediatype has previously
400      * been saved, it will retrieve related PortletMediatypes from storage.
401      * If this Mediatype is new, it will return
402      * an empty collection or the current collection, the criteria
403      * is ignored on a new object.
404      * This method takes in the Connection also as input so that
405      * referenced objects can also be obtained using a Connection
406      * that is taken as input
407      */

408     public List JavaDoc getPortletMediatypes(Criteria criteria,Connection JavaDoc con) throws TorqueException
409     {
410         if (collPortletMediatypes == null)
411         {
412             if (isNew())
413             {
414                collPortletMediatypes = new ArrayList JavaDoc();
415             }
416             else
417             {
418                        criteria.add(PortletMediatypePeer.MEDIA_ID, getId() );
419                        collPortletMediatypes = PortletMediatypePeer.doSelect(criteria,con);
420              }
421          }
422          else
423          {
424              // criteria has no effect for a new object
425
if (!isNew())
426              {
427                  // the following code is to determine if a new query is
428
// called for. If the criteria is the same as the last
429
// one, just return the collection.
430
criteria.add(PortletMediatypePeer.MEDIA_ID, getId() );
431                      if (!lastPortletMediatypesCriteria.equals(criteria))
432                  {
433                      collPortletMediatypes = PortletMediatypePeer.doSelect(criteria,con);
434                  }
435              }
436          }
437          lastPortletMediatypesCriteria = criteria;
438
439          return collPortletMediatypes;
440      }
441
442                         
443
444               
445                     
446                     
447                                 
448                                                               
449                                         
450                     
451                     
452           
453     /**
454      * If this collection has already been initialized with
455      * an identical criteria, it returns the collection.
456      * Otherwise if this Mediatype is new, it will return
457      * an empty collection; or if this Mediatype has previously
458      * been saved, it will retrieve related PortletMediatypes from storage.
459      *
460      * This method is protected by default in order to keep the public
461      * api reasonable. You can provide public methods for those you
462      * actually need in Mediatype.
463      */

464     protected List JavaDoc getPortletMediatypesJoinPortletDbEntry(Criteria criteria)
465         throws TorqueException
466     {
467         if (collPortletMediatypes == null)
468         {
469             if (isNew())
470             {
471                collPortletMediatypes = new ArrayList JavaDoc();
472             }
473             else
474             {
475                             criteria.add(PortletMediatypePeer.MEDIA_ID, getId() );
476                             collPortletMediatypes = PortletMediatypePeer.doSelectJoinPortletDbEntry(criteria);
477             }
478         }
479         else
480         {
481             // the following code is to determine if a new query is
482
// called for. If the criteria is the same as the last
483
// one, just return the collection.
484
boolean newCriteria = true;
485                             criteria.add(PortletMediatypePeer.MEDIA_ID, getId() );
486                         if (!lastPortletMediatypesCriteria.equals(criteria))
487             {
488                 collPortletMediatypes = PortletMediatypePeer.doSelectJoinPortletDbEntry(criteria);
489             }
490         }
491         lastPortletMediatypesCriteria = criteria;
492
493         return collPortletMediatypes;
494     }
495                   
496                     
497                               
498                                 
499                                                               
500                                         
501                     
502                     
503           
504     /**
505      * If this collection has already been initialized with
506      * an identical criteria, it returns the collection.
507      * Otherwise if this Mediatype is new, it will return
508      * an empty collection; or if this Mediatype has previously
509      * been saved, it will retrieve related PortletMediatypes from storage.
510      *
511      * This method is protected by default in order to keep the public
512      * api reasonable. You can provide public methods for those you
513      * actually need in Mediatype.
514      */

515     protected List JavaDoc getPortletMediatypesJoinMediatype(Criteria criteria)
516         throws TorqueException
517     {
518         if (collPortletMediatypes == null)
519         {
520             if (isNew())
521             {
522                collPortletMediatypes = new ArrayList JavaDoc();
523             }
524             else
525             {
526                             criteria.add(PortletMediatypePeer.MEDIA_ID, getId() );
527                             collPortletMediatypes = PortletMediatypePeer.doSelectJoinMediatype(criteria);
528             }
529         }
530         else
531         {
532             // the following code is to determine if a new query is
533
// called for. If the criteria is the same as the last
534
// one, just return the collection.
535
boolean newCriteria = true;
536                             criteria.add(PortletMediatypePeer.MEDIA_ID, getId() );
537                         if (!lastPortletMediatypesCriteria.equals(criteria))
538             {
539                 collPortletMediatypes = PortletMediatypePeer.doSelectJoinMediatype(criteria);
540             }
541         }
542         lastPortletMediatypesCriteria = criteria;
543
544         return collPortletMediatypes;
545     }
546                             
547
548
549           
550     private static List JavaDoc fieldNames = null;
551
552     /**
553      * Generate a list of field names.
554      */

555     public static synchronized List JavaDoc getFieldNames()
556     {
557         if (fieldNames == null)
558         {
559             fieldNames = new ArrayList JavaDoc();
560               fieldNames.add("Id");
561               fieldNames.add("Name");
562               fieldNames.add("Hidden");
563               fieldNames.add("Mimetype");
564               fieldNames.add("Role");
565               fieldNames.add("Title");
566               fieldNames.add("Description");
567               fieldNames.add("Image");
568               fieldNames = Collections.unmodifiableList(fieldNames);
569         }
570         return fieldNames;
571     }
572
573     /**
574      * Retrieves a field from the object by name passed in
575      * as a String.
576      */

577     public Object JavaDoc getByName(String JavaDoc name)
578     {
579           if (name.equals("Id"))
580         {
581                 return new Long JavaDoc(getId());
582             }
583           if (name.equals("Name"))
584         {
585                 return getName();
586             }
587           if (name.equals("Hidden"))
588         {
589                 return new Boolean JavaDoc(getHidden());
590             }
591           if (name.equals("Mimetype"))
592         {
593                 return getMimetype();
594             }
595           if (name.equals("Role"))
596         {
597                 return getRole();
598             }
599           if (name.equals("Title"))
600         {
601                 return getTitle();
602             }
603           if (name.equals("Description"))
604         {
605                 return getDescription();
606             }
607           if (name.equals("Image"))
608         {
609                 return getImage();
610             }
611           return null;
612     }
613     
614     /**
615      * Retrieves a field from the object by name passed in
616      * as a String. The String must be one of the static
617      * Strings defined in this Class' Peer.
618      */

619     public Object JavaDoc getByPeerName(String JavaDoc name)
620     {
621           if (name.equals(MediatypePeer.ID ))
622         {
623                 return new Long JavaDoc(getId());
624             }
625           if (name.equals(MediatypePeer.NAME ))
626         {
627                 return getName();
628             }
629           if (name.equals(MediatypePeer.HIDDEN ))
630         {
631                 return new Boolean JavaDoc(getHidden());
632             }
633           if (name.equals(MediatypePeer.MIMETYPE ))
634         {
635                 return getMimetype();
636             }
637           if (name.equals(MediatypePeer.ROLE ))
638         {
639                 return getRole();
640             }
641           if (name.equals(MediatypePeer.TITLE ))
642         {
643                 return getTitle();
644             }
645           if (name.equals(MediatypePeer.DESCRIPTION ))
646         {
647                 return getDescription();
648             }
649           if (name.equals(MediatypePeer.IMAGE ))
650         {
651                 return getImage();
652             }
653           return null;
654     }
655
656     /**
657      * Retrieves a field from the object by Position as specified
658      * in the xml schema. Zero-based.
659      */

660     public Object JavaDoc getByPosition(int pos)
661     {
662             if ( pos == 0 )
663         {
664                 return new Long JavaDoc(getId());
665             }
666               if ( pos == 1 )
667         {
668                 return getName();
669             }
670               if ( pos == 2 )
671         {
672                 return new Boolean JavaDoc(getHidden());
673             }
674               if ( pos == 3 )
675         {
676                 return getMimetype();
677             }
678               if ( pos == 4 )
679         {
680                 return getRole();
681             }
682               if ( pos == 5 )
683         {
684                 return getTitle();
685             }
686               if ( pos == 6 )
687         {
688                 return getDescription();
689             }
690               if ( pos == 7 )
691         {
692                 return getImage();
693             }
694               return null;
695     }
696      
697     /**
698      * Stores the object in the database. If the object is new,
699      * it inserts it; otherwise an update is performed.
700      */

701     public void save() throws Exception JavaDoc
702     {
703           save(MediatypePeer.getMapBuilder()
704                 .getDatabaseMap().getName());
705       }
706
707     /**
708      * Stores the object in the database. If the object is new,
709      * it inserts it; otherwise an update is performed.
710        * Note: this code is here because the method body is
711      * auto-generated conditionally and therefore needs to be
712      * in this file instead of in the super class, BaseObject.
713        */

714     public void save(String JavaDoc dbName) throws TorqueException
715     {
716         Connection JavaDoc con = null;
717           try
718         {
719             con = Transaction.begin(dbName);
720             save(con);
721             Transaction.commit(con);
722         }
723         catch(TorqueException e)
724         {
725             Transaction.safeRollback(con);
726             throw e;
727         }
728       }
729
730       /** flag to prevent endless save loop, if this object is referenced
731         by another object which falls in this transaction. */

732     private boolean alreadyInSave = false;
733       /**
734      * Stores the object in the database. If the object is new,
735      * it inserts it; otherwise an update is performed. This method
736      * is meant to be used as part of a transaction, otherwise use
737      * the save() method and the connection details will be handled
738      * internally
739      */

740     public void save(Connection JavaDoc con) throws TorqueException
741     {
742           if (!alreadyInSave)
743         {
744             alreadyInSave = true;
745
746
747   
748             // If this object has been modified, then save it to the database.
749
if (isModified())
750             {
751                 if (isNew())
752                 {
753                     MediatypePeer.doInsert((Mediatype)this, con);
754                     setNew(false);
755                 }
756                 else
757                 {
758                     MediatypePeer.doUpdate((Mediatype)this, con);
759                 }
760
761                       if (isCacheOnSave())
762                 {
763                     MediatypeManager.putInstance(this);
764                 }
765               }
766
767                                       
768                             if (collPortletMediatypes != null )
769             {
770                 for (int i = 0; i < collPortletMediatypes.size(); i++)
771                 {
772                     ((PortletMediatype)collPortletMediatypes.get(i)).save(con);
773                 }
774             }
775                           alreadyInSave = false;
776         }
777       }
778
779     /**
780      * Specify whether to cache the object after saving to the db.
781      * This method returns false
782      */

783     protected boolean isCacheOnSave()
784     {
785         return true;
786     }
787
788                         
789       /**
790      * Set the PrimaryKey using ObjectKey.
791      *
792      * @param ObjectKey id
793      */

794     public void setPrimaryKey(ObjectKey id)
795         throws TorqueException {
796             setId(((NumberKey)id).longValue());
797         }
798
799     /**
800      * Set the PrimaryKey using a String.
801      */

802     public void setPrimaryKey(String JavaDoc key) throws TorqueException
803     {
804             setId(Long.parseLong(key));
805         }
806
807   
808     /**
809      * returns an id that differentiates this object from others
810      * of its class.
811      */

812     public ObjectKey getPrimaryKey()
813     {
814           return SimpleKey.keyFor(getId());
815       }
816  
817
818     /**
819      * Makes a copy of this object.
820      * It creates a new object filling in the simple attributes.
821        * It then fills all the association collections.
822        */

823       public Mediatype copy() throws TorqueException
824     {
825         Mediatype copyObj = new Mediatype();
826             copyObj.setId(id);
827           copyObj.setName(name);
828           copyObj.setHidden(hidden);
829           copyObj.setMimetype(mimetype);
830           copyObj.setRole(role);
831           copyObj.setTitle(title);
832           copyObj.setDescription(description);
833           copyObj.setImage(image);
834   
835                       copyObj.setId(0);
836                                                       
837                                       
838                 
839         List JavaDoc v = getPortletMediatypes();
840         for (int i = 0; i < v.size(); i++)
841         {
842             PortletMediatype obj = (PortletMediatype) v.get(i);
843             copyObj.addPortletMediatype(obj.copy());
844         }
845                             return copyObj;
846     }
847
848     /**
849      * returns a peer instance associated with this om. Since Peer classes
850      * are not to have any instance attributes, this method returns the
851      * same instance for all member of this class. The method could therefore
852      * be static, but this would prevent one from overriding the behavior.
853      */

854     public MediatypePeer getPeer()
855     {
856         return peer;
857     }
858 }
859
Popular Tags