コード例 #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();
  }
コード例 #2
0
 protected org.openntf.domino.Name testName(final String what, final NotesBug... notesbug)
     throws NotesException {
   Session s = Factory.getSession(SessionType.CURRENT);
   lotus.domino.Session ls = s.getFactory().toLotus(s);
   org.openntf.domino.Name o = s.createName(what);
   lotus.domino.Name n = ls.createName(what);
   compareNames(n.getCanonical(), n, o, notesbug);
   return o;
 }
コード例 #3
0
 /*
  * (non-Javadoc)
  *
  * @see org.openntf.domino.Replication#getCutoffDate()
  */
 @Override
 public DateTime getCutoffDate() {
   try {
     return Factory.fromLotus(getDelegate().getCutoffDate(), DateTime.class, this);
   } catch (NotesException e) {
     DominoUtils.handleException(e);
     return null;
   }
 }
コード例 #4
0
 protected Session getSession() {
   try {
     Session session = Factory.fromLotus(NotesFactory.createSession(), Session.class, null);
     return session;
   } catch (Throwable t) {
     DominoUtils.handleException(t);
     return null;
   }
 }
コード例 #5
0
 /*
  * (non-Javadoc)
  *
  * @see org.openntf.domino.DirectoryNavigator#getNthItemValue(int)
  */
 @Override
 public Vector<Object> getNthItemValue(int n) {
   try {
     return Factory.wrapColumnValues(getDelegate().getNthItemValue(n));
   } catch (NotesException e) {
     DominoUtils.handleException(e);
     return null;
   }
 }
コード例 #6
0
 /*
  * (non-Javadoc)
  *
  * @see org.openntf.domino.Directory#createNavigator()
  */
 @Override
 public DirectoryNavigator createNavigator() {
   try {
     return Factory.fromLotus(getDelegate().createNavigator(), DirectoryNavigator.class, this);
   } catch (NotesException e) {
     DominoUtils.handleException(e);
     return null;
   }
 }
コード例 #7
0
 /*
  * (non-Javadoc)
  *
  * @see org.openntf.domino.Replication#getEntry(java.lang.String, java.lang.String)
  */
 @Override
 public ReplicationEntry getEntry(final String source, final String destination) {
   try {
     return Factory.fromLotus(
         getDelegate().getEntry(source, destination), ReplicationEntry.class, this);
   } catch (NotesException e) {
     DominoUtils.handleException(e);
     return null;
   }
 }
コード例 #8
0
 /*
  * (non-Javadoc)
  *
  * @see org.openntf.domino.Replication#getEntries()
  */
 @Override
 public Vector<org.openntf.domino.ReplicationEntry> getEntries() {
   try {
     return Factory.fromLotusAsVector(
         getDelegate().getEntries(), org.openntf.domino.ReplicationEntry.class, this);
   } catch (NotesException e) {
     DominoUtils.handleException(e);
     return null;
   }
 }
コード例 #9
0
 /*
  * (non-Javadoc)
  *
  * @see org.openntf.domino.NotesProperty#getValues()
  */
 @Override
 public Vector<Object> getValues() {
   try {
     // Does this even use DateTime? Who knows?
     return Factory.wrapColumnValues(getDelegate().getValues(), this.getAncestorSession());
   } catch (NotesException e) {
     DominoUtils.handleException(e);
     return null;
   }
 }
コード例 #10
0
 private Document createDocument() {
   if (db == null) db = Factory.getSession().getDatabase("", "log.nsf");
   try {
     Document doc = db.createDocument();
     return doc;
   } catch (NullPointerException npe) {
     System.err.println("Cannot create demo doc. Is your server running?");
     return null;
   }
 }
コード例 #11
0
  @Override
  public void run() {
    try {

      for (Fixes fix : Fixes.values()) Factory.getSession().setFixEnable(fix, true);
      DominoUtils.setBubbleExceptions(true);

      File file = new File("tests/");
      FilenameFilter filefilter =
          new FilenameFilter() {
            public boolean accept(final File dir, final String name) {
              return name.endsWith(".txt") || dir.isDirectory();
            }
          };

      // Reading directory contents
      File[] files = file.listFiles(filefilter);

      for (int i = 0; i < files.length; i++) {
        System.out.println(files[i]);
        BufferedReader br = new BufferedReader(new FileReader(files[i]));
        String line;
        while ((line = br.readLine()) != null) {
          line = line.trim();
          if (Strings.isBlankString(line)) {

          } else if (line.startsWith("#")) {
            NTF(line);
          } else {
            execute(line, true, true, true);
          }
        }
        br.close();
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    // System.out.println(Factory.dumpCounters(true));
    db = null;
    Factory.terminate();
    System.out.println(Factory.dumpCounters(true));
  }
コード例 #12
0
 /*
  * (non-Javadoc)
  *
  * @see org.openntf.domino.Directory#lookupNames(java.lang.String, java.lang.String, java.lang.String)
  */
 @Override
 public DirectoryNavigator lookupNames(String view, String name, String item) {
   try {
     return Factory.fromLotus(
         getDelegate().lookupNames(view, name, item), DirectoryNavigator.class, this);
   } catch (NotesException e) {
     DominoUtils.handleException(e);
     return null;
   }
 }
コード例 #13
0
 /*
  * (non-Javadoc)
  *
  * @see org.openntf.domino.Directory#lookupAllNames(java.lang.String, java.util.Vector)
  */
 @SuppressWarnings("unchecked")
 @Override
 public DirectoryNavigator lookupAllNames(String view, Vector items) {
   try {
     return Factory.fromLotus(
         getDelegate().lookupAllNames(view, items), DirectoryNavigator.class, this);
   } catch (NotesException e) {
     DominoUtils.handleException(e);
     return null;
   }
 }
コード例 #14
0
  /**
   * Determines the sessionType under which the current runnable should run. The first non-null
   * value of the following list is returned
   *
   * <ul>
   *   <li>If the runnable implements <code>IDominoRunnable</code>: result of <code>getSessionType
   *       </code>
   *   <li>the value of {@link SessionType} Annotation
   *   <li>DominoSessionType.DEFAULT
   * </ul>
   *
   * @param task the runnable to determine the DominoSessionType
   */
  protected synchronized void init(final Object task) {
    threadInitializer =
        ServiceLocator.findApplicationService(ThreadInitializerFactory.class).create();
    request = LifeCycleManager.getCurrentRequest();
    if (request == null) {
      request = new RequestImpl("DominoTasklet: " + task.getClass().getName());
    } else {
      request = request.clone("DominoTasklet: " + task.getClass().getName());
    }
    DominoTasklet annot = task.getClass().getAnnotation(DominoTasklet.class);
    if (annot != null) {
      if (sessionFactory == null) {
        switch (annot.session()) {
          case CLONE:
            sessionFactory = Factory.getSessionFactory(SessionType.CURRENT);
            break;

          case CLONE_FULL_ACCESS:
            sessionFactory = Factory.getSessionFactory(SessionType.CURRENT_FULL_ACCESS);
            break;

          case FULL_ACCESS:
            sessionFactory = Factory.getSessionFactory(SessionType.FULL_ACCESS);
            break;

          case NATIVE:
            sessionFactory = Factory.getSessionFactory(SessionType.NATIVE);
            break;

          case NONE:
            sessionFactory = null;
            break;

          case SIGNER:
            sessionFactory = Factory.getSessionFactory(SessionType.SIGNER);
            break;

          case SIGNER_FULL_ACCESS:
            sessionFactory = Factory.getSessionFactory(SessionType.SIGNER_FULL_ACCESS);
            break;

          case TRUSTED:
            sessionFactory = Factory.getSessionFactory(SessionType.TRUSTED);
            break;

          default:
            break;
        }
        if ((annot.session() != DominoTasklet.Session.NONE) && sessionFactory == null) {
          throw new IllegalStateException("Could not create a Fatory for " + annot.session());
        }
      }
    }
  }
コード例 #15
0
    @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();
      // }

    }
コード例 #16
0
 @Override
 public RET call() throws Exception {
   threadInitializer.initThread();
   try {
     LifeCycleManager.beforeRequest(request);
     try {
       Factory.setSessionFactory(sessionFactory, SessionType.CURRENT);
       return inner.call();
     } catch (Exception e) {
       System.err.println("Error while executing " + inner.getClass().getName());
       e.printStackTrace();
       throw e;
     } finally {
       LifeCycleManager.afterRequest();
     }
   } finally {
     threadInitializer.termThread();
   }
 }
コード例 #17
0
 /** @deprecated needed for {@link Externalizable} - do not use! */
 @Deprecated
 public DateTime() {
   // it does not matter which session we use here, so we use the current one!
   super(null, Factory.getSession(SessionType.CURRENT), NOTES_TIME);
 }
コード例 #18
0
  protected void execute(
      final String line, final boolean testLotus, final boolean testDoc, final boolean testMap) {
    // TODO Auto-generated method stub

    List<Object> ntfDocResult = null;
    List<Object> ntfMapResult = null;
    List<Object> lotusResult = null;
    Throwable ntfError = null;
    boolean lotusFailed = false;
    boolean parserFailed = false;
    // Setup procedure, prepare the demo docs & maps
    StringBuffer errors = new StringBuffer();

    double rnd = Math.random();
    Document ntfDoc = createDocument();
    Document lotusDoc = createDocument();
    Map<String, Object> ntfMap = new HashMap<String, Object>();

    fillDemoDoc(ntfDoc, rnd);
    fillDemoDoc(lotusDoc, rnd);
    fillDemoDoc(ntfMap, rnd);
    lotus.domino.Session rawSession = Factory.toLotus(Factory.getSession());
    lotus.domino.Document rawDocument = Factory.toLotus(lotusDoc);
    if (testLotus) {
      try {

        lotusResult = rawSession.evaluate(line, rawDocument);
      } catch (NotesException e) {
        errors.append(LOTUS("\tLotus failed: ") + ERROR(e) + "\n");
        lotusFailed = true;
      } catch (Throwable t) {
        System.err.println(ERROR("FATAL") + LOTUS("\tLotus failed: ") + ERROR(t));
      }
    }

    // benchmark the AtFormulaParser
    ASTNode ast = null;
    FormulaParser parser = Formulas.getParser();
    try {
      ast = parser.parse(line);
    } catch (FormulaParseException e) {
      errors.append(NTF("\tParser failed: ") + ERROR(e) + "\n");
      e.printStackTrace();
      parserFailed = true;
    } catch (Throwable t) {
      System.err.println(ERROR("FATAL") + NTF("\tParser failed: ") + ERROR(t));
      t.printStackTrace();
    }

    if (!parserFailed) {
      if (testDoc) {
        try {
          FormulaContext ctx1 = Formulas.createContext(ntfDoc, parser);
          ntfDocResult = ast.solve(ctx1);
        } catch (EvaluateException e) {
          errors.append(NTF("\tDoc-Evaluate failed: ") + ERROR(e) + "\n");
          ntfError = e;
          parserFailed = true;
        } catch (Throwable t) {
          System.err.println(ERROR("FATAL") + NTF("\tDoc-Evaluate failed: ") + ERROR(t));
          t.printStackTrace();
        }
      }
      if (testMap) {
        try {
          // benchmark the evaluate with a map as context
          FormulaContext ctx2 = Formulas.createContext(ntfMap, parser);
          ntfMapResult = ast.solve(ctx2);
        } catch (EvaluateException e) {
          errors.append(NTF("\tMap-Evaluate failed: ") + ERROR(e) + "\n");
          ntfError = e;
          parserFailed = true;
        } catch (Throwable t) {
          System.err.println(ERROR("FATAL") + NTF("\tMap-Evaluate failed: ") + ERROR(t));
          t.printStackTrace();
        }
      }
    }

    if (lotusFailed && parserFailed) {
      System.out.println(SUCCESS() + dump(line + " = UNDEFINED"));

      return;
    }

    if (testLotus && testDoc) {
      if (compareList(ntfDocResult, lotusResult)) {
        System.out.println(SUCCESS() + line + " = " + dump(ntfDocResult));
      } else {
        System.err.println(FAIL() + NTF("DOC:") + line);
        System.err.println(
            "\tResult:   "
                + dump(ntfDocResult)
                + " Size: "
                + ((ntfDocResult == null) ? 0 : ntfDocResult.size()));
        System.err.println(
            "\tExpected: "
                + dump(lotusResult)
                + " Size: "
                + ((lotusResult == null) ? 0 : lotusResult.size()));
        if (parserFailed || lotusFailed) {
          System.err.println(errors.toString());
          if (ntfError != null) {
            ntfError.printStackTrace(System.err);
          }
        }
        BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
        try {
          console.readLine();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } else {
      if (parserFailed) {
        ntfError.printStackTrace();
      }
      System.err.println(
          "\tDocResult:   "
              + dump(ntfDocResult)
              + " Size: "
              + ((ntfDocResult == null) ? 0 : ntfDocResult.size()));
      System.err.println(
          "\tMapResult:   "
              + dump(ntfMapResult)
              + " Size: "
              + ((ntfMapResult == null) ? 0 : ntfMapResult.size()));
    }
    System.out.println(NTF("Read fields\t") + ast.getReadFields());
    System.out.println(NTF("Modified fields\t") + ast.getModifiedFields());
    System.out.println(NTF("Variables\t") + ast.getVariables());
    System.out.println(NTF("Functions\t") + ast.getFunctions());
  }
コード例 #19
0
 /**
  * Gets the Domino program folder (notes for XPiNC app running locally)
  *
  * @return String domino folder
  * @since org.openntf.domino.xsp 2.5.0
  */
 public String getProgramFolder() {
   String filename = Factory.getProgramPath();
   filename = filename.replace("\\", "/");
   if (!filename.endsWith("/")) filename += "/";
   return filename;
 }