Search in sources :

Example 21 with Database

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

the class DElementStore method getVertexIds.

// @Override
// public Set<Vertex> getCachedVertices() {
// FastSet<Vertex> result = new FastSet<Vertex>();
// for (Element elem : getElementCache().values()) {
// if (elem instanceof Vertex) {
// result.add((Vertex) elem);
// }
// }
// return result.unmodifiable();
// }
protected List<NoteCoordinate> getVertexIds() {
    FastTable<NoteCoordinate> result = new FastTable<NoteCoordinate>();
    Object raw = getStoreDelegate();
    if (raw instanceof Database) {
        Database db = (Database) raw;
        NoteCollection nc = db.createNoteCollection(false);
        nc.setSelectDocuments(true);
        nc.setSelectionFormula(org.openntf.domino.graph2.DVertex.FORMULA_FILTER);
        nc.buildCollection();
        for (String noteid : nc) {
            result.add(NoteCoordinate.Utils.getNoteCoordinate(nc, noteid));
        }
    } else {
        // TODO NTF implement alternative
        throw new IllegalStateException("Non-Domino implementations not yet available");
    }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) NoteCollection(org.openntf.domino.NoteCollection) FastTable(javolution.util.FastTable) Database(org.openntf.domino.Database)

Example 22 with Database

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

the class DElementStore method findElementDelegate.

// @Override
@Override
public Object findElementDelegate(final Object delegateKey) throws IllegalStateException, IllegalArgumentException {
    Object result = null;
    Object del = null;
    del = getStoreDelegate();
    if (isProxied()) {
        // System.out.println("TEMP DEBUG Retrieving from proxied store for key " + String.valueOf(delegateKey));
        NoteCoordinate nc = null;
        if (delegateKey instanceof NoteCoordinate) {
            nc = (NoteCoordinate) delegateKey;
        } else if (delegateKey instanceof CharSequence) {
            nc = NoteCoordinate.Utils.getNoteCoordinate((CharSequence) delegateKey);
        }
        if (nc != null) {
            long dbkey = nc.getReplicaLong();
            if (getProxyStoreKey().equals(dbkey)) {
                del = getProxyStoreDelegate();
            }
        }
    }
    if (del instanceof Database) {
        Database db = (Database) del;
        boolean isDeletedDoc;
        db.getAncestorSession().setFixEnable(Fixes.MIME_BLOCK_ITEM_INTERFACE, false);
        if (delegateKey instanceof Serializable) {
            if (delegateKey instanceof ViewEntryCoordinate) {
                result = ((ViewEntryCoordinate) delegateKey).getViewEntry();
            } else if (delegateKey instanceof NoteCoordinate) {
                String unid = ((NoteCoordinate) delegateKey).getUNID();
                try {
                    result = db.getDocumentWithKey(unid, false);
                } catch (UserAccessException uae) {
                // this is normal and acceptable. Don't report.
                } catch (RuntimeException re) {
                    throw re;
                }
                if (result != null) {
                    if (((Document) result).isDeleted()) {
                        isDeletedDoc = true;
                        result = null;
                    }
                }
            // System.out.println("Retrieved result using NoteCoordinate with unid " + unid);
            } else if (delegateKey instanceof CharSequence) {
                String skey = ((CharSequence) delegateKey).toString();
                if (skey.length() > 50) {
                    String prefix = skey.subSequence(0, 2).toString();
                    String mid = skey.subSequence(2, 50).toString();
                    if ((prefix.equals("EC") || prefix.equals("ED") || prefix.equals("ET") || prefix.equals("EU")) && DominoUtils.isMetaversalId(mid)) {
                        ViewEntryCoordinate vec = ViewEntryCoordinate.Utils.getViewEntryCoordinate(skey);
                        result = vec.getViewEntry();
                    } else if ((prefix.equals("VC") || prefix.equals("VD") || prefix.equals("VT") || prefix.equals("VU")) && DominoUtils.isMetaversalId(mid)) {
                        ViewEntryCoordinate vec = ViewEntryCoordinate.Utils.getViewEntryCoordinate(skey);
                        result = vec.getViewEntry();
                    }
                }
            }
            if (result == null) {
                result = db.getDocumentWithKey((Serializable) delegateKey, false);
                if (result != null) {
                    if (((Document) result).isDeleted()) {
                        isDeletedDoc = true;
                        result = null;
                    }
                }
            }
            if (result != null) {
                // }
                if (isProxied()) {
                    // System.out.println("TEMP DEBUG from findElementDelegate: ElementStore "
                    // + ((Database) getStoreDelegate()).getApiPath() + "is proxied. Setting up proxy on delegate...");
                    result = setupProxy(result, (Serializable) delegateKey);
                } else {
                // System.out.println("TEMP DEBUG ElementStore " + ((Database) getStoreDelegate()).getApiPath() + " is not proxied.");
                }
            }
        } else {
            if (delegateKey != null) {
                System.out.println("WARNING: Unknown delegatekey of type " + delegateKey.getClass().getName() + ". Creating a brand new delegate.");
            }
            // null is a perfectly valid key, since it means we want to let the system assign it.
            result = db.createDocument();
        // throw new IllegalArgumentException("Cannot find a delegate with a key of type "
        // + (delegateKey == null ? "null" : delegateKey.getClass().getName()));
        }
    } else {
        throw new IllegalStateException("ElementStore delegate is not a Database; it's a " + (del == null ? "null" : del.getClass().getName()) + ". We don't handle this case yet.");
    // TODO NTF alternative strategies...
    }
    // }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) Serializable(java.io.Serializable) Document(org.openntf.domino.Document) UserAccessException(org.openntf.domino.exceptions.UserAccessException) ViewEntryCoordinate(org.openntf.domino.big.ViewEntryCoordinate) Database(org.openntf.domino.Database)

Example 23 with Database

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

the class DElementStore method getVertexIds.

protected List<NoteCoordinate> getVertexIds(final String formulaFilter) {
    FastTable<NoteCoordinate> result = new FastTable<NoteCoordinate>();
    Object raw = getStoreDelegate();
    if (raw instanceof Database) {
        Database db = (Database) raw;
        NoteCollection nc = db.createNoteCollection(false);
        nc.setSelectDocuments(true);
        nc.setSelectionFormula(formulaFilter);
        nc.buildCollection();
        for (String noteid : nc) {
            result.add(NoteCoordinate.Utils.getNoteCoordinate(nc, noteid));
        }
    } else {
        // TODO NTF implement alternative
        throw new IllegalStateException("Non-Domino implementations not yet available");
    }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) NoteCollection(org.openntf.domino.NoteCollection) FastTable(javolution.util.FastTable) Database(org.openntf.domino.Database)

Example 24 with Database

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

the class DElementStore method wrapProxiedVertex.

public DProxyVertex wrapProxiedVertex(final Map<String, Object> delegate) {
    // System.out.println("Wrapping a proxied vertex...");
    DVertex vertex = new DVertex(getConfiguration().getGraph(), delegate);
    Object pDelegate = getProxyStoreDelegate();
    Serializable pKey = null;
    Map<String, Object> proxyDelegate = null;
    pKey = getKeyProperty(delegate);
    if (pKey == null) {
        if (delegate instanceof Document) {
            pKey = ((Document) delegate).getMetaversalID();
        } else {
        // TODO future implementations...
        }
    }
    if (pDelegate instanceof Database) {
        Database pDb = ((Database) pDelegate);
        // System.out.println("Creating proxy version in database " + pDb.getApiPath());
        Document pDoc = pDb.getDocumentWithKey(pKey, true);
        if (pDoc != null && pDoc.isNewNote()) {
            pDoc.save();
        }
        proxyDelegate = pDoc;
    } else {
    // TODO future implementations...
    }
    DProxyVertex result = new DProxyVertex(getConfiguration().getGraph(), vertex, proxyDelegate);
    return result;
}
Also used : Serializable(java.io.Serializable) Database(org.openntf.domino.Database) Document(org.openntf.domino.Document)

Example 25 with Database

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

the class ViewCheckUniqueTest method NotesMain.

@SuppressWarnings("unused")
public void NotesMain() {
    Session session;
    Database database;
    try {
        Session s;
        Database db;
        if (this.session != null) {
            s = this.session;
            db = this.database;
            try {
                StringBuilder sb = new StringBuilder();
                Document doc = db.createDocument();
                doc.put("FirstName", "Aaron");
                doc.put("LastName", "Monroe");
                View view = db.getView("AllContacts");
                ArrayList<String> key = new ArrayList<String>();
                key.add(doc.getItemValueString("FirstName"));
                key.add(doc.getItemValueString("LastName"));
                if (view.checkUnique(key, doc)) {
                    sb.append("No document yet exists with name Aaron Monroe");
                } else {
                    sb.append("Document already exists with name Aaron Monroe");
                }
                System.out.println(sb.toString());
            } catch (Throwable t) {
                System.err.println(t);
            }
        }
    } catch (Throwable t) {
    }
}
Also used : Database(org.openntf.domino.Database) ArrayList(java.util.ArrayList) Document(org.openntf.domino.Document) View(org.openntf.domino.View) 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