public static String selectTaskId() {
      XhiveDriverIf driver = XhiveDriverFactory.getDriver("xhive://localhost:1235");
      if (driver.isInitialized() == false) driver.init();

      XhiveSessionIf session = driver.createSession("xqapi-test");
      session.connect("Administrator", "imen", "vbpmn");
      session.begin();
      String s2 = "";
      try {
        XhiveLibraryIf rootLibrary = session.getDatabase().getRoot();
        // (1)
        int j = 0;
        IterableIterator<? extends XhiveXQueryValueIf> result =
            rootLibrary.executeXQuery(
                "for  $a in fn:doc('Last_activity.xml')/Activities return $a/id");

        while (result.hasNext()) {
          s2 = result.next().toString();
          j = s2.indexOf("<id>");
          s2 = s2.substring(j + 4);
          j = s2.indexOf("</id>");
          s2 = s2.substring(0, j);
        }

        session.commit();
      } finally {
        session.rollback();
      }
      return s2;
    }
    public static void UpdateTaskId(String id) {
      XhiveDriverIf driver = XhiveDriverFactory.getDriver("xhive://localhost:1235");
      if (driver.isInitialized() == false) driver.init();

      XhiveSessionIf session = driver.createSession("xqapi-test");
      session.connect("Administrator", "imen", "vbpmn");
      session.begin();

      try {
        XhiveLibraryIf rootLibrary = session.getDatabase().getRoot();
        // (1)
        int j = 0;

        j = Integer.parseInt(id);
        j++;
        IterableIterator<? extends XhiveXQueryValueIf> result =
            rootLibrary.executeXQuery(
                "for  $a in fn:doc('Last_activity.xml')/Activities let $o:='"
                    + j
                    + "' return replace value of node $a/id with $o");

        session.commit();
      } finally {
        session.rollback();
      }
    }
    public static String Selectstate(String id_v) {
      XhiveDriverIf driver = XhiveDriverFactory.getDriver("xhive://localhost:1235");
      int i = 0;
      if (driver.isInitialized() == false) driver.init();

      XhiveSessionIf session = driver.createSession("xqapi-test");
      session.connect("Administrator", "imen", "vbpmn");
      session.begin();
      String s2 = "";
      try {
        XhiveLibraryIf rootLibrary = session.getDatabase().getRoot();
        // (1)
        int j = 0;
        IterableIterator<? extends XhiveXQueryValueIf> result =
            rootLibrary.executeXQuery(
                "for $o in doc('Processes.xml')/Processes/Process for $i in $o/versions/version where $i/id_v='"
                    + id_v
                    + "' return $i/state");
        //  IterableIterator<? extends XhiveXQueryValueIf>  result = rootLibrary.executeXQuery("for
        // $p in fn:doc('Processes.xml')/Processes/Process  let $i:=<version></version> where
        // $p/name='"+name+"' return insert nodes  $i into $p/versions");
        while (result.hasNext()) {
          s2 = result.next().toString();
          System.out.println(j + "s2" + s2);
          j++;
        }
        s2 = s2.substring(7);
        j = s2.indexOf("<");
        s2 = s2.substring(0, j);

        session.commit();
      } finally {
        session.rollback();
      }

      return s2;
    }
Ejemplo n.º 4
0
  public static void main(String[] args) {

    // the name of the database
    String databaseName = "apriori";

    // the name and password of the administrator of the database
    String administratorName = SampleProperties.administratorName;
    String administratorPassword = SampleProperties.administratorPassword;

    // create a session
    XhiveDriverIf driver = XhiveDriverFactory.getDriver();
    driver.init(1024);
    XhiveSessionIf session = driver.createSession();

    try {

      // open a connection to the database
      session.connect(administratorName, administratorPassword, databaseName);

      // create a Reporter for some nice output
      Reporter rep = new Reporter();

      // begin the transaction
      session.begin();

      // get a handle to the database
      XhiveDatabaseIf united_nations_db = session.getDatabase();

      // get a handle to the root library
      XhiveLibraryIf rootLibrary = united_nations_db.getRoot();

      // get/create the "UN Charter" library
      XhiveLibraryIf charterLib =
          DataLoader.createLibrary(united_nations_db, rootLibrary, "UN Charter", session);

      // load the sample documents
      DataLoader.storeDocuments(united_nations_db, charterLib, session);

      // retrieve the documents thru DOM operations
      System.out.println("\n#Retrieving documents thru DOM operations...");

      // count the number of children of the "UN Charter" library
      int nrChildren = 0;
      if (charterLib.hasChildNodes()) {
        Node n = charterLib.getFirstChild();
        while (n != null) {
          nrChildren++;
          n = n.getNextSibling();
        }
      }
      System.out.println("library \"UN Charter\" has " + nrChildren + " children");

      // retrieve the documents by ID
      System.out.println("\n#Retrieving documents by ID...");
      int anId = 10;
      Node child = charterLib.get(anId);
      System.out.println(
          "document with ID = "
              + anId
              + " in \"UN Charter\" has name: "
              + ((XhiveLibraryChildIf) child).getName());

      // retrieve the documents by name
      System.out.println("\n#Retrieving documents by name...");
      String documentName = "UN Charter - Chapter 2";
      Document docRetrievedByName = (Document) charterLib.get(documentName);
      System.out.println(
          "the ID of the document with name \""
              + documentName
              + "\" is: "
              + ((XhiveLibraryChildIf) docRetrievedByName).getId());

      // retrieve the name of the document by executeFullPathXPointerQuery (FPXPQ)
      System.out.println("\n#Retrieving documents by executeFullPathXPointerQuery...");
      Document docRetrievedByFPXPQ =
          (Document) rootLibrary.getByPath("/UN Charter/UN Charter - Chapter 2");
      System.out.println(docRetrievedByFPXPQ.toString());

      // use FPXPQ with a relative path
      System.out.println(
          "\n#Retrieving documents by executeFullPathXPointerQuery - using relative path...");
      // create a new sub library of UN Charter
      XhiveLibraryIf newLib = charterLib.createLibrary(XhiveLibraryIf.LOCK_WITH_PARENT);
      newLib.setName("sub library of UN Charter");
      charterLib.appendChild(newLib);

      // execute the FullPathXPointerQuery relative to the new sub library
      docRetrievedByFPXPQ = (Document) newLib.getByPath("../UN Charter - Chapter 3");
      System.out.println(docRetrievedByFPXPQ.toString());

      // and delete the sub library
      charterLib.removeChild(newLib);

      session.commit();

    } catch (Exception e) {

      System.out.println("RetrieveDocuments sample failed: ");
      e.printStackTrace();

    } finally {

      // disconnect and remove the session
      if (session.isOpen()) {
        session.rollback();
      }
      if (session.isConnected()) {
        session.disconnect();
      }

      driver.close();
    }
  }