Exemplo n.º 1
0
 // 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
   }
 }
Exemplo n.º 2
0
  // 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();
  }
Exemplo n.º 3
0
 /*
  * @{InheritDoc}
  */
 public List<String> getAllDocumentsNames() {
   List<String> names = new ArrayList<String>();
   XmlContainer cont = null;
   XmlTransaction trans = null;
   try {
     cont = xmlManager.openContainer(containerName);
     trans = xmlManager.createTransaction();
     XmlResults results = cont.getAllDocuments(trans, XmlDocumentConfig.DEFAULT);
     while (results.hasNext()) {
       names.add(results.next().asDocument().getName());
     }
     results.delete();
     return names;
   } catch (XmlException e) {
     logger.logWarning(this.getClass().toString(), "Retrieving all documents names failed!");
     return null;
   } finally {
     commitAndClose(trans, cont);
   }
 }
Exemplo n.º 4
0
 /*
  * @{InheritDoc}
  */
 public List<String[]> getAllIndexes() {
   List<String[]> indexes = new ArrayList<String[]>();
   XmlIndexSpecification indexSpec = null;
   XmlContainer cont = null;
   XmlTransaction trans = null;
   try {
     cont = xmlManager.openContainer(containerName);
     trans = xmlManager.createTransaction();
     indexSpec = cont.getIndexSpecification();
     XmlIndexDeclaration indexDeclaration = null;
     while ((indexDeclaration = (indexSpec.next())) != null) {
       indexes.add(new String[] {indexDeclaration.name, indexDeclaration.index});
     }
     return indexes;
   } catch (XmlException e) {
     logger.logWarning(this.getClass().toString(), "Listing indexes failed! - Xml exeption");
     return null;
   } finally {
     indexSpec.delete();
     commitAndClose(trans, cont);
   }
 }