Search in sources :

Example 1 with WrapperFactory

use of org.openntf.domino.WrapperFactory in project org.openntf.domino by OpenNTF.

the class AbstractSessionFactory method wrapSession.

protected Session wrapSession(final lotus.domino.Session raw, final boolean selfCreated) {
    WrapperFactory wf = Factory.getWrapperFactory();
    org.openntf.domino.Session sess = wf.fromLotus(raw, Session.SCHEMA, wf);
    sess.setNoRecycle(!selfCreated);
    Fixes[] fixes = Factory.getThreadConfig().fixes;
    if (fixes != null) {
        for (Fixes fix : fixes) {
            if (fix.isKhan()) {
                sess.setFixEnable(fix, true);
            }
        }
    }
    sess.setAutoMime(Factory.getThreadConfig().autoMime);
    sess.setConvertMIME(false);
    if (selfCreated && currentApiPath_ != null) {
        Database db = sess.getCurrentDatabase();
        if (db == null) {
            db = sess.getDatabase(currentApiPath_);
            setCurrentDatabase(sess, db);
        }
    }
    return sess;
}
Also used : WrapperFactory(org.openntf.domino.WrapperFactory) Fixes(org.openntf.domino.ext.Session.Fixes) Database(org.openntf.domino.Database) Session(org.openntf.domino.Session)

Example 2 with WrapperFactory

use of org.openntf.domino.WrapperFactory in project org.openntf.domino by OpenNTF.

the class DominoJUnitRunner method beforeTest.

@Override
protected void beforeTest(final FrameworkMethod method) {
    try {
        String runAs = getRunAs(method);
        String db = getDatabase(method);
        Factory.initThread(Factory.STRICT_THREAD_CONFIG);
        if (runAs == null) {
            Factory.setSessionFactory(new NativeSessionFactory(db), SessionType.CURRENT);
            Factory.setSessionFactory(new SessionFullAccessFactory(db), SessionType.CURRENT_FULL_ACCESS);
        } else {
            Factory.setSessionFactory(new NamedSessionFactory(db, runAs), SessionType.CURRENT);
            Factory.setSessionFactory(new SessionFullAccessFactory(db, runAs), SessionType.CURRENT_FULL_ACCESS);
        }
        TestEnv.session = Factory.getSession(SessionType.CURRENT);
        TestEnv.database = TestEnv.session.getCurrentDatabase();
        if (db != null) {
            assertNotNull(TestEnv.database);
        }
        if (isRunLegacy(method)) {
            WrapperFactory wf = Factory.getWrapperFactory();
            TestEnv.session = wf.toLotus(TestEnv.session);
            TestEnv.database = wf.toLotus(TestEnv.database);
        }
    } catch (NotesException ne) {
        ne.printStackTrace();
        fail(ne.toString());
    }
}
Also used : NotesException(lotus.domino.NotesException) WrapperFactory(org.openntf.domino.WrapperFactory) SessionFullAccessFactory(org.openntf.domino.session.SessionFullAccessFactory) NamedSessionFactory(org.openntf.domino.session.NamedSessionFactory) NativeSessionFactory(org.openntf.domino.session.NativeSessionFactory)

Example 3 with WrapperFactory

use of org.openntf.domino.WrapperFactory in project org.openntf.domino by OpenNTF.

the class DominoJUnitRunner method afterTest.

@Override
protected void afterTest(final FrameworkMethod method) {
    WrapperFactory wf = Factory.getWrapperFactory();
    wf.recycle(TestEnv.database);
    wf.recycle(TestEnv.session);
    TestEnv.session = null;
    TestEnv.database = null;
    Factory.termThread();
}
Also used : WrapperFactory(org.openntf.domino.WrapperFactory)

Example 4 with WrapperFactory

use of org.openntf.domino.WrapperFactory in project org.openntf.domino by OpenNTF.

the class NotesJUnitRunner method afterTest.

@Override
protected void afterTest(final FrameworkMethod method) {
    // TODO Auto-generated method stub
    WrapperFactory wf = Factory.getWrapperFactory();
    wf.recycle(TestEnv.database);
    wf.recycle(TestEnv.session);
    TestEnv.session = null;
    TestEnv.database = null;
}
Also used : WrapperFactory(org.openntf.domino.WrapperFactory)

Example 5 with WrapperFactory

use of org.openntf.domino.WrapperFactory in project org.openntf.domino by OpenNTF.

the class FormulaContextNotes method evaluateNative.

/**
 * does a native evaluate. This is needed for all functions that are too complex to implement in java or the algorithm is unknown
 *
 * @param formula
 *            the formula to evaluate
 * @param params
 *            the parameters are mapped to the field p1, p2 and so on
 * @return the value
 */
@SuppressWarnings("nls")
public ValueHolder evaluateNative(final String formula, final ValueHolder... params) {
    Database db = getDatabase();
    if (db == null)
        throw new UnsupportedOperationException("No database set: Can't evaluate Lotus native formula");
    Session session = db.getAncestorSession();
    WrapperFactory wf = session.getFactory();
    lotus.domino.Document rawDocument = wf.toLotus(getDocument());
    Document tmpDoc = null;
    if (params.length > 0) {
        tmpDoc = db.createDocument();
        rawDocument = session.getFactory().toLotus(tmpDoc);
        // fill the document
        for (int i = 0; i < params.length; i++) {
            try {
                // $NON-NLS-1$
                tmpDoc.replaceItemValue("p" + (i + 1), params[i].toList());
            } catch (EvaluateException e) {
                return params[i];
            }
        }
    } else {
        rawDocument = wf.toLotus(getDocument());
    }
    try {
        log_.warning("Evaluating native formula: '" + formula + "' This may affect performance");
        lotus.domino.Session rawSession = wf.toLotus(session);
        Vector<?> v = rawSession.evaluate(formula, rawDocument);
        Vector<Object> wrapped = wf.wrapColumnValues(v, session);
        rawSession.recycle(v);
        return ValueHolder.valueOf(wrapped);
    } catch (NotesException e) {
        log_.warning("NotesException: " + e.text);
        if (e.text.contains("Could not evaluate formula:"))
            return ValueHolder.valueOf(new EvaluateException(-1, -1, e));
        return ValueHolder.valueOf(new RuntimeException(e));
    }
}
Also used : Document(org.openntf.domino.Document) EvaluateException(org.openntf.formula.EvaluateException) NotesException(lotus.domino.NotesException) WrapperFactory(org.openntf.domino.WrapperFactory) Database(org.openntf.domino.Database) Session(org.openntf.domino.Session)

Aggregations

WrapperFactory (org.openntf.domino.WrapperFactory)5 NotesException (lotus.domino.NotesException)2 Database (org.openntf.domino.Database)2 Session (org.openntf.domino.Session)2 Document (org.openntf.domino.Document)1 Fixes (org.openntf.domino.ext.Session.Fixes)1 NamedSessionFactory (org.openntf.domino.session.NamedSessionFactory)1 NativeSessionFactory (org.openntf.domino.session.NativeSessionFactory)1 SessionFullAccessFactory (org.openntf.domino.session.SessionFullAccessFactory)1 EvaluateException (org.openntf.formula.EvaluateException)1