Project

General

Profile

Revision 5108

Added by daigle over 10 years ago

move dbconnection object out of base class and create it for each db access so it can be released

View differences:

src/edu/ucsb/nceas/metacat/accesscontrol/XMLAccessAccess.java
44 44
	private Logger logMetacat = Logger.getLogger(XMLAccessAccess.class);
45 45
	
46 46
	// Constructor
47
	public XMLAccessAccess() throws AccessException {
48
		super("XMLAccessAccess");
49
	}
47
	public XMLAccessAccess() throws AccessException {}
50 48
	
51 49
	/**
52 50
	 * Get all xml access for a document
......
66 64
			
67 65
		// first get the job from the db and put it into a DAO
68 66
		PreparedStatement pstmt = null;
69
		try {
67
		DBConnection conn = null;
68
		int serialNumber = -1;
69
		try {			
70
			conn = DBConnectionPool.getDBConnection("XMLAccessAccess.getXMLAccessForDoc");
71
    		serialNumber = conn.getCheckOutSerialNumber();
72

  
70 73
			String sql = "SELECT * FROM xml_access WHERE docid = ?";
71 74
			pstmt = conn.prepareStatement(sql);
72 75

  
......
98 101
			logMetacat.error(errorStr);
99 102
			throw new AccessException(errorStr);
100 103
		} finally {
101
			try {
102
				if (pstmt != null) {
103
					pstmt.close();
104
				}
105
			} catch (SQLException sqle) {
106
				logMetacat.error("XMLAccessAccess.getXMLAccessForDoc - An error occurred " 
107
						+ "closing prepared statement: " + sqle.getMessage());
108
			} 
104
			closeDBObjects(pstmt, conn, serialNumber, logMetacat);
109 105
		}		
110 106
	}
111 107
	
......
134 130
			
135 131
		// first get the job from the db and put it into a DAO
136 132
		PreparedStatement pstmt = null;
133
		DBConnection conn = null;
134
		int serialNumber = -1;
137 135
		try {
136
			conn = DBConnectionPool.getDBConnection("XMLAccessAccess.getXMLAccessForPrincipal");
137
    		serialNumber = conn.getCheckOutSerialNumber();
138
			
138 139
			String sql = "SELECT * FROM xml_access WHERE docid = ? AND principal_name = ?";
139 140
			pstmt = conn.prepareStatement(sql);
140 141

  
......
167 168
			logMetacat.error(errorStr);
168 169
			throw new AccessException(errorStr);
169 170
		} finally {
170
			try {
171
				if (pstmt != null) {
172
					pstmt.close();
173
				}
174
			} catch (SQLException sqle) {
175
				logMetacat.error("XMLAccessAccess.getXMLAccessForPrincipal - An error occurred " 
176
						+ "closing prepared statement: " + sqle.getMessage());
177
			} 
171
			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
178 172
		}		
179 173
	}
180 174
	
......
211 205
					
212 206
		// first get the job from the db and put it into a DAO
213 207
		PreparedStatement pstmt = null;
208
		DBConnection conn = null;
209
		int serialNumber = -1;
214 210
		try {
211
			conn = DBConnectionPool.getDBConnection("XMLAccessAccess.getXMLAccessForPrincipal");
212
    		serialNumber = conn.getCheckOutSerialNumber();
213
    		
215 214
			String sql = "SELECT * FROM xml_access WHERE docid = ? AND principal_name = ? " + 
216 215
				"AND perm_type = ? AND perm_order = ?";
217 216
			pstmt = conn.prepareStatement(sql);
......
247 246
			logMetacat.error(errorStr);
248 247
			throw new AccessException(errorStr);
249 248
		} finally {
250
			try {
251
				if (pstmt != null) {
252
					pstmt.close();
253
				}
254
			} catch (SQLException sqle) {
255
				logMetacat.error("XMLAccessAccess.getXMLAccessForPrincipal - An error occurred " 
256
						+ "closing prepared statement: " + sqle.getMessage());
257
			} 
249
			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
258 250
		}		
259 251
	}
260 252
	
......
275 267
	 *            permission order
276 268
	 */
