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