Revision 1130
Added by Jing Tao over 22 years ago
src/edu/ucsb/nceas/metacat/AccessionNumber.java | ||
---|---|---|
244 | 244 |
{ |
245 | 245 |
String uniqueid; |
246 | 246 |
String sysdate = dbAdapter.getDateTimeFunction(); |
247 |
|
|
247 |
DBConnection conn = null; |
|
248 |
int serialNumber = -1; |
|
248 | 249 |
try { |
249 |
PreparedStatement pstmt; |
|
250 |
PreparedStatement pstmt = null; |
|
251 |
|
|
252 |
//check out DBConnection |
|
253 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getUniqueID"); |
|
254 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
250 | 255 |
pstmt = conn.prepareStatement |
251 | 256 |
("INSERT INTO accession_number (site_code, date_created) " + |
252 | 257 |
"VALUES (?, " + sysdate + ")"); |
... | ... | |
254 | 259 |
pstmt.execute(); |
255 | 260 |
pstmt.close(); |
256 | 261 |
|
257 |
uniqueid = "" + dbAdapter.getUniqueID(conn, "accession_number");
|
|
262 |
uniqueid = "" + dbAdapter.getUniqueID("accession_number"); |
|
258 | 263 |
|
259 | 264 |
} catch (SQLException e) { |
260 | 265 |
throw new |
261 | 266 |
SQLException("Error on AccessionNumber.getUniqueID(): "+e.getMessage()); |
262 | 267 |
} |
263 |
|
|
268 |
finally |
|
269 |
{ |
|
270 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
271 |
} |
|
264 | 272 |
return uniqueid; |
265 | 273 |
} |
266 | 274 |
|
... | ... | |
269 | 277 |
throws SQLException { |
270 | 278 |
|
271 | 279 |
boolean hasAccNumber = false; |
280 |
DBConnection conn = null; |
|
281 |
int serialNumber = -1; |
|
272 | 282 |
|
273 | 283 |
try { |
274 |
PreparedStatement pstmt; |
|
284 |
PreparedStatement pstmt = null; |
|
285 |
//check out DBConnection |
|
286 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberUsed"); |
|
287 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
275 | 288 |
pstmt = conn.prepareStatement( |
276 | 289 |
"SELECT 'x' FROM xml_documents " + |
277 | 290 |
"WHERE docid = ? " + |
... | ... | |
288 | 301 |
} catch (SQLException e) { |
289 | 302 |
throw new SQLException |
290 | 303 |
("Error on AccessionNumber.accNumberUsed(accNumber): " + e.getMessage()); |
291 |
} |
|
304 |
} |
|
305 |
finally |
|
306 |
{ |
|
307 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
308 |
} |
|
292 | 309 |
|
293 | 310 |
return hasAccNumber; |
294 | 311 |
} |
... | ... | |
297 | 314 |
private boolean accNumberIsCurrent(String accNumber) throws SQLException { |
298 | 315 |
|
299 | 316 |
boolean hasCurrentAccNumber = false; |
317 |
DBConnection conn = null; |
|
318 |
int serialNumber = -1; |
|
300 | 319 |
|
301 | 320 |
try { |
302 |
PreparedStatement pstmt; |
|
321 |
PreparedStatement pstmt = null; |
|
322 |
//check out DBConnection |
|
323 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberIsCurre"); |
|
324 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
303 | 325 |
pstmt = conn.prepareStatement( |
304 | 326 |
"SELECT 'x' FROM xml_documents " + |
305 | 327 |
"WHERE docid = ?"); |
... | ... | |
313 | 335 |
throw new SQLException( |
314 | 336 |
"Error on AccessionNumber.accNumberIsCurrent(String accNumber): " + |
315 | 337 |
e.getMessage()); |
316 |
} |
|
338 |
} |
|
339 |
finally |
|
340 |
{ |
|
341 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
342 |
} |
|
317 | 343 |
|
318 | 344 |
return hasCurrentAccNumber; |
319 | 345 |
} |
... | ... | |
322 | 348 |
private String getLastRevision(String docid) throws SQLException |
323 | 349 |
{ |
324 | 350 |
String rev = ""; |
351 |
DBConnection conn = null; |
|
352 |
int serialNumber = -1; |
|
325 | 353 |
|
326 | 354 |
try { |
327 |
PreparedStatement pstmt; |
|
355 |
PreparedStatement pstmt = null; |
|
356 |
//check out DBConnection |
|
357 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevision"); |
|
358 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
328 | 359 |
pstmt = conn.prepareStatement |
329 | 360 |
("SELECT rev FROM xml_documents WHERE docid='" + docid + "'"); |
330 | 361 |
pstmt.execute(); |
... | ... | |
338 | 369 |
throw new SQLException( |
339 | 370 |
"Error on AccessionNumber.getLastRevision(): " + e.getMessage()); |
340 | 371 |
} |
372 |
finally |
|
373 |
{ |
|
374 |
DBConnectionPool.returnDBConnection(conn,serialNumber); |
|
375 |
} |
|
341 | 376 |
|
342 | 377 |
return rev; |
343 | 378 |
} |
... | ... | |
350 | 385 |
private int getLastRevisionNumber(String docId) throws SQLException |
351 | 386 |
{ |
352 | 387 |
int rev = 1; |
388 |
DBConnection conn =null; |
|
389 |
int serialNumber = -1; |
|
353 | 390 |
|
354 | 391 |
try { |
355 |
PreparedStatement pStmt; |
|
392 |
PreparedStatement pStmt = null; |
|
393 |
//check out DBConnection |
|
394 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevisionN"); |
|
395 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
396 |
|
|
356 | 397 |
pStmt = conn.prepareStatement |
357 | 398 |
("SELECT rev FROM xml_documents WHERE docid='" + docId + "'"); |
358 | 399 |
pStmt.execute(); |
... | ... | |
366 | 407 |
throw new SQLException( |
367 | 408 |
"Error on AccessionNumber.getLastRevision(): " + e.getMessage()); |
368 | 409 |
} |
369 |
|
|
410 |
finally |
|
411 |
{ |
|
412 |
DBConnectionPool.returnDBConnection(conn,serialNumber); |
|
413 |
} |
|
370 | 414 |
return rev; |
371 | 415 |
} |
372 | 416 |
|
... | ... | |
374 | 418 |
private String getNextRevision(String docid) throws SQLException |
375 | 419 |
{ |
376 | 420 |
String rev = ""; |
377 |
|
|
421 |
DBConnection conn = null; |
|
422 |
int serialNumber = -1; |
|
378 | 423 |
try { |
379 |
PreparedStatement pstmt; |
|
424 |
PreparedStatement pstmt = null; |
|
425 |
//check out DBConnection |
|
426 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getNextRevision"); |
|
427 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
380 | 428 |
pstmt = conn.prepareStatement |
381 | 429 |
("SELECT rev+1 FROM xml_documents WHERE docid='" + docid + "'"); |
382 | 430 |
pstmt.execute(); |
... | ... | |
390 | 438 |
throw new SQLException( |
391 | 439 |
"Error on AccessionNumber.getNextRevision(): " + e.getMessage()); |
392 | 440 |
} |
441 |
finally |
|
442 |
{ |
|
443 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
444 |
} |
|
393 | 445 |
|
394 | 446 |
return rev; |
395 | 447 |
} |
Also available in: Unified diff
Change for every method to use getDBConnection and returnDBConnection to manage DBConnection.