Revision 954
Added by Jing Tao almost 23 years ago
src/edu/ucsb/nceas/metacat/AccessionNumber.java | ||
---|---|---|
80 | 80 |
* @param accnum the accession number to be checked for validness |
81 | 81 |
*/ |
82 | 82 |
public AccessionNumber (Connection conn, String accnum, String action) |
83 |
throws AccessionNumberException, SQLException
|
|
84 |
{
|
|
83 |
throws AccessionNumberException, SQLException, NumberFormatException
|
|
84 |
{ |
|
85 | 85 |
this(conn); |
86 | 86 |
|
87 | 87 |
this.rev = null; |
... | ... | |
121 | 121 |
// UPDATE or DELETE |
122 | 122 |
} else if ( action.equals("UPDATE") || action.equals("DELETE")) { |
123 | 123 |
String l_rev = ""; |
124 |
int reversionNumber=Integer.parseInt(rev); |
|
124 | 125 |
|
125 | 126 |
// Accession# is not provided; throw an exception to prevent the action |
126 | 127 |
if ( docid == null ) { |
... | ... | |
136 | 137 |
throw new AccessionNumberException |
137 | 138 |
("Document not found for Accession number " + docid); |
138 | 139 |
|
139 |
// Revision number is not the recent one; throw an exception
|
|
140 |
//Revision number is less than or equal the recent one; throw a exception
|
|
140 | 141 |
} else if ( action.equals("UPDATE") && |
141 |
!rev.equals(l_rev = getNextRevision(docid)) ) {
|
|
142 |
reversionNumber <= getLastRevisionNumber(docid) ) {
|
|
142 | 143 |
throw new AccessionNumberException |
143 |
("Next revision number must be "+ l_rev); |
|
144 |
("Next revision number couldn't be less than or equal " |
|
145 |
+ getLastRevisionNumber(docid)); |
|
144 | 146 |
|
145 | 147 |
// Revision number is not the recent one; throw an exception |
146 | 148 |
} else if ( action.equals("DELETE") && |
... | ... | |
339 | 341 |
|
340 | 342 |
return rev; |
341 | 343 |
} |
344 |
|
|
345 |
/** |
|
346 |
* Get last revision number from database for a docid |
|
347 |
* The return value is integer because we want compare it to there new one |
|
348 |
* @param docid <sitecode>.<uniqueid> part of Accession Number |
|
349 |
*/ |
|
350 |
private int getLastRevisionNumber(String docId) throws SQLException |
|
351 |
{ |
|
352 |
int rev = 1; |
|
353 |
|
|
354 |
try { |
|
355 |
PreparedStatement pStmt; |
|
356 |
pStmt = conn.prepareStatement |
|
357 |
("SELECT rev FROM xml_documents WHERE docid='" + docId + "'"); |
|
358 |
pStmt.execute(); |
|
342 | 359 |
|
360 |
ResultSet rs = pStmt.getResultSet(); |
|
361 |
boolean hasRow = rs.next(); |
|
362 |
rev = rs.getInt(1); |
|
363 |
pStmt.close(); |
|
364 |
|
|
365 |
} catch (SQLException e) { |
|
366 |
throw new SQLException( |
|
367 |
"Error on AccessionNumber.getLastRevision(): " + e.getMessage()); |
|
368 |
} |
|
369 |
|
|
370 |
return rev; |
|
371 |
} |
|
372 |
|
|
343 | 373 |
// get the next revision number for docid |
344 | 374 |
private String getNextRevision(String docid) throws SQLException |
345 | 375 |
{ |
Also available in: Unified diff
A method named getLastRevisionNumber was added. And condition for checking accession number was revised too. Now metacat wouldn't refuse a revsion number which is 2 or more greater than current revision number in the database. This is for bug 417.