Revision 847
Added by Matt Jones about 23 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
327 | 327 |
handleGetDataGuideAction(out, params, response); |
328 | 328 |
} else if (action.equals("getlastdocid")) { |
329 | 329 |
PrintWriter out = response.getWriter(); |
330 |
handleGetLastDocidAction(out, params, response);
|
|
330 |
handleGetMaxDocidAction(out, params, response);
|
|
331 | 331 |
} else if (action.equals("login") || action.equals("logout")) { |
332 | 332 |
} else if (action.equals("protocoltest")) { |
333 | 333 |
String testURL = "metacat://dev.nceas.ucsb.edu/NCEAS.897766.9"; |
... | ... | |
1445 | 1445 |
* Handle the "getlastdocid" action. |
1446 | 1446 |
* Get the latest docid with rev number from db connection in XML format |
1447 | 1447 |
*/ |
1448 |
private void handleGetLastDocidAction(PrintWriter out, Hashtable params,
|
|
1448 |
private void handleGetMaxDocidAction(PrintWriter out, Hashtable params,
|
|
1449 | 1449 |
HttpServletResponse response) { |
1450 | 1450 |
|
1451 | 1451 |
Connection conn = null; |
1452 |
String username = ((String[])params.get("username"))[0]; |
|
1452 |
String scope = ((String[])params.get("scope"))[0]; |
|
1453 |
if (scope == null) { |
|
1454 |
scope = ((String[])params.get("username"))[0]; |
|
1455 |
} |
|
1453 | 1456 |
|
1454 | 1457 |
try { |
1455 | 1458 |
|
1456 | 1459 |
// get connection from the pool |
1457 | 1460 |
conn = util.getConnection(); |
1458 | 1461 |
DBUtil dbutil = new DBUtil(conn); |
1459 |
String lastDocid = dbutil.getLastDocid(username);
|
|
1462 |
String lastDocid = dbutil.getMaxDocid(scope);
|
|
1460 | 1463 |
out.println("<?xml version=\"1.0\"?>"); |
1461 | 1464 |
out.println("<lastDocid>"); |
1462 |
out.println(" <username>" + username + "</username>");
|
|
1465 |
out.println(" <scope>" + scope + "</scope>");
|
|
1463 | 1466 |
out.println(" <docid>" + lastDocid + "</docid>"); |
1464 | 1467 |
out.println("</lastDocid>"); |
1465 | 1468 |
|
src/edu/ucsb/nceas/metacat/DBUtil.java | ||
---|---|---|
92 | 92 |
String dtdschema = dbutil.readDTDSchema(doctype); |
93 | 93 |
System.out.println(dtdschema); |
94 | 94 |
} else if ( args[0].equals("-dl") ) { |
95 |
String username = "";
|
|
96 |
if ( args.length == 2 ) { username = args[1]; }
|
|
97 |
String docid = dbutil.getLastDocid(username);
|
|
95 |
String scope = "";
|
|
96 |
if ( args.length == 2 ) { scope = args[1]; }
|
|
97 |
String docid = dbutil.getMaxDocid(scope);
|
|
98 | 98 |
System.out.println(docid); |
99 | 99 |
} else { |
100 | 100 |
System.err.println( |
... | ... | |
348 | 348 |
} |
349 | 349 |
|
350 | 350 |
/** |
351 |
* get the lastest Accession Number used by user
|
|
351 |
* get the lastest Accession Number from a particular scope
|
|
352 | 352 |
*/ |
353 |
public String getLastDocid(String user)
|
|
353 |
public String getMaxDocid(String scope)
|
|
354 | 354 |
throws SQLException { |
355 | 355 |
|
356 | 356 |
String accnum = null; |
... | ... | |
359 | 359 |
try { |
360 | 360 |
|
361 | 361 |
PreparedStatement pstmt = |
362 |
conn.prepareStatement("SELECT docid, rev, date_updated " + |
|
363 |
"FROM xml_documents " + |
|
364 |
"WHERE user_owner = ? " + |
|
365 |
"AND date_updated = (SELECT MAX(date_updated) " + |
|
366 |
"FROM xml_documents " + |
|
367 |
"WHERE user_owner = ?) " + |
|
368 |
"UNION " + |
|
369 |
"SELECT docid, rev, date_updated " + |
|
370 |
"FROM xml_revisions " + |
|
371 |
"WHERE user_owner = ? " + |
|
372 |
"AND date_updated = (SELECT MAX(date_updated) " + |
|
373 |
"FROM xml_revisions " + |
|
374 |
"WHERE user_owner = ?) " + |
|
375 |
"ORDER BY date_updated"); |
|
376 |
pstmt.setString(1,user); |
|
377 |
pstmt.setString(2,user); |
|
378 |
pstmt.setString(3,user); |
|
379 |
pstmt.setString(4,user); |
|
362 |
conn.prepareStatement( |
|
363 |
"SELECT docid, rev, acc FROM " + |
|
364 |
"( " + |
|
365 |
"SELECT docid, rev, acc FROM " + |
|
366 |
"(" + |
|
367 |
"SELECT docid, rev, " + |
|
368 |
"SUBSTR(docid, INSTR(docid, '" + sep + "', 1)+1)+0 acc " + |
|
369 |
"FROM xml_documents " + |
|
370 |
"WHERE docid LIKE ? " + |
|
371 |
"ORDER BY acc DESC " + |
|
372 |
") " + |
|
373 |
"WHERE rownum = 1 " + |
|
374 |
"UNION " + |
|
375 |
"SELECT docid, rev, acc FROM " + |
|
376 |
"(" + |
|
377 |
"SELECT docid, rev, " + |
|
378 |
"SUBSTR(docid, INSTR(docid, '" + sep + "', 1)+1)+0 acc " + |
|
379 |
"FROM xml_revisions " + |
|
380 |
"WHERE docid LIKE ? " + |
|
381 |
"ORDER BY acc DESC " + |
|
382 |
") " + |
|
383 |
"WHERE rownum = 1 " + |
|
384 |
") " + |
|
385 |
"ORDER BY acc DESC" |
|
386 |
); |
|
387 |
|
|
388 |
pstmt.setString(1,scope + sep + "%"); |
|
389 |
pstmt.setString(2,scope + sep + "%"); |
|
380 | 390 |
pstmt.execute(); |
381 | 391 |
ResultSet rs = pstmt.getResultSet(); |
382 |
boolean tableHasRows = rs.next(); //0, 1 or 2 possible num of rows |
|
383 |
// get the last one which is the latest accnum |
|
384 |
while (tableHasRows) { |
|
392 |
boolean tableHasRows = rs.next(); |
|
393 |
// 0, 1 or 2 possible num of rows |
|
394 |
// get the first one which is the max accnum |
|
395 |
if (tableHasRows) { |
|
385 | 396 |
accnum = rs.getString(1) + sep + rs.getString(2); |
386 |
tableHasRows = rs.next(); |
|
397 |
//tableHasRows = rs.next();
|
|
387 | 398 |
} |
388 | 399 |
|
389 | 400 |
pstmt.close(); |
390 | 401 |
|
391 | 402 |
} catch (SQLException e) { |
392 |
throw new SQLException("DBUtil.readLastDocid(). " + e.getMessage());
|
|
403 |
throw new SQLException("DBUtil.getMaxDocid(). " + e.getMessage());
|
|
393 | 404 |
} |
394 | 405 |
|
395 | 406 |
return accnum; |
Also available in: Unified diff
Fixed the function to return the max id for a given scope. Now the function
takes a parameter named 'scope' and returns the largest docid that has been
used under that scope in this metacat instance (it used to return the most
recently created docid, which is clearly different). For compatibility with
older versions of metacat the routine falls back to using the username
parameter if scope is not provided, but this is deprecated in favor of using
the scope parameter.