|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| package org.objectledge.scheduler.db; |
|
30 |
| |
|
31 |
| import org.objectledge.database.persistence.InputRecord; |
|
32 |
| import org.objectledge.database.persistence.OutputRecord; |
|
33 |
| import org.objectledge.database.persistence.Persistence; |
|
34 |
| import org.objectledge.database.persistence.PersistenceException; |
|
35 |
| import org.objectledge.database.persistence.Persistent; |
|
36 |
| import org.objectledge.scheduler.AbstractJobDescriptor; |
|
37 |
| import org.objectledge.scheduler.AbstractScheduler; |
|
38 |
| import org.objectledge.scheduler.InvalidScheduleException; |
|
39 |
| import org.objectledge.scheduler.JobModificationException; |
|
40 |
| import org.objectledge.scheduler.Schedule; |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| public class DBJobDescriptor extends AbstractJobDescriptor |
|
48 |
| implements Persistent |
|
49 |
| { |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| public static final String TABLE_NAME = "ledge_scheduler"; |
|
54 |
| |
|
55 |
| |
|
56 |
| public static final String[] KEY_COLUMNS = new String[] { "job_id" }; |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| private Persistence persistence; |
|
62 |
| |
|
63 |
| |
|
64 |
| private AbstractScheduler scheduler; |
|
65 |
| |
|
66 |
| |
|
67 |
| private long jobId = -1L; |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
1426
| DBJobDescriptor(Persistence persistence, AbstractScheduler scheduler)
|
|
76 |
| { |
|
77 |
1426
| this.persistence = persistence;
|
|
78 |
1426
| this.scheduler = scheduler;
|
|
79 |
| } |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
1150
| public String getTable()
|
|
89 |
| { |
|
90 |
1150
| return TABLE_NAME;
|
|
91 |
| } |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
2116
| public String[] getKeyColumns()
|
|
99 |
| { |
|
100 |
2116
| return KEY_COLUMNS;
|
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
368
| public void getData(OutputRecord record) throws PersistenceException
|
|
107 |
| { |
|
108 |
368
| record.setLong("job_id", jobId);
|
|
109 |
368
| record.setString("job_name", getName());
|
|
110 |
368
| record.setString("schedule_type", getSchedule().getType());
|
|
111 |
368
| record.setString("schedule_config", getSchedule().getConfig());
|
|
112 |
368
| record.setString("job_class_name", getJobClassName());
|
|
113 |
368
| if (getArgument() != null)
|
|
114 |
| { |
|
115 |
0
| record.setString("argument", getArgument());
|
|
116 |
| } |
|
117 |
| else |
|
118 |
| { |
|
119 |
368
| record.setNull("argument");
|
|
120 |
| } |
|
121 |
368
| record.setInteger("run_count", getRunCount());
|
|
122 |
368
| record.setInteger("run_count_limit", getRunCountLimit());
|
|
123 |
368
| if (getLastRunTime() != null)
|
|
124 |
| { |
|
125 |
0
| record.setTimestamp("last_run_time", getLastRunTime());
|
|
126 |
| } |
|
127 |
| else |
|
128 |
| { |
|
129 |
368
| record.setNull("last_run_time");
|
|
130 |
| } |
|
131 |
368
| if (getTimeLimitStart() != null)
|
|
132 |
| { |
|
133 |
0
| record.setTimestamp("run_time_limit_start", getTimeLimitStart());
|
|
134 |
| } |
|
135 |
| else |
|
136 |
| { |
|
137 |
368
| record.setNull("run_time_limit_start");
|
|
138 |
| } |
|
139 |
368
| if (getTimeLimitEnd() != null)
|
|
140 |
| { |
|
141 |
0
| record.setTimestamp("run_time_limit_end", getTimeLimitEnd());
|
|
142 |
| } |
|
143 |
| else |
|
144 |
| { |
|
145 |
368
| record.setNull("run_time_limit_end");
|
|
146 |
| } |
|
147 |
368
| record.setBoolean("reentrant", isReentrant());
|
|
148 |
368
| record.setBoolean("enabled", isEnabled());
|
|
149 |
| } |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
828
| public void setData(InputRecord record) throws PersistenceException
|
|
155 |
| { |
|
156 |
828
| jobId = record.getLong("job_id");
|
|
157 |
828
| String name = record.getString("job_name");
|
|
158 |
828
| String scheduleType = record.getString("schedule_type");
|
|
159 |
828
| String scheduleConfig = record.getString("schedule_config");
|
|
160 |
828
| String jobClassName = record.getString("job_class_name");
|
|
161 |
828
| Schedule schedule = null;
|
|
162 |
828
| try
|
|
163 |
| { |
|
164 |
828
| schedule = scheduler.createSchedule(scheduleType, scheduleConfig);
|
|
165 |
| } |
|
166 |
| catch (InvalidScheduleException e) |
|
167 |
| { |
|
168 |
0
| throw new PersistenceException("failed to create schedule", e);
|
|
169 |
| } |
|
170 |
828
| try
|
|
171 |
| { |
|
172 |
828
| super.init(name, schedule, jobClassName);
|
|
173 |
828
| if (!record.isNull("argument"))
|
|
174 |
| { |
|
175 |
0
| argument = record.getString("argument");
|
|
176 |
| } |
|
177 |
828
| if (!record.isNull("run_count"))
|
|
178 |
| { |
|
179 |
828
| runCount = record.getInteger("run_count");
|
|
180 |
| } |
|
181 |
828
| if (!record.isNull("run_count_limit"))
|
|
182 |
| { |
|
183 |
828
| runCountLimit = record.getInteger("run_count_limit");
|
|
184 |
| } |
|
185 |
828
| if (!record.isNull("last_run_time"))
|
|
186 |
| { |
|
187 |
0
| lastRunTime = record.getDate("last_run_time");
|
|
188 |
| } |
|
189 |
828
| if (!record.isNull("run_time_limit_start"))
|
|
190 |
| { |
|
191 |
0
| runTimeLimitStart = record.getDate("run_time_limit_start");
|
|
192 |
| } |
|
193 |
828
| if (!record.isNull("run_time_limit_end"))
|
|
194 |
| { |
|
195 |
0
| runTimeLimitEnd = record.getDate("run_time_limit_end");
|
|
196 |
| } |
|
197 |
828
| if (!record.isNull("auto_clean"))
|
|
198 |
| { |
|
199 |
828
| autoClean = record.getBoolean("auto_clean");
|
|
200 |
| } |
|
201 |
828
| if (!record.isNull("reentrant"))
|
|
202 |
| { |
|
203 |
828
| reentrant = record.getBoolean("reentrant");
|
|
204 |
| } |
|
205 |
828
| if (!record.isNull("enabled"))
|
|
206 |
| { |
|
207 |
828
| enabled = record.getBoolean("enabled");
|
|
208 |
| } |
|
209 |
| } |
|
210 |
| catch (Exception e) |
|
211 |
| { |
|
212 |
0
| throw new PersistenceException("Failed to initialize scheduled job", e);
|
|
213 |
| } |
|
214 |
| } |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
322
| public boolean getSaved()
|
|
220 |
| { |
|
221 |
322
| return jobId != -1L;
|
|
222 |
| } |
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
| |
|
227 |
966
| public void setSaved(long id)
|
|
228 |
| { |
|
229 |
966
| this.jobId = id;
|
|
230 |
| } |
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
| |
|
235 |
| |
|
236 |
| |
|
237 |
184
| protected void saveChanges() throws JobModificationException
|
|
238 |
| { |
|
239 |
184
| try
|
|
240 |
| { |
|
241 |
184
| persistence.save(this);
|
|
242 |
| } |
|
243 |
| catch (PersistenceException e) |
|
244 |
| { |
|
245 |
0
| throw new JobModificationException("failed to save job state", e);
|
|
246 |
| } |
|
247 |
| } |
|
248 |
| |
|
249 |
| } |