Project

General

Profile

« Previous | Next » 

Revision 2376

Added by sgarg almost 20 years ago

Modifying code so that nodedata is stored in xml_index table next to the paths.
This helps in making the search faster.

View differences:

src/edu/ucsb/nceas/metacat/QuerySpecification.java
908 908
            Hashtable unaccessableNodePair)
909 909
    {
910 910
        StringBuffer self = new StringBuffer();
911
        self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata, ");
912
        self.append("xml_nodes.parentnodeid ");
913
        self.append("from xml_index, xml_nodes where xml_index.nodeid=");
914
        self.append("xml_nodes.parentnodeid and (xml_index.path like '");
911
        self.append("select path, docid, nodedata, ");
912
        self.append("nodeid ");
913
        self.append("from xml_index where (path like '");
915 914
        boolean firstfield = true;
916 915
        //put the returnfields into the query
917 916
        //the for loop allows for multiple fields
......
921 920
                self.append((String) returnFieldList.elementAt(i));
922 921
                self.append("' ");
923 922
            } else {
924
                self.append("or xml_index.path like '");
923
                self.append("or path like '");
925 924
                self.append((String) returnFieldList.elementAt(i));
926 925
                self.append("' ");
927 926
            }
928 927
        }
929
        self.append(") AND xml_nodes.docid in (");
928
        self.append(") AND docid in (");
930 929
        self.append(doclist);
931
        self.append(") AND xml_nodes.nodetype = 'TEXT'");
930
        self.append(")");
931
        //self.append(") AND xml_nodes.nodetype = 'TEXT'");
932 932

  
933 933
        addAccessRestrictionSQL(unaccessableNodePair, self);
934 934

  
src/edu/ucsb/nceas/metacat/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
src/edu/ucsb/nceas/metacat/DBQuery.java
719 719
               fielddata = MetaCatUtil.normalize(fielddata);
720 720
               String parentId = rs.getString(4);
721 721
               StringBuffer value = new StringBuffer();
722
               if (!containsKey(parentidList, parentId))
722

  
723
	       // if xml_index is used, there would be just one record per nodeid
724
	       // as xml_index just keeps one entry for each path
725
               if (useXMLIndex || !containsKey(parentidList, parentId))
723 726
               {
724 727
                  // don't need to merger nodedata
725 728
                  value.append("<param name=\"");
src/edu/ucsb/nceas/metacat/PathIndexEntry.java
27 27
/**
28 28
 * PathIndexEntry contains all of the data fields needed to insert an path into
29 29
 * the xml_index table.
30
 * 
30
 *
31 31
 * @author jones
32 32
 */
33 33
public class PathIndexEntry
34 34
{
35 35
    protected long nodeId;
36 36
    protected String path;
37
    protected String docid; 
37
    protected String docid;
38 38
    protected String docType;
39 39
    protected long parentId;
40
    
40
    protected String nodedata;
41

  
41 42
    /**
42 43
     * Construct a new PathIndexEntry.
43
     * 
44
     *
44 45
     * @param nodeId the node identifier
45 46
     * @param path the path in the xml document
46 47
     * @param docid the document identifier
47 48
     * @param docType the document type
48 49
     * @param parentId the identifier of the parent node
49 50
     */
50
    public PathIndexEntry(long nodeId, String path, String docid, 
51
            String docType, long parentId)
51
    public PathIndexEntry(long nodeId, String path, String docid,
52
            String docType, long parentId, String nodedata)
52 53
    {
53 54
        this.nodeId = nodeId;
54 55
        this.path = path;
55 56
        this.docid = docid;
56 57
        this.docType = docType;
57 58
        this.parentId = parentId;
59
        this.nodedata = nodedata;
58 60
    }
59 61
}

Also available in: Unified diff