Revision 5108
Added by daigle over 14 years ago
ScheduledJobAccess.java | ||
---|---|---|
38 | 38 |
import org.apache.log4j.Logger; |
39 | 39 |
import org.quartz.Job; |
40 | 40 |
|
41 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
|
41 | 42 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
42 | 43 |
import edu.ucsb.nceas.metacat.shared.AccessException; |
43 | 44 |
import edu.ucsb.nceas.metacat.shared.BaseAccess; |
... | ... | |
48 | 49 |
private Logger logMetacat = Logger.getLogger(ScheduledJobAccess.class); |
49 | 50 |
|
50 | 51 |
// Constructor |
51 |
public ScheduledJobAccess() throws AccessException { |
|
52 |
super("ScheduledJobAccess"); |
|
53 |
} |
|
52 |
public ScheduledJobAccess() throws AccessException {} |
|
54 | 53 |
|
55 | 54 |
/** |
56 | 55 |
* Get a job based on it's id |
... | ... | |
64 | 63 |
|
65 | 64 |
// first get the job from the db and put it into a DAO |
66 | 65 |
PreparedStatement pstmt = null; |
66 |
DBConnection conn = null; |
|
67 |
int serialNumber = -1; |
|
67 | 68 |
try { |
69 |
conn = DBConnectionPool.getDBConnection("ScheduledJobAccess.getJob"); |
|
70 |
serialNumber = conn.getCheckOutSerialNumber(); |
|
71 |
|
|
68 | 72 |
String sql = "SELECT * FROM scheduled_job WHERE id = ? AND status != 'deleted'"; |
69 | 73 |
pstmt = conn.prepareStatement(sql); |
70 | 74 |
|
... | ... | |
86 | 90 |
throw new AccessException("ScheduledJobAccess.getJob - SQL error when getting scheduled job: " |
87 | 91 |
+ jobId + " : " + sqle.getMessage()); |
88 | 92 |
} finally { |
89 |
try { |
|
90 |
if (pstmt != null) { |
|
91 |
pstmt.close(); |
|
92 |
} |
|
93 |
} catch (SQLException sqle) { |
|
94 |
logMetacat.error("ScheduledJobAccess.getJob - An error occurred " |
|
95 |
+ "closing prepared statement: " + sqle.getMessage()); |
|
96 |
} |
|
93 |
closeDBObjects(pstmt, conn, serialNumber, logMetacat); |
|
97 | 94 |
} |
98 | 95 |
|
99 | 96 |
// Now get all the job parameters and put those into a list of job parameter |
... | ... | |
119 | 116 |
|
120 | 117 |
// first get the job from the db and put it into a DAO |
121 | 118 |
PreparedStatement pstmt = null; |
119 |
DBConnection conn = null; |
|
120 |
int serialNumber = -1; |
|
122 | 121 |
try { |
122 |
conn = DBConnectionPool.getDBConnection("ScheduledJobAccess.getJobByName"); |
|
123 |
serialNumber = conn.getCheckOutSerialNumber(); |
|
124 |
|
|
123 | 125 |
String sql = "SELECT * FROM scheduled_job WHERE name = ? AND status != 'deleted'"; |
124 | 126 |
pstmt = conn.prepareStatement(sql); |
125 | 127 |
|
... | ... | |
144 | 146 |
throw new AccessException("ScheduledJobAccess.getJobByName - SQL error when getting scheduled job by name: " |
145 | 147 |
+ jobName + " : " + sqle.getMessage()); |
146 | 148 |
} finally { |
147 |
try { |
|
148 |
if (pstmt != null) { |
|
149 |
pstmt.close(); |
|
150 |
} |
|
151 |
} catch (SQLException sqle) { |
|
152 |
logMetacat.error("ScheduledJobAccess.getJobByName - An error occurred " |
|
153 |
+ "closing prepared statement: " + sqle.getMessage()); |
|
154 |
} finally { |
|
155 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
156 |
} |
|
149 |
closeDBObjects(pstmt, conn, serialNumber, logMetacat); |
|
157 | 150 |
} |
158 | 151 |
|
159 | 152 |
// Now get all the job parameters and put those into a list of job parameter |
... | ... | |
216 | 209 |
|
217 | 210 |
// Get all jobs where the status is not deleted |
218 | 211 |
PreparedStatement pstmt = null; |
212 |
DBConnection conn = null; |
|
213 |
int serialNumber = -1; |
|
219 | 214 |
try { |
215 |
conn = DBConnectionPool.getDBConnection("ScheduledJobAccess.getAllJobs"); |
|
216 |
serialNumber = conn.getCheckOutSerialNumber(); |
|
217 |
|
|
220 | 218 |
String sql = "SELECT * FROM scheduled_job WHERE status != 'deleted'"; |
221 | 219 |
if (groupName != null) { |
222 | 220 |
sql += " AND group_name = ?" ; |
... | ... | |
260 | 258 |
throw new AccessException("ScheduledJobAccess.getJobByName - SQL error when getting all jobs : " |
261 | 259 |
+ sqle.getMessage()); |
262 | 260 |
} finally { |
263 |
try { |
|
264 |
if (pstmt != null) { |
|
265 |
pstmt.close(); |
|
266 |
} |
|
267 |
} catch (SQLException sqle) { |
|
268 |
logMetacat.error("ScheduledJobAccess.getAllJobs - An error occurred " |
|
269 |
+ "closing prepared statement: " + sqle.getMessage()); |
|
270 |
} finally { |
|
271 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
272 |
} |
|
261 |
closeDBObjects(pstmt, conn, serialNumber, logMetacat); |
|
273 | 262 |
} |
274 | 263 |
|
275 | 264 |
} |
... | ... | |
324 | 313 |
*/ |
325 | 314 |
public void createJob(ScheduledJobDAO jobDAO, HashMap<String, String> jobParams) throws AccessException { |
326 | 315 |
PreparedStatement pstmt = null; |
316 |
DBConnection conn = null; |
|
317 |
int serialNumber = -1; |
|
327 | 318 |
|
328 | 319 |
// First insert the job |
329 | 320 |
try { |
321 |
conn = DBConnectionPool.getDBConnection("ScheduledJobAccess.createJob"); |
|
322 |
serialNumber = conn.getCheckOutSerialNumber(); |
|
323 |
|
|
330 | 324 |
String sql = |
331 | 325 |
"INSERT INTO scheduled_job (date_created, date_updated, status, name, trigger_name, group_name, class_name, start_time, end_time, interval_value, interval_unit) " |
332 | 326 |
+ "VALUES(now(), now(), ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
... | ... | |
364 | 358 |
throw new AccessException("ScheduledJobAccess.createJob - SQL error when creating scheduled job " |
365 | 359 |
+ jobDAO.getName() + " : " + sqle.getMessage()); |
366 | 360 |
} finally { |
367 |
try { |
|
368 |
if (pstmt != null) { |
|
369 |
pstmt.close(); |
|
370 |
} |
|
371 |
} catch (SQLException sqle) { |
|
372 |
logMetacat.error("ScheduledJobAccess.createJob - An error occurred " |
|
373 |
+ "closing prepared statement: " + sqle.getMessage()); |
|
374 |
} finally { |
|
375 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
376 |
} |
|
361 |
closeDBObjects(pstmt, conn, serialNumber, logMetacat); |
|
377 | 362 |
} |
378 | 363 |
|
379 | 364 |
// Then iterate through the job params and insert them into the db |
... | ... | |
411 | 396 |
} |
412 | 397 |
|
413 | 398 |
PreparedStatement pstmt = null; |
399 |
DBConnection conn = null; |
|
400 |
int serialNumber = -1; |
|
414 | 401 |
|
415 | 402 |
try { |
403 |
conn = DBConnectionPool.getDBConnection("ScheduledJobAccess.createJob"); |
|
404 |
serialNumber = conn.getCheckOutSerialNumber(); |
|
405 |
|
|
416 | 406 |
String sql = "UPDATE scheduled_job SET status = ? WHERE id = ?"; |
417 | 407 |
|
418 | 408 |
pstmt = conn.prepareStatement(sql); |
... | ... | |
428 | 418 |
throw new AccessException("ScheduledJobAccess.deleteJob - SQL error when " |
429 | 419 |
+ "deleting scheduled job " + jobDAO.getName() + " : " + sqle.getMessage()); |
430 | 420 |
} finally { |
431 |
try { |
|
432 |
if (pstmt != null) { |
|
433 |
pstmt.close(); |
|
434 |
} |
|
435 |
} catch (SQLException sqle) { |
|
436 |
logMetacat.error("ScheduledJobAccess.updateJobStatus - An error occurred " |
|
437 |
+ "closing prepared statement: " + sqle.getMessage()); |
|
438 |
} finally { |
|
439 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
440 |
} |
|
421 |
closeDBObjects(pstmt, conn, serialNumber, logMetacat); |
|
441 | 422 |
} |
442 | 423 |
|
443 | 424 |
} |
Also available in: Unified diff
move dbconnection object out of base class and create it for each db access so it can be released