Revision 5108
Added by daigle over 14 years ago
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
move dbconnection object out of base class and create it for each db access so it can be released