Example #1
0
 public Manager(boolean nuevo, File f) {
   Diagram diagram;
   if (!nuevo) {
     xM = new XmlManager(f);
     diagram = xM.getDiagram();
   } else {
     diagram = new Diagram("");
   }
   MT = new ModoTextoManager(diagram); // Modo editor de texto
   // MG = new ModoGraficoManager(); //Editor modo gráfico
   // No se si instanciarlo altiro
   this.ClickEvent = new pEvent();
   this.ClickEvent.addEventListener(this);
 }
Example #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();
  }
Example #3
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