public Iterable<Edge> getEdges(final Direction iDirection, final String... iLabels) { return getEdges(null, iDirection, iLabels); }
/** * Returns the edges connected to the current Vertex. If you are interested on just counting the edges use @countEdges that it's * more efficient for this use case. * * @param iDirection The direction between OUT, IN or BOTH * @param iLabels Optional labels as Strings to consider * * @return */ @Override public Iterable<Edge> getEdges(final Direction iDirection, final String... iLabels) { return getEdges(null, iDirection, iLabels); }
protected Set<OrientEdge> getNeighborEdges(final OrientVertex node) { context.incrementVariable("getNeighbors"); final Set<OrientEdge> neighbors = new HashSet<OrientEdge>(); if (node != null) { for (Edge v : node.getEdges(paramDirection, paramEdgeTypeNames)) { final OrientEdge ov = (OrientEdge) v; if (ov != null) neighbors.add(ov); } } return neighbors; }
@Override protected double getDistance(final OrientVertex node, final OrientVertex parent, final OrientVertex target) { final Iterator<Edge> edges = node.getEdges(target, paramDirection).iterator(); if (edges.hasNext()) { final Edge e = edges.next(); if (e != null) { final Object fieldValue = e.getProperty(paramWeightFieldName); if (fieldValue != null) if (fieldValue instanceof Float) return (Float) fieldValue; else if (fieldValue instanceof Number) return ((Number) fieldValue).doubleValue(); } } return MIN; }
@SuppressWarnings("unchecked") private <T> T findEdgeImpl(final Class<T> edgeClass, final Object first, final Object second, final Direction direction) { final Iterator<Edge> it = getVertex(first) .getEdges(getVertex(second), direction, edgeClass.getSimpleName()).iterator(); T res = null; if (it.hasNext()) { res = objectDb.get().load(((OrientEdge) it.next()).getIdentity()); } return res; }
private void removeEdges(OrientGraph tx, OrientVertex vertex) { OrientVertex destination = tx.getVertex(documentModel.getObject().getIdentity()); Iterable<Edge> edges = vertex.getEdges(destination, Direction.BOTH); for(Edge edge : edges) { tx.removeEdge(edge); } }
protected Object v2e(final OrientBaseGraph graph, final OIdentifiable iRecord, final Direction iDirection, final String[] iLabels) { final ODocument rec = iRecord.getRecord(); OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(rec); if (immutableClass != null && immutableClass.isVertexType()) { // VERTEX final OrientVertex vertex = graph.getVertex(rec); if (vertex != null) return vertex.getEdges(iDirection, iLabels); } return null; }
protected void upBranchDb(String branchType, Map<String, Object> data) throws Exception { String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1); String index = className + ".categoryId"; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); OrientVertex updateUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex branch = (OrientVertex)graph.getVertexByKey(index, data.get("categoryId")); if(branch != null && updateUser != null) { // remove DownVote edge if there is. for (Edge edge : updateUser.getEdges(branch, Direction.OUT, "DownVote")) { if(edge.getVertex(Direction.IN).equals(branch)) graph.removeEdge(edge); } updateUser.addEdge("UpVote", branch); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected void downBranchDb(String branchType, Map<String, Object> data) throws Exception { String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1); String index = className + ".categoryId"; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); OrientVertex updateUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex branch = (OrientVertex)graph.getVertexByKey(index, data.get("categoryId")); if(branch != null && updateUser != null) { // remove UpVote edge if there is. for (Edge edge : updateUser.getEdges(branch, Direction.OUT, "UpVote")) { if(edge.getVertex(Direction.IN).equals(branch)) graph.removeEdge(edge); } updateUser.addEdge("DownVote", branch); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
public long countEdges(final Direction iDirection, final String... iLabels) { long counter = 0; if (graph.isUseVertexFieldsForEdgeLabels() || iLabels == null || iLabels.length == 0) { // VERY FAST final ODocument doc = getRecord(); for (String fieldName : doc.fieldNames()) { final OPair<Direction, String> connection = getConnection( iDirection, fieldName, iLabels); if (connection == null) // SKIP THIS FIELD continue; final Object fieldValue = doc.field(fieldName); if (fieldValue != null) if (fieldValue instanceof Collection<?>) counter += ((Collection<?>) fieldValue).size(); else if (fieldValue instanceof Map<?, ?>) counter += ((Map<?, ?>) fieldValue).size(); else counter++; } } else { // SLOWER: BROWSE & FILTER for (Edge e : getEdges(iDirection, iLabels)) if (e != null) counter++; } return counter; }
protected void downVotePost(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex post = (OrientVertex) graph.getVertexByKey("Post.entityId", data.get("entityId")); if (post != null && updateUser != null) { // remove UpVote edge if there is. for (Edge edge : updateUser.getEdges(post, Direction.OUT, "UpVote")) { if (edge.getVertex(Direction.IN).equals(post)) graph.removeEdge(edge); } updateUser.addEdge("DownVote", post); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected void upVoteProduct(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex product = (OrientVertex) graph.getVertexByKey("Product.entityId", data.get("entityId")); if (product != null && updateUser != null) { // remove DownVote edge if there is. for (Edge edge : updateUser.getEdges(product, Direction.OUT, "DownVote")) { if (edge.getVertex(Direction.IN).equals(product)) graph.removeEdge(edge); } updateUser.addEdge("UpVote", product); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected void upVoteUser(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex user = (OrientVertex)graph.getVertexByKey("User.userId", data.get("userId")); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", data.get("voteUserId")); if(user != null && voteUser != null) { for (Edge edge : voteUser.getEdges(user, Direction.OUT, "DownVote")) { if(edge.getVertex(Direction.IN).equals(user)) graph.removeEdge(edge); } voteUser.addEdge("UpVote", user); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
protected void downVoteUser(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex user = (OrientVertex)graph.getVertexByKey("User.userId", data.get("userId")); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", data.get("voteUserId")); if(user != null && voteUser != null) { for (Edge edge : voteUser.getEdges(user, Direction.OUT, "UpVote")) { if(edge.getVertex(Direction.IN).equals(user)) graph.removeEdge(edge); } voteUser.addEdge("DownVote", user); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); throw e; } finally { graph.shutdown(); } }
protected void downVoteProduct(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex product = (OrientVertex) graph.getVertexByKey("Product.entityId", data.get("entityId")); if (product != null && updateUser != null) { // remove UpVote edge if there is. for (Edge edge : updateUser.getEdges(product, Direction.OUT, "UpVote")) { if (edge.getVertex(Direction.IN).equals(product)) graph.removeEdge(edge); } updateUser.addEdge("DownVote", product); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
protected void upVotePost(Map<String, Object> data) { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { graph.begin(); OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId")); OrientVertex post = (OrientVertex) graph.getVertexByKey("Post.entityId", data.get("entityId")); if (post != null && updateUser != null) { // remove DownVote edge if there is. for (Edge edge : updateUser.getEdges(post, Direction.OUT, "DownVote")) { if (edge.getVertex(Direction.IN).equals(post)) graph.removeEdge(edge); } updateUser.addEdge("UpVote", post); } graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
for (Edge e : getEdges(Direction.BOTH)) allEdges.add(e);
for (Edge edge : user.getEdges(comment, Direction.OUT, "ReportSpam")) { if(edge.getVertex(Direction.IN).equals(comment)) { reported = true;
protected void delComment(Map<String, Object> data) throws Exception { OrientGraph graph = ServiceLocator.getInstance().getGraph(); try{ graph.begin(); String commentId = (String)data.get("commentId"); OrientVertex comment = (OrientVertex)graph.getVertexByKey("Comment.commentId", commentId); // remove the edge to this comment for (Edge edge : comment.getEdges(Direction.IN)) { graph.removeEdge(edge); } graph.removeVertex(comment); graph.commit(); } catch (Exception e) { logger.error("Exception:", e); graph.rollback(); } finally { graph.shutdown(); } }
if(user != null) { for (Edge edge : user.getEdges(comment, Direction.OUT, "UpVote")) { if (edge.getVertex(Direction.IN).equals(comment)) { graph.removeEdge(edge); for (Edge edge : user.getEdges(comment, Direction.OUT, "DownVote")) { if(edge.getVertex(Direction.IN).equals(comment)) { downVoted = true;