Ejemplo n.º 1
0
  public void resetDbs() {
    System.out.println("Resetting Star Wars test databases");
    Session session = Factory.getSession(SessionType.NATIVE);
    Database crewDb = session.getDatabase(crewPath);
    if (crewDb != null) {
      crewDb.getAllDocuments().removeAll(true);
    } else {
      Factory.println("crewDb was null");
    }
    Database movieDb = session.getDatabase(moviePath);
    if (movieDb != null) {
      movieDb.getAllDocuments().removeAll(true);
    }
    Database characterDb = session.getDatabase(charactersPath);
    if (characterDb != null) {
      characterDb.getAllDocuments().removeAll(true);
    }
    Database edgeDb = session.getDatabase(edgePath);
    if (edgeDb != null) {
      edgeDb.getAllDocuments().removeAll(true);
    }

    //		Database nabDb = session.getDatabase("", "names.nsf");
    //		Document ntfDoc = nabDb.getDocumentByUNID(ntfUnid);
    //		ntfDoc.removeItem("_COUNT_OPEN_OUT_rates");
    //		ntfDoc.removeItem("_OPEN_OUT_rates");
    //		ntfDoc.removeItem("_ODA_GRAPHTYPE");
    //		ntfDoc.save();

    session.recycle();
    System.gc();
  }
  @Override
  public void run() {
    Session session = this.getSession();
    session.setConvertMIME(false);
    session.setFixEnable(Fixes.APPEND_ITEM_VALUE, true);
    session.setFixEnable(Fixes.FORCE_JAVA_DATES, true);
    session.setFixEnable(Fixes.CREATE_DB, true);
    Database db = session.getDatabase("", "log.nsf");
    Document doc = db.createDocument();
    doc.replaceItemValue("form", "Events");
    doc.replaceItemValue("Server", "Test");
    Map<String, String> map = new HashMap<String, String>();
    map.put("me", "us");
    map.put("myself", "ourselves");
    map.put("I", "we");
    doc.replaceItemValue("map", map);
    doc.save();
    String unid = doc.getUniversalID();
    doc = null;
    Document docJunk = db.createDocument();
    doc = db.getDocumentByUNID(unid);
    System.out.println(doc.getNoteID());
    Object o = doc.getItemValue("map", Map.class);
    System.out.println(o.getClass().getName());
    Map<String, String> remap = (Map<String, String>) o;

    for (String key : remap.keySet()) {
      System.out.println(key + ":" + remap.get(key));
    }
    session.setConvertMIME(true);
    doc = null;
    docJunk = db.createDocument();
    doc = db.getDocumentByUNID(unid);
    Vector<Item> items = doc.getItems();
    for (Item item : items) {
      if (item.getName().equalsIgnoreCase("map")) {
        System.out.println("map: " + item.getType());
        System.out.println("map value: " + item.getText());
      }
    }
    doc.replaceItemValue("foo", "bar");
    doc.save();
    session.setConvertMIME(false);
    o = null;
    doc = null;
    docJunk = db.createDocument();
    doc = db.getDocumentByUNID(unid);
    o = doc.getItemValue("map", Map.class);
    System.out.println(o.getClass().getName());
    remap = (Map<String, String>) o;

    for (String key : remap.keySet()) {
      System.out.println(key + ":" + remap.get(key));
    }

    System.out.println("Complete");
  }
    @Override
    public void run() {
      long start = System.nanoTime();

      Session s = Factory.getSession();
      Database db = s.getDatabase("", "events4.nsf");
      Base.lock(s, db);

      int delay = 500;
      DominoChildThread[] threads = new DominoChildThread[THREAD_COUNT];
      Map<String, lotus.domino.Base> context = new HashMap<String, lotus.domino.Base>();
      context.put("session", s);
      context.put("database", db);
      for (int i = 0; i < THREAD_COUNT; i++) {
        threads[i] = new DominoChildThread(new Doer(), "Scratch Test " + i);
        threads[i].setContext(context);
      }

      for (DominoChildThread thread : threads) {
        thread.start();
        try {
          Thread.sleep(delay);
        } catch (InterruptedException e1) {
          DominoUtils.handleException(e1);
        }
      }

      for (DominoChildThread thread : threads) {
        try {
          thread.join();
        } catch (InterruptedException e) {
          DominoUtils.handleException(e);
        }
      }

      for (DominoChildThread thread : threads) {
        thread.close();
      }

      Base.unlock(s, db);

      // boolean keepGoing = true;
      // while (keepGoing) {
      // for (Thread t : threads) {
      // keepGoing = (keepGoing || t.isAlive());
      // }
      // Thread.yield();
      // }

    }