Search in sources :

Example 1 with DVertex

use of org.openntf.domino.graph2.DVertex in project org.openntf.domino by OpenNTF.

the class DElementStore method removeEdge.

@Override
public void removeEdge(final Edge edge, final Vertex removingVertex) {
    if (edge instanceof DEdge) {
        if (org.openntf.domino.ViewEntry.class.equals(((DEdge) edge).getDelegateType())) {
            throw new UnsupportedOperationException("ViewEntry edges cannot be removed.");
        }
    }
    startTransaction(edge);
    Vertex in = edge.getVertex(Direction.IN);
    if (!in.equals(removingVertex)) {
        ((DVertex) in).removeEdge(edge);
        removeCache(in);
    }
    Vertex out = edge.getVertex(Direction.OUT);
    if (!out.equals(removingVertex)) {
        ((DVertex) out).removeEdge(edge);
        removeCache(out);
    }
    removeCache(edge);
    ((DEdge) edge)._remove();
}
Also used : ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Vertex(com.tinkerpop.blueprints.Vertex) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex)

Example 2 with DVertex

use of org.openntf.domino.graph2.DVertex in project org.openntf.domino by OpenNTF.

the class DElementStore method removeEdge.

/*public Element getElement_OLD(final Object id, final Class<? extends Element> type) throws IllegalStateException {
			Element result = null;
			Element chk = getCachedElement(id, Element.class);
			if (chk != null) {
				result = chk;
			} else {
				boolean isProxiedSource = false;
				Object delegate = null;
				if (id instanceof NoteCoordinate && isProxied()) {
					NoteCoordinate nc = (NoteCoordinate) id;
					if (getStoreKey().equals(nc.getReplicaLong())) {
						//this is a request for a vertex out of the proxied store, not the proxy itself
						Database db = (Database) getStoreDelegate();
						String unid = nc.getUNID();
						delegate = db.getDocumentByUNID(unid, true);
						if (delegate != null) {
							isProxiedSource = true;
						}
					}
				}
				if (delegate == null) {
					Object localkey = localizeKey(id);
					delegate = findElementDelegate(localkey);
				}
				if (delegate != null) {
					if (delegate instanceof Element) {
						result = (Element) delegate;
					} else if (delegate instanceof Document) {
						if (isProxiedSource) {
							DVertex vertex = new DVertex(getConfiguration().getGraph(), (Document) delegate);
							result = vertex;
						} else if (((Document) delegate).hasItem("$Index") || ((Document) delegate).hasItem("$Collation")) {
							DVertex vertex = new DVertex(getConfiguration().getGraph(), (Document) delegate);
							result = vertex;
						} else {
							Object typeChk = ((Document) delegate).get(org.openntf.domino.graph2.DElement.TYPE_FIELD);
							String strChk = org.openntf.domino.utils.TypeUtils.toString(typeChk);
							if (org.openntf.domino.graph2.DVertex.GRAPH_TYPE_VALUE.equals(strChk)) {
								DVertex vertex = new DVertex(getConfiguration().getGraph(), (Document) delegate);
								result = vertex;
							} else if (org.openntf.domino.graph2.DEdge.GRAPH_TYPE_VALUE.equals(strChk)) {
								DEdge edge = new DEdge(getConfiguration().getGraph(), (Document) delegate);
								result = edge;
							} else {
								DVertex vertex = new DVertex(getConfiguration().getGraph(), (Document) delegate);
								result = vertex;
							}
						}
					} else if (delegate instanceof ViewEntry) {
						if (id instanceof ViewEntryCoordinate) {
							ViewEntryCoordinate vec = (ViewEntryCoordinate) id;
							String entryType = vec.getEntryType();
							if (entryType.startsWith("E")) {
								DEdge edge = new DEntryEdge(getConfiguration().getGraph(), (ViewEntry) delegate, (ViewEntryCoordinate) id, this);
								result = edge;
							} else if (entryType.startsWith("V")) {
								ViewEntry entry = (ViewEntry) delegate;
								if (entry.isCategory()) {
									Map<String, Object> delegateMap = new LinkedHashMap<String, Object>();
									delegateMap.put("value", entry.getCategoryValue());
									delegateMap.put("position", entry.getPosition());
									delegateMap.put("noteid", entry.getNoteID());
									DCategoryVertex vertex = new DCategoryVertex(getConfiguration().getGraph(), delegateMap,
											entry.getParentView());
									vertex.delegateKey_ = vec;
									result = vertex;
								} else {
									System.out.println("TEMP DEBUG ViewVertex entry is not a category");
								}
							}
						} else {
							System.out.println("TEMP DEBUG ViewEntry's id is not a ViewEntryCoordinate. It's a " + id.getClass().getName());
						}
					}
					getElementCache().put(result.getId(), result);
					getKeyMap().put(id, (NoteCoordinate) result.getId()); //TODO shouldn't force NoteCoordinate, but it covers all current use cases
				}
			}
			return result;
		}*/
