Project

General

Profile

« Previous | Next » 

Revision 2301

Whitespace changes that fix a few formatting problems after Jing's commit.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
1156 1156
    /**
1157 1157
     * Build the index records for this document.  For each node, all absolute
1158 1158
     * and relative paths to the root of the document are created and inserted
1159
     * into the xml_index table.  This requires that the DocumentImpl instance
1160
     * exists, so first call the constructor that reads the document from the
1159
     * into the xml_index table.  This requires that the DocumentImpl instance 
1160
     * exists, so first call the constructor that reads the document from the 
1161 1161
     * database.
1162 1162
     *
1163 1163
     * @throws McdbException on error getting the node records for the document
......
1179 1179
            Long nodeId = new Long(currentNode.getNodeId());
1180 1180
            nodeRecordMap.put(nodeId, currentNode);
1181 1181
        }
1182

  
1183
        // Opening separate db connection for deleting and writing
1182
        
1183
        // Opening separate db connection for deleting and writing 
1184 1184
        // XML Index -- be sure that it is all in one db transaction
1185 1185
        int serialNumber = -1;
1186 1186
        DBConnection dbConn = null;
......
1191 1191
            dbConn.setAutoCommit(false);
1192 1192
            //make sure record is done
1193 1193
            //checkDocumentTable();
1194

  
1194
            
1195 1195
            // Delete the previous index entries for this document
1196 1196
            deleteNodeIndex(dbConn);
1197

  
1197
            
1198 1198
            // Step through all of the node records we were given
1199 1199
            // and build the new index and update the database
1200 1200
            it = nodeRecordLists.iterator();
......
1204 1204
                if (currentNode.nodetype.equals("ELEMENT") ||
1205 1205
                    currentNode.nodetype.equals("ATTRIBUTE") ) {
1206 1206

  
1207
                    System.err.println("\nStarting Node: " +
1208
                        currentNode.getNodeId() + " (" +
1209
                        currentNode.getParentNodeId() + "): " +
1207
                    System.err.println("\nStarting Node: " + 
1208
                        currentNode.getNodeId() + " (" + 
1209
                        currentNode.getParentNodeId() + "): " + 
1210 1210
                        currentNode.getNodeName() + " (" +
1211 1211
                        currentNode.getNodeType() + ")");
1212 1212
                    if (atRootElement) {
1213 1213
                        rootNodeId = currentNode.getNodeId();
1214 1214
                        atRootElement = false;
1215 1215
                    }
1216
                    traverseParents(nodeRecordMap, rootNodeId,
1216
                    traverseParents(nodeRecordMap, rootNodeId, 
1217 1217
                            currentNode.getNodeId(),
1218 1218
                            currentNode.getNodeId(), "", pathList);
1219 1219
                    updateNodeIndex(dbConn, pathList);
1220

  
1221 1220
                }
1222

  
1223 1221
            }
1224 1222
            dbConn.commit();
1225 1223
        } catch (SQLException e) {
1226 1224
            MetaCatUtil.debugMessage(
1227 1225
                "SQL Exception while inserting path index in " +
1228 1226
                "DocumentImpl.buildIndex for document " + docid, 10);
1229
                      MetaCatUtil.debugMessage(e.getMessage(), 10);
1227
      		MetaCatUtil.debugMessage(e.getMessage(), 10);
1230 1228
            e.printStackTrace();
1231 1229
            try {
1232 1230
                dbConn.rollback();
1233 1231
            } catch (SQLException sqle) {
1234
                    MetaCatUtil.debugMessage(
1235
                                        "Error while rolling back commit in DocumentImpl.buildIndex"
1232
            	MetaCatUtil.debugMessage(
1233
					"Error while rolling back commit in DocumentImpl.buildIndex"
1236 1234
                    + "\n" + sqle.getMessage(), 10);
1237 1235
            }
1238 1236
        } finally {
1239
                        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1237
			DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1240 1238
        }
1241 1239
    }
1242 1240

  
......
1251 1249
     * @param children the string representation of all child nodes of this id
1252 1250
     * @param pathList the hash to which paths are added
1253 1251
     */
