Project

General

Profile

« Previous | Next » 

Revision 4967

Added by daigle almost 15 years ago

Workflow scheduler and archiving fixes for TPC workflow engine

View differences:

ScheduledJobAccess.java
101 101

  
102 102
		PreparedStatement pstmt = null;
103 103
		try {
104
			String sql = "SELECT * FROM scheduled_job WHERE name = ? status != 'deleted'"; 
104
			String sql = "SELECT * FROM scheduled_job WHERE name = ? AND status != 'deleted'"; 
105 105
			pstmt = conn.prepareStatement(sql);
106 106

  
107 107
			pstmt.setString(1, jobName);
......
141 141
		return jobDAO;		
142 142
	}
143 143
	
144
	public HashMap<Long, ScheduledJobDAO> getJobsWithParameter(String groupName, String paramName, String paramValue) throws AccessException {
145

  
146
		HashMap<Long, ScheduledJobDAO> allJobsMap = getAllJobs(groupName);
147
		HashMap<Long, ScheduledJobDAO> jobsWithParamMap = new HashMap<Long, ScheduledJobDAO>();
148
		
149
		for (Long jobDAOId : allJobsMap.keySet()) {
150
			ScheduledJobDAO jobDAO = allJobsMap.get(jobDAOId); 
151
			if (paramValue != null && paramName != null) {
152
				ScheduledJobParamDAO jobParamDAO = jobDAO.getJobParam(paramName);
153
				if(jobParamDAO != null && jobParamDAO.getValue().equals(paramValue)) {
154
					jobsWithParamMap.put(jobDAOId, jobDAO);
155
				}
156
			}
157
		}		
158
		
159
		return jobsWithParamMap;
160
	}
161
	
144 162
	public HashMap<Long, ScheduledJobDAO> getAllJobs(String groupName) throws AccessException {
145 163
		ScheduledJobDAO jobDAO = null;
146 164
		
......
275 293
				scheduledJobParamsAccess.createJobParams(updatedJobDAO.getId(), jobParams);
276 294
			} catch (AccessException ae) {
277 295
				if (updatedJobDAO != null) {
278
					deleteJob(updatedJobDAO);
296
					updatedJobDAO.setStatus(StatusUtil.DELETED);
297
					updateJobStatus(updatedJobDAO);
279 298
					scheduledJobParamsAccess.deleteJobParams(updatedJobDAO.getId());
280 299
				} else {
281 300
					logMetacat.warn("ScheduledJobAccess.createJob - Tried to delete non-existant scheduled job: " 
......
285 304
		}
286 305
	}
287 306
	
288
	public void deleteJob(ScheduledJobDAO jobDAO) throws AccessException {	
289
		ScheduledJobParamAccess scheduledJobParamsAccess = new ScheduledJobParamAccess();
290
		
291
		if (jobDAO == null) {
292
			throw new AccessException("ScheduledJobAccess.deleteJob - job DAO cannot be null.");
293
		}
294
		scheduledJobParamsAccess.deleteJobParams(jobDAO.getId());
295
		
296
		PreparedStatement pstmt = null;
297
		
298
		try {
299
			String sql = "UPDATE scheduled_job SET status = ? WHERE id = ?";	
300
			pstmt.setString(1, StatusUtil.DELETED);
301
			pstmt.setLong(2, jobDAO.getId());
302
			
303
			logMetacat.info("ScheduledJobAccess.deleteJob - " + sql);
304
			
305
			logMetacat.info("SQL params:  [" + StatusUtil.DELETED + ","
306
					+ jobDAO.getId() + "]");
307

  
308
			pstmt.execute();
309
		} catch (SQLException sqle) {
310
			throw new AccessException("ScheduledJobAccess.deleteJob - SQL error when " 
311
					+ "deleting scheduled job " + jobDAO.getName()  + " : "  + sqle.getMessage());
312
		} finally {
313
			try {
314
				if (pstmt != null) {
315
					pstmt.close();
316
				}
317
			} catch (SQLException sqle) {
318
				logMetacat.error("ScheduledJobAccess.deleteJob - An error occurred " 
319
						+ "closing prepared statement: " + sqle.getMessage());
320
			} finally {
321
				DBConnectionPool.returnDBConnection(conn, serialNumber);
322
			}
323
		}				
324
	}
325
	
326 307
	public void updateJobStatus(ScheduledJobDAO jobDAO) throws AccessException {	
327 308
		
328 309
		if (jobDAO == null) {
......
333 314
		
334 315
		try {
335 316
			String sql = "UPDATE scheduled_job SET status = ? WHERE id = ?";	
317
			
318
			pstmt = conn.prepareStatement(sql);
336 319
			pstmt.setString(1, jobDAO.getStatus());
337 320
			pstmt.setLong(2, jobDAO.getId());
338 321
			

Also available in: Unified diff