Revision 2641
Added by Jing Tao over 18 years ago
DocumentImpl.java | ||
---|---|---|
106 | 106 |
static final int READ = 4; |
107 | 107 |
protected static final AbstractDatabase dbAdapter = MetaCatUtil.dbAdapter; |
108 | 108 |
protected DBConnection connection = null; |
109 |
protected String docid = null; |
|
110 |
protected String updatedVersion = null; |
|
109 |
//protected String updatedVersion = null; |
|
111 | 110 |
protected String docname = null; |
112 | 111 |
protected String doctype = null; |
113 | 112 |
private String validateType = null; //base on dtd or schema |
... | ... | |
116 | 115 |
private String system_id = null; |
117 | 116 |
private String userowner = null; |
118 | 117 |
private String userupdated = null; |
118 |
protected String docid = null; // without revision |
|
119 | 119 |
private int rev; |
120 | 120 |
private int serverlocation; |
121 | 121 |
private String docHomeServer; |
... | ... | |
142 | 142 |
* @param conn |
143 | 143 |
* the database connection from which to read the document |
144 | 144 |
* @param docid |
145 |
* the identifier of the document to be created |
|
145 |
* the identifier of the document to be created, it should |
|
146 |
* be with revision |
|
146 | 147 |
* @param readNodes |
147 | 148 |
* flag indicating whether the xmlnodes should be read |
148 | 149 |
*/ |
149 |
public DocumentImpl(String docid, boolean readNodes) throws McdbException
|
|
150 |
public DocumentImpl(String accNum, boolean readNodes) throws McdbException
|
|
150 | 151 |
{ |
151 | 152 |
try { |
152 | 153 |
//this.conn = conn; |
153 |
this.docid = docid; |
|
154 |
this.docid = MetaCatUtil.getDocIdFromAccessionNumber(accNum); |
|
155 |
this.rev = MetaCatUtil.getRevisionFromAccessionNumber(accNum); |
|
154 | 156 |
|
155 | 157 |
// Look up the document information |
156 |
getDocumentInfo(docid); |
|
158 |
getDocumentInfo(docid, rev);
|
|
157 | 159 |
|
158 | 160 |
if (readNodes) { |
159 | 161 |
// Download all of the document nodes using a single SQL query |
... | ... | |
235 | 237 |
this.docname = docName; |
236 | 238 |
this.doctype = docType; |
237 | 239 |
this.docid = docId; |
238 |
this.updatedVersion = newRevision; |
|
240 |
this.rev = (new Integer(newRevision)).intValue(); |
|
241 |
//this.updatedVersion = newRevision; |
|
239 | 242 |
writeDocumentToDB(action, user, pub, catalogId, serverCode, createDate, updateDate); |
240 | 243 |
} |
241 | 244 |
|
... | ... | |
384 | 387 |
DBConnection dbconn = null; |
385 | 388 |
PreparedStatement pstmt = null; |
386 | 389 |
int serialNumber = -1; |
390 |
int revision = (new Integer(rev)).intValue(); |
|
387 | 391 |
String sqlDateString = dbAdapter.getDateTimeFunction(); |
388 | 392 |
if (createDate == null) |
389 | 393 |
{ |
... | ... | |
421 | 425 |
sql.append(doctype).append("','"); |
422 | 426 |
sql.append(user).append("','"); |
423 | 427 |
sql.append(user).append("','"); |
424 |
sql.append(serverCode).append("','");
|
|
425 |
sql.append(rev).append("',");
|
|
428 |
sql.append(serverCode).append("',"); |
|
429 |
sql.append(revision).append(",");
|
|
426 | 430 |
sql.append(createDate).append(","); |
427 | 431 |
sql.append(updateDate).append(","); |
428 | 432 |
sql.append("'0')"); |
... | ... | |
433 | 437 |
sql.append(user).append("', "); |
434 | 438 |
sql.append("server_location='"); |
435 | 439 |
sql.append(serverCode).append("',"); |
436 |
sql.append("rev='");
|
|
437 |
sql.append(rev).append("',");
|
|
440 |
sql.append("rev="); |
|
441 |
sql.append(revision).append(",");
|
|
438 | 442 |
sql.append("date_updated="); |
439 | 443 |
sql.append(updateDate); |
440 | 444 |
sql.append(" where docid='"); |
... | ... | |
541 | 545 |
String action = null; |
542 | 546 |
MetaCatUtil.debugMessage("The user specifyRev: " + userSpecifyRev, 30); |
543 | 547 |
// Revision for this docid in current database |
544 |
int revInDataBase = getLatestRevisionNumber(docid);
|
|
548 |
int revInDataBase =DBUtil.getLatestRevisionInDocumentTable(docid);
|
|
545 | 549 |
MetaCatUtil.debugMessage("The rev in data base: " + revInDataBase, 30); |
546 | 550 |
// String to store the revision |
547 | 551 |
String rev = null; |
... | ... | |
1201 | 1205 |
nodeRecordMap.put(nodeId, currentNode); |
1202 | 1206 |
} |
1203 | 1207 |
|
1204 |
DocumentIdentifier doc = null; |
|
1205 |
try { |
|
1208 |
//DocumentIdentifier doc = null; |
|
1209 |
//String doc = MetaCatUtil.getDocIdFromAccessionNumber(docid); |
|
1210 |
String doc = docid; |
|
1211 |
//System.out.println("The doc is-----!!!!!!!!!!!!!!!!!! "+doc); |
|
1212 |
/*try { |
|
1206 | 1213 |
doc = new DocumentIdentifier(docid); |
1207 | 1214 |
} catch (AccessionNumberException e){ |
1208 | 1215 |
MetaCatUtil.debugMessage("AccessionNumber Exception while " |
... | ... | |
1210 | 1217 |
+ "in DocumentImpl.buildIndex for " |
1211 | 1218 |
+ "document " + docid, 10); |
1212 | 1219 |
MetaCatUtil.debugMessage(e.getMessage(), 10); |
1213 |
} |
|
1220 |
}*/
|
|
1214 | 1221 |
|
1215 | 1222 |
// Opening separate db connection for deleting and writing |
1216 | 1223 |
// XML Index -- be sure that it is all in one db transaction |
... | ... | |
1229 | 1236 |
// Delete all the entries in xml_queryresult |
1230 | 1237 |
PreparedStatement pstmt = dbConn.prepareStatement( |
1231 | 1238 |
"DELETE FROM xml_queryresult WHERE docid = ?"); |
1232 |
pstmt.setString(1, doc.getIdentifier());
|
|
1239 |
pstmt.setString(1, doc); |
|
1233 | 1240 |
pstmt.execute(); |
1234 | 1241 |
pstmt.close(); |
1235 | 1242 |
dbConn.increaseUsageCount(1); |
... | ... | |
1237 | 1244 |
// Delete all the entries in xml_queryresult |
1238 | 1245 |
pstmt = dbConn.prepareStatement( |
1239 | 1246 |
"DELETE FROM xml_path_index WHERE docid = ?"); |
1240 |
pstmt.setString(1, doc.getIdentifier());
|
|
1247 |
pstmt.setString(1, doc); |
|
1241 | 1248 |
pstmt.execute(); |
1242 | 1249 |
pstmt.close(); |
1243 | 1250 |
dbConn.increaseUsageCount(1); |
1244 |
|
|
1251 |
//System.out.println("after dleteing !!!!!!!!!!!1"); |
|
1245 | 1252 |
// Step through all of the node records we were given |
1246 | 1253 |
// and build the new index and update the database |
1247 | 1254 |
it = nodeRecordLists.iterator(); |
1255 |
//System.out.println("before iterator!!!!!!!!!!!1"); |
|
1248 | 1256 |
while (it.hasNext()) { |
1257 |
//System.out.println("here!!!!!!!!!!!!!!!"); |
|
1249 | 1258 |
NodeRecord currentNode = (NodeRecord) it.next(); |
1250 | 1259 |
HashMap pathList = new HashMap(); |
1251 | 1260 |
if (currentNode.nodetype.equals("ELEMENT") || |
... | ... | |
1304 | 1313 |
+ " ) AND n.parentnodeid=i.nodeid AND" |
1305 | 1314 |
+ " n.nodetype LIKE 'TEXT' and n.docid = ?"); |
1306 | 1315 |
|
1307 |
pstmt.setString(1, doc.getIdentifier());
|
|
1316 |
pstmt.setString(1, doc); |
|
1308 | 1317 |
|
1309 | 1318 |
pstmt.execute(); |
1310 | 1319 |
rs = pstmt.getResultSet(); |
... | ... | |
1312 | 1321 |
int count = 0; |
1313 | 1322 |
|
1314 | 1323 |
while (rs.next()) { |
1324 |
//System.out.println("update xml_path_index!!!!!!!1"); |
|
1315 | 1325 |
String docid = rs.getString(1); |
1316 | 1326 |
String nodedata = rs.getString(2); |
1317 | 1327 |
float nodedatanumerical = rs.getFloat(3); |
... | ... | |
1424 | 1434 |
*/ |
1425 | 1435 |
private void deleteNodeIndex(DBConnection conn) throws SQLException |
1426 | 1436 |
{ |
1427 |
String familyId = MetaCatUtil.getDocIdFromString(docid); |
|
1437 |
//String familyId = MetaCatUtil.getDocIdFromString(docid); |
|
1438 |
String familyId = docid; |
|
1428 | 1439 |
String sql = "DELETE FROM xml_index WHERE docid LIKE ?"; |
1429 | 1440 |
MetaCatUtil.debugMessage(sql, 55); |
1430 | 1441 |
MetaCatUtil.debugMessage("SQL is: " + sql, 60); |
... | ... | |
1460 | 1471 |
"parentnodeid) " + "VALUES (?, ?, ?, ?, ?)"); |
1461 | 1472 |
// Increase usage count for the connection |
1462 | 1473 |
conn.increaseUsageCount(1); |
1463 |
String familyId = MetaCatUtil.getDocIdFromString(docid);
|
|
1474 |
String familyId = docid;
|
|
1464 | 1475 |
pstmt.setString(3, familyId); |
1465 | 1476 |
pstmt.setString(4, doctype); |
1466 | 1477 |
|
... | ... | |
1479 | 1490 |
pstmt.close(); |
1480 | 1491 |
} |
1481 | 1492 |
|
1482 |
private boolean isRevisionOnly(DocumentIdentifier docid) throws Exception
|
|
1493 |
private boolean isRevisionOnly(String docid, int revision) throws Exception
|
|
1483 | 1494 |
{ |
1484 |
//System.out.println("inRevisionOnly");
|
|
1495 |
//System.out.println("inRevisionOnly given "+ docid + "."+ revision);
|
|
1485 | 1496 |
DBConnection dbconn = null; |
1486 | 1497 |
int serialNumber = -1; |
1487 | 1498 |
PreparedStatement pstmt = null; |
1488 |
String rev = docid.getRev(); |
|
1489 |
String newid = docid.getIdentifier(); |
|
1499 |
String newid = docid; |
|
1490 | 1500 |
|
1491 | 1501 |
try { |
1492 | 1502 |
dbconn = DBConnectionPool |
... | ... | |
1497 | 1507 |
pstmt.execute(); |
1498 | 1508 |
ResultSet rs = pstmt.getResultSet(); |
1499 | 1509 |
boolean tablehasrows = rs.next(); |
1500 |
if (rev.equals("newest") || rev.equals("all")) { return false; } |
|
1501 |
|
|
1510 |
//if (rev.equals("newest") || rev.equals("all")) { return false; }
|
|
1511 |
|
|
1502 | 1512 |
if (tablehasrows) { |
1503 | 1513 |
int r = rs.getInt(1); |
1514 |
//System.out.println("the rev in xml_documents table is "+r); |
|
1504 | 1515 |
pstmt.close(); |
1505 |
if (new Integer(rev).intValue() == r) { //the current revision
|
|
1516 |
if (revision == r) { //the current revision
|
|
1506 | 1517 |
// in in xml_documents |
1507 | 1518 |
//System.out.println("returning false"); |
1508 | 1519 |
return false; |
1509 |
} else if (new Integer(rev).intValue() < r) { //the current
|
|
1520 |
} else if (revision < r) { //the current
|
|
1510 | 1521 |
// revision is in |
1511 | 1522 |
// xml_revisions. |
1512 | 1523 |
//System.out.println("returning true"); |
1513 | 1524 |
return true; |
1514 |
} else if (new Integer(rev).intValue() > r) { //error, rev
|
|
1525 |
} else if (revision > r) { //error, rev
|
|
1515 | 1526 |
// cannot be |
1516 | 1527 |
// greater than r |
1517 | 1528 |
throw new Exception( |
1518 | 1529 |
"requested revision cannot be greater than " |
1519 | 1530 |
+ "the latest revision number."); } |
1520 | 1531 |
} |
1532 |
else |
|
1533 |
{ |
|
1534 |
//System.out.println("in revision table branch -------"); |
|
1535 |
// if we couldn't find it in xml_documents we |
|
1536 |
// need to find it in xml_revision table |
|
1537 |
Vector revList = DBUtil.getRevListFromRevisionTable(docid); |
|
1538 |
for (int i=0; i<revList.size(); i++) |
|
1539 |
{ |
|
1540 |
Integer k = (Integer) revList.elementAt(i); |
|
1541 |
//System.out.println("The rev in xml_revision talbe "+ k.toString()); |
|
1542 |
} |
|
1543 |
|
|
1544 |
if (revList.contains(new Integer(revision))) |
|
1545 |
{ |
|
1546 |
return true; |
|
1547 |
} |
|
1548 |
} |
|
1521 | 1549 |
// Get miss docid and rev, throw to McdDocNotFoundException |
1522 |
String missDocId = MetaCatUtil.getDocIdFromString(docid.toString()); |
|
1523 |
String missRevision = MetaCatUtil.getRevisionStringFromString(docid |
|
1524 |
.toString()); |
|
1550 |
String missDocId = docid; |
|
1551 |
String missRevision = (new Integer(revision)).toString(); |
|
1525 | 1552 |
throw new McdbDocNotFoundException("the requested docid '" |
1526 | 1553 |
+ docid.toString() + "' does not exist", missDocId, |
1527 | 1554 |
missRevision); |
... | ... | |
1532 | 1559 |
}//finally |
1533 | 1560 |
} |
1534 | 1561 |
|
1535 |
private void getDocumentInfo(String docid) throws McdbException, |
|
1562 |
/*private void getDocumentInfo(String docid) throws McdbException,
|
|
1536 | 1563 |
AccessionNumberException, Exception |
1537 | 1564 |
{ |
1538 | 1565 |
getDocumentInfo(new DocumentIdentifier(docid)); |
1539 |
} |
|
1566 |
}*/
|
|
1540 | 1567 |
|
1541 | 1568 |
/** |
1542 | 1569 |
* Look up the document type information from the database |
... | ... | |
1544 | 1571 |
* @param docid |
1545 | 1572 |
* the id of the document to look up |
1546 | 1573 |
*/ |
1547 |
private void getDocumentInfo(DocumentIdentifier docid)
|
|
1574 |
private void getDocumentInfo(String docid, int revision)
|
|
1548 | 1575 |
throws McdbException, Exception |
1549 | 1576 |
{ |
1550 | 1577 |
DBConnection dbconn = null; |
... | ... | |
1553 | 1580 |
String table = "xml_documents"; |
1554 | 1581 |
|
1555 | 1582 |
try { |
1556 |
if (isRevisionOnly(docid)) { //pull the document from xml_revisions |
|
1583 |
if (isRevisionOnly(docid, revision)) { //pull the document from xml_revisions
|
|
1557 | 1584 |
// instead of from xml_documents; |
1558 | 1585 |
table = "xml_revisions"; |
1559 | 1586 |
} |
... | ... | |
1577 | 1604 |
sql.append("date_created, date_updated, user_owner, user_updated,"); |
1578 | 1605 |
sql.append(" server_location, public_access, rev"); |
1579 | 1606 |
sql.append(" FROM ").append(table); |
1580 |
sql.append(" WHERE docid LIKE '").append(docid.getIdentifier());
|
|
1581 |
sql.append("' and rev like '").append(docid.getRev()).append("'");
|
|
1607 |
sql.append(" WHERE docid LIKE '").append(docid); |
|
1608 |
sql.append("' and rev like '").append(revision).append("'");
|
|
1582 | 1609 |
|
1583 | 1610 |
pstmt = dbconn.prepareStatement(sql.toString()); |
1584 | 1611 |
|
... | ... | |
1641 | 1668 |
pstmt.close(); |
1642 | 1669 |
} |
1643 | 1670 |
} catch (SQLException e) { |
1644 |
System.out.println("error in DocumentImpl.getDocumentInfo: "
|
|
1645 |
+ e.getMessage()); |
|
1671 |
MetaCatUtil.debugMessage("error in DocumentImpl.getDocumentInfo: "
|
|
1672 |
+ e.getMessage(), 30);
|
|
1646 | 1673 |
e.printStackTrace(System.out); |
1647 | 1674 |
throw new McdbException("Error accessing database connection in " |
1648 | 1675 |
+ "DocumentImpl.getDocumentInfo: ", e); |
... | ... | |
1660 | 1687 |
|
1661 | 1688 |
if (this.docname == null) { |
1662 | 1689 |
throw new McdbDocNotFoundException( |
1663 |
"Document not found: " + docid, docid.getIdentifier(), docid |
|
1664 |
.getRev()); |
|
1690 |
"Document not found: " + docid, docid, (new Integer(revision)).toString()); |
|
1665 | 1691 |
} |
1666 | 1692 |
} |
1667 | 1693 |
|
... | ... | |
1782 | 1808 |
String nodedata = null; |
1783 | 1809 |
String quotechar = dbAdapter.getStringDelimiter(); |
1784 | 1810 |
String table = "xml_nodes"; |
1785 |
|
|
1811 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!for root node id "+rootnodeid); |
|
1786 | 1812 |
try { |
1787 |
if (isRevisionOnly(new DocumentIdentifier(docid))) { //pull the document from xml_revisions
|
|
1813 |
if (isRevisionOnly(docid, rev)) { //pull the document from xml_revisions
|
|
1788 | 1814 |
// instead of from xml_documents; |
1789 | 1815 |
table = "xml_nodes_revisions"; |
1816 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!2"); |
|
1790 | 1817 |
} |
1791 | 1818 |
} catch (McdbDocNotFoundException notFound) { |
1792 | 1819 |
throw notFound; |
... | ... | |
1795 | 1822 |
MetaCatUtil.debugMessage("error in DocumentImpl.getDocumentInfo: " |
1796 | 1823 |
+ e.getMessage(), 30); |
1797 | 1824 |
} |
1798 |
|
|
1825 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!3"); |
|
1799 | 1826 |
try { |
1800 | 1827 |
dbconn = DBConnectionPool |
1801 | 1828 |
.getDBConnection("DocumentImpl.getNodeRecordList"); |
... | ... | |
1807 | 1834 |
|
1808 | 1835 |
// Bind the values to the query |
1809 | 1836 |
pstmt.setLong(1, rootnodeid); |
1810 |
|
|
1837 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!4"); |
|
1811 | 1838 |
pstmt.execute(); |
1812 | 1839 |
ResultSet rs = pstmt.getResultSet(); |
1840 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!5"); |
|
1813 | 1841 |
boolean tableHasRows = rs.next(); |
1814 | 1842 |
while (tableHasRows) { |
1843 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!6"); |
|
1815 | 1844 |
nodeid = rs.getLong(1); |
1816 | 1845 |
parentnodeid = rs.getLong(2); |
1817 | 1846 |
nodeindex = rs.getLong(3); |
... | ... | |
1829 | 1858 |
tableHasRows = rs.next(); |
1830 | 1859 |
} |
1831 | 1860 |
pstmt.close(); |
1861 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!7"); |
|
1832 | 1862 |
|
1833 | 1863 |
} catch (SQLException e) { |
1834 | 1864 |
throw new McdbException("Error in DocumentImpl.getNodeRecordList " |
... | ... | |
1844 | 1874 |
DBConnectionPool.returnDBConnection(dbconn, serialNumber); |
1845 | 1875 |
} |
1846 | 1876 |
} |
1847 |
|
|
1877 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!8"); |
|
1848 | 1878 |
return nodeRecordList; |
1849 | 1879 |
|
1850 | 1880 |
} |
... | ... | |
1853 | 1883 |
private void writeDocumentToDB(String action, String user, String pub, |
1854 | 1884 |
String catalogid, int serverCode, String createDate, String updateDate) throws SQLException, Exception |
1855 | 1885 |
{ |
1886 |
//System.out.println("!!!!!!!!1write document to db " +docid +"."+rev); |
|
1856 | 1887 |
String sysdate = dbAdapter.getDateTimeFunction(); |
1857 | 1888 |
if (createDate == null) |
1858 | 1889 |
{ |
... | ... | |
1911 | 1942 |
*/ |
1912 | 1943 |
pstmt.setInt(8, (new Integer(catalogid)).intValue()); |
1913 | 1944 |
pstmt.setInt(9, serverCode); |
1914 |
pstmt.setInt(10, Integer.parseInt(updatedVersion));
|
|
1945 |
pstmt.setInt(10, rev);
|
|
1915 | 1946 |
|
1916 | 1947 |
} else if (action.equals("UPDATE")) { |
1917 |
|
|
1948 |
int thisrev = DBUtil.getLatestRevisionInDocumentTable(docid); |
|
1949 |
MetaCatUtil.debugMessage("this revsion is: " + thisrev, 40); |
|
1918 | 1950 |
// Save the old document publicaccessentry in a backup table |
1919 |
thisdoc = new DocumentImpl(docid, false); |
|
1951 |
String accNumber = docid+MetaCatUtil.getOption("accNumSeparator")+thisrev; |
|
1952 |
thisdoc = new DocumentImpl(accNumber, false); |
|
1920 | 1953 |
DocumentImpl.archiveDocRevision(connection, docid, user, thisdoc); |
1921 | 1954 |
MetaCatUtil.debugMessage("after archiveDoc", 30); |
1922 |
|
|
1923 |
int thisrev = thisdoc.getRev(); |
|
1924 |
MetaCatUtil.debugMessage("this revsion is: " + thisrev, 40); |
|
1925 | 1955 |
//if the updated vesion is not greater than current one, |
1926 | 1956 |
//throw it into a exception |
1927 |
if (Integer.parseInt(updatedVersion) <= thisrev) {
|
|
1957 |
if (rev <= thisrev) {
|
|
1928 | 1958 |
throw new Exception("Next revision number couldn't be less" |
1929 | 1959 |
+ " than or equal " + thisrev); |
1930 | 1960 |
} else { |
1931 | 1961 |
//set the user specified revision |
1932 |
thisrev = Integer.parseInt(updatedVersion);
|
|
1962 |
thisrev = rev;
|
|
1933 | 1963 |
} |
1934 | 1964 |
MetaCatUtil.debugMessage("final revsion is: " + thisrev, 40); |
1935 | 1965 |
boolean useXMLIndex = (new Boolean(MetaCatUtil |
... | ... | |
2115 | 2145 |
+ accnum); |
2116 | 2146 |
} |
2117 | 2147 |
|
2118 |
DocumentIdentifier id = new DocumentIdentifier(accnum); |
|
2119 |
String updaterev = id.getRev(); |
|
2148 |
//DocumentIdentifier id = new DocumentIdentifier(accnum); |
|
2149 |
int revision = MetaCatUtil.getRevisionFromAccessionNumber(accnum); |
|
2150 |
String updaterev = (new Integer(revision)).toString(); |
|
2120 | 2151 |
String server = MetacatReplication |
2121 | 2152 |
.getServerNameForServerCode(serverCode); |
2122 | 2153 |
MetacatReplication.replLog("attempting to lock " + accnum); |
... | ... | |
2218 | 2249 |
|
2219 | 2250 |
conn.setAutoCommit(false); |
2220 | 2251 |
parser.parse(new InputSource(xml)); |
2252 |
//System.out.println("commit!!!!!!!!!!!!!!!!!111"); |
|
2221 | 2253 |
conn.commit(); |
2222 | 2254 |
conn.setAutoCommit(true); |
2223 | 2255 |
|
... | ... | |
2242 | 2274 |
} |
2243 | 2275 |
|
2244 | 2276 |
// run access db base on relation table and access object |
2277 |
//System.out.println("the accnum will be write into access table "+accnum); |
|
2245 | 2278 |
runRelationAndAccessHandler(accnum, user, groups, serverCode); |
2246 | 2279 |
|
2247 | 2280 |
// Delete enteries from xml_queryresult for given docid if |
... | ... | |
2322 | 2355 |
int userSpecifyRev = MetaCatUtil.getRevisionFromAccessionNumber(accnum); |
2323 | 2356 |
MetaCatUtil.debugMessage("The user specifyRev: " + userSpecifyRev, 30); |
2324 | 2357 |
// Revision for this docid in current database |
2325 |
int revInDataBase = getLatestRevisionNumber(docid);
|
|
2358 |
int revInDataBase = DBUtil.getLatestRevisionInDocumentTable(docid);
|
|
2326 | 2359 |
MetaCatUtil.debugMessage("The rev in data base: " + revInDataBase, 30); |
2327 | 2360 |
// String to store the revision |
2328 | 2361 |
String rev = (new Integer(userSpecifyRev)).toString(); |
... | ... | |
2371 | 2404 |
conn.commit(); |
2372 | 2405 |
conn.setAutoCommit(true); |
2373 | 2406 |
|
2407 |
|
|
2374 | 2408 |
// write to xml_node complete. start the indexing thread. |
2375 | 2409 |
// this only for xml_documents |
2376 | 2410 |
DBSAXHandler dbx = (DBSAXHandler) parser.getContentHandler(); |
... | ... | |
2416 | 2450 |
} catch (Exception ee) { |
2417 | 2451 |
conn.rollback(); |
2418 | 2452 |
conn.setAutoCommit(true); |
2453 |
if (tableName.equals(REVISIONTABLE)) |
|
2454 |
{ |
|
2455 |
// because we couldn't register the table into xml_revsion |
|
2456 |
// we need to delete the nodes in xml_ndoes. |
|
2457 |
deleteXMLNodes(rootId); |
|
2458 |
} |
|
2419 | 2459 |
MetacatReplication.replErrorLog("Failed to " + "create access " |
2420 | 2460 |
+ "rule for package: " + accnum + " because " |
2421 | 2461 |
+ ee.getMessage()); |
... | ... | |
2445 | 2485 |
Vector packagedoctypes = new Vector(); |
2446 | 2486 |
packagedoctypes = MetaCatUtil.getOptionList(packagedoctype); |
2447 | 2487 |
String docIdWithoutRev = MetaCatUtil.getDocIdFromString(accnumber); |
2488 |
int revision = MetaCatUtil.getRevisionFromAccessionNumber(accnumber); |
|
2448 | 2489 |
if (documenttype != null && |
2449 | 2490 |
packagedoctypes.contains(documenttype)) { |
2450 | 2491 |
dbconn = DBConnectionPool.getDBConnection( |
... | ... | |
2455 | 2496 |
String aclid = RelationHandler.getAccessFileID(docIdWithoutRev); |
2456 | 2497 |
// if there are access file, write ACL for that package |
2457 | 2498 |
if (aclid != null) { |
2458 |
runAccessControlList(dbconn, aclid, userName, group, |
|
2499 |
runAccessControlList(dbconn, aclid, revision, userName, group,
|
|
2459 | 2500 |
servercode); |
2460 | 2501 |
} |
2461 | 2502 |
dbconn.commit(); |
... | ... | |
2471 | 2512 |
serialNumber = dbconn.getCheckOutSerialNumber(); |
2472 | 2513 |
dbconn.setAutoCommit(false); |
2473 | 2514 |
// write ACL for the package |
2474 |
runAccessControlList(dbconn, docIdWithoutRev, userName, group, |
|
2515 |
runAccessControlList(dbconn, docIdWithoutRev, revision, userName, group,
|
|
2475 | 2516 |
servercode); |
2476 | 2517 |
dbconn.commit(); |
2477 | 2518 |
dbconn.setAutoCommit(true); |
... | ... | |
2496 | 2537 |
|
2497 | 2538 |
// It runs in xmlIndex thread. It writes ACL for a package. |
2498 | 2539 |
private static void runAccessControlList(DBConnection conn, String aclid, |
2499 |
String users, String[] group, int servercode) throws Exception |
|
2540 |
int rev, String users, String[] group, int servercode) throws Exception
|
|
2500 | 2541 |
{ |
2501 | 2542 |
// read the access file from xml_nodes |
2502 | 2543 |
// parse the access file and store the access info into xml_access |
2503 |
AccessControlList aclobj = new AccessControlList(conn, aclid, users, |
|
2544 |
AccessControlList aclobj = new AccessControlList(conn, aclid, rev, users,
|
|
2504 | 2545 |
group, servercode); |
2505 | 2546 |
|
2506 | 2547 |
} |
... | ... | |
2931 | 2972 |
|
2932 | 2973 |
try { |
2933 | 2974 |
if (doc == null) { |
2934 |
doc = new DocumentImpl(docid); |
|
2975 |
String accNumber = docid + MetaCatUtil.getOption("accNumSeparator") + |
|
2976 |
DBUtil.getLatestRevisionInDocumentTable(docid); |
|
2977 |
doc = new DocumentImpl(accNumber); |
|
2935 | 2978 |
} |
2936 | 2979 |
|
2937 | 2980 |
long rootNodeId = doc.getRootNodeID(); |
... | ... | |
3114 | 3157 |
} |
3115 | 3158 |
} |
3116 | 3159 |
|
3117 |
/** |
|
3118 |
* Get last revision number from database for a docid If couldn't find an |
|
3119 |
* entry, -1 will return The return value is integer because we want compare |
|
3120 |
* it to there new one |
|
3121 |
* |
|
3122 |
* @param docid |
|
3123 |
* <sitecode>. <uniqueid>part of Accession Number |
|
3124 |
*/ |
|
3125 |
public static int getLatestRevisionNumber(String docId) throws SQLException |
|
3126 |
{ |
|
3127 |
int rev = 1; |
|
3128 |
PreparedStatement pStmt = null; |
|
3129 |
DBConnection dbConn = null; |
|
3130 |
int serialNumber = -1; |
|
3131 |
// get rid of rev |
|
3132 |
docId = MetaCatUtil.getDocIdFromString(docId); |
|
3133 |
try { |
|
3134 |
//check out DBConnection |
|
3135 |
dbConn = DBConnectionPool |
|
3136 |
.getDBConnection("DocumentImpl.getLatestRevisionNumber"); |
|
3137 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
|
3160 |
|
|
3138 | 3161 |
|
3139 |
pStmt = dbConn |
|
3140 |
.prepareStatement("SELECT rev FROM xml_documents WHERE docid='" |
|
3141 |
+ docId + "'"); |
|
3142 |
pStmt.execute(); |
|
3143 |
|
|
3144 |
ResultSet rs = pStmt.getResultSet(); |
|
3145 |
boolean hasRow = rs.next(); |
|
3146 |
if (hasRow) { |
|
3147 |
rev = rs.getInt(1); |
|
3148 |
pStmt.close(); |
|
3149 |
} else { |
|
3150 |
rev = -1; |
|
3151 |
pStmt.close(); |
|
3152 |
} |
|
3153 |
}//try |
|
3154 |
finally { |
|
3155 |
try { |
|
3156 |
pStmt.close(); |
|
3157 |
} catch (Exception ee) { |
|
3158 |
MetaCatUtil.debugMessage("Error in DocumentImpl." |
|
3159 |
+ "getLatestRevisionNumber: " + ee.getMessage(), 50); |
|
3160 |
} finally { |
|
3161 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
3162 |
} |
|
3163 |
}//finally |
|
3164 |
|
|
3165 |
return rev; |
|
3166 |
}//getLatestRevisionNumber |
|
3167 |
|
|
3168 | 3162 |
/** |
3169 | 3163 |
* Get server location form database for a accNum |
3170 | 3164 |
* |
... | ... | |
3471 | 3465 |
if (action.equals("READ")) { |
3472 | 3466 |
DocumentImpl xmldoc = new DocumentImpl(docid); |
3473 | 3467 |
if (useOldReadAlgorithm) { |
3474 |
System.out.println(xmldoc.readUsingSlowAlgorithm());
|
|
3468 |
MetaCatUtil.debugMessage(xmldoc.readUsingSlowAlgorithm(), 10);
|
|
3475 | 3469 |
} else { |
3476 | 3470 |
xmldoc.toXml(new PrintWriter(System.out), null, null, true); |
3477 | 3471 |
} |
3478 | 3472 |
} else if (action.equals("DELETE")) { |
3479 | 3473 |
DocumentImpl.delete(docid, null, null,null); |
3480 |
System.out.println("Document deleted: " + docid); |
|
3474 |
//System.out.println("Document deleted: " + docid);
|
|
3481 | 3475 |
} else { |
3482 | 3476 |
/* |
3483 | 3477 |
* String newdocid = DocumentImpl.write(dbconn, filename, null, |
... | ... | |
3498 | 3492 |
double insertTime = (stopTime - connTime) / 1000; |
3499 | 3493 |
double executionTime = (stopTime - startTime) / 1000; |
3500 | 3494 |
if (showRuntime) { |
3501 |
System.out.println("\n\nTotal Execution time was: "
|
|
3502 |
+ executionTime + " seconds."); |
|
3503 |
System.out.println("Time to open DB connection was: "
|
|
3504 |
+ dbOpenTime + " seconds."); |
|
3505 |
System.out.println("Time to insert document was: " + insertTime
|
|
3506 |
+ " seconds."); |
|
3495 |
MetaCatUtil.debugMessage("\n\nTotal Execution time was: "
|
|
3496 |
+ executionTime + " seconds.", 10);
|
|
3497 |
MetaCatUtil.debugMessage("Time to open DB connection was: "
|
|
3498 |
+ dbOpenTime + " seconds.", 10);
|
|
3499 |
MetaCatUtil.debugMessage("Time to insert document was: " + insertTime
|
|
3500 |
+ " seconds.", 10);
|
|
3507 | 3501 |
} |
3508 | 3502 |
dbconn.close(); |
3509 | 3503 |
} catch (McdbException me) { |
3510 | 3504 |
me.toXml(new PrintWriter(System.err)); |
3511 | 3505 |
} catch (AccessionNumberException ane) { |
3512 |
System.out.println(ane.getMessage());
|
|
3506 |
System.err.println(ane.getMessage());
|
|
3513 | 3507 |
} catch (Exception e) { |
3514 | 3508 |
System.err.println("EXCEPTION HANDLING REQUIRED"); |
3515 | 3509 |
System.err.println(e.getMessage()); |
... | ... | |
3640 | 3634 |
DBConnectionPool.returnDBConnection(dbconn, serialNumber); |
3641 | 3635 |
} |
3642 | 3636 |
} |
3637 |
|
|
3638 |
/* |
|
3639 |
* This method will delete the xml_nodes table for a given root id |
|
3640 |
* This method will be called in the time_replication for revision table |
|
3641 |
* In revision replication, xml first will insert into xml_nodes, then |
|
3642 |
* move to xml_nodes_revision and register into xml_revsion table. |
|
3643 |
* if in the second step some error happend, we need to delete the |
|
3644 |
* node in xml_nodes table as roll back |
|
3645 |
*/ |
|
3646 |
static private void deleteXMLNodes(long rootId) throws Exception |
|
3647 |
{ |
|
3648 |
DBConnection dbconn = null; |
|
3649 |
int serialNumber = -1; |
|
3650 |
//MetaCatUtil util = new MetaCatUtil(); |
|
3651 |
AccessionNumber ac; |
|
3652 |
PreparedStatement pstmt = null; |
|
3653 |
String sql = "DELETE FROM xml_documents WHERE docid = "+ rootId; |
|
3654 |
try |
|
3655 |
{ |
|
3656 |
//dbconn = util.openDBConnection(); |
|
3657 |
dbconn = DBConnectionPool.getDBConnection( |
|
3658 |
"DeletedDocumentImpl.deletXMLNode"); |
|
3659 |
serialNumber = dbconn.getCheckOutSerialNumber(); |
|
3660 |
pstmt = dbconn.prepareStatement(sql); |
|
3661 |
// Increase dbconnection usage count |
|
3662 |
dbconn.increaseUsageCount(1); |
|
3663 |
pstmt.close(); |
|
3664 |
dbconn.close(); |
|
3665 |
} |
|
3666 |
finally |
|
3667 |
{ |
|
3668 |
|
|
3669 |
DBConnectionPool.returnDBConnection(dbconn, serialNumber); |
|
3670 |
} |
|
3671 |
} |
|
3643 | 3672 |
} |
Also available in: Unified diff
Change the code to make sure DocumentImpl class's constructor should have rev attached.