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);
}
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);
}
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]));
}
}
}
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;
}
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();
}
Aggregations