Esempio 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
   }
 }
Esempio n. 2
0
  public static void main(String args[]) throws Throwable {

    File path2DbEnv = null;

    for (int i = 0; i < args.length; ++i) {
      if (args[i].startsWith("-")) {
        switch (args[i].charAt(1)) {
          case 'h':
            path2DbEnv = new File(args[++i]);
            break;
          default:
            usage();
        }
      }
    }

    if (path2DbEnv == null || !path2DbEnv.isDirectory()) {
      usage();
    }

    myDbEnv env = null;
    XmlContainer openedContainer = null;
    XmlTransaction txn = null;
    try {
      // Open an environment
      env = new myDbEnv(path2DbEnv);
      XmlManager theMgr = env.getManager();

      // open a transactional container
      XmlContainerConfig config = new XmlContainerConfig();
      config.setTransactional(true);
      openedContainer = theMgr.openContainer(theContainer, config);

      // Start a transaction
      txn = theMgr.createTransaction();

      // Replace the index on the "product" node.
      replaceAnIndex(
          theMgr,
          openedContainer,
          "",
          "product",
          "node-attribute-substring-string node-element-equality-string",
          txn);
      // Commit the index replacement
      txn.commit();
    } catch (Exception e) {
      System.err.println("Error replacing index for container " + theContainer);
      System.err.println("   Message: " + e.getMessage());
      // In the event of an error, we abort the operation
      // The database is left in the same state as it was in before
      // we started this operation.
      if (txn != null) {
        txn.abort();
      }
      throw e;

    } finally {
      cleanup(env, openedContainer);
    }
  } // end main