277 269
	public void addXMLAccess(String docId, String principalName, Long permission, String permType, 
278
			String permOrder) throws AccessException {
270
			String permOrder) throws AccessException, PermOrderException {
271
		
272
		permOrderConflict(docId, permOrder);
273
		
279 274
		Vector<XMLAccessDAO> xmlAccessList = 
280 275
			getXMLAccessForPrincipal(docId, principalName, permType, permOrder);
281 276
		
......
299 294
		}
300 295
		
301 296
		XMLAccessDAO xmlAccessDAO = xmlAccessList.get(0);
302
		
303
		
297
				
304 298
		// if the permission on the xml access dao does not already contain the permission we are 
305 299
		//trying to add, update the access record with the existing permission bitwis OR-ed with our
306 300
		// new permission
......
318 312
	 * @param xmlAccessList
319 313
	 *            list of xml access dao objects that hold new access for the document
320 314
	 */
321
	public void setXMLAccess(String docId, Vector<XMLAccessDAO> xmlAccessList) throws AccessException {
315
	public void replaceAccess(String docId, Vector<XMLAccessDAO> xmlAccessList) throws AccessException {
322 316
		deleteXMLAccessForDoc(docId);
323 317
		
324 318
		// if more than one record exists for this principal on this document with the same
......
398 392
					+ "xml access permissions for doc id: " + docId + ", principal: " + 
399 393
					principalName + ":" + sqle.getMessage());
400 394
		} finally {
401
			try {
402
				if (pstmt != null) {
403
					pstmt.close();
404
				}
405
			} catch (SQLException sqle) {
406
				logMetacat.error("XMLAccessAccess.insertXMLAccess - SQL error when closing prepared " + 
407
						"statement after inserting xml access permissions for doc id: " + docId + 
408
						", principal: " +  principalName + ":" + sqle.getMessage());
409
			} finally {
410
				DBConnectionPool.returnDBConnection(conn, serialNumber);
411
			}
395
			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
412 396
		}   
413 397
	}
414 398
	
......
465 449
					+ "xml access permissions for doc id: " + docId + ", principal: " + 
466 450
					principalName + ":" + sqle.getMessage());
467 451
		} finally {
468
			try {
469
				if (pstmt != null) {
470
					pstmt.close();
471
				}
472
			} catch (SQLException sqle) {
473
				logMetacat.error("XMLAccessAccess.updateXMLAccessPermission - SQL error when closing prepared " + 
474
						"statement after updating xml access permissions for doc id: " + docId + 
475
						", principal: " +  principalName + ":" + sqle.getMessage());
476
			} finally {
477
				DBConnectionPool.returnDBConnection(conn, serialNumber);
478
			}
452
			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
479 453
		}
480 454
		
481 455
	}
......
564 538
			throw new AccessException("XMLAccessAccess.deleteXMLAccessForDoc - SQL error when deleting"
565 539
					+ "xml access permissions for doc id: " + docId + ":" + sqle.getMessage());
566 540
		} finally {
567
			try {
568
				if (pstmt != null) {
569
					pstmt.close();
570
				}
571
			} catch (SQLException sqle) {
572
				logMetacat.error("XMLAccessAccess.deleteXMLAccessForDoc - SQL error when closing prepared " + 
573
						"statement after deleting xml access permissions for doc id: " + ":" + sqle.getMessage());
574
			} finally {
575
				DBConnectionPool.returnDBConnection(conn, serialNumber);
576
			}
541
			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
577 542
		}	   
578 543
	}
579 544
	
......
620 585
					+ "xml access permissions for doc id: " + docId + ", principal: " + 
621 586
					principalName + ":" + sqle.getMessage());
622 587
		} finally {
623
			try {
624
				if (pstmt != null) {
625
					pstmt.close();
626
				}
627
			} catch (SQLException sqle) {
628
				logMetacat.error("XMLAccessAccess.deleteXMLAccessForPrincipal - SQL error when closing prepared " + 
629
						"statement after deleting xml access permissions for doc id: " + docId + 
630
						", principal: " +  principalName + ":" + sqle.getMessage());
631
			} finally {
632
				DBConnectionPool.returnDBConnection(conn, serialNumber);
633
			}
588
			closeDBObjects(pstmt, conn, serialNumber, logMetacat);
634 589
		}	   
635 590
	}
636 591
	
......
642 597
	 * @param principal
643 598
	 *            principal credentials
644 599
	 */
600
	private void permOrderConflict(String docId, String permOrder) throws AccessException, PermOrderException {
601
		if (docId == null) {
602
			throw new AccessException("XMLAccessAccess.permOrderConflict - docid is required when " + 
603
					"determining perm order conflict");
604
		}
605
		if (permOrder == null) {
606
			throw new AccessException("XMLAccessAccess.permOrderConflict - perm order is required when " + 
607
					"determining perm order conflict");
608
		}
609
		
610
	    PreparedStatement pstmt = null;
611
		DBConnection conn = null;
612
		int serialNumber = -1;
613
		try {
614
			// check out DBConnection
615
			conn = DBConnectionPool.getDBConnection("XMLAccessAccess.permOrderConflict");
616
			String sql = "SELECT * FROM xml_access WHERE docid = ? AND perm_order != ?";
617
			pstmt = conn.prepareStatement(sql);
618

  
619
			// Bind the values to the query
620
			pstmt.setString(1, docId);
621
			pstmt.setString(2, permOrder);
622
			
623
			String sqlReport = "XMLAccessAccess.permOrderConflict - SQL: " + sql;
624
			sqlReport += " [" + docId + "," + permOrder + "]";
625
			
626
			logMetacat.info(sqlReport);
627

  
628
			pstmt.execute();
629
			
630
			ResultSet resultSet = pstmt.getResultSet();
631
			if (resultSet.next()) {			
632
				throw new PermOrderException("XMLAccessAccess.addXMLAccess - cannot add permission " + 
633
					"record for doc id: " + docId + "with permOrder: " + permOrder + " due to permOrder conflict");
634
			}
635
		} catch (SQLException sqle) {
636
			throw new AccessException("XMLAccessAccess.permOrderConflict - SQL error when checking"
637
					+ "for perm order conflict on: " + docId + ":" + sqle.getMessage());
638
		} finally {
639
			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
640
		}
641
	   
642
	}
643
	
644
	/**
645
	 * Delete xml access.  This removes all access records from the database for a principal 
646
	 * for a given document, perm type and perm order
647
	 * @param docId
648
	 *            document id
649
	 * @param principal
650
	 *            principal credentials
651
	 */
645 652
	private void deleteXMLAccessForPrincipal(String docId, String principalName, String permType, String permOrder) throws AccessException {
646 653
		if (docId == null) {
647 654
			throw new AccessException("XMLAccessAccess.deleteXMLAccessForPrincipal - docid is required when " + 
......
668 675
		try {
669 676
			// check out DBConnection
670 677
			conn = DBConnectionPool.getDBConnection("XMLAccessAccess.deleteXMLAccessForPrincipal");
671
			String sql = "DELETE FROM xml_access WHERE docid = ? AND principal_name = ?" +
672
				"AND perm_type = ? AND perm_ord";
678
			String sql = "DELETE FROM xml_access WHERE docid = ? AND principal_name = ? " +
679
				"AND perm_type = ? AND perm_order = ?";
673 680
			pstmt = conn.prepareStatement(sql);
674 681

  
675 682
			// Bind the values to the query
......
689 696
					+ "xml access permissions for doc id: " + docId + ", principal: " + 
690 697
					principalName + ":" + sqle.getMessage());
691 698
		} finally {
692
			try {
693
				if (pstmt != null) {
694
					pstmt.close();
695
				}
696
			} catch (SQLException sqle) {
697
				logMetacat.error("XMLAccessAccess.deleteXMLAccessForPrincipal - SQL error when closing prepared " + 
698
						"statement after deleting xml access permissions for doc id: " + docId + 
699
						", principal: " +  principalName + ":" + sqle.getMessage());
700
			} finally {
701
				DBConnectionPool.returnDBConnection(conn, serialNumber);
702
			}
699
			closeDBObjects(pstmt, conn, serialNumber, logMetacat); 
703 700
		}
704 701
	   
705 702
	}
src/edu/ucsb/nceas/metacat/shared/BaseAccess.java
27 27

  
28 28
package edu.ucsb.nceas.metacat.shared;
29 29

  
30
import java.sql.PreparedStatement;
30 31
import java.sql.ResultSet;
31 32
import java.sql.SQLException;
32 33

  
34
import org.apache.log4j.Logger;
35

  
33 36
import edu.ucsb.nceas.metacat.database.DBConnection;
34 37
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
35 38

  
36 39
public abstract class BaseAccess {
37 40
	
38
	protected DBConnection conn = null;
39
    protected int serialNumber = -1;
40
    protected ResultSet rs = null;
41
	
42
    protected BaseAccess(String methodName) throws AccessException {
43
        //check out DBConnection
44
    	try {
45
    		conn = DBConnectionPool.
46
                	getDBConnection(methodName);
47
    		serialNumber = conn.getCheckOutSerialNumber();
48
    	} catch (SQLException sqle) {
49
    		throw new AccessException("Could not get connection from DB connection pool: " 
50
    				+ sqle.getMessage());
51
    	}
52
    }
53 41
    
54 42
    protected abstract BaseDAO populateDAO(ResultSet resultSet) throws SQLException ;
43
    
44
    protected void closeDBObjects(PreparedStatement pstmt, DBConnection conn,  
45
    		int serialNumber, Logger logMetacat) {
46
		try {
47
			if (pstmt != null) {
48
				pstmt.close();
49
			}
50
		} catch (SQLException sqle) {
51
			logMetacat.error("BaseAccess.closeDBObjects - An error occurred "
52
					+ "closing prepared statement: " + sqle.getMessage());
53
		} finally {
54
			DBConnectionPool.returnDBConnection(conn, serialNumber);
55
		}
56
	}
55 57
}
src/edu/ucsb/nceas/metacat/scheduler/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
	}
src/edu/ucsb/nceas/metacat/scheduler/ScheduledJobParamAccess.java
39 39

  
40 40
import org.apache.log4j.Logger;
41 41

  
42
import edu.ucsb.nceas.metacat.database.DBConnection;
42 43
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
43 44
import edu.ucsb.nceas.metacat.shared.AccessException;
44 45
import edu.ucsb.nceas.metacat.shared.BaseAccess;
......
49 50
	private Logger logMetacat = Logger.getLogger(ScheduledJobParamAccess.class);
50 51
	
51 52
	// Constructor
52
	public ScheduledJobParamAccess() throws AccessException {
53
		super("ScheduledJobParamsAccess");
54
	}
53
	public ScheduledJobParamAccess() throws AccessException {}
55 54
	
56 55
	/**
57 56
	 * Insert job parameters into the database.
......
72 71
			jobParamsDAO.setValue(jobParams.get(paramKey));
73 72
			
74 73
			PreparedStatement pstmt = null;
74
			DBConnection conn = null;
75
			int serialNumber = -1;
75 76
			
76 77
			try {
78
				conn = DBConnectionPool.getDBConnection("ScheduledJobParamAccess.createJobParams");
79
	    		serialNumber = conn.getCheckOutSerialNumber();
80

  
77 81
				String sql = 
78 82
					"INSERT INTO scheduled_job_params (date_created, date_updated, status, job_id, key, value) " 
79 83
					+ "VALUES(now(), now(), ?, ?, ?, ?)";		
......
96 100
				throw new AccessException("ScheduledJobParamsAccess.createJobParams - SQL error when creating scheduled job parameter : "    
97 101
					 + sqle.getMessage());
98 102
			} finally {
99
				try {
100
					if (pstmt != null) {
101
						pstmt.close();
102
					}
103
				} catch (SQLException sqle) {
104
					logMetacat.error("ScheduledJobParamAccess.createJobParams - An error occurred " 
105
							+ "closing prepared statement: " + sqle.getMessage());
106
				} finally {
107
					DBConnectionPool.returnDBConnection(conn, serialNumber);
108
				}
103
				closeDBObjects(pstmt, conn, serialNumber, logMetacat);
109 104
			}	
110 105
		}
111 106
	}
......
118 113
	 */
119 114
	protected void deleteJobParams(Long jobId) throws AccessException {
120 115
		PreparedStatement pstmt = null;
116
		DBConnection conn = null;
117
		int serialNumber = -1;
121 118
		
122 119
		// change the status to deleted
123 120
		try {
121
			conn = DBConnectionPool.getDBConnection("ScheduledJobParamAccess.deleteJobParams");
122
    		serialNumber = conn.getCheckOutSerialNumber();
123

  
124 124
			String sql = "UPDATE scheduled_job_params SET status = ? WHERE jobId = ?";		
125 125
			pstmt = conn.prepareStatement(sql);
126 126
			
......
134 134
			throw new AccessException("ScheduledJobParamsAccess.deleteJobParams - SQL error " 
135 135
					+ "when deleting scheduled job params for job" + jobId  + " : "  + sqle.getMessage());
136 136
		} finally {
137
			try {
138
				if (pstmt != null) {
139
					pstmt.close();
140
				}
141
			} catch (SQLException sqle) {
142
				logMetacat.error("ScheduledJobParamsAccess.deleteJobParams - An error occurred " 
143
						+ "closing prepared statement: " + sqle.getMessage());
144
			} finally {
145
				DBConnectionPool.returnDBConnection(conn, serialNumber);
146
			}
137
			closeDBObjects(pstmt, conn, serialNumber, logMetacat);
147 138
		}	
148 139
		
149 140
	}	
......
160 151
		
161 152
		// Get the job parameters for the job id
162 153
		PreparedStatement pstmt = null;
154
		DBConnection conn = null;
155
		int serialNumber = -1;
156
		
163 157
		ScheduledJobParamDAO jobParamDAO = null;
164 158
		try {
159
			conn = DBConnectionPool.getDBConnection("ScheduledJobParamAccess.getJobParamsForJobId");
160
    		serialNumber = conn.getCheckOutSerialNumber();
161

  
165 162
			String sql = "SELECT * FROM scheduled_job_params WHERE job_id = ? AND status != 'deleted'"; 
166 163
			pstmt = conn.prepareStatement(sql);
167 164

  
......
185 182
			throw new AccessException("ScheduledJobAccess.getJobParamsForJobId - SQL error when getting " 
186 183
					+ "scheduled job parameter for job id: " + jobId  + " : "  + sqle.getMessage());
187 184
		} finally {
188
			try {
189
				if (pstmt != null) {
190
					pstmt.close();
191
				}
192
			} catch (SQLException sqle) {
193
				logMetacat.error("ScheduledJobParamAccess.getJobParamsForJobId - An error occurred " 
194
						+ "closing prepared statement: " + sqle.getMessage());
195
			} finally {
196
				DBConnectionPool.returnDBConnection(conn, serialNumber);
197
			}
185
			closeDBObjects(pstmt, conn, serialNumber, logMetacat);
198 186
		}
199 187
		
200 188
	}
......
209 197
		
210 198
		// get all job parameters
211 199
		PreparedStatement pstmt = null;
200
		DBConnection conn = null;
201
		int serialNumber = -1;
202
		
212 203
		ScheduledJobParamDAO jobParamDAO = null;
213 204
		try {
205
			conn = DBConnectionPool.getDBConnection("ScheduledJobParamAccess.getAllJobParams");
206
    		serialNumber = conn.getCheckOutSerialNumber();
207

  
214 208
			String sql = "SELECT * FROM scheduled_job_params WHERE status != 'deleted'"; 
215 209
			pstmt = conn.prepareStatement(sql);
216 210
			
......
231 225
			throw new AccessException("ScheduledJobParamAccess.getAllJobParams - SQL error when getting " 
232 226
					+ "scheduled job parameters : "  + sqle.getMessage());
233 227
		} finally {
234
			try {
235
				if (pstmt != null) {
236
					pstmt.close();
237
				}
238
			} catch (SQLException sqle) {
239
				logMetacat.error("ScheduledJobParamsAccess.getAllJobParams - An error occurred " 
240
						+ "closing prepared statement: " + sqle.getMessage());
241
			} finally {
242
				DBConnectionPool.returnDBConnection(conn, serialNumber);
243
			}
228
			closeDBObjects(pstmt, conn, serialNumber, logMetacat);
244 229
		}
245 230
		
246 231
	}

Also available in: Unified diff