1 package org.apache.turbine.services.schedule;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.torque.TorqueException;
25 import org.apache.torque.criteria.Criteria;
26 import org.apache.turbine.util.TurbineException;
27
28
29
30
31
32
33
34
35
36
37 @Deprecated
38 public class TorqueSchedulerService extends AbstractSchedulerService
39 {
40
41
42
43
44
45
46 @Override
47 protected List<? extends JobEntry> loadJobs() throws TurbineException
48 {
49
50 try
51 {
52 List<JobEntryTorque> jobsTorque = JobEntryTorquePeer.doSelect(new Criteria());
53
54 for (JobEntryTorque job : jobsTorque)
55 {
56 job.calcRunTime();
57 }
58
59 return jobsTorque;
60 }
61 catch (TorqueException e)
62 {
63 throw new TurbineException("Error retrieving initial job list from persistent storage.", e);
64 }
65 }
66
67
68
69
70 @Override
71 public JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, String task) throws TurbineException
72 {
73 JobEntryTorque jet = new JobEntryTorque();
74 jet.setSecond(sec);
75 jet.setMinute(min);
76 jet.setHour(hour);
77 jet.setWeekDay(wd);
78 jet.setDayOfMonth(day_mo);
79 jet.setTask(task);
80
81 return jet;
82 }
83
84
85
86
87
88
89
90
91
92
93 @Override
94 public JobEntry getJob(int oid) throws TurbineException
95 {
96 try
97 {
98 JobEntryTorque je = JobEntryTorquePeer.retrieveByPK(oid);
99 return scheduleQueue.getJob(je);
100 }
101 catch (TorqueException e)
102 {
103 throw new TurbineException("Error retrieving job from persistent storage.", e);
104 }
105 }
106
107
108
109
110
111
112
113
114
115 @Override
116 public void removeJob(JobEntry je) throws TurbineException
117 {
118 try
119 {
120
121 Criteria c = new Criteria().where(JobEntryTorquePeer.JOB_ID, Integer.valueOf(je.getJobId()));
122 JobEntryTorquePeer.doDelete(c);
123
124
125 scheduleQueue.remove(je);
126
127
128 restart();
129 }
130 catch (TorqueException e)
131 {
132 throw new TurbineException("Problem removing Scheduled Job: " + je.getTask(), e);
133 }
134 }
135
136
137
138
139
140
141
142
143
144 @Override
145 public void updateJob(JobEntry je) throws TurbineException
146 {
147 try
148 {
149 je.calcRunTime();
150
151
152 if (je.isNew())
153 {
154 scheduleQueue.add(je);
155 }
156 else
157 {
158 scheduleQueue.modify(je);
159 }
160
161 if (je instanceof JobEntryTorque)
162 {
163 ((JobEntryTorque)je).save();
164 }
165
166 restart();
167 }
168 catch (TorqueException e)
169 {
170 throw new TurbineException("Problem persisting Scheduled Job: " + je.getTask(), e);
171 }
172 catch (TurbineException e)
173 {
174 throw new TurbineException("Problem updating Scheduled Job: " + je.getTask(), e);
175 }
176 }
177 }