1 package org.apache.turbine.services.schedule;
2
3
4 import java.math.BigDecimal;
5 import java.sql.Connection;
6 import java.util.ArrayList;
7 import java.util.Collections;
8 import java.util.Date;
9 import java.util.List;
10
11 import org.apache.commons.lang.ObjectUtils;
12 import org.apache.torque.TorqueException;
13 import org.apache.torque.map.TableMap;
14 import org.apache.torque.om.BaseObject;
15 import org.apache.torque.om.ComboKey;
16 import org.apache.torque.om.DateKey;
17 import org.apache.torque.om.NumberKey;
18 import org.apache.torque.om.ObjectKey;
19 import org.apache.torque.om.SimpleKey;
20 import org.apache.torque.om.StringKey;
21 import org.apache.torque.om.Persistent;
22 import org.apache.torque.util.Criteria;
23 import org.apache.torque.util.Transaction;
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public abstract class BaseJobEntry extends BaseObject
38 {
39
40 private static final long serialVersionUID = 1308842746584L;
41
42
43 private static final JobEntryPeer peer =
44 new JobEntryPeer();
45
46
47
48 private int jobId;
49
50
51 private int second = -1;
52
53
54 private int minute = -1;
55
56
57 private int hour = -1;
58
59
60 private int weekDay = -1;
61
62
63 private int dayOfMonth = -1;
64
65
66 private String task;
67
68
69 private String email;
70
71
72 private byte[] property;
73
74
75
76
77
78
79
80 public int getJobId()
81 {
82 return jobId;
83 }
84
85
86
87
88
89
90
91 public void setJobId(int v)
92 {
93
94 if (this.jobId != v)
95 {
96 this.jobId = v;
97 setModified(true);
98 }
99
100
101 }
102
103
104
105
106
107
108 public int getSecond()
109 {
110 return second;
111 }
112
113
114
115
116
117
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
133
134
135
136 public int getMinute()
137 {
138 return minute;
139 }
140
141
142
143
144
145
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
161
162
163
164 public int getHour()
165 {
166 return hour;
167 }
168
169
170
171
172
173
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
189
190
191
192 public int getWeekDay()
193 {
194 return weekDay;
195 }
196
197
198
199
200
201
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
217
218
219
220 public int getDayOfMonth()
221 {
222 return dayOfMonth;
223 }
224
225
226
227
228
229
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
245
246
247
248 public String getTask()
249 {
250 return task;
251 }
252
253
254
255
256
257
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
273
274
275
276 public String getEmail()
277 {
278 return email;
279 }
280
281
282
283
284
285
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
301
302
303
304 public byte[] getProperty()
305 {
306 return property;
307 }
308
309
310
311
312
313
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
333
334
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
357
358
359
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
404
405
406
407
408
409
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
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
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
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
503
504
505
506
507
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
552
553
554
555
556
557
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
603
604
605
606
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
651
652
653
654
655
656
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
702
703
704
705
706 public void save() throws Exception
707 {
708 save(JobEntryPeer.DATABASE_NAME);
709 }
710
711
712
713
714
715
716
717
718
719
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
738
739 private boolean alreadyInSave = false;
740
741
742
743
744
745
746
747
748
749
750 public void save(Connection con) throws TorqueException
751 {
752 if (!alreadyInSave)
753 {
754 alreadyInSave = true;
755
756
757
758
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
779
780
781
782 public void setPrimaryKey(ObjectKey key)
783
784 {
785 setJobId(((NumberKey) key).intValue());
786 }
787
788
789
790
791
792
793 public void setPrimaryKey(String key)
794 {
795 setJobId(Integer.parseInt(key));
796 }
797
798
799
800
801
802
803 public ObjectKey getPrimaryKey()
804 {
805 return SimpleKey.keyFor(getJobId());
806 }
807
808
809
810
811
812
813
814
815 public JobEntry copy() throws TorqueException
816 {
817 return copy(true);
818 }
819
820
821
822
823
824
825
826
827
828 public JobEntry copy(Connection con) throws TorqueException
829 {
830 return copy(true, con);
831 }
832
833
834
835
836
837
838
839
840
841
842 public JobEntry copy(boolean deepcopy) throws TorqueException
843 {
844 return copyInto(new JobEntry(), deepcopy);
845 }
846
847
848
849
850
851
852
853
854
855
856
857 public JobEntry copy(boolean deepcopy, Connection con) throws TorqueException
858 {
859 return copyInto(new JobEntry(), deepcopy, con);
860 }
861
862
863
864
865
866
867
868 protected JobEntry copyInto(JobEntry copyObj) throws TorqueException
869 {
870 return copyInto(copyObj, true);
871 }
872
873
874
875
876
877
878
879
880
881 protected JobEntry copyInto(JobEntry copyObj, Connection con) throws TorqueException
882 {
883 return copyInto(copyObj, true, con);
884 }
885
886
887
888
889
890
891
892
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
917
918
919
920
921
922
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
948
949
950
951
952 public JobEntryPeer getPeer()
953 {
954 return peer;
955 }
956
957
958
959
960
961
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 }