Revision 2767
Added by sgarg about 19 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
1006 | 1006 |
while (it.hasNext()) { |
1007 | 1007 |
|
1008 | 1008 |
NodeRecord currentNode = (NodeRecord) it.next(); |
1009 |
logMetacat.info("[Got Node ID: " + currentNode.nodeid + " ("
|
|
1010 |
+ currentNode.parentnodeid + ", " + currentNode.nodeindex
|
|
1011 |
+ ", " + currentNode.nodetype + ", " + currentNode.nodename
|
|
1012 |
+ ", " + currentNode.nodedata + ")]");
|
|
1009 |
logMetacat.info("[Got Node ID: " + currentNode.getNodeId() + " ("
|
|
1010 |
+ currentNode.getParentNodeId() + ", " + currentNode.getNodeIndex()
|
|
1011 |
+ ", " + currentNode.getNodeType() + ", " + currentNode.getNodeName()
|
|
1012 |
+ ", " + currentNode.getNodeData() + ")]");
|
|
1013 | 1013 |
// Print the end tag for the previous node if needed |
1014 | 1014 |
// |
1015 | 1015 |
// This is determined by inspecting the parent nodeid for the |
... | ... | |
1028 | 1028 |
// is handled by the NodeComparator class used by the TreeSet |
1029 | 1029 |
if (!atRootElement) { |
1030 | 1030 |
NodeRecord currentElement = (NodeRecord) openElements.peek(); |
1031 |
if (currentNode.parentnodeid != currentElement.nodeid) {
|
|
1032 |
while (currentNode.parentnodeid != currentElement.nodeid) {
|
|
1031 |
if (currentNode.getParentNodeId() != currentElement.getNodeId()) {
|
|
1032 |
while (currentNode.getParentNodeId() != currentElement.getNodeId()) {
|
|
1033 | 1033 |
currentElement = (NodeRecord) openElements.pop(); |
1034 | 1034 |
logMetacat.info("\n POPPED: " |
1035 |
+ currentElement.nodename);
|
|
1035 |
+ currentElement.getNodeName());
|
|
1036 | 1036 |
if (previousNodeWasElement) { |
1037 | 1037 |
out.print(">"); |
1038 | 1038 |
previousNodeWasElement = false; |
1039 | 1039 |
} |
1040 |
if (currentElement.nodeprefix != null) {
|
|
1041 |
out.print("</" + currentElement.nodeprefix + ":"
|
|
1042 |
+ currentElement.nodename + ">");
|
|
1040 |
if (currentElement.getNodePrefix() != null) {
|
|
1041 |
out.print("</" + currentElement.getNodePrefix() + ":"
|
|
1042 |
+ currentElement.getNodeName() + ">");
|
|
1043 | 1043 |
} else { |
1044 |
out.print("</" + currentElement.nodename + ">");
|
|
1044 |
out.print("</" + currentElement.getNodeName() + ">");
|
|
1045 | 1045 |
} |
1046 | 1046 |
currentElement = (NodeRecord) openElements.peek(); |
1047 | 1047 |
} |
... | ... | |
1049 | 1049 |
} |
1050 | 1050 |
|
1051 | 1051 |
// Handle the DOCUMENT node |
1052 |
if (currentNode.nodetype.equals("DOCUMENT")) {
|
|
1052 |
if (currentNode.getNodeType().equals("DOCUMENT")) {
|
|
1053 | 1053 |
out.print("<?xml version=\"1.0\"?>"); |
1054 | 1054 |
|
1055 | 1055 |
// Handle the ELEMENT nodes |
1056 |
} else if (currentNode.nodetype.equals("ELEMENT")) {
|
|
1056 |
} else if (currentNode.getNodeType().equals("ELEMENT")) {
|
|
1057 | 1057 |
if (atRootElement) { |
1058 | 1058 |
atRootElement = false; |
1059 | 1059 |
} else { |
... | ... | |
1079 | 1079 |
} |
1080 | 1080 |
firstElement = false; |
1081 | 1081 |
openElements.push(currentNode); |
1082 |
logMetacat.info("\n PUSHED: " + currentNode.nodename);
|
|
1082 |
logMetacat.info("\n PUSHED: " + currentNode.getNodeName());
|
|
1083 | 1083 |
previousNodeWasElement = true; |
1084 |
if (currentNode.nodeprefix != null) {
|
|
1085 |
out.print("<" + currentNode.nodeprefix + ":"
|
|
1086 |
+ currentNode.nodename);
|
|
1084 |
if (currentNode.getNodePrefix() != null) {
|
|
1085 |
out.print("<" + currentNode.getNodePrefix() + ":"
|
|
1086 |
+ currentNode.getNodeName());
|
|
1087 | 1087 |
} else { |
1088 |
out.print("<" + currentNode.nodename);
|
|
1088 |
out.print("<" + currentNode.getNodeName());
|
|
1089 | 1089 |
} |
1090 | 1090 |
|
1091 | 1091 |
// if currentNode is inline and handle eml2, set flag proccess |
1092 | 1092 |
// in |
1093 |
if (currentNode.nodename != null
|
|
1094 |
&& currentNode.nodename.equals(Eml200SAXHandler.INLINE)
|
|
1093 |
if (currentNode.getNodeName() != null
|
|
1094 |
&& currentNode.getNodeName().equals(Eml200SAXHandler.INLINE)
|
|
1095 | 1095 |
&& proccessEml2) { |
1096 | 1096 |
prcocessInlineData = true; |
1097 | 1097 |
} |
1098 | 1098 |
|
1099 | 1099 |
// Handle the ATTRIBUTE nodes |
1100 |
} else if (currentNode.nodetype.equals("ATTRIBUTE")) {
|
|
1101 |
if (currentNode.nodeprefix != null) {
|
|
1102 |
out.print(" " + currentNode.nodeprefix + ":"
|
|
1103 |
+ currentNode.nodename + "=\""
|
|
1104 |
+ currentNode.nodedata + "\"");
|
|
1100 |
} else if (currentNode.getNodeType().equals("ATTRIBUTE")) {
|
|
1101 |
if (currentNode.getNodePrefix() != null) {
|
|
1102 |
out.print(" " + currentNode.getNodePrefix() + ":"
|
|
1103 |
+ currentNode.getNodeName() + "=\""
|
|
1104 |
+ currentNode.getNodeData() + "\"");
|
|
1105 | 1105 |
} else { |
1106 |
out.print(" " + currentNode.nodename + "=\""
|
|
1107 |
+ currentNode.nodedata + "\"");
|
|
1106 |
out.print(" " + currentNode.getNodeName() + "=\""
|
|
1107 |
+ currentNode.getNodeData() + "\"");
|
|
1108 | 1108 |
} |
1109 | 1109 |
|
1110 | 1110 |
// Handle the NAMESPACE nodes |
1111 |
} else if (currentNode.nodetype.equals("NAMESPACE")) {
|
|
1112 |
out.print(" xmlns:" + currentNode.nodename + "=\""
|
|
1113 |
+ currentNode.nodedata + "\"");
|
|
1111 |
} else if (currentNode.getNodeType().equals("NAMESPACE")) {
|
|
1112 |
out.print(" xmlns:" + currentNode.getNodeName() + "=\""
|
|
1113 |
+ currentNode.getNodeData() + "\"");
|
|
1114 | 1114 |
|
1115 | 1115 |
// Handle the TEXT nodes |
1116 |
} else if (currentNode.nodetype.equals("TEXT")) {
|
|
1116 |
} else if (currentNode.getNodeType().equals("TEXT")) {
|
|
1117 | 1117 |
if (previousNodeWasElement) { |
1118 | 1118 |
out.print(">"); |
1119 | 1119 |
} |
1120 | 1120 |
if (!prcocessInlineData) { |
1121 | 1121 |
// if it is not inline data just out put data |
1122 |
out.print(currentNode.nodedata);
|
|
1122 |
out.print(currentNode.getNodeData());
|
|
1123 | 1123 |
} else { |
1124 | 1124 |
// if it is inline data first to get the inline data |
1125 | 1125 |
// internal id |
1126 |
String fileName = currentNode.nodedata;
|
|
1126 |
String fileName = currentNode.getNodeData();
|
|
1127 | 1127 |
String accessfileName = MetaCatUtil |
1128 | 1128 |
.getDocIdWithoutRevFromInlineDataID(fileName); |
1129 | 1129 |
// check if user has read permision for this inline data |
... | ... | |
1176 | 1176 |
}// in inlinedata part |
1177 | 1177 |
previousNodeWasElement = false; |
1178 | 1178 |
// Handle the COMMENT nodes |
1179 |
} else if (currentNode.nodetype.equals("COMMENT")) {
|
|
1179 |
} else if (currentNode.getNodeType().equals("COMMENT")) {
|
|
1180 | 1180 |
if (previousNodeWasElement) { |
1181 | 1181 |
out.print(">"); |
1182 | 1182 |
} |
1183 |
out.print("<!--" + currentNode.nodedata + "-->");
|
|
1183 |
out.print("<!--" + currentNode.getNodeData() + "-->");
|
|
1184 | 1184 |
previousNodeWasElement = false; |
1185 | 1185 |
|
1186 | 1186 |
// Handle the PI nodes |
1187 |
} else if (currentNode.nodetype.equals("PI")) {
|
|
1187 |
} else if (currentNode.getNodeType().equals("PI")) {
|
|
1188 | 1188 |
if (previousNodeWasElement) { |
1189 | 1189 |
out.print(">"); |
1190 | 1190 |
} |
1191 |
out.print("<?" + currentNode.nodename + " "
|
|
1192 |
+ currentNode.nodedata + "?>");
|
|
1191 |
out.print("<?" + currentNode.getNodeName() + " "
|
|
1192 |
+ currentNode.getNodeData() + "?>");
|
|
1193 | 1193 |
previousNodeWasElement = false; |
1194 | 1194 |
// Handle the DTD nodes (docname, publicid, systemid) |
1195 |
} else if (currentNode.nodetype.equals(DTD)) {
|
|
1195 |
} else if (currentNode.getNodeType().equals(DTD)) {
|
|
1196 | 1196 |
storedDTD = true; |
1197 | 1197 |
if (currentNode.getNodeName().equals(DOCNAME)) { |
1198 | 1198 |
dbDocName = currentNode.getNodeData(); |
... | ... | |
1233 | 1233 |
// Print the final end tag for the root element |
1234 | 1234 |
while (!openElements.empty()) { |
1235 | 1235 |
NodeRecord currentElement = (NodeRecord) openElements.pop(); |
1236 |
logMetacat.info("\n POPPED: " + currentElement.nodename);
|
|
1237 |
if (currentElement.nodeprefix != null) {
|
|
1238 |
out.print("</" + currentElement.nodeprefix + ":"
|
|
1239 |
+ currentElement.nodename + ">");
|
|
1236 |
logMetacat.info("\n POPPED: " + currentElement.getNodeName());
|
|
1237 |
if (currentElement.getNodePrefix() != null) {
|
|
1238 |
out.print("</" + currentElement.getNodePrefix() + ":"
|
|
1239 |
+ currentElement.getNodeName() + ">");
|
|
1240 | 1240 |
} else { |
1241 |
out.print("</" + currentElement.nodename + ">");
|
|
1241 |
out.print("</" + currentElement.getNodeName() + ">");
|
|
1242 | 1242 |
} |
1243 | 1243 |
} |
1244 | 1244 |
out.flush(); |
... | ... | |
1255 | 1255 |
*/ |
1256 | 1256 |
public void buildIndex() throws McdbException |
1257 | 1257 |
{ |
1258 |
logMetacat.warn("buildIndex called on docid " + docid); |
|
1258 | 1259 |
TreeSet nodeRecordLists = getNodeRecordList(rootnodeid); |
1259 | 1260 |
boolean atRootElement = true; |
1260 | 1261 |
long rootNodeId = -1; |
... | ... | |
1269 | 1270 |
nodeRecordMap.put(nodeId, currentNode); |
1270 | 1271 |
} |
1271 | 1272 |
|
1272 |
//DocumentIdentifier doc = null; |
|
1273 |
//String doc = MetaCatUtil.getDocIdFromAccessionNumber(docid); |
|
1274 | 1273 |
String doc = docid; |
1275 |
/*try { |
|
1276 |
doc = new DocumentIdentifier(docid); |
|
1277 |
} catch (AccessionNumberException e){ |
|
1278 |
logMetacat.info("AccessionNumber Exception while " |
|
1279 |
+ " inserting path index " |
|
1280 |
+ "in DocumentImpl.buildIndex for " |
|
1281 |
+ "document " + docid, 10); |
|
1282 |
logMetacat.info(e.getMessage(), 10); |
|
1283 |
}*/ |
|
1284 | 1274 |
|
1285 | 1275 |
// Opening separate db connection for deleting and writing |
1286 | 1276 |
// XML Index -- be sure that it is all in one db transaction |
... | ... | |
1296 | 1286 |
// Delete the previous index entries for this document |
1297 | 1287 |
deleteNodeIndex(dbConn); |
1298 | 1288 |
|
1299 |
// Delete all the entries in xml_queryresult |
|
1300 |
PreparedStatement pstmt = dbConn.prepareStatement( |
|
1301 |
"DELETE FROM xml_queryresult WHERE docid = ?"); |
|
1302 |
pstmt.setString(1, doc); |
|
1303 |
pstmt.execute(); |
|
1304 |
pstmt.close(); |
|
1305 |
dbConn.increaseUsageCount(1); |
|
1306 |
|
|
1307 |
// Delete all the entries in xml_queryresult |
|
1308 |
pstmt = dbConn.prepareStatement( |
|
1309 |
"DELETE FROM xml_path_index WHERE docid = ?"); |
|
1310 |
pstmt.setString(1, doc); |
|
1311 |
pstmt.execute(); |
|
1312 |
pstmt.close(); |
|
1313 |
dbConn.increaseUsageCount(1); |
|
1314 |
//System.out.println("after dleteing !!!!!!!!!!!1"); |
|
1315 | 1289 |
// Step through all of the node records we were given |
1316 | 1290 |
// and build the new index and update the database |
1317 | 1291 |
it = nodeRecordLists.iterator(); |
1292 |
Vector pathsFound = new Vector();; |
|
1318 | 1293 |
while (it.hasNext()) { |
1319 | 1294 |
NodeRecord currentNode = (NodeRecord) it.next(); |
1320 | 1295 |
HashMap pathList = new HashMap(); |
1321 |
if (currentNode.nodetype.equals("ELEMENT") ||
|
|
1322 |
currentNode.nodetype.equals("ATTRIBUTE") ) {
|
|
1296 |
if (currentNode.getNodeType().equals("ELEMENT") ||
|
|
1297 |
currentNode.getNodeType().equals("ATTRIBUTE")){
|
|
1323 | 1298 |
|
1324 | 1299 |
if (atRootElement) { |
1325 | 1300 |
rootNodeId = currentNode.getNodeId(); |
... | ... | |
1327 | 1302 |
} |
1328 | 1303 |
traverseParents(nodeRecordMap, rootNodeId, |
1329 | 1304 |
currentNode.getNodeId(), |
1330 |
currentNode.getNodeId(), "", pathList); |
|
1305 |
currentNode.getNodeId(), |
|
1306 |
"", pathList, pathsFound); |
|
1331 | 1307 |
updateNodeIndex(dbConn, pathList); |
1308 |
} else if (currentNode.getNodeType().equals("TEXT")){ |
|
1309 |
if(!currentNode.getNodeData().trim().equals("") |
|
1310 |
&& !pathsFound.isEmpty()){ |
|
1311 |
updatePathIndex(dbConn, currentNode, pathsFound); |
|
1312 |
pathsFound.removeAllElements(); |
|
1313 |
} |
|
1332 | 1314 |
} |
1333 | 1315 |
} |
1334 |
|
|
1316 |
|
|
1335 | 1317 |
dbConn.commit(); |
1336 | 1318 |
} catch (SQLException e) { |
1337 |
logMetacat.error("SQL Exception while inserting path index "
|
|
1319 |
logMetacat.error("SQL Exception while indexing "
|
|
1338 | 1320 |
+ "in DocumentImpl.buildIndex for " |
1339 | 1321 |
+ "document " + docid); |
1340 | 1322 |
logMetacat.error(e.getMessage()); |
... | ... | |
1349 | 1331 |
} finally { |
1350 | 1332 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
1351 | 1333 |
} |
1352 |
|
|
1353 |
try { |
|
1354 |
dbConn = DBConnectionPool.getDBConnection("DocumentImpl.buildIndex-pathIndex"); |
|
1355 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
|
1356 |
dbConn.setAutoCommit(false); |
|
1357 |
|
|
1358 |
ResultSet rs = null; |
|
1359 |
PreparedStatement pstmt1 = null; |
|
1360 |
|
|
1361 |
String pathList = ""; |
|
1362 |
for (int i = 0; i < MetaCatUtil.pathsForIndexing.size(); i++) { |
|
1363 |
pathList = pathList + "i.path = '" + |
|
1364 |
(String)MetaCatUtil.pathsForIndexing.get(i) + "' OR "; |
|
1365 |
} |
|
1366 |
|
|
1367 |
pathList = pathList.substring(0,pathList.length()-4); |
|
1368 |
|
|
1369 |
PreparedStatement pstmt = dbConn.prepareStatement("SELECT DISTINCT n.docid, " |
|
1370 |
+ "n.nodedata, n.nodedatanumerical," |
|
1371 |
+ " n.parentnodeid, i.path FROM" |
|
1372 |
+ " xml_nodes n, xml_index i WHERE" |
|
1373 |
+ " (" + pathList |
|
1374 |
+ " ) AND n.parentnodeid=i.nodeid AND" |
|
1375 |
+ " n.nodetype LIKE 'TEXT' and n.docid = ?" |
|
1376 |
+ " order by n.parentnodeid"); |
|
1377 |
|
|
1378 |
pstmt.setString(1, doc); |
|
1379 |
|
|
1380 |
pstmt.execute(); |
|
1381 |
rs = pstmt.getResultSet(); |
|
1382 |
dbConn.increaseUsageCount(1); |
|
1383 |
|
|
1384 |
int count = 0; |
|
1385 |
|
|
1386 |
while (rs.next()) { |
|
1387 |
//System.out.println("update xml_path_index!!!!!!!1"); |
|
1388 |
String docid = rs.getString(1); |
|
1389 |
String nodedata = rs.getString(2); |
|
1390 |
float nodedatanumerical = rs.getFloat(3); |
|
1391 |
int parentnodeid = rs.getInt(4); |
|
1392 |
String path = rs.getString(5); |
|
1393 |
|
|
1394 |
if (!nodedata.trim().equals("")) { |
|
1395 |
pstmt1 = dbConn.prepareStatement("INSERT INTO " |
|
1396 |
+ "xml_path_index (docid, path, nodedata, " |
|
1397 |
+ "nodedatanumerical, parentnodeid)" |
|
1398 |
+ " VALUES (?, ?, ?, ?, ?)"); |
|
1399 |
|
|
1400 |
pstmt1.setString(1, docid); |
|
1401 |
pstmt1.setString(2, path); |
|
1402 |
pstmt1.setString(3, nodedata); |
|
1403 |
pstmt1.setFloat(4, nodedatanumerical); |
|
1404 |
pstmt1.setInt(5, parentnodeid); |
|
1405 |
|
|
1406 |
pstmt1.execute(); |
|
1407 |
pstmt1.close(); |
|
1408 |
dbConn.increaseUsageCount(1); |
|
1409 |
|
|
1410 |
count++; |
|
1411 |
} |
|
1412 |
} |
|
1413 |
|
|
1414 |
rs.close(); |
|
1415 |
pstmt.close(); |
|
1416 |
dbConn.increaseUsageCount(1); |
|
1417 |
|
|
1418 |
logMetacat.warn("Indexed " + count |
|
1419 |
+ " records for docid: " + docid); |
|
1420 |
|
|
1421 |
dbConn.commit(); |
|
1422 |
} catch (SQLException e) { |
|
1423 |
logMetacat.error("SQL Exception while inserting path index " |
|
1424 |
+ "in DocumentImpl.buildIndex for " |
|
1425 |
+ "document " + docid); |
|
1426 |
logMetacat.error(e.getMessage()); |
|
1427 |
try { |
|
1428 |
dbConn.rollback(); |
|
1429 |
} catch (SQLException sqle) { |
|
1430 |
logMetacat.error("Error while rolling back " |
|
1431 |
+ "commit in DocumentImpl" |
|
1432 |
+ ".buildIndex" + "\n" |
|
1433 |
+ sqle.getMessage()); |
|
1434 |
} |
|
1435 |
} finally { |
|
1436 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
1437 |
} |
|
1334 |
|
|
1335 |
logMetacat.warn("BuildIndex complete for docid " + docid); |
|
1438 | 1336 |
} |
1439 | 1337 |
|
1440 | 1338 |
/** |
... | ... | |
1451 | 1349 |
*/ |
1452 | 1350 |
private void traverseParents(HashMap records, long rootNodeId, |
1453 | 1351 |
long leafNodeId, long id, |
1454 |
String children, HashMap pathList) { |
|
1455 |
Long nodeId = new Long(id);
|
|
1352 |
String children, HashMap pathList, Vector pathsFoundForIndexing) {
|
|
1353 |
Long nodeId = new Long(id);
|
|
1456 | 1354 |
NodeRecord current = (NodeRecord)records.get(nodeId); |
1457 | 1355 |
long parentId = current.getParentNodeId(); |
1458 | 1356 |
String currentName = current.getNodeName(); |
1459 |
if (current.nodetype.equals("ELEMENT") ||
|
|
1460 |
current.nodetype.equals("ATTRIBUTE") ) {
|
|
1461 |
|
|
1357 |
if (current.getNodeType().equals("ELEMENT") ||
|
|
1358 |
current.getNodeType().equals("ATTRIBUTE") ) {
|
|
1359 |
|
|
1462 | 1360 |
if (children.equals("")) { |
1463 |
if (current.nodetype.equals("ATTRIBUTE")) {
|
|
1361 |
if (current.getNodeType().equals("ATTRIBUTE")) {
|
|
1464 | 1362 |
currentName = "@" + currentName; |
1465 | 1363 |
} |
1466 | 1364 |
logMetacat.debug("A: " + currentName +"\n"); |
1467 | 1365 |
pathList.put(currentName, new PathIndexEntry(leafNodeId, |
1468 | 1366 |
currentName, docid, doctype, parentId)); |
1367 |
if(MetaCatUtil.pathsForIndexing.contains(currentName)){ |
|
1368 |
logMetacat.debug("paths found " + currentName); |
|
1369 |
pathsFoundForIndexing.add(currentName); |
|
1370 |
} |
|
1469 | 1371 |
} |
1470 | 1372 |
currentName = "/" + currentName; |
1471 | 1373 |
currentName = currentName + children; |
1472 | 1374 |
if (parentId != 0) { |
1473 | 1375 |
traverseParents(records, rootNodeId, leafNodeId, |
1474 |
parentId, currentName, pathList); |
|
1376 |
parentId, currentName, pathList, pathsFoundForIndexing);
|
|
1475 | 1377 |
} |
1476 | 1378 |
String path = current.getNodeName() + children; |
1379 |
|
|
1477 | 1380 |
if (!children.equals("")) { |
1478 | 1381 |
logMetacat.debug("B: " + path +"\n"); |
1479 | 1382 |
pathList.put(path, new PathIndexEntry(leafNodeId, path, docid, |
1480 | 1383 |
doctype, parentId)); |
1384 |
if(MetaCatUtil.pathsForIndexing.contains(path)){ |
|
1385 |
logMetacat.debug("paths found " + path); |
|
1386 |
pathsFoundForIndexing.add(path); |
|
1387 |
} |
|
1481 | 1388 |
} |
1482 | 1389 |
if (id == rootNodeId) { |
1483 | 1390 |
String fullPath = '/' + path; |
1484 | 1391 |
logMetacat.debug("C: " + fullPath +"\n"); |
1485 | 1392 |
pathList.put(fullPath, new PathIndexEntry(leafNodeId, fullPath, |
1486 | 1393 |
docid, doctype, parentId)); |
1394 |
if(MetaCatUtil.pathsForIndexing.contains(fullPath)){ |
|
1395 |
logMetacat.debug("paths found " + fullPath); |
|
1396 |
pathsFoundForIndexing.add(fullPath); |
|
1397 |
} |
|
1487 | 1398 |
} |
1488 |
} |
|
1399 |
}
|
|
1489 | 1400 |
} |
1490 | 1401 |
|
1491 | 1402 |
/** |
... | ... | |
1514 | 1425 |
pstmt.close(); |
1515 | 1426 |
logMetacat.info("Deleted " + rows + " rows from xml_index " + |
1516 | 1427 |
"for document " + docid); |
1428 |
|
|
1429 |
// Delete all the entries in xml_queryresult |
|
1430 |
pstmt = conn.prepareStatement( |
|
1431 |
"DELETE FROM xml_queryresult WHERE docid = ?"); |
|
1432 |
pstmt.setString(1, docid); |
|
1433 |
rows = pstmt.executeUpdate(); |
|
1434 |
conn.increaseUsageCount(1); |
|
1435 |
pstmt.close(); |
|
1436 |
logMetacat.info("Deleted " + rows + " rows from xml_queryresult " + |
|
1437 |
"for document " + docid); |
|
1438 |
|
|
1439 |
// Delete all the entries in xml_path_index |
|
1440 |
pstmt = conn.prepareStatement( |
|
1441 |
"DELETE FROM xml_path_index WHERE docid = ?"); |
|
1442 |
pstmt.setString(1, docid); |
|
1443 |
rows = pstmt.executeUpdate(); |
|
1444 |
conn.increaseUsageCount(1); |
|
1445 |
pstmt.close(); |
|
1446 |
logMetacat.info("Deleted " + rows + " rows from xml_path_index " + |
|
1447 |
"for document " + docid); |
|
1448 |
|
|
1517 | 1449 |
} |
1518 | 1450 |
|
1519 | 1451 |
/** |
... | ... | |
1541 | 1473 |
// Step through the hashtable and insert each of the path values |
1542 | 1474 |
Iterator it = pathList.values().iterator(); |
1543 | 1475 |
while (it.hasNext()) { |
1544 |
PathIndexEntry entry = (PathIndexEntry)it.next(); |
|
1545 |
logMetacat.debug("Inserting: " + entry.nodeId + |
|
1546 |
" (" + entry.parentId + "): " + entry.path); |
|
1547 |
pstmt.setLong(1, entry.nodeId); |
|
1548 |
pstmt.setString(2, entry.path); |
|
1549 |
pstmt.setLong(5, entry.parentId); |
|
1550 |
pstmt.executeUpdate(); |
|
1476 |
PathIndexEntry entry = (PathIndexEntry)it.next(); |
|
1477 |
logMetacat.debug("Inserting: " + entry.nodeId + |
|
1478 |
" (" + entry.parentId + "): " + entry.path); |
|
1479 |
pstmt.setLong(1, entry.nodeId); |
|
1480 |
pstmt.setString(2, entry.path); |
|
1481 |
pstmt.setLong(5, entry.parentId); |
|
1482 |
pstmt.executeUpdate(); |
|
1483 |
} |
|
1484 |
// Close the database statement |
|
1485 |
pstmt.close(); |
|
1486 |
} |
|
1487 |
|
|
1488 |
/** |
|
1489 |
* Insert the paths from the pathList into the xml_path_index table on the |
|
1490 |
* database. |
|
1491 |
* |
|
1492 |
* @param conn the database connection to use, keeping a single transaction |
|
1493 |
* @param pathList the hash of paths to insert |
|
1494 |
* @throws SQLException if there is an error inserting into the db |
|
1495 |
*/ |
|
1496 |
private void updatePathIndex(DBConnection conn, NodeRecord currentNode, Vector pathList) |
|
1497 |
throws SQLException { |
|
1498 |
// Create an insert statement to reuse for all of the path |
|
1499 |
// insertions |
|
1500 |
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " |
|
1501 |
+ "xml_path_index (docid, path, nodedata, " |
|
1502 |
+ "nodedatanumerical, parentnodeid)" |
|
1503 |
+ " VALUES (?, ?, ?, ?, ?)"); |
|
1504 |
pstmt.setString(1, docid); |
|
1505 |
// Step through the hashtable and insert each of the path values |
|
1506 |
Iterator it = pathList.iterator(); |
|
1507 |
while (it.hasNext()) { |
|
1508 |
String path = (String)it.next(); |
|
1509 |
logMetacat.debug("Inserting: "+ path); |
|
1510 |
pstmt.setString(2, path); |
|
1511 |
pstmt.setString(3, currentNode.getNodeData()); |
|
1512 |
pstmt.setFloat(4, currentNode.getNodeDataNumerical()); |
|
1513 |
pstmt.setLong(5, currentNode.getParentNodeId()); |
|
1514 |
pstmt.execute(); |
|
1551 | 1515 |
} |
1552 | 1516 |
// Close the database statement |
1553 | 1517 |
pstmt.close(); |
... | ... | |
1777 | 1741 |
String nodename = null; |
1778 | 1742 |
String nodeprefix = null; |
1779 | 1743 |
String nodedata = null; |
1780 |
String quotechar = dbAdapter.getStringDelimiter();
|
|
1744 |
float nodedatanumerical = -1;
|
|
1781 | 1745 |
String sql = "SELECT nodeid,parentnodeid,nodeindex, " |
1782 |
+ "nodetype,nodename,nodeprefix,nodedata " |
|
1746 |
+ "nodetype,nodename,nodeprefix,nodedata,nodedatanumerical "
|
|
1783 | 1747 |
+ "FROM xml_nodes WHERE rootnodeid = ?"; |
1784 | 1748 |
|
1785 | 1749 |
// go through the access control for some nodes |
... | ... | |
1815 | 1779 |
nodeprefix = rs.getString(6); |
1816 | 1780 |
nodedata = rs.getString(7); |
1817 | 1781 |
nodedata = MetaCatUtil.normalize(nodedata); |
1782 |
nodedatanumerical = rs.getFloat(8); |
|
1783 |
|
|
1818 | 1784 |
// add the data to the node record list hashtable |
1819 | 1785 |
NodeRecord currentRecord = new NodeRecord(nodeid, parentnodeid, |
1820 |
nodeindex, nodetype, nodename, nodeprefix, nodedata); |
|
1786 |
nodeindex, nodetype, nodename, nodeprefix, nodedata, nodedatanumerical);
|
|
1821 | 1787 |
nodeRecordList.add(currentRecord); |
1822 | 1788 |
|
1823 | 1789 |
// Advance to the next node |
... | ... | |
1869 | 1835 |
String nodename = null; |
1870 | 1836 |
String nodeprefix = null; |
1871 | 1837 |
String nodedata = null; |
1838 |
float nodedatanumerical = -1; |
|
1872 | 1839 |
String quotechar = dbAdapter.getStringDelimiter(); |
1873 | 1840 |
String table = "xml_nodes"; |
1874 | 1841 |
//System.out.println("in getNodeREcorelist !!!!!!!!!!!for root node id "+rootnodeid); |
... | ... | |
1892 | 1859 |
serialNumber = dbconn.getCheckOutSerialNumber(); |
1893 | 1860 |
pstmt = dbconn |
1894 | 1861 |
.prepareStatement("SELECT nodeid,parentnodeid,nodeindex, " |
1895 |
+ "nodetype,nodename,nodeprefix,nodedata " |
|
1862 |
+ "nodetype,nodename,nodeprefix,nodedata, nodedatanumerical "
|
|
1896 | 1863 |
+ "FROM " + table + " WHERE rootnodeid = ?"); |
1897 | 1864 |
|
1898 | 1865 |
// Bind the values to the query |
... | ... | |
1911 | 1878 |
nodename = rs.getString(5); |
1912 | 1879 |
nodeprefix = rs.getString(6); |
1913 | 1880 |
nodedata = rs.getString(7); |
1914 |
nodedata = MetaCatUtil.normalize(nodedata); |
|
1881 |
nodedata = MetaCatUtil.normalize(nodedata); |
|
1882 |
nodedatanumerical = rs.getFloat(8); |
|
1883 |
|
|
1915 | 1884 |
// add the data to the node record list hashtable |
1916 | 1885 |
NodeRecord currentRecord = new NodeRecord(nodeid, parentnodeid, |
1917 |
nodeindex, nodetype, nodename, nodeprefix, nodedata); |
|
1886 |
nodeindex, nodetype, nodename, nodeprefix, nodedata, nodedatanumerical);
|
|
1918 | 1887 |
nodeRecordList.add(currentRecord); |
1919 | 1888 |
|
1920 | 1889 |
// Advance to the next node |
Also available in: Unified diff
1. Modified buildIndex() so that only one connection is used for both indexing nodes and indexing paths.
2. Modified the indexing algo so that indexing of paths is done while nodes are being indexed. Results in a much faster indexing algo
3. Replaced access to NodeRecord.<variable> with NodeRecord.<getVariable>