Revision 2372
Added by sgarg almost 20 years ago
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(); |
... | ... | |
1208 | 1208 |
rootNodeId = currentNode.getNodeId(); |
1209 | 1209 |
atRootElement = false; |
1210 | 1210 |
} |
1211 |
traverseParents(nodeRecordMap, rootNodeId,
|
|
1211 |
traverseParents(nodeRecordMap, rootNodeId, |
|
1212 | 1212 |
currentNode.getNodeId(), |
1213 | 1213 |
currentNode.getNodeId(), "", pathList); |
1214 | 1214 |
updateNodeIndex(dbConn, pathList); |
... | ... | |
1244 | 1244 |
* @param children the string representation of all child nodes of this id |
1245 | 1245 |
* @param pathList the hash to which paths are added |
1246 | 1246 |
*/ |
1247 |
private void traverseParents(HashMap records, long rootNodeId,
|
|
1248 |
long leafNodeId, long id,
|
|
1247 |
private void traverseParents(HashMap records, long rootNodeId, |
|
1248 |
long leafNodeId, long id, |
|
1249 | 1249 |
String children, HashMap pathList) { |
1250 | 1250 |
Long nodeId = new Long(id); |
1251 | 1251 |
NodeRecord current = (NodeRecord)records.get(nodeId); |
... | ... | |
1271 | 1271 |
String path = current.getNodeName() + children; |
1272 | 1272 |
if (!children.equals("")) { |
1273 | 1273 |
MetaCatUtil.debugMessage("B: " + path +"\n", 60); |
1274 |
pathList.put(path, new PathIndexEntry(leafNodeId, path, docid,
|
|
1274 |
pathList.put(path, new PathIndexEntry(leafNodeId, path, docid, |
|
1275 | 1275 |
doctype, parentId)); |
1276 | 1276 |
} |
1277 | 1277 |
if (id == rootNodeId) { |
... | ... | |
1284 | 1284 |
} |
1285 | 1285 |
|
1286 | 1286 |
/** |
1287 |
* Delete the paths from the xml_index table on the database in preparation
|
|
1287 |
* Delete the paths from the xml_index table on the database in preparation |
|
1288 | 1288 |
* of a subsequent update. |
1289 | 1289 |
* |
1290 | 1290 |
* @param conn the database connection to use, keeping a single transaction |
... | ... | |
1296 | 1296 |
String sql = "DELETE FROM xml_index WHERE docid LIKE ?"; |
1297 | 1297 |
MetaCatUtil.debugMessage(sql, 55); |
1298 | 1298 |
MetaCatUtil.debugMessage("SQL is: " + sql, 60); |
1299 |
|
|
1299 |
|
|
1300 | 1300 |
PreparedStatement pstmt = conn.prepareStatement(sql); |
1301 | 1301 |
|
1302 | 1302 |
// Increase usage count for the connection |
1303 | 1303 |
conn.increaseUsageCount(1); |
1304 |
|
|
1304 |
|
|
1305 | 1305 |
// Execute the delete and close the statement |
1306 | 1306 |
pstmt.setString(1, familyId); |
1307 | 1307 |
int rows = pstmt.executeUpdate(); |
... | ... | |
1309 | 1309 |
MetaCatUtil.debugMessage("Deleted " + rows + " rows from xml_index " + |
1310 | 1310 |
"for document " + docid, 55); |
1311 | 1311 |
} |
1312 |
|
|
1312 |
|
|
1313 | 1313 |
/** |
1314 | 1314 |
* Insert the paths from the pathList into the xml_index table on the |
1315 | 1315 |
* database. |
... | ... | |
1318 | 1318 |
* @param pathList the hash of paths to insert |
1319 | 1319 |
* @throws SQLException if there is an error inserting into the db |
1320 | 1320 |
*/ |
1321 |
private void updateNodeIndex(DBConnection conn, HashMap pathList)
|
|
1321 |
private void updateNodeIndex(DBConnection conn, HashMap pathList) |
|
1322 | 1322 |
throws SQLException |
1323 | 1323 |
{ |
1324 | 1324 |
// Create an insert statement to reuse for all of the path |
... | ... | |
1331 | 1331 |
String familyId = MetaCatUtil.getDocIdFromString(docid); |
1332 | 1332 |
pstmt.setString(3, familyId); |
1333 | 1333 |
pstmt.setString(4, doctype); |
1334 |
|
|
1334 |
|
|
1335 | 1335 |
// Step through the hashtable and insert each of the path values |
1336 | 1336 |
Iterator it = pathList.values().iterator(); |
1337 | 1337 |
while (it.hasNext()) { |
... | ... | |
1346 | 1346 |
// Close the database statement |
1347 | 1347 |
pstmt.close(); |
1348 | 1348 |
} |
1349 |
|
|
1349 |
|
|
1350 | 1350 |
private boolean isRevisionOnly(DocumentIdentifier docid) throws Exception |
1351 | 1351 |
{ |
1352 | 1352 |
//System.out.println("inRevisionOnly"); |
... | ... | |
2333 | 2333 |
String docid = MetaCatUtil.getDocIdFromAccessionNumber(accnum); |
2334 | 2334 |
//String rev = ac.getRev(); |
2335 | 2335 |
|
2336 |
// Check if the document exists. |
|
2337 |
pstmt = conn.prepareStatement("SELECT * FROM xml_documents " |
|
2338 |
+ "WHERE docid = ?"); |
|
2339 |
pstmt.setString(1, docid); |
|
2340 |
pstmt.execute(); |
|
2341 |
ResultSet rs = pstmt.getResultSet(); |
|
2342 |
if(!rs.next()){ |
|
2343 |
rs.close(); |
|
2344 |
throw new Exception("Docid " + accnum + " does not exsist. " |
|
2345 |
+ "Please check that you have specified the" |
|
2346 |
+ " revision number of the document also."); |
|
2347 |
} |
|
2348 |
rs.close(); |
|
2349 |
pstmt.close(); |
|
2350 |
conn.increaseUsageCount(1); |
|
2351 |
|
|
2336 | 2352 |
// get the type of deleting docid, this will be used in forcereplication |
2337 | 2353 |
String type = getDocTypeFromDB(conn, docid); |
2338 | 2354 |
if (type != null && type.trim().equals("BIN")) |
Also available in: Unified diff
Modified code to fix bug # 1850