1254

  
1255
    private void traverseParents(HashMap records, long rootNodeId,
1256
            long leafNodeId, long id,
1252
    private void traverseParents(HashMap records, long rootNodeId, 
1253
            long leafNodeId, long id, 
1257 1254
            String children, HashMap pathList) {
1258 1255
        Long nodeId = new Long(id);
1259 1256
        NodeRecord current = (NodeRecord)records.get(nodeId);
......
1276 1273
            String path = current.getNodeName() + children;
1277 1274
            if (!children.equals("")) {
1278 1275
                System.err.print("B: " + path +"\n");
1279
                pathList.put(path, new PathIndexEntry(leafNodeId, path, docid,
1276
                pathList.put(path, new PathIndexEntry(leafNodeId, path, docid, 
1280 1277
                    doctype, parentId));
1281 1278
            }
1282 1279
            if (id == rootNodeId) {
......
1284 1281
                System.err.print("C: " + fullPath +"\n");
1285 1282
                pathList.put(fullPath, new PathIndexEntry(leafNodeId, fullPath,
1286 1283
                    docid, doctype, parentId));
1287

  
1288 1284
            }
1289 1285
        }
1290 1286
    }
1291 1287

  
1292 1288
    /**
1293
     * Delete the paths from the xml_index table on the database in preparation
1289
     * Delete the paths from the xml_index table on the database in preparation 
1294 1290
     * of a subsequent update.
1295 1291
     *
1296 1292
     * @param conn the database connection to use, keeping a single transaction
1297 1293
     * @throws SQLException if there is an error deleting from the db
1298 1294
     */
1299
    public void deleteNodeIndex(DBConnection conn) throws SQLException
1295
    private void deleteNodeIndex(DBConnection conn) throws SQLException
1300 1296
    {
1301 1297
        String familyId = MetaCatUtil.getDocIdFromString(docid);
1302 1298
        String sql = "DELETE FROM xml_index WHERE docid LIKE ?";
1303 1299
        MetaCatUtil.debugMessage(sql, 55);
1304 1300
        System.err.println("SQL is: " + sql);
1305

  
1301
        
1306 1302
        PreparedStatement pstmt = conn.prepareStatement(sql);
1307 1303

  
1308 1304
        // Increase usage count for the connection
1309 1305
        conn.increaseUsageCount(1);
1310

  
1306
        
1311 1307
        // Execute the delete and close the statement
1312 1308
        pstmt.setString(1, familyId);
1313 1309
        int rows = pstmt.executeUpdate();
......
1315 1311
        MetaCatUtil.debugMessage("Deleted " + rows + " rows from xml_index " +
1316 1312
            "for document " + docid, 55);
1317 1313
    }
1318

  
1314
    
1319 1315
    /**
1320
         * Insert the paths from the pathList into the xml_index table on the
1316
	 * Insert the paths from the pathList into the xml_index table on the
1321 1317
     * database.
1322 1318
     *
1323 1319
     * @param conn the database connection to use, keeping a single transaction
1324 1320
     * @param pathList the hash of paths to insert
1325 1321
     * @throws SQLException if there is an error inserting into the db
1326 1322
     */
1327
    private void updateNodeIndex(DBConnection conn, HashMap pathList)
1328
            throws SQLException
1323
    private void updateNodeIndex(DBConnection conn, HashMap pathList) 
1324
    	throws SQLException
1329 1325
    {
1330 1326
        // Create an insert statement to reuse for all of the path
1331 1327
        // insertions
......
1337 1333
        String familyId = MetaCatUtil.getDocIdFromString(docid);
1338 1334
        pstmt.setString(3, familyId);
1339 1335
        pstmt.setString(4, doctype);
1340

  
1336
        
1341 1337
        // Step through the hashtable and insert each of the path values
1342 1338
        Iterator it = pathList.values().iterator();
1343 1339
        while (it.hasNext()) {
......
1352 1348
        // Close the database statement
1353 1349
        pstmt.close();
1354 1350
    }
1355

  
1351
    
1356 1352
    private boolean isRevisionOnly(DocumentIdentifier docid) throws Exception
1357 1353
    {
1358 1354
        //System.out.println("inRevisionOnly");

Also available in: Unified diff