001    package org.apache.turbine.services.schedule;
002    
003    
004    import java.math.BigDecimal;
005    import java.sql.Connection;
006    import java.util.ArrayList;
007    import java.util.Collections;
008    import java.util.Date;
009    import java.util.List;
010    
011    import org.apache.commons.lang.ObjectUtils;
012    import org.apache.torque.TorqueException;
013    import org.apache.torque.map.TableMap;
014    import org.apache.torque.om.BaseObject;
015    import org.apache.torque.om.ComboKey;
016    import org.apache.torque.om.DateKey;
017    import org.apache.torque.om.NumberKey;
018    import org.apache.torque.om.ObjectKey;
019    import org.apache.torque.om.SimpleKey;
020    import org.apache.torque.om.StringKey;
021    import org.apache.torque.om.Persistent;
022    import org.apache.torque.util.Criteria;
023    import org.apache.torque.util.Transaction;
024    
025    
026    
027    
028    
029    /**
030     * This class was autogenerated by Torque on:
031     *
032     * [Thu Jun 23 17:25:46 CEST 2011]
033     *
034     * You should not use this class directly.  It should not even be
035     * extended all references should be to JobEntry
036     */
037    public abstract class BaseJobEntry extends BaseObject
038    {
039        /** Serial version */
040        private static final long serialVersionUID = 1308842746584L;
041    
042        /** The Peer class */
043        private static final JobEntryPeer peer =
044            new JobEntryPeer();
045    
046    
047        /** The value for the jobId field */
048        private int jobId;
049    
050        /** The value for the second field */
051        private int second = -1;
052    
053        /** The value for the minute field */
054        private int minute = -1;
055    
056        /** The value for the hour field */
057        private int hour = -1;
058    
059        /** The value for the weekDay field */
060        private int weekDay = -1;
061    
062        /** The value for the dayOfMonth field */
063        private int dayOfMonth = -1;
064    
065        /** The value for the task field */
066        private String task;
067    
068        /** The value for the email field */
069        private String email;
070    
071        /** The value for the property field */
072        private byte[] property;
073    
074    
075        /**
076         * Get the JobId
077         *
078         * @return int
079         */
080        public int getJobId()
081        {
082            return jobId;
083        }
084    
085    
086        /**
087         * Set the value of JobId
088         *
089         * @param v new value
090         */
091        public void setJobId(int v) 
092        {
093    
094            if (this.jobId != v)
095            {
096                this.jobId = v;
097                setModified(true);
098            }
099    
100    
101        }
102    
103        /**
104         * Get the Second
105         *
106         * @return int
107         */
108        public int getSecond()
109        {
110            return second;
111        }
112    
113    
114        /**
115         * Set the value of Second
116         *
117         * @param v new value
118         */
119        public void setSecond(int v) 
120        {
121    
122            if (this.second != v)
123            {
124                this.second = v;
125                setModified(true);
126            }
127    
128    
129        }
130    
131        /**
132         * Get the Minute
133         *
134         * @return int
135         */
136        public int getMinute()
137        {
138            return minute;
139        }
140    
141    
142        /**
143         * Set the value of Minute
144         *
145         * @param v new value
146         */
147        public void setMinute(int v) 
148        {
149    
150            if (this.minute != v)
151            {
152                this.minute = v;
153                setModified(true);
154            }
155    
156    
157        }
158    
159        /**
160         * Get the Hour
161         *
162         * @return int
163         */
164        public int getHour()
165        {
166            return hour;
167        }
168    
169    
170        /**
171         * Set the value of Hour
172         *
173         * @param v new value
174         */
175        public void setHour(int v) 
176        {
177    
178            if (this.hour != v)
179            {
180                this.hour = v;
181                setModified(true);
182            }
183    
184    
185        }
186    
187        /**
188         * Get the WeekDay
189         *
190         * @return int
191         */
192        public int getWeekDay()
193        {
194            return weekDay;
195        }
196    
197    
198        /**
199         * Set the value of WeekDay
200         *
201         * @param v new value
202         */
203        public void setWeekDay(int v) 
204        {
205    
206            if (this.weekDay != v)
207            {
208                this.weekDay = v;
209                setModified(true);
210            }
211    
212    
213        }
214    
215        /**
216         * Get the DayOfMonth
217         *
218         * @return int
219         */
220        public int getDayOfMonth()
221        {
222            return dayOfMonth;
223        }
224    
225    
226        /**
227         * Set the value of DayOfMonth
228         *
229         * @param v new value
230         */
231        public void setDayOfMonth(int v) 
232        {
233    
234            if (this.dayOfMonth != v)
235            {
236                this.dayOfMonth = v;
237                setModified(true);
238            }
239    
240    
241        }
242    
243        /**
244         * Get the Task
245         *
246         * @return String
247         */
248        public String getTask()
249        {
250            return task;
251        }
252    
253    
254        /**
255         * Set the value of Task
256         *
257         * @param v new value
258         */
259        public void setTask(String v) 
260        {
261    
262            if (!ObjectUtils.equals(this.task, v))
263            {
264                this.task = v;
265                setModified(true);
266            }
267    
268    
269        }
270    
271        /**
272         * Get the Email
273         *
274         * @return String
275         */
276        public String getEmail()
277        {
278            return email;
279        }
280    
281    
282        /**
283         * Set the value of Email
284         *
285         * @param v new value
286         */
287        public void setEmail(String v) 
288        {
289    
290            if (!ObjectUtils.equals(this.email, v))
291            {
292                this.email = v;
293                setModified(true);
294            }
295    
296    
297        }
298    
299        /**
300         * Get the Property
301         *
302         * @return byte[]
303         */
304        public byte[] getProperty()
305        {
306            return property;
307        }
308    
309    
310        /**
311         * Set the value of Property
312         *
313         * @param v new value
314         */
315        public void setProperty(byte[] v) 
316        {
317    
318            if (!ObjectUtils.equals(this.property, v))
319            {
320                this.property = v;
321                setModified(true);
322            }
323    
324    
325        }
326    
327           
328            
329        private static List<String> fieldNames = null;
330    
331        /**
332         * Generate a list of field names.
333         *
334         * @return a list of field names
335         */
336        public static synchronized List<String> getFieldNames()
337        {
338            if (fieldNames == null)
339            {
340                fieldNames = new ArrayList<String>();
341                fieldNames.add("JobId");
342                fieldNames.add("Second");
343                fieldNames.add("Minute");
344                fieldNames.add("Hour");
345                fieldNames.add("WeekDay");
346                fieldNames.add("DayOfMonth");
347                fieldNames.add("Task");
348                fieldNames.add("Email");
349                fieldNames.add("Property");
350                fieldNames = Collections.unmodifiableList(fieldNames);
351            }
352            return fieldNames;
353        }
354    
355        /**
356         * Retrieves a field from the object by field (Java) name passed in as a String.
357         *
358         * @param name field name
359         * @return value
360         */
361        public Object getByName(String name)
362        {
363            if (name.equals("JobId"))
364            {
365                return new Integer(getJobId());
366            }
367            if (name.equals("Second"))
368            {
369                return new Integer(getSecond());
370            }
371            if (name.equals("Minute"))
372            {
373                return new Integer(getMinute());
374            }
375            if (name.equals("Hour"))
376            {
377                return new Integer(getHour());
378            }
379            if (name.equals("WeekDay"))
380            {
381                return new Integer(getWeekDay());
382            }
383            if (name.equals("DayOfMonth"))
384            {
385                return new Integer(getDayOfMonth());
386            }
387            if (name.equals("Task"))
388            {
389                return getTask();
390            }
391            if (name.equals("Email"))
392            {
393                return getEmail();
394            }
395            if (name.equals("Property"))
396            {
397                return getProperty();
398            }
399            return null;
400        }
401    
402        /**
403         * Set a field in the object by field (Java) name.
404         *
405         * @param name field name
406         * @param value field value
407         * @return True if value was set, false if not (invalid name / protected field).
408         * @throws IllegalArgumentException if object type of value does not match field object type.
409         * @throws TorqueException If a problem occurs with the set[Field] method.
410         */
411        public boolean setByName(String name, Object value )
412            throws TorqueException, IllegalArgumentException
413        {
414            if (name.equals("JobId"))
415            {
416                if (value == null || ! (Integer.class.isInstance(value)))
417                {
418                    throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
419                }
420                setJobId(((Integer) value).intValue());
421                return true;
422            }
423            if (name.equals("Second"))
424            {
425                if (value == null || ! (Integer.class.isInstance(value)))
426                {
427                    throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
428                }
429                setSecond(((Integer) value).intValue());
430                return true;
431            }
432            if (name.equals("Minute"))
433            {
434                if (value == null || ! (Integer.class.isInstance(value)))
435                {
436                    throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
437                }
438                setMinute(((Integer) value).intValue());
439                return true;
440            }
441            if (name.equals("Hour"))
442            {
443                if (value == null || ! (Integer.class.isInstance(value)))
444                {
445                    throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
446                }
447                setHour(((Integer) value).intValue());
448                return true;
449            }
450            if (name.equals("WeekDay"))
451            {
452                if (value == null || ! (Integer.class.isInstance(value)))
453                {
454                    throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
455                }
456                setWeekDay(((Integer) value).intValue());
457                return true;
458            }
459            if (name.equals("DayOfMonth"))
460            {
461                if (value == null || ! (Integer.class.isInstance(value)))
462                {
463                    throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
464                }
465                setDayOfMonth(((Integer) value).intValue());
466                return true;
467            }
468            if (name.equals("Task"))
469            {
470                // Object fields can be null
471                if (value != null && ! String.class.isInstance(value))
472                {
473                    throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
474                }
475                setTask((String) value);
476                return true;
477            }
478            if (name.equals("Email"))
479            {
480                // Object fields can be null
481                if (value != null && ! String.class.isInstance(value))
482                {
483                    throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
484                }
485                setEmail((String) value);
486                return true;
487            }
488            if (name.equals("Property"))
489            {
490                // Object fields can be null
491                if (value != null && ! byte[].class.isInstance(value))
492                {
493                    throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
494                }
495                setProperty((byte[]) value);
496                return true;
497            }
498            return false;
499        }
500    
501        /**
502         * Retrieves a field from the object by name passed in
503         * as a String.  The String must be one of the static
504         * Strings defined in this Class' Peer.
505         *
506         * @param name peer name
507         * @return value
508         */
509        public Object getByPeerName(String name)
510        {
511            if (name.equals(JobEntryPeer.JOB_ID))
512            {
513                return new Integer(getJobId());
514            }
515            if (name.equals(JobEntryPeer.SECOND))
516            {
517                return new Integer(getSecond());
518            }
519            if (name.equals(JobEntryPeer.MINUTE))
520            {
521                return new Integer(getMinute());
522            }
523            if (name.equals(JobEntryPeer.HOUR))
524            {
525                return new Integer(getHour());
526            }
527            if (name.equals(JobEntryPeer.WEEK_DAY))
528            {
529                return new Integer(getWeekDay());
530            }
531            if (name.equals(JobEntryPeer.DAY_OF_MONTH))
532            {
533                return new Integer(getDayOfMonth());
534            }
535            if (name.equals(JobEntryPeer.TASK))
536            {
537                return getTask();
538            }
539            if (name.equals(JobEntryPeer.EMAIL))
540            {
541                return getEmail();
542            }
543            if (name.equals(JobEntryPeer.PROPERTY))
544            {
545                return getProperty();
546            }
547            return null;
548        }
549    
550        /**
551         * Set field values by Peer Field Name
552         *
553         * @param name field name
554         * @param value field value
555         * @return True if value was set, false if not (invalid name / protected field).
556         * @throws IllegalArgumentException if object type of value does not match field object type.
557         * @throws TorqueException If a problem occurs with the set[Field] method.
558         */
559        public boolean setByPeerName(String name, Object value)
560            throws TorqueException, IllegalArgumentException
561        {
562          if (JobEntryPeer.JOB_ID.equals(name))
563            {
564                return setByName("JobId", value);
565            }
566          if (JobEntryPeer.SECOND.equals(name))
567            {
568                return setByName("Second", value);
569            }
570          if (JobEntryPeer.MINUTE.equals(name))
571            {
572                return setByName("Minute", value);
573            }
574          if (JobEntryPeer.HOUR.equals(name))
575            {
576                return setByName("Hour", value);
577            }
578          if (JobEntryPeer.WEEK_DAY.equals(name))
579            {
580                return setByName("WeekDay", value);
581            }
582          if (JobEntryPeer.DAY_OF_MONTH.equals(name))
583            {
584                return setByName("DayOfMonth", value);
585            }
586          if (JobEntryPeer.TASK.equals(name))
587            {
588                return setByName("Task", value);
589            }
590          if (JobEntryPeer.EMAIL.equals(name))
591            {
592                return setByName("Email", value);
593            }
594          if (JobEntryPeer.PROPERTY.equals(name))
595            {
596                return setByName("Property", value);
597            }
598            return false;
599        }
600    
601        /**
602         * Retrieves a field from the object by Position as specified
603         * in the xml schema.  Zero-based.
604         *
605         * @param pos position in xml schema
606         * @return value
607         */
608        public Object getByPosition(int pos)
609        {
610            if (pos == 0)
611            {
612                return new Integer(getJobId());
613            }
614            if (pos == 1)
615            {
616                return new Integer(getSecond());
617            }
618            if (pos == 2)
619            {
620                return new Integer(getMinute());
621            }
622            if (pos == 3)
623            {
624                return new Integer(getHour());
625            }
626            if (pos == 4)
627            {
628                return new Integer(getWeekDay());
629            }
630            if (pos == 5)
631            {
632                return new Integer(getDayOfMonth());
633            }
634            if (pos == 6)
635            {
636                return getTask();
637            }
638            if (pos == 7)
639            {
640                return getEmail();
641            }
642            if (pos == 8)
643            {
644                return getProperty();
645            }
646            return null;
647        }
648    
649        /**
650         * Set field values by its position (zero based) in the XML schema.
651         *
652         * @param position The field position
653         * @param value field value
654         * @return True if value was set, false if not (invalid position / protected field).
655         * @throws IllegalArgumentException if object type of value does not match field object type.
656         * @throws TorqueException If a problem occurs with the set[Field] method.
657         */
658        public boolean setByPosition(int position, Object value)
659            throws TorqueException, IllegalArgumentException
660        {
661        if (position == 0)
662            {
663                return setByName("JobId", value);
664            }
665        if (position == 1)
666            {
667                return setByName("Second", value);
668            }
669        if (position == 2)
670            {
671                return setByName("Minute", value);
672            }
673        if (position == 3)
674            {
675                return setByName("Hour", value);
676            }
677        if (position == 4)
678            {
679                return setByName("WeekDay", value);
680            }
681        if (position == 5)
682            {
683                return setByName("DayOfMonth", value);
684            }
685        if (position == 6)
686            {
687                return setByName("Task", value);
688            }
689        if (position == 7)
690            {
691                return setByName("Email", value);
692            }
693        if (position == 8)
694            {
695                return setByName("Property", value);
696            }
697            return false;
698        }
699         
700        /**
701         * Stores the object in the database.  If the object is new,
702         * it inserts it; otherwise an update is performed.
703         *
704         * @throws Exception
705         */
706        public void save() throws Exception
707        {
708            save(JobEntryPeer.DATABASE_NAME);
709        }
710    
711        /**
712         * Stores the object in the database.  If the object is new,
713         * it inserts it; otherwise an update is performed.
714         * Note: this code is here because the method body is
715         * auto-generated conditionally and therefore needs to be
716         * in this file instead of in the super class, BaseObject.
717         *
718         * @param dbName
719         * @throws TorqueException
720         */
721        public void save(String dbName) throws TorqueException
722        {
723            Connection con = null;
724            try
725            {
726                con = Transaction.begin(dbName);
727                save(con);
728                Transaction.commit(con);
729            }
730            catch(TorqueException e)
731            {
732                Transaction.safeRollback(con);
733                throw e;
734            }
735        }
736    
737        /** flag to prevent endless save loop, if this object is referenced
738            by another object which falls in this transaction. */
739        private boolean alreadyInSave = false;
740        /**
741         * Stores the object in the database.  If the object is new,
742         * it inserts it; otherwise an update is performed.  This method
743         * is meant to be used as part of a transaction, otherwise use
744         * the save() method and the connection details will be handled
745         * internally
746         *
747         * @param con
748         * @throws TorqueException
749         */
750        public void save(Connection con) throws TorqueException
751        {
752            if (!alreadyInSave)
753            {
754                alreadyInSave = true;
755    
756    
757    
758                // If this object has been modified, then save it to the database.
759                if (isModified())
760                {
761                    if (isNew())
762                    {
763                        JobEntryPeer.doInsert((JobEntry) this, con);
764                        setNew(false);
765                    }
766                    else
767                    {
768                        JobEntryPeer.doUpdate((JobEntry) this, con);
769                    }
770                }
771    
772                alreadyInSave = false;
773            }
774        }
775    
776    
777        /**
778         * Set the PrimaryKey using ObjectKey.
779         *
780         * @param key jobId ObjectKey
781         */
782        public void setPrimaryKey(ObjectKey key)
783            
784        {
785            setJobId(((NumberKey) key).intValue());
786        }
787    
788        /**
789         * Set the PrimaryKey using a String.
790         *
791         * @param key
792         */
793        public void setPrimaryKey(String key) 
794        {
795            setJobId(Integer.parseInt(key));
796        }
797    
798    
799        /**
800         * returns an id that differentiates this object from others
801         * of its class.
802         */
803        public ObjectKey getPrimaryKey()
804        {
805            return SimpleKey.keyFor(getJobId());
806        }
807     
808    
809        /**
810         * Makes a copy of this object.
811         * It creates a new object filling in the simple attributes.
812         * It then fills all the association collections and sets the
813         * related objects to isNew=true.
814         */
815        public JobEntry copy() throws TorqueException
816        {
817            return copy(true);
818        }
819    
820        /**
821         * Makes a copy of this object using connection.
822         * It creates a new object filling in the simple attributes.
823         * It then fills all the association collections and sets the
824         * related objects to isNew=true.
825         *
826         * @param con the database connection to read associated objects.
827         */
828        public JobEntry copy(Connection con) throws TorqueException
829        {
830            return copy(true, con);
831        }
832    
833        /**
834         * Makes a copy of this object.
835         * It creates a new object filling in the simple attributes.
836         * If the parameter deepcopy is true, it then fills all the
837         * association collections and sets the related objects to
838         * isNew=true.
839         *
840         * @param deepcopy whether to copy the associated objects.
841         */
842        public JobEntry copy(boolean deepcopy) throws TorqueException
843        {
844            return copyInto(new JobEntry(), deepcopy);
845        }
846    
847        /**
848         * Makes a copy of this object using connection.
849         * It creates a new object filling in the simple attributes.
850         * If the parameter deepcopy is true, it then fills all the
851         * association collections and sets the related objects to
852         * isNew=true.
853         *
854         * @param deepcopy whether to copy the associated objects.
855         * @param con the database connection to read associated objects.
856         */
857        public JobEntry copy(boolean deepcopy, Connection con) throws TorqueException
858        {
859            return copyInto(new JobEntry(), deepcopy, con);
860        }
861      
862        /**
863         * Fills the copyObj with the contents of this object.
864         * The associated objects are also copied and treated as new objects.
865         *
866         * @param copyObj the object to fill.
867         */
868        protected JobEntry copyInto(JobEntry copyObj) throws TorqueException
869        {
870            return copyInto(copyObj, true);
871        }
872    
873      
874        /**
875         * Fills the copyObj with the contents of this object using connection.
876         * The associated objects are also copied and treated as new objects.
877         *
878         * @param copyObj the object to fill.
879         * @param con the database connection to read associated objects.
880         */
881        protected JobEntry copyInto(JobEntry copyObj, Connection con) throws TorqueException
882        {
883            return copyInto(copyObj, true, con);
884        }
885      
886        /**
887         * Fills the copyObj with the contents of this object.
888         * If deepcopy is true, The associated objects are also copied
889         * and treated as new objects.
890         *
891         * @param copyObj the object to fill.
892         * @param deepcopy whether the associated objects should be copied.
893         */
894        protected JobEntry copyInto(JobEntry copyObj, boolean deepcopy) throws TorqueException
895        {
896            copyObj.setJobId(jobId);
897            copyObj.setSecond(second);
898            copyObj.setMinute(minute);
899            copyObj.setHour(hour);
900            copyObj.setWeekDay(weekDay);
901            copyObj.setDayOfMonth(dayOfMonth);
902            copyObj.setTask(task);
903            copyObj.setEmail(email);
904            copyObj.setProperty(property);
905    
906            copyObj.setJobId( 0);
907    
908            if (deepcopy)
909            {
910            }
911            return copyObj;
912        }
913            
914        
915        /**
916         * Fills the copyObj with the contents of this object using connection.
917         * If deepcopy is true, The associated objects are also copied
918         * and treated as new objects.
919         *
920         * @param copyObj the object to fill.
921         * @param deepcopy whether the associated objects should be copied.
922         * @param con the database connection to read associated objects.
923         */
924        protected JobEntry copyInto(JobEntry copyObj, boolean deepcopy, Connection con) throws TorqueException
925        {
926            copyObj.setJobId(jobId);
927            copyObj.setSecond(second);
928            copyObj.setMinute(minute);
929            copyObj.setHour(hour);
930            copyObj.setWeekDay(weekDay);
931            copyObj.setDayOfMonth(dayOfMonth);
932            copyObj.setTask(task);
933            copyObj.setEmail(email);
934            copyObj.setProperty(property);
935    
936            copyObj.setJobId( 0);
937    
938            if (deepcopy)
939            {
940            }
941            return copyObj;
942        }
943        
944        
945    
946        /**
947         * returns a peer instance associated with this om.  Since Peer classes
948         * are not to have any instance attributes, this method returns the
949         * same instance for all member of this class. The method could therefore
950         * be static, but this would prevent one from overriding the behavior.
951         */
952        public JobEntryPeer getPeer()
953        {
954            return peer;
955        }
956    
957        /**
958         * Retrieves the TableMap object related to this Table data without
959         * compiler warnings of using getPeer().getTableMap().
960         *
961         * @return The associated TableMap object.
962         */
963        public TableMap getTableMap() throws TorqueException
964        {
965            return JobEntryPeer.getTableMap();
966        }
967    
968    
969        public String toString()
970        {
971            StringBuffer str = new StringBuffer();
972            str.append("JobEntry:\n");
973            str.append("JobId = ")
974               .append(getJobId())
975               .append("\n");
976            str.append("Second = ")
977               .append(getSecond())
978               .append("\n");
979            str.append("Minute = ")
980               .append(getMinute())
981               .append("\n");
982            str.append("Hour = ")
983               .append(getHour())
984               .append("\n");
985            str.append("WeekDay = ")
986               .append(getWeekDay())
987               .append("\n");
988            str.append("DayOfMonth = ")
989               .append(getDayOfMonth())
990               .append("\n");
991            str.append("Task = ")
992               .append(getTask())
993               .append("\n");
994            str.append("Email = ")
995               .append(getEmail())
996               .append("\n");
997            str.append("Property = ")
998               .append("<binary>")
999               .append("\n");
1000            return(str.toString());
1001        }
1002    }