// Utility function to clean up objects, exceptions or not, // containers and environments must be closed. private static void cleanup(myDbEnv env, XmlContainer openedContainer) { try { if (openedContainer != null) openedContainer.delete(); if (env != null) env.cleanup(); } catch (Exception e) { // ignore exceptions on close } }
// Method used to replace an index with a new index type private static void replaceAnIndex( XmlManager mgr, XmlContainer container, String URI, String nodeName, String indexType, XmlTransaction txn) throws Throwable { System.out.println("Replacing index specification " + indexType + " for node " + nodeName); // Retrieve the index specification from the container XmlIndexSpecification idxSpec = container.getIndexSpecification(txn); // See what indexes exist on the container int count = 0; System.out.println("Before index replacement."); XmlIndexDeclaration idxDecl = null; while ((idxDecl = (idxSpec.next())) != null) { System.out.println( "\tFor node '" + idxDecl.name + "', found index: '" + idxDecl.index + "'."); count++; } System.out.println(count + " indexes found."); // Replace the container's index specification with a new specification idxSpec.replaceIndex(URI, nodeName, indexType); // Set the specification back to the container container.setIndexSpecification(txn, idxSpec, mgr.createUpdateContext()); // Look at the indexes again to make sure our replacement took. count = 0; idxSpec.reset(); System.out.println("After index replacement."); while ((idxDecl = (idxSpec.next())) != null) { System.out.println( "\tFor node '" + idxDecl.name + "', found index: '" + idxDecl.index + "'."); count++; } System.out.println(count + " indexes found."); idxSpec.delete(); }