Search in sources :

Example 11 with Session

use of lotus.domino.Session in project org.openntf.domino by OpenNTF.

the class NotesRunner method run.

@Override
public void run() {
    try {
        System.out.println("Starting NotesRunner");
        Session session = NotesFactory.createSession();
        run4(session);
        session.recycle();
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.out.println("FINI!");
}
Also used : Session(lotus.domino.Session)

Example 12 with Session

use of lotus.domino.Session in project org.openntf.domino by OpenNTF.

the class TestRunner method run.

@SuppressWarnings({ "null", "unchecked" })
@Override
public void run() {
    Factory.enableCounters(true, false);
    try {
        System.out.println("Please type a Lotus domino @formula. Quit with CTRL+Z:");
        ASTNode n = null;
        List<Object> v = null;
        // String str = "t:={start}; @for(i:=1;i != 10; i:= i + 1; t:=t:@if(i = 1; {one} ; i <= 3; {two or three}; {four or more})); t";
        // String str = "x:=1:2*+32:64:1;x**x**x**x";
        String str = "@time(1800;2;3;4;15;18)";
        // String str = "@Transform((1:2:3)*+(0:3:6:9);{x};x*x)";
        System.out.println("Formula to test: " + str);
        long time = System.currentTimeMillis();
        // String str = "\"ab\\n\\x\\\"xyzz\"";
        // String str = "t:={start}; @for(i:=1;i != 10; i:= i + 1; t:=t:@Text(i)); @Transform(t;{x};x+{ test }+t)";
        // System.out.println(str);
        List<Function> funcs = new ArrayList<Function>();
        funcs.addAll(Formulas.getFunctionFactory().getFunctions().values());
        Collections.sort(funcs, new Comparator<Function>() {

            @Override
            public int compare(final Function o1, final Function o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
        for (Function func : funcs) {
            System.out.println(func);
        }
        FormulaParser parser = Formulas.getParser();
        for (int i = 1; i < 10000; i++) {
            java.io.StringReader sr = new java.io.StringReader(str);
            // java.io.Reader r = new java.io.BufferedReader(sr);
            n = parser.parse(sr, false);
        }
        time = System.currentTimeMillis() - time;
        System.err.println("[FormulaEngine] 10000x building AST tree\ttook " + time + "ms.");
        // n.dump("");
        time = System.currentTimeMillis();
        for (int i = 1; i < 10000; i++) {
            FormulaContext ctx = Formulas.createContext(null, parser);
            v = n.solve(ctx);
        }
        time = System.currentTimeMillis() - time;
        System.err.println("[FormulaEngine] 10000x evaluating AST tree\ttook " + time + "ms.");
        System.out.println("Result:\t" + v);
        org.openntf.domino.Session odaSess = Factory.getSession(SessionType.CURRENT);
        Session sess = odaSess.getFactory().toLotus(odaSess);
        @SuppressWarnings("unused") long startEvaluate = System.currentTimeMillis();
        try {
            time = System.currentTimeMillis();
            for (int i = 1; i < 10000; i++) {
                v = sess.evaluate(str);
            }
            time = System.currentTimeMillis() - time;
            System.err.println("[NotesNative] 10000x calling session.evaluate\ttook " + time + "ms.");
            System.out.println("Result:\t" + v);
        } catch (NotesException e) {
            e.printStackTrace();
        }
        System.out.println("Thank you.");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) FormulaContext(org.openntf.formula.FormulaContext) FormulaParser(org.openntf.formula.FormulaParser) NotesException(lotus.domino.NotesException) Function(org.openntf.formula.Function) NotesException(lotus.domino.NotesException) ASTNode(org.openntf.formula.ASTNode) Session(lotus.domino.Session)

Example 13 with Session

use of lotus.domino.Session in project org.openntf.domino by OpenNTF.

the class Connect17Standard method run.

@SuppressWarnings("unchecked")
@Override
public void run() {
    org.openntf.domino.Session sess = Factory.getSession(SessionType.NATIVE);
    try {
        TreeSet<String> names = new TreeSet<String>();
        Session session = TypeUtils.toLotus(sess);
        // Point to ExtLib demo, create a view called AllContactsByState
        // Copy AllContacts but adding a categorised column for State
        Database extLib = session.getDatabase(session.getServerName(), "odademo/oda_1.nsf");
        View states = extLib.getView("AllStates");
        states.setAutoUpdate(false);
        ViewEntry entState = states.getAllEntries().getFirstEntry();
        View byState = extLib.getView("AllContactsByState");
        byState.setAutoUpdate(false);
        Vector<String> key = new Vector<String>();
        Vector<String> stateVals = entState.getColumnValues();
        key.add(stateVals.get(0));
        ViewEntryCollection ec = byState.getAllEntriesByKey(key, true);
        ViewEntry ent = ec.getFirstEntry();
        while (null != ent) {
            Vector<Object> vals = ent.getColumnValues();
            names.add((String) vals.get(7));
            ViewEntry tmpEnt = ec.getNextEntry();
            ent.recycle(vals);
            ent.recycle();
            ent = tmpEnt;
        }
        System.out.println(names.toString());
    } catch (NotesException e) {
        e.printStackTrace();
    }
}
Also used : View(lotus.domino.View) NotesException(lotus.domino.NotesException) ViewEntry(lotus.domino.ViewEntry) TreeSet(java.util.TreeSet) Database(lotus.domino.Database) ViewEntryCollection(lotus.domino.ViewEntryCollection) Vector(java.util.Vector) Session(lotus.domino.Session)

Example 14 with Session

use of lotus.domino.Session in project org.openntf.domino by OpenNTF.

the class LegacyCollectionPerfTest method run.

@Override
public void run() {
    try {
        System.out.println("Starting NotesRunner");
        Session session = NotesFactory.createSession();
        Long sessId = getLotusId(session);
        sessionid.set(sessId);
        Database db = session.getDatabase("", "events4.nsf");
        System.out.println("Db id:" + getLotusId(db));
        try {
            lotus.domino.Document doc = null;
            lotus.domino.Document nextDoc = null;
            lotus.domino.DocumentCollection allDocs = db.getAllDocuments();
            System.out.println("All Collection has " + allDocs.getCount() + " documents");
            int[] nids = new int[allDocs.getCount()];
            long walkStartTime = System.nanoTime();
            doc = allDocs.getFirstDocument();
            int i = 0;
            while (doc != null) {
                nextDoc = allDocs.getNextDocument(doc);
                nids[i++] = Integer.valueOf(doc.getNoteID(), 16);
                doc.recycle();
                doc = nextDoc;
            }
            long walkEndTime = System.nanoTime();
            System.out.println("DOCWALK: noteid array has " + allDocs.getCount() + " entries in " + (walkEndTime - walkStartTime) / 1000 + "us");
            long ncStartTime = System.nanoTime();
            NoteCollection nc = db.createNoteCollection(false);
            nc.add(allDocs);
            nids = nc.getNoteIDs();
            long ncBuildTime = System.nanoTime();
            System.out.println("NOTECOLL: noteid array has " + nids.length + " entries in " + (ncBuildTime - ncStartTime) / 1000 + "us");
            // for (int j = 0; j < nids.length; j++) {
            // doc = db.getDocumentByID(Integer.toString(nids[j], 16));
            // }
            // long ncWalkTime = System.nanoTime();
            // System.out.println("NOTECOLL: noteid array walked " + nids.length + " entries in " + (ncWalkTime - ncBuildTime) / 1000
            // + "us");
            long mergeStartTime = System.nanoTime();
            DocumentCollection mergeColl = db.search("@False", db.getLastModified(), 1);
            for (int j = 0; j < nids.length; j++) {
                mergeColl.merge(nids[j]);
            }
            long mergeBuildTime = System.nanoTime();
            System.out.println("MERGECOLL: mergeColl has " + mergeColl.getCount() + " entries in " + (mergeBuildTime - mergeStartTime) / 1000 + "us");
            doc = mergeColl.getFirstDocument();
            while (doc != null) {
                nextDoc = mergeColl.getNextDocument(doc);
                int n = Integer.valueOf(doc.getNoteID(), 16);
                doc.recycle();
                doc = nextDoc;
            }
            long mergeWalkTime = System.nanoTime();
            System.out.println("MERGECOLL: mergeColl walked " + mergeColl.getCount() + " entries in " + (mergeWalkTime - mergeBuildTime) / 1000 + "us");
            System.out.println("MERGECOLL: mergeColl total time " + mergeColl.getCount() + " entries in " + (mergeWalkTime - ncStartTime) / 1000 + "us");
            walkStartTime = System.nanoTime();
            doc = allDocs.getFirstDocument();
            i = 0;
            while (doc != null) {
                nextDoc = allDocs.getNextDocument(doc);
                nids[i++] = Integer.valueOf(doc.getNoteID(), 16);
                doc.recycle();
                doc = nextDoc;
            }
            walkEndTime = System.nanoTime();
            System.out.println("DOCWALK: noteid array has " + allDocs.getCount() + " entries in " + (walkEndTime - walkStartTime) / 1000 + "us");
            ncStartTime = System.nanoTime();
            nc = db.createNoteCollection(false);
            nc.add(allDocs);
            nids = nc.getNoteIDs();
            ncBuildTime = System.nanoTime();
            System.out.println("NOTECOLL: noteid array has " + nids.length + " entries in " + (ncBuildTime - ncStartTime) / 1000 + "us");
            // for (int j = 0; j < nids.length; j++) {
            // doc = db.getDocumentByID(Integer.toString(nids[j], 16));
            // }
            // long ncWalkTime = System.nanoTime();
            // System.out.println("NOTECOLL: noteid array walked " + nids.length + " entries in " + (ncWalkTime - ncBuildTime) / 1000
            // + "us");
            mergeStartTime = System.nanoTime();
            mergeColl = db.search("@False", db.getLastModified(), 1);
            for (int j = 0; j < nids.length; j++) {
                mergeColl.merge(nids[j]);
            }
            mergeBuildTime = System.nanoTime();
            System.out.println("MERGECOLL: mergeColl has " + mergeColl.getCount() + " entries in " + (mergeBuildTime - mergeStartTime) / 1000 + "us");
            doc = mergeColl.getFirstDocument();
            while (doc != null) {
                nextDoc = mergeColl.getNextDocument(doc);
                int n = Integer.valueOf(doc.getNoteID(), 16);
                doc.recycle();
                doc = nextDoc;
            }
            mergeWalkTime = System.nanoTime();
            System.out.println("MERGECOLL: mergeColl walked " + mergeColl.getCount() + " entries in " + (mergeWalkTime - mergeBuildTime) / 1000 + "us");
            System.out.println("MERGECOLL: mergeColl total time " + mergeColl.getCount() + " entries in " + (mergeWalkTime - ncStartTime) / 1000 + "us");
            nc.recycle();
            allDocs.recycle();
            mergeColl.recycle();
        } catch (Throwable t) {
            t.printStackTrace();
        }
        session.recycle();
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.out.println("FINI!");
}
Also used : DocumentCollection(lotus.domino.DocumentCollection) NoteCollection(lotus.domino.NoteCollection) Database(lotus.domino.Database) DocumentCollection(lotus.domino.DocumentCollection) Session(lotus.domino.Session)

Example 15 with Session

use of lotus.domino.Session in project org.openntf.domino by OpenNTF.

the class XotsDominoExecutor method initModule.

/**
 * Helper for WrappedCallable/WrappedRunnable
 *
 * @param ctx
 * @param mcl
 * @param wrapper
 * @throws ServletException
 */
static void initModule(final NotesContext ctx, final ClassLoader mcl, final Object wrappedObject) throws ServletException {
    if (mcl instanceof ModuleClassLoader) {
        URLClassLoader dcl = (URLClassLoader) ((ModuleClassLoader) mcl).getDynamicClassLoader();
        String className = wrappedObject.getClass().getName();
        String str = className.replace('.', '/') + ".class";
        URL url = dcl.findResource(str);
        if (url != null && url.getProtocol().startsWith("xspnsf")) {
            // Set up the "TopLevelXPageSigner == Signer of the runnable
            // As soon as we are in a xspnsf, we do not have a SessionFactory!
            ctx.setSignerSessionRights("WEB-INF/classes/" + str);
            // RPr: There is a bug: you can decide if you want to use "sessionAsSigner" or "sessionAsSignerFullAccess"
            // But you cannot use both simultaneously!
            Session signerSession = ctx.getSessionAsSigner(true);
            if (signerSession != null) {
                Factory.setSessionFactory(new XPageSignerSessionFactory(false), SessionType.SIGNER);
                Factory.setSessionFactory(new XPageSignerSessionFactory(true), SessionType.SIGNER_FULL_ACCESS);
            } else {
                // do not setup signer sessions if it is not properly signed!
                Factory.setSessionFactory(new InvalidSessionFactory(), SessionType.SIGNER);
                Factory.setSessionFactory(new InvalidSessionFactory(), SessionType.SIGNER_FULL_ACCESS);
            }
        } else {
            // The code is not part from an NSF, so it resides on the server
            Factory.setSessionFactory(new XPageNamedSessionFactory(Factory.getLocalServerName(), false), SessionType.SIGNER);
            Factory.setSessionFactory(new XPageNamedSessionFactory(Factory.getLocalServerName(), true), SessionType.SIGNER_FULL_ACCESS);
        }
    }
    Factory.setClassLoader(mcl);
}
Also used : InvalidSessionFactory(org.openntf.domino.xsp.session.InvalidSessionFactory) XPageNamedSessionFactory(org.openntf.domino.xsp.session.XPageNamedSessionFactory) ModuleClassLoader(com.ibm.domino.xsp.module.nsf.ModuleClassLoader) URLClassLoader(java.net.URLClassLoader) XPageSignerSessionFactory(org.openntf.domino.xsp.session.XPageSignerSessionFactory) URL(java.net.URL) Session(lotus.domino.Session)

Aggregations

Session (lotus.domino.Session)24 Database (lotus.domino.Database)18 Document (lotus.domino.Document)12 NotesException (lotus.domino.NotesException)8 View (lotus.domino.View)4 ViewEntry (lotus.domino.ViewEntry)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 ExecutionException (java.util.concurrent.ExecutionException)2 DateTime (lotus.domino.DateTime)2 DocumentCollection (lotus.domino.DocumentCollection)2 Name (lotus.domino.Name)2 NoteCollection (lotus.domino.NoteCollection)2 ViewNavigator (lotus.domino.ViewNavigator)2 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 NotesSession (com.ibm.designer.domino.napi.NotesSession)1 HttpService (com.ibm.designer.runtime.domino.adapter.HttpService)1 ModuleClassLoader (com.ibm.domino.xsp.module.nsf.ModuleClassLoader)1 Sort (jakarta.nosql.Sort)1