Revision 1215
Added by Jing Tao over 22 years ago
src/edu/ucsb/nceas/metacat/AccessionNumber.java | ||
---|---|---|
45 | 45 |
|
46 | 46 |
private static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter; |
47 | 47 |
|
48 |
private Connection conn = null; |
|
48 |
//private Connection conn = null;
|
|
49 | 49 |
private String sitecode = null; |
50 | 50 |
private String sep = null; |
51 | 51 |
private String docid = null; |
... | ... | |
54 | 54 |
/** |
55 | 55 |
* Construct an AccessionNumber |
56 | 56 |
*/ |
57 |
public AccessionNumber () |
|
58 |
throws SQLException, ClassNotFoundException |
|
59 |
{ |
|
57 |
//public AccessionNumber ()
|
|
58 |
//throws SQLException, ClassNotFoundException
|
|
59 |
//{
|
|
60 | 60 |
// Open a connection to the database from here |
61 |
this((new MetaCatUtil()).openDBConnection()); |
|
62 |
} |
|
61 |
//this((new MetaCatUtil()).openDBConnection());
|
|
62 |
//}
|
|
63 | 63 |
|
64 | 64 |
/** |
65 | 65 |
* Construct an AccessionNumber |
66 | 66 |
* |
67 | 67 |
* @param conn the db connection to read from and write Accession# to |
68 | 68 |
*/ |
69 |
public AccessionNumber (Connection conn)
|
|
69 |
public AccessionNumber () |
|
70 | 70 |
{ |
71 | 71 |
this.sitecode = MetaCatUtil.getOption("sitecode"); |
72 | 72 |
this.sep = MetaCatUtil.getOption("accNumSeparator"); |
73 |
this.conn = conn; |
|
73 |
//this.conn = conn;
|
|
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
/** NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT |
... | ... | |
79 | 79 |
* @param conn the db connection to read Accession number from |
80 | 80 |
* @param accnum the accession number to be checked for validness |
81 | 81 |
*/ |
82 |
public AccessionNumber (Connection conn, String accnum, String action)
|
|
82 |
public AccessionNumber (String accnum, String action) |
|
83 | 83 |
throws AccessionNumberException, SQLException, NumberFormatException |
84 | 84 |
{ |
85 |
this(conn);
|
|
85 |
this(); |
|
86 | 86 |
|
87 | 87 |
this.rev = null; |
88 | 88 |
this.docid = accnum; |
... | ... | |
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(conn.getConnections(), |
|
263 |
"accession_number"); |
|
264 |
//because we only count the connection usage one when it check in |
|
265 |
//but it use twice. So we need to increase one |
|
266 |
conn.increaseUsageCount(1); |
|
258 | 267 |
|
259 | 268 |
} catch (SQLException e) { |
260 | 269 |
throw new |
261 | 270 |
SQLException("Error on AccessionNumber.getUniqueID(): "+e.getMessage()); |
262 | 271 |
} |
263 |
|
|
272 |
finally |
|
273 |
{ |
|
274 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
275 |
} |
|
264 | 276 |
return uniqueid; |
265 | 277 |
} |
266 | 278 |
|
... | ... | |
269 | 281 |
throws SQLException { |
270 | 282 |
|
271 | 283 |
boolean hasAccNumber = false; |
284 |
DBConnection conn = null; |
|
285 |
int serialNumber = -1; |
|
272 | 286 |
|
273 | 287 |
try { |
274 |
PreparedStatement pstmt; |
|
288 |
PreparedStatement pstmt = null; |
|
289 |
//check out DBConnection |
|
290 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberUsed"); |
|
291 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
275 | 292 |
pstmt = conn.prepareStatement( |
276 | 293 |
"SELECT 'x' FROM xml_documents " + |
277 | 294 |
"WHERE docid = ? " + |
... | ... | |
288 | 305 |
} catch (SQLException e) { |
289 | 306 |
throw new SQLException |
290 | 307 |
("Error on AccessionNumber.accNumberUsed(accNumber): " + e.getMessage()); |
291 |
} |
|
308 |
} |
|
309 |
finally |
|
310 |
{ |
|
311 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
312 |
} |
|
292 | 313 |
|
293 | 314 |
return hasAccNumber; |
294 | 315 |
} |
... | ... | |
297 | 318 |
private boolean accNumberIsCurrent(String accNumber) throws SQLException { |
298 | 319 |
|
299 | 320 |
boolean hasCurrentAccNumber = false; |
321 |
DBConnection conn = null; |
|
322 |
int serialNumber = -1; |
|
300 | 323 |
|
301 | 324 |
try { |
302 |
PreparedStatement pstmt; |
|
325 |
PreparedStatement pstmt = null; |
|
326 |
//check out DBConnection |
|
327 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberIsCurre"); |
|
328 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
303 | 329 |
pstmt = conn.prepareStatement( |
304 | 330 |
"SELECT 'x' FROM xml_documents " + |
305 | 331 |
"WHERE docid = ?"); |
... | ... | |
313 | 339 |
throw new SQLException( |
314 | 340 |
"Error on AccessionNumber.accNumberIsCurrent(String accNumber): " + |
315 | 341 |
e.getMessage()); |
316 |
} |
|
342 |
} |
|
343 |
finally |
|
344 |
{ |
|
345 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
346 |
} |
|
317 | 347 |
|
318 | 348 |
return hasCurrentAccNumber; |
319 | 349 |
} |
... | ... | |
322 | 352 |
private String getLastRevision(String docid) throws SQLException |
323 | 353 |
{ |
324 | 354 |
String rev = ""; |
355 |
DBConnection conn = null; |
|
356 |
int serialNumber = -1; |
|
325 | 357 |
|
326 | 358 |
try { |
327 |
PreparedStatement pstmt; |
|
359 |
PreparedStatement pstmt = null; |
|
360 |
//check out DBConnection |
|
361 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevision"); |
|
362 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
328 | 363 |
pstmt = conn.prepareStatement |
329 | 364 |
("SELECT rev FROM xml_documents WHERE docid='" + docid + "'"); |
330 | 365 |
pstmt.execute(); |
... | ... | |
338 | 373 |
throw new SQLException( |
339 | 374 |
"Error on AccessionNumber.getLastRevision(): " + e.getMessage()); |
340 | 375 |
} |
376 |
finally |
|
377 |
{ |
|
378 |
DBConnectionPool.returnDBConnection(conn,serialNumber); |
|
379 |
} |
|
341 | 380 |
|
342 | 381 |
return rev; |
343 | 382 |
} |
... | ... | |
350 | 389 |
private int getLastRevisionNumber(String docId) throws SQLException |
351 | 390 |
{ |
352 | 391 |
int rev = 1; |
392 |
DBConnection conn =null; |
|
393 |
int serialNumber = -1; |
|
353 | 394 |
|
354 | 395 |
try { |
355 |
PreparedStatement pStmt; |
|
396 |
PreparedStatement pStmt = null; |
|
397 |
//check out DBConnection |
|
398 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevisionN"); |
|
399 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
400 |
|
|
356 | 401 |
pStmt = conn.prepareStatement |
357 | 402 |
("SELECT rev FROM xml_documents WHERE docid='" + docId + "'"); |
358 | 403 |
pStmt.execute(); |
... | ... | |
366 | 411 |
throw new SQLException( |
367 | 412 |
"Error on AccessionNumber.getLastRevision(): " + e.getMessage()); |
368 | 413 |
} |
369 |
|
|
414 |
finally |
|
415 |
{ |
|
416 |
DBConnectionPool.returnDBConnection(conn,serialNumber); |
|
417 |
} |
|
370 | 418 |
return rev; |
371 | 419 |
} |
372 | 420 |
|
... | ... | |
374 | 422 |
private String getNextRevision(String docid) throws SQLException |
375 | 423 |
{ |
376 | 424 |
String rev = ""; |
377 |
|
|
425 |
DBConnection conn = null; |
|
426 |
int serialNumber = -1; |
|
378 | 427 |
try { |
379 |
PreparedStatement pstmt; |
|
428 |
PreparedStatement pstmt = null; |
|
429 |
//check out DBConnection |
|
430 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getNextRevision"); |
|
431 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
380 | 432 |
pstmt = conn.prepareStatement |
381 | 433 |
("SELECT rev+1 FROM xml_documents WHERE docid='" + docid + "'"); |
382 | 434 |
pstmt.execute(); |
... | ... | |
390 | 442 |
throw new SQLException( |
391 | 443 |
"Error on AccessionNumber.getNextRevision(): " + e.getMessage()); |
392 | 444 |
} |
445 |
finally |
|
446 |
{ |
|
447 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
448 |
} |
|
393 | 449 |
|
394 | 450 |
return rev; |
395 | 451 |
} |
Also available in: Unified diff
Merge DBConnection branch to head.