Search in sources :

Example 21 with Document

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

the class DatabaseDesign method getDesignElementByName.

@SuppressWarnings("unchecked")
public <T extends DesignBase> T getDesignElementByName(final Class<T> type, final String name, final boolean create) {
    if (DominoUtils.isUnid(name)) {
        Document doc = database_.getDocumentByUNID(name);
        return (T) DesignFactory.fromDocument(doc);
    }
    Iterator<T> elems = getDesignElementsByName(type, name).iterator();
    if (elems.hasNext()) {
        return elems.next();
    }
    if (!create) {
        return null;
    }
    for (ODPMapping mapping : ODPMapping.values()) {
        Class<? extends AbstractDesignBase> cls = mapping.getInstanceClass();
        if (type.isAssignableFrom(cls)) {
            try {
                Constructor<? extends AbstractDesignBase> cTor = cls.getConstructor(Database.class);
                AbstractDesignBase ret = cTor.newInstance(getAncestorDatabase());
                if (ret instanceof DesignBaseNamed) {
                    ((DesignBaseNamed) ret).setName(name);
                }
                return (T) ret;
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }
    throw new IllegalArgumentException("Cannot Create a DesignElement of type " + type.getName() + " with name " + name);
}
Also used : DesignBaseNamed(org.openntf.domino.design.DesignBaseNamed) XMLDocument(org.openntf.domino.utils.xml.XMLDocument) Document(org.openntf.domino.Document) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with Document

use of org.openntf.domino.Document 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 23 with Document

use of org.openntf.domino.Document 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 24 with Document

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

the class DatabaseSchema method createDocument.

@SuppressWarnings("unused")
@Override
public Document createDocument(final Database db, final String doctype) {
    DocumentDefinition def = getDocumentDefinitions().get(doctype);
    if (def == null)
        return null;
    Document result = db.createDocument();
    // $NON-NLS-1$
    result.replaceItemValue("$$SchemaType", doctype);
    // $NON-NLS-1$
    result.replaceItemValue("form", def.getName());
    Map<String, IItemDefinition> itemDefs = def.getItemDefinitions();
    for (String key : itemDefs.keySet()) {
        IItemDefinition itemDef = itemDefs.get(key);
        Item item = itemDef.createDefaultItem(result, def);
    }
    return result;
}
Also used : Item(org.openntf.domino.Item) Document(org.openntf.domino.Document) IItemDefinition(org.openntf.domino.schema.IItemDefinition)

Example 25 with Document

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

Aggregations

Document (org.openntf.domino.Document)112 Database (org.openntf.domino.Database)48 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)31 Session (org.openntf.domino.Session)28 Map (java.util.Map)20 HashSet (java.util.HashSet)15 LinkedHashMap (java.util.LinkedHashMap)15 DocumentCollection (org.openntf.domino.DocumentCollection)15 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 Item (org.openntf.domino.Item)13 Set (java.util.Set)12 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 HashMap (java.util.HashMap)9 View (org.openntf.domino.View)9 Collection (java.util.Collection)8 UserAccessException (org.openntf.domino.exceptions.UserAccessException)8 Serializable (java.io.Serializable)7 Test (org.junit.Test)7 NotesException (lotus.domino.NotesException)6