Revision 2376
Added by sgarg over 19 years ago
DocumentImpl.java | ||
---|---|---|
1180 | 1180 |
nodeRecordMap.put(nodeId, currentNode); |
1181 | 1181 |
} |
1182 | 1182 |
|
1183 |
// Build a map of the node records that can be accessed by nodeId |
|
1184 |
HashMap parentNodeRecordMap = new HashMap(); |
|
1185 |
Iterator ite = nodeRecordLists.iterator(); |
|
1186 |
while (ite.hasNext()) { |
|
1187 |
NodeRecord currentNode = (NodeRecord) ite.next(); |
|
1188 |
Long nodeId = new Long(currentNode.getParentNodeId()); |
|
1189 |
parentNodeRecordMap.put(nodeId, currentNode); |
|
1190 |
} |
|
1191 |
|
|
1183 | 1192 |
// Opening separate db connection for deleting and writing |
1184 | 1193 |
// XML Index -- be sure that it is all in one db transaction |
1185 | 1194 |
int serialNumber = -1; |
... | ... | |
1204 | 1213 |
if (currentNode.nodetype.equals("ELEMENT") || |
1205 | 1214 |
currentNode.nodetype.equals("ATTRIBUTE") ) { |
1206 | 1215 |
|
1216 |
String nodedata = null; |
|
1217 |
|
|
1218 |
if (currentNode.nodetype.equals("ELEMENT") ) { |
|
1219 |
Long nodeid = new Long(currentNode.getNodeId()); |
|
1220 |
NodeRecord node = |
|
1221 |
(NodeRecord) parentNodeRecordMap.get(nodeid); |
|
1222 |
if(node!=null){ |
|
1223 |
nodedata = node.getNodeData(); |
|
1224 |
} |
|
1225 |
} else { |
|
1226 |
nodedata = currentNode.getNodeData(); |
|
1227 |
} |
|
1228 |
|
|
1207 | 1229 |
if (atRootElement) { |
1208 | 1230 |
rootNodeId = currentNode.getNodeId(); |
1209 | 1231 |
atRootElement = false; |
1210 | 1232 |
} |
1211 | 1233 |
traverseParents(nodeRecordMap, rootNodeId, |
1212 | 1234 |
currentNode.getNodeId(), |
1213 |
currentNode.getNodeId(), "", pathList); |
|
1235 |
currentNode.getNodeId(), "", pathList, nodedata);
|
|
1214 | 1236 |
updateNodeIndex(dbConn, pathList); |
1215 | 1237 |
} |
1216 | 1238 |
} |
... | ... | |
1243 | 1265 |
* @param id the id of the current node to be processed |
1244 | 1266 |
* @param children the string representation of all child nodes of this id |
1245 | 1267 |
* @param pathList the hash to which paths are added |
1268 |
* @param nodedata the nodedata for the current node |
|
1246 | 1269 |
*/ |
1247 | 1270 |
private void traverseParents(HashMap records, long rootNodeId, |
1248 | 1271 |
long leafNodeId, long id, |
1249 |
String children, HashMap pathList) { |
|
1272 |
String children, HashMap pathList, String nodedata) {
|
|
1250 | 1273 |
Long nodeId = new Long(id); |
1251 | 1274 |
NodeRecord current = (NodeRecord)records.get(nodeId); |
1252 | 1275 |
long parentId = current.getParentNodeId(); |
... | ... | |
1259 | 1282 |
currentName = "@" + currentName; |
1260 | 1283 |
} |
1261 | 1284 |
MetaCatUtil.debugMessage("A: " + currentName +"\n", 60); |
1262 |
pathList.put(currentName, new PathIndexEntry( |
|
1263 |
leafNodeId, currentName, docid, doctype, parentId));
|
|
1285 |
pathList.put(currentName, new PathIndexEntry(leafNodeId,
|
|
1286 |
currentName, docid, doctype, parentId, nodedata));
|
|
1264 | 1287 |
} |
1265 | 1288 |
currentName = "/" + currentName; |
1266 | 1289 |
currentName = currentName + children; |
1267 | 1290 |
if (parentId != 0) { |
1268 | 1291 |
traverseParents(records, rootNodeId, leafNodeId, |
1269 |
parentId, currentName, pathList); |
|
1292 |
parentId, currentName, pathList, nodedata);
|
|
1270 | 1293 |
} |
1271 | 1294 |
String path = current.getNodeName() + children; |
1272 | 1295 |
if (!children.equals("")) { |
1273 | 1296 |
MetaCatUtil.debugMessage("B: " + path +"\n", 60); |
1274 | 1297 |
pathList.put(path, new PathIndexEntry(leafNodeId, path, docid, |
1275 |
doctype, parentId)); |
|
1298 |
doctype, parentId, nodedata));
|
|
1276 | 1299 |
} |
1277 | 1300 |
if (id == rootNodeId) { |
1278 | 1301 |
String fullPath = '/' + path; |
1279 | 1302 |
MetaCatUtil.debugMessage("C: " + fullPath +"\n", 60); |
1280 | 1303 |
pathList.put(fullPath, new PathIndexEntry(leafNodeId, fullPath, |
1281 |
docid, doctype, parentId)); |
|
1304 |
docid, doctype, parentId, nodedata));
|
|
1282 | 1305 |
} |
1283 | 1306 |
} |
1284 | 1307 |
} |
... | ... | |
1325 | 1348 |
// insertions |
1326 | 1349 |
PreparedStatement pstmt = conn.prepareStatement( |
1327 | 1350 |
"INSERT INTO xml_index (nodeid, path, docid, doctype, " + |
1328 |
"parentnodeid) " + "VALUES (?, ?, ?, ?, ?)");
|
|
1351 |
"parentnodeid, nodedata) " + "VALUES (?, ?, ?, ?, ?, ?)");
|
|
1329 | 1352 |
// Increase usage count for the connection |
1330 | 1353 |
conn.increaseUsageCount(1); |
1331 | 1354 |
String familyId = MetaCatUtil.getDocIdFromString(docid); |
... | ... | |
1341 | 1364 |
pstmt.setLong(1, entry.nodeId); |
1342 | 1365 |
pstmt.setString(2, entry.path); |
1343 | 1366 |
pstmt.setLong(5, entry.parentId); |
1367 |
pstmt.setString(6, entry.nodedata); |
|
1344 | 1368 |
pstmt.executeUpdate(); |
1345 | 1369 |
} |
1346 | 1370 |
// Close the database statement |
Also available in: Unified diff
Modifying code so that nodedata is stored in xml_index table next to the paths.
This helps in making the search faster.