View Javadoc

1   package olr.om;
2   
3   
4   import java.sql.Connection;
5   import java.util.ArrayList;
6   import java.util.Collections;
7   import java.util.List;
8   
9   import org.apache.commons.lang.ObjectUtils;
10  import org.apache.torque.TorqueException;
11  import org.apache.torque.om.BaseObject;
12  import org.apache.torque.om.NumberKey;
13  import org.apache.torque.om.ObjectKey;
14  import org.apache.torque.om.SimpleKey;
15  import org.apache.torque.util.Criteria;
16  import org.apache.torque.util.Transaction;
17  
18  
19  /***
20   * This class was autogenerated by Torque on:
21   *
22   * [Tue Jul 13 14:47:47 CEST 2004]
23   *
24   * You should not use this class directly.  It should not even be
25   * extended all references should be to RdfGroup
26   */
27  public abstract class BaseRdfGroup extends BaseObject
28  {
29      /*** The Peer class */
30      private static final RdfGroupPeer peer =
31          new RdfGroupPeer();
32  
33          
34      /*** The value for the id field */
35      private int id;
36        
37      /*** The value for the name field */
38      private String name;
39        
40      /*** The value for the description field */
41      private String description;
42        
43      /*** The value for the roleAdmin field */
44      private int roleAdmin;
45        
46      /*** The value for the roleContributor field */
47      private int roleContributor;
48        
49      /*** The value for the roleUser field */
50      private int roleUser;
51        
52      /*** The value for the template field */
53      private String template;
54    
55      
56      /***
57       * Get the Id
58       *
59       * @return int
60       */
61      public int getId()
62      {
63          return id;
64      }
65  
66                                                
67      /***
68       * Set the value of Id
69       *
70       * @param v new value
71       */
72      public void setId(int v) throws TorqueException
73      {
74      
75                    if (this.id != v)
76                {
77              this.id = v;
78              setModified(true);
79          }
80      
81            
82                                    
83          // update associated RdfUser
84          if (collRdfUsers != null)
85          {
86              for (int i = 0; i < collRdfUsers.size(); i++)
87              {
88                  ((RdfUser) collRdfUsers.get(i))
89                      .setGroupId(v);
90              }
91          }
92                        }
93    
94      /***
95       * Get the Name
96       *
97       * @return String
98       */
99      public String getName()
100     {
101         return name;
102     }
103 
104                         
105     /***
106      * Set the value of Name
107      *
108      * @param v new value
109      */
110     public void setName(String v) 
111     {
112     
113                   if (!ObjectUtils.equals(this.name, v))
114               {
115             this.name = v;
116             setModified(true);
117         }
118     
119           
120               }
121   
122     /***
123      * Get the Description
124      *
125      * @return String
126      */
127     public String getDescription()
128     {
129         return description;
130     }
131 
132                         
133     /***
134      * Set the value of Description
135      *
136      * @param v new value
137      */
138     public void setDescription(String v) 
139     {
140     
141                   if (!ObjectUtils.equals(this.description, v))
142               {
143             this.description = v;
144             setModified(true);
145         }
146     
147           
148               }
149   
150     /***
151      * Get the RoleAdmin
152      *
153      * @return int
154      */
155     public int getRoleAdmin()
156     {
157         return roleAdmin;
158     }
159 
160                         
161     /***
162      * Set the value of RoleAdmin
163      *
164      * @param v new value
165      */
166     public void setRoleAdmin(int v) 
167     {
168     
169                   if (this.roleAdmin != v)
170               {
171             this.roleAdmin = v;
172             setModified(true);
173         }
174     
175           
176               }
177   
178     /***
179      * Get the RoleContributor
180      *
181      * @return int
182      */
183     public int getRoleContributor()
184     {
185         return roleContributor;
186     }
187 
188                         
189     /***
190      * Set the value of RoleContributor
191      *
192      * @param v new value
193      */
194     public void setRoleContributor(int v) 
195     {
196     
197                   if (this.roleContributor != v)
198               {
199             this.roleContributor = v;
200             setModified(true);
201         }
202     
203           
204               }
205   
206     /***
207      * Get the RoleUser
208      *
209      * @return int
210      */
211     public int getRoleUser()
212     {
213         return roleUser;
214     }
215 
216                         
217     /***
218      * Set the value of RoleUser
219      *
220      * @param v new value
221      */
222     public void setRoleUser(int v) 
223     {
224     
225                   if (this.roleUser != v)
226               {
227             this.roleUser = v;
228             setModified(true);
229         }
230     
231           
232               }
233   
234     /***
235      * Get the Template
236      *
237      * @return String
238      */
239     public String getTemplate()
240     {
241         return template;
242     }
243 
244                         
245     /***
246      * Set the value of Template
247      *
248      * @param v new value
249      */
250     public void setTemplate(String v) 
251     {
252     
253                   if (!ObjectUtils.equals(this.template, v))
254               {
255             this.template = v;
256             setModified(true);
257         }
258     
259           
260               }
261   
262          
263                                 
264             
265     /***
266      * Collection to store aggregation of collRdfUsers
267      */
268     protected List collRdfUsers;
269 
270     /***
271      * Temporary storage of collRdfUsers to save a possible db hit in
272      * the event objects are add to the collection, but the
273      * complete collection is never requested.
274      */
275     protected void initRdfUsers()
276     {
277         if (collRdfUsers == null)
278         {
279             collRdfUsers = new ArrayList();
280         }
281     }
282 
283     /***
284      * Method called to associate a RdfUser object to this object
285      * through the RdfUser foreign key attribute
286      *
287      * @param l RdfUser
288      * @throws TorqueException
289      */
290     public void addRdfUser(RdfUser l) throws TorqueException
291     {
292         getRdfUsers().add(l);
293         l.setRdfGroup((RdfGroup) this);
294     }
295 
296     /***
297      * The criteria used to select the current contents of collRdfUsers
298      */
299     private Criteria lastRdfUsersCriteria = null;
300 
301     /***
302      * If this collection has already been initialized, returns
303      * the collection. Otherwise returns the results of
304      * getRdfUsers(new Criteria())
305      *
306      * @throws TorqueException
307      */
308     public List getRdfUsers() throws TorqueException
309     {
310         if (collRdfUsers == null)
311         {
312             collRdfUsers = getRdfUsers(new Criteria(10));
313         }
314         return collRdfUsers;
315     }
316 
317     /***
318      * If this collection has already been initialized with
319      * an identical criteria, it returns the collection.
320      * Otherwise if this RdfGroup has previously
321      * been saved, it will retrieve related RdfUsers from storage.
322      * If this RdfGroup is new, it will return
323      * an empty collection or the current collection, the criteria
324      * is ignored on a new object.
325      *
326      * @throws TorqueException
327      */
328     public List getRdfUsers(Criteria criteria) throws TorqueException
329     {
330         if (collRdfUsers == null)
331         {
332             if (isNew())
333             {
334                collRdfUsers = new ArrayList();
335             }
336             else
337             {
338                       criteria.add(RdfUserPeer.GROUP_ID, getId() );
339                       collRdfUsers = RdfUserPeer.doSelect(criteria);
340             }
341         }
342         else
343         {
344             // criteria has no effect for a new object
345             if (!isNew())
346             {
347                 // the following code is to determine if a new query is
348                 // called for.  If the criteria is the same as the last
349                 // one, just return the collection.
350                       criteria.add(RdfUserPeer.GROUP_ID, getId());
351                       if (!lastRdfUsersCriteria.equals(criteria))
352                 {
353                     collRdfUsers = RdfUserPeer.doSelect(criteria);
354                 }
355             }
356         }
357         lastRdfUsersCriteria = criteria;
358 
359         return collRdfUsers;
360     }
361 
362     /***
363      * If this collection has already been initialized, returns
364      * the collection. Otherwise returns the results of
365      * getRdfUsers(new Criteria(),Connection)
366      * This method takes in the Connection also as input so that
367      * referenced objects can also be obtained using a Connection
368      * that is taken as input
369      */
370     public List getRdfUsers(Connection con) throws TorqueException
371     {
372         if (collRdfUsers == null)
373         {
374             collRdfUsers = getRdfUsers(new Criteria(10), con);
375         }
376         return collRdfUsers;
377     }
378 
379     /***
380      * If this collection has already been initialized with
381      * an identical criteria, it returns the collection.
382      * Otherwise if this RdfGroup has previously
383      * been saved, it will retrieve related RdfUsers from storage.
384      * If this RdfGroup is new, it will return
385      * an empty collection or the current collection, the criteria
386      * is ignored on a new object.
387      * This method takes in the Connection also as input so that
388      * referenced objects can also be obtained using a Connection
389      * that is taken as input
390      */
391     public List getRdfUsers(Criteria criteria, Connection con)
392             throws TorqueException
393     {
394         if (collRdfUsers == null)
395         {
396             if (isNew())
397             {
398                collRdfUsers = new ArrayList();
399             }
400             else
401             {
402                        criteria.add(RdfUserPeer.GROUP_ID, getId());
403                        collRdfUsers = RdfUserPeer.doSelect(criteria, con);
404              }
405          }
406          else
407          {
408              // criteria has no effect for a new object
409              if (!isNew())
410              {
411                  // the following code is to determine if a new query is
412                  // called for.  If the criteria is the same as the last
413                  // one, just return the collection.
414                        criteria.add(RdfUserPeer.GROUP_ID, getId());
415                        if (!lastRdfUsersCriteria.equals(criteria))
416                  {
417                      collRdfUsers = RdfUserPeer.doSelect(criteria, con);
418                  }
419              }
420          }
421          lastRdfUsersCriteria = criteria;
422 
423          return collRdfUsers;
424      }
425 
426                   
427               
428                     
429                               
430                                 
431                                                               
432                                         
433                     
434                     
435           
436     /***
437      * If this collection has already been initialized with
438      * an identical criteria, it returns the collection.
439      * Otherwise if this RdfGroup is new, it will return
440      * an empty collection; or if this RdfGroup has previously
441      * been saved, it will retrieve related RdfUsers from storage.
442      *
443      * This method is protected by default in order to keep the public
444      * api reasonable.  You can provide public methods for those you
445      * actually need in RdfGroup.
446      */
447     protected List getRdfUsersJoinRdfGroup(Criteria criteria)
448         throws TorqueException
449     {
450         if (collRdfUsers == null)
451         {
452             if (isNew())
453             {
454                collRdfUsers = new ArrayList();
455             }
456             else
457             {
458                             criteria.add(RdfUserPeer.GROUP_ID, getId());
459                             collRdfUsers = RdfUserPeer.doSelectJoinRdfGroup(criteria);
460             }
461         }
462         else
463         {
464             // the following code is to determine if a new query is
465             // called for.  If the criteria is the same as the last
466             // one, just return the collection.
467             boolean newCriteria = true;
468                         criteria.add(RdfUserPeer.GROUP_ID, getId());
469                         if (!lastRdfUsersCriteria.equals(criteria))
470             {
471                 collRdfUsers = RdfUserPeer.doSelectJoinRdfGroup(criteria);
472             }
473         }
474         lastRdfUsersCriteria = criteria;
475 
476         return collRdfUsers;
477     }
478                             
479 
480 
481           
482     private static List fieldNames = null;
483 
484     /***
485      * Generate a list of field names.
486      *
487      * @return a list of field names
488      */
489     public static synchronized List getFieldNames()
490     {
491         if (fieldNames == null)
492         {
493             fieldNames = new ArrayList();
494               fieldNames.add("Id");
495               fieldNames.add("Name");
496               fieldNames.add("Description");
497               fieldNames.add("RoleAdmin");
498               fieldNames.add("RoleContributor");
499               fieldNames.add("RoleUser");
500               fieldNames.add("Template");
501               fieldNames = Collections.unmodifiableList(fieldNames);
502         }
503         return fieldNames;
504     }
505 
506     /***
507      * Retrieves a field from the object by name passed in as a String.
508      *
509      * @param name field name
510      * @return value
511      */
512     public Object getByName(String name)
513     {
514           if (name.equals("Id"))
515         {
516                 return new Integer(getId());
517             }
518           if (name.equals("Name"))
519         {
520                 return getName();
521             }
522           if (name.equals("Description"))
523         {
524                 return getDescription();
525             }
526           if (name.equals("RoleAdmin"))
527         {
528                 return new Integer(getRoleAdmin());
529             }
530           if (name.equals("RoleContributor"))
531         {
532                 return new Integer(getRoleContributor());
533             }
534           if (name.equals("RoleUser"))
535         {
536                 return new Integer(getRoleUser());
537             }
538           if (name.equals("Template"))
539         {
540                 return getTemplate();
541             }
542           return null;
543     }
544     
545     /***
546      * Retrieves a field from the object by name passed in
547      * as a String.  The String must be one of the static
548      * Strings defined in this Class' Peer.
549      *
550      * @param name peer name
551      * @return value
552      */
553     public Object getByPeerName(String name)
554     {
555           if (name.equals(RdfGroupPeer.ID))
556         {
557                 return new Integer(getId());
558             }
559           if (name.equals(RdfGroupPeer.NAME))
560         {
561                 return getName();
562             }
563           if (name.equals(RdfGroupPeer.DESCRIPTION))
564         {
565                 return getDescription();
566             }
567           if (name.equals(RdfGroupPeer.ROLE_ADMIN))
568         {
569                 return new Integer(getRoleAdmin());
570             }
571           if (name.equals(RdfGroupPeer.ROLE_CONTRIBUTOR))
572         {
573                 return new Integer(getRoleContributor());
574             }
575           if (name.equals(RdfGroupPeer.ROLE_USER))
576         {
577                 return new Integer(getRoleUser());
578             }
579           if (name.equals(RdfGroupPeer.TEMPLATE))
580         {
581                 return getTemplate();
582             }
583           return null;
584     }
585 
586     /***
587      * Retrieves a field from the object by Position as specified
588      * in the xml schema.  Zero-based.
589      *
590      * @param pos position in xml schema
591      * @return value
592      */
593     public Object getByPosition(int pos)
594     {
595             if (pos == 0)
596         {
597                 return new Integer(getId());
598             }
599               if (pos == 1)
600         {
601                 return getName();
602             }
603               if (pos == 2)
604         {
605                 return getDescription();
606             }
607               if (pos == 3)
608         {
609                 return new Integer(getRoleAdmin());
610             }
611               if (pos == 4)
612         {
613                 return new Integer(getRoleContributor());
614             }
615               if (pos == 5)
616         {
617                 return new Integer(getRoleUser());
618             }
619               if (pos == 6)
620         {
621                 return getTemplate();
622             }
623               return null;
624     }
625      
626     /***
627      * Stores the object in the database.  If the object is new,
628      * it inserts it; otherwise an update is performed.
629      *
630      * @throws Exception
631      */
632     public void save() throws Exception
633     {
634           save(RdfGroupPeer.getMapBuilder()
635                 .getDatabaseMap().getName());
636       }
637 
638     /***
639      * Stores the object in the database.  If the object is new,
640      * it inserts it; otherwise an update is performed.
641        * Note: this code is here because the method body is
642      * auto-generated conditionally and therefore needs to be
643      * in this file instead of in the super class, BaseObject.
644        *
645      * @param dbName
646      * @throws TorqueException
647      */
648     public void save(String dbName) throws TorqueException
649     {
650         Connection con = null;
651           try
652         {
653             con = Transaction.begin(dbName);
654             save(con);
655             Transaction.commit(con);
656         }
657         catch(TorqueException e)
658         {
659             Transaction.safeRollback(con);
660             throw e;
661         }
662       }
663 
664       /*** flag to prevent endless save loop, if this object is referenced
665         by another object which falls in this transaction. */
666     private boolean alreadyInSave = false;
667       /***
668      * Stores the object in the database.  If the object is new,
669      * it inserts it; otherwise an update is performed.  This method
670      * is meant to be used as part of a transaction, otherwise use
671      * the save() method and the connection details will be handled
672      * internally
673      *
674      * @param con
675      * @throws TorqueException
676      */
677     public void save(Connection con) throws TorqueException
678     {
679           if (!alreadyInSave)
680         {
681             alreadyInSave = true;
682 
683 
684   
685             // If this object has been modified, then save it to the database.
686             if (isModified())
687             {
688                 if (isNew())
689                 {
690                     RdfGroupPeer.doInsert((RdfGroup) this, con);
691                     setNew(false);
692                 }
693                 else
694                 {
695                     RdfGroupPeer.doUpdate((RdfGroup) this, con);
696                 }
697             }
698 
699                                       
700                 
701             if (collRdfUsers != null)
702             {
703                 for (int i = 0; i < collRdfUsers.size(); i++)
704                 {
705                     ((RdfUser) collRdfUsers.get(i)).save(con);
706                 }
707             }
708                           alreadyInSave = false;
709         }
710       }
711 
712 
713                           
714       /***
715      * Set the PrimaryKey using ObjectKey.
716      *
717      * @param  id ObjectKey
718      */
719     public void setPrimaryKey(ObjectKey key)
720         throws TorqueException
721     {
722             setId(((NumberKey) key).intValue());
723         }
724 
725     /***
726      * Set the PrimaryKey using a String.
727      *
728      * @param key
729      */
730     public void setPrimaryKey(String key) throws TorqueException
731     {
732             setId(Integer.parseInt(key));
733         }
734 
735   
736     /***
737      * returns an id that differentiates this object from others
738      * of its class.
739      */
740     public ObjectKey getPrimaryKey()
741     {
742           return SimpleKey.keyFor(getId());
743       }
744 
745  
746 
747     /***
748      * Makes a copy of this object.
749      * It creates a new object filling in the simple attributes.
750        * It then fills all the association collections and sets the
751      * related objects to isNew=true.
752        */
753       public RdfGroup copy() throws TorqueException
754     {
755         return copyInto(new RdfGroup());
756     }
757   
758     protected RdfGroup copyInto(RdfGroup copyObj) throws TorqueException
759     {
760           copyObj.setId(id);
761           copyObj.setName(name);
762           copyObj.setDescription(description);
763           copyObj.setRoleAdmin(roleAdmin);
764           copyObj.setRoleContributor(roleContributor);
765           copyObj.setRoleUser(roleUser);
766           copyObj.setTemplate(template);
767   
768                     copyObj.setId(0);
769                                                 
770                                       
771                 
772         List v = getRdfUsers();
773         for (int i = 0; i < v.size(); i++)
774         {
775             RdfUser obj = (RdfUser) v.get(i);
776             copyObj.addRdfUser(obj.copy());
777         }
778                     
779         return copyObj;
780     }
781 
782     /***
783      * returns a peer instance associated with this om.  Since Peer classes
784      * are not to have any instance attributes, this method returns the
785      * same instance for all member of this class. The method could therefore
786      * be static, but this would prevent one from overriding the behavior.
787      */
788     public RdfGroupPeer getPeer()
789     {
790         return peer;
791     }
792 
793     public String toString()
794     {
795         StringBuffer str = new StringBuffer();
796         str.append("RdfGroup:\n");
797         str.append("Id = ")
798            .append(getId())
799            .append("\n");
800         str.append("Name = ")
801            .append(getName())
802            .append("\n");
803         str.append("Description = ")
804            .append(getDescription())
805            .append("\n");
806         str.append("RoleAdmin = ")
807            .append(getRoleAdmin())
808            .append("\n");
809         str.append("RoleContributor = ")
810            .append(getRoleContributor())
811            .append("\n");
812         str.append("RoleUser = ")
813            .append(getRoleUser())
814            .append("\n");
815         str.append("Template = ")
816            .append(getTemplate())
817            .append("\n");
818         return(str.toString());
819     }
820 }