// @Override
// public Element getElement(final Object id) throws IllegalStateException {
// return getElement(id, Element.class);
// }
// @Override
// public Edge getEdge(final Object id) {
// return (Edge) getElement(id, Edge.class);
// }
@Override
public void removeEdge(final Edge edge) {
    if (edge instanceof DEdge) {
        if (org.openntf.domino.ViewEntry.class.equals(((DEdge) edge).getDelegateType())) {
            throw new UnsupportedOperationException("ViewEntry edges cannot be removed.");
        }
    }
    startTransaction(edge);
    Vertex in = edge.getVertex(Direction.IN);
    if (in != null) {
        ((DVertex) in).removeEdge(edge);
    }
    Vertex out = edge.getVertex(Direction.OUT);
    if (out != null) {
        ((DVertex) out).removeEdge(edge);
    }
    removeCache(edge);
    ((DEdge) edge)._remove();
}
Also used : ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Vertex(com.tinkerpop.blueprints.Vertex) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex)

Example 3 with DVertex

use of org.openntf.domino.graph2.DVertex in project org.openntf.domino by OpenNTF.

the class DElementStore method addVertex.

@Override
public Vertex addVertex(final Object id, final boolean temporary) {
    Vertex result = null;
    if (id != null) {
        Element chk = getElement(id);
        if (chk != null && chk instanceof Vertex) {
            return (Vertex) chk;
        }
    }
    Object localkey = localizeKey(id);
    Map<String, Object> delegate = addElementDelegate(localkey, Vertex.class, temporary);
    if (delegate != null) {
        if (isProxied()) {
            // System.out.println("TEMP DEBUG from addVertex: ElementStore " + ((Database) getStoreDelegate()).getApiPath()
            // + " is proxied. Setting up proxy on delegate...");
            result = setupProxy(delegate, (Serializable) id);
        } else {
            DVertex vertex = new DVertex(getConfiguration().getGraph(), delegate);
            result = vertex;
        }
        if (!temporary) {
            getElementCache().put((NoteCoordinate) result.getId(), result);
            if (id != null) {
                // TODO shouldn't force NoteCoordinate, but it covers all current use cases
                getKeyMap().put(id, (NoteCoordinate) result.getId());
            }
            getConfiguration().getGraph().startTransaction(result);
        }
    }
    return result;
}
Also used : ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Vertex(com.tinkerpop.blueprints.Vertex) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) Serializable(java.io.Serializable) Element(com.tinkerpop.blueprints.Element)

Example 4 with DVertex

use of org.openntf.domino.graph2.DVertex in project org.openntf.domino by OpenNTF.

the class DFramedTransactionalGraph method frame.

public <F> F frame(final Vertex vertex, Class<F> kind, final boolean temporary) {
    if (vertex == null) {
        return null;
    }
    if (vertex instanceof DCategoryVertex) {
        kind = (Class<F>) CategoryVertex.class;
    } else {
        Map map = ((DVertex) vertex).getDelegate();
        if (map instanceof Document) {
            if (DesignFactory.isView((Document) map)) {
                kind = (Class<F>) ViewVertex.class;
            }
            if (DesignFactory.isIcon((Document) map) || DesignFactory.isACL((Document) map)) {
                // System.out.println("TEMP DEBUG framing an icon note");
                kind = (Class<F>) DbInfoVertex.class;
            }
        }
    }
    DConfiguration config = (DConfiguration) this.getConfig();
    Class<F> klazz = (Class<F>) (kind == null ? config.getDefaultVertexFrameType() : kind);
    if (config.getReplacementType(klazz) != null) {
        klazz = (Class<F>) config.getReplacementType(klazz);
    }
    DTypeManager manager = config.getTypeManager();
    klazz = (Class<F>) manager.initElement(klazz, this, vertex, temporary);
    for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
        if (!(initializer instanceof JavaFrameInitializer)) {
            initializer.initElement(klazz, this, vertex);
        }
    }
    F result = null;
    try {
        result = super.frame(vertex, klazz);
    } catch (Throwable t) {
        System.out.println("Exception while attempting to frame a vertex " + vertex.getId() + " with class " + klazz.getName());
        t.printStackTrace();
        // DominoUtils.handleException(e);
        try {
            result = (F) super.frame(vertex, config.getDefaultVertexFrameType());
        } catch (Exception e) {
            System.out.println("Exception while attempting to frame a vertex " + vertex.getId() + " with class " + klazz.getName());
            e.printStackTrace();
            DominoUtils.handleException(e);
        }
    }
    for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
        if (initializer instanceof JavaFrameInitializer) {
            ((JavaFrameInitializer) initializer).initElement(klazz, this, result);
        }
    }
    if (vertex instanceof DProxyVertex) {
        List<CaseInsensitiveString> proxied = config.getTypeRegistry().getProxied(klazz);
        if (proxied != null) {
            ((DProxyVertex) vertex).setProxied(proxied);
        }
    }
    if (result instanceof Eventable) {
        if (((Eventable) result).isNew()) {
            try {
                // $NON-NLS-1$
                Method crystal = result.getClass().getMethod("create");
                if (crystal != null) {
                    ((Eventable) result).create();
                }
            } catch (Throwable t) {
            // nothing
            }
        } else {
        // try {
        // Method crystal = result.getClass().getMethod("read", null);
        // if (crystal != null) {
        // ((Eventable) result).read();
        // }
        // } catch (Throwable t) {
        // //nothing
        // }
        }
    }
    return result;
}
Also used : CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Eventable(org.openntf.domino.graph2.builtin.Eventable) Method(java.lang.reflect.Method) Document(org.openntf.domino.Document) JavaFrameInitializer(com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer) FrameInitializer(com.tinkerpop.frames.FrameInitializer) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) DTypeManager(org.openntf.domino.graph2.impl.DConfiguration.DTypeManager) JavaFrameInitializer(com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer) Map(java.util.Map)

Example 5 with DVertex

use of org.openntf.domino.graph2.DVertex in project org.openntf.domino by OpenNTF.

the class AbstractIncidenceHandler method countEdges.

@SuppressWarnings({ "rawtypes", "unused" })
private int countEdges(final Annotation annotation, final Vertex vertex) {
    int result = 0;
    Direction dir = Direction.BOTH;
    String label = "";
    if (annotation instanceof Adjacency) {
        dir = ((Adjacency) annotation).direction();
        label = ((Adjacency) annotation).label();
    } else if (annotation instanceof AdjacencyUnique) {
        dir = ((AdjacencyUnique) annotation).direction();
        label = ((AdjacencyUnique) annotation).label();
    } else if (annotation instanceof Incidence) {
        dir = ((Incidence) annotation).direction();
        label = ((Incidence) annotation).label();
    } else if (annotation instanceof IncidenceUnique) {
        dir = ((IncidenceUnique) annotation).direction();
        label = ((IncidenceUnique) annotation).label();
    }
    switch(dir) {
        case OUT:
            if (vertex instanceof DVertex) {
                result = ((DVertex) vertex).getOutEdgeCount(label);
            } else {
                Iterable<Edge> it = vertex.getEdges(Direction.OUT, label);
                if (it instanceof Collection) {
                    result = ((Collection) it).size();
                } else {
                    for (Edge e : it) {
                        result++;
                    }
                }
            }
            break;
        case IN:
            if (vertex instanceof DVertex) {
                result = ((DVertex) vertex).getInEdgeCount(label);
            } else {
                Iterable<Edge> it = vertex.getEdges(Direction.IN, label);
                if (it instanceof Collection) {
                    result = ((Collection) it).size();
                } else {
                    for (Edge e : it) {
                        result++;
                    }
                }
            }
            break;
        case BOTH:
            throw new UnsupportedOperationException("Direction.BOTH it not supported on 'add' or 'set' methods");
    }
    return result;
}
Also used : DVertex(org.openntf.domino.graph2.DVertex) Collection(java.util.Collection) Adjacency(com.tinkerpop.frames.Adjacency) Direction(com.tinkerpop.blueprints.Direction) Edge(com.tinkerpop.blueprints.Edge) Incidence(com.tinkerpop.frames.Incidence)

Aggregations

CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)9 Set (java.util.Set)6 DbInfoVertex (org.openntf.domino.graph2.builtin.DbInfoVertex)6 ViewVertex (org.openntf.domino.graph2.builtin.ViewVertex)6 Vertex (com.tinkerpop.blueprints.Vertex)5 DVertex (org.openntf.domino.graph2.DVertex)5 VertexFrame (com.tinkerpop.frames.VertexFrame)4 Method (java.lang.reflect.Method)4 Map (java.util.Map)4 CategoryVertex (org.openntf.domino.graph2.builtin.CategoryVertex)4 BigString (org.openntf.domino.types.BigString)4 Edge (com.tinkerpop.blueprints.Edge)3 EdgeFrame (com.tinkerpop.frames.EdgeFrame)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Document (org.openntf.domino.Document)3 UserAccessException (org.openntf.domino.exceptions.UserAccessException)3 DEdgeEntryList (org.openntf.domino.graph2.impl.DEdgeEntryList)3 DVertexList (org.openntf.domino.graph2.impl.DVertexList)3