Search in sources :

Example 16 with Database

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

the class NoteCoordinate method getView.

public View getView() {
    Database database = getDatabase("");
    Document doc = getDocument("");
    return database.getView(doc);
}
Also used : Database(org.openntf.domino.Database) Document(org.openntf.domino.Document)

Example 17 with Database

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

the class ConfigurationObject method syncCache.

/**
 * Syncs the <code>cache_<code> with the backend document. must be called from a proper initialized thread!
 */
public void syncCache() {
    Database odaDb_ = Configuration.getOdaDb();
    if (odaDb_ == null) {
        // we don't have an ODA-DB. so it's useless to query it again;
        // do not read the doc again before Sun Aug 17 17:12:55 EST 292278994
        nextDocAccess = Long.MAX_VALUE;
        return;
    }
    synchronized (dirty_) {
        // Create the document, if cache is dirty;
        Document doc = getDocument(true);
        if (doc == null)
            return;
        // write back all dirty keys to the document
        if (!dirty_.isEmpty()) {
            for (String dirtyKey : dirty_) {
                doc.put(dirtyKey, cache_.get(dirtyKey));
            }
            doc.save();
            dirty_.clear();
        }
        // read all keys from the document that are specified in the schema
        Object[] s = schema();
        for (int i = 0; i < s.length; i += 2) {
            cache_.put((String) s[i], doc.getItemValue((String) s[i], (Class<?>) s[i + 1]));
        }
    }
}
Also used : Database(org.openntf.domino.Database) Document(org.openntf.domino.Document)

Example 18 with Database

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

the class DatabaseTransaction method rollback.

/**
 * Discard all cached updates - updated documents are reverted back to their original state and documents marked for removal are kept in
 * Database. This transaction is then closed and a new one needs to be {@link org.openntf.domino.Database#startTransaction() started}.
 */
public void rollback() {
    // TODO - NTF release locks
    Queue<DatabaseDescendant> uq = getUpdateQueue();
    // synchronized (uq) {
    DatabaseDescendant next = uq.poll();
    while (next != null) {
        if (next instanceof org.openntf.domino.Document) {
            org.openntf.domino.Document doc = (org.openntf.domino.Document) next;
            doc.rollback();
            if (isDocLock(doc)) {
                doc.unlock();
            }
        }
        // TODO NTF - Implement other database objects
        next = uq.poll();
    }
    // }
    Queue<DatabaseDescendant> rq = getRemoveQueue();
    // synchronized (rq) {
    /*DatabaseDescendant*/
    next = rq.poll();
    while (next != null) {
        if (next instanceof org.openntf.domino.Document) {
            org.openntf.domino.Document doc = (org.openntf.domino.Document) next;
            doc.rollback();
            if (isDocLock(doc)) {
                doc.unlock();
            }
        }
        // TODO NTF - Implement other database objects
        next = rq.poll();
    }
    // }
    for (Database db : databases_) {
        db.closeTransaction();
    }
}
Also used : Database(org.openntf.domino.Database) Document(org.openntf.domino.Document) Document(org.openntf.domino.Document) DatabaseDescendant(org.openntf.domino.types.DatabaseDescendant)

Example 19 with Database

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

the class DatabaseTransaction method commit.

// public boolean isCommitting() {
// return isCommitting_;
// }
/**
 * Writes all cached updates to Documents - updated documents are saved and documents marked for removal will be removed. This
 * transaction is then closed and a new one needs to be {@link org.openntf.domino.Database#startTransaction() started}.
 */
public void commit() {
    // System.out.println("Committing transaction with update size " + getUpdateQueue().size());
    isCommitting_ = true;
    Queue<DatabaseDescendant> uq = getUpdateQueue();
    // synchronized (uq) {
    DatabaseDescendant next = uq.poll();
    while (next != null) {
        if (next instanceof Document) {
            boolean result = ((Document) next).save();
            if (!result) {
            // System.out.println("Transaction document save failed.");
            // TODO NTF - take some action to indicate that the save failed, potentially cancelling the transaction
            } else {
                if (isDocLock(next)) {
                    ((Document) next).unlock();
                }
            }
        }
        // TODO NTF - Implement other database objects
        next = uq.poll();
    }
    // }
    Queue<DatabaseDescendant> rq = getRemoveQueue();
    // synchronized (rq) {
    /*DatabaseDescendant*/
    next = rq.poll();
    while (next != null) {
        if (next instanceof org.openntf.domino.Document) {
            org.openntf.domino.Document doc = (org.openntf.domino.Document) next;
            if (isDocLock(doc)) {
                doc.unlock();
            }
            doc.forceDelegateRemove();
        }
        // TODO NTF - Implement other database objects
        next = rq.poll();
    }
    // }
    for (Database db : databases_) {
        db.closeTransaction();
    }
// database_.closeTransaction();
}
Also used : Database(org.openntf.domino.Database) Document(org.openntf.domino.Document) Document(org.openntf.domino.Document) DatabaseDescendant(org.openntf.domino.types.DatabaseDescendant)

Example 20 with Database

use of org.openntf.domino.Database 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)

Aggregations

Database (org.openntf.domino.Database)131 Session (org.openntf.domino.Session)73 Document (org.openntf.domino.Document)49 Test (org.junit.Test)19 View (org.openntf.domino.View)19 DbDirectory (org.openntf.domino.DbDirectory)17 NotesException (lotus.domino.NotesException)12 ArrayList (java.util.ArrayList)11 NoteCollection (org.openntf.domino.NoteCollection)11 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)10 DocumentCollection (org.openntf.domino.DocumentCollection)8 NoteCoordinate (org.openntf.domino.big.NoteCoordinate)8 Date (java.util.Date)6 UserAccessException (org.openntf.domino.exceptions.UserAccessException)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 ViewEntry (org.openntf.domino.ViewEntry)5 FastTable (javolution.util.FastTable)4 Item (org.openntf.domino.Item)4 RichTextItem (org.openntf.domino.RichTextItem)4