protected float getShortestDistance(final OrientVertex destination) { if (destination == null) return Float.MAX_VALUE; final Float d = distance.get(destination.getIdentity()); return d == null ? Float.MAX_VALUE : d; }
protected boolean isNotSettled(final OrientVertex vertex) { return unSettledNodes.contains(vertex) || !distance.containsKey(vertex.getIdentity()); }
public LinkedList<OrientVertex> getPath() { final LinkedList<OrientVertex> path = new LinkedList<OrientVertex>(); OrientVertex step = paramDestinationVertex; // Check if a path exists if (predecessors.get(step.getIdentity()) == null) return null; path.add(step); while (predecessors.get(step.getIdentity()) != null) { step = predecessors.get(step.getIdentity()); path.add(step); } // Put it into the correct order Collections.reverse(path); return path; }
for (Vertex v : graph.getVerticesOfClass("DoctorA")) { OrientVertex vertex = (OrientVertex) v; dbentity.DoctorEntity disent = new DoctorEntity(vertex.getIdentity().toString(), v.getProperty("NAME"), v.getProperty("specialization")); al.add(disent); }
protected void findMinimalDistances(final OrientVertex node) { for (OrientVertex neighbor : getNeighbors(node)) { final float d = sumDistances(getShortestDistance(node), getDistance(node, neighbor)); if (getShortestDistance(neighbor) > d) { distance.put(neighbor.getIdentity(), d); predecessors.put(neighbor.getIdentity(), node); unSettledNodes.add(neighbor); } } }
protected List<ORID> walkRight(final OSQLFunctionShortestPath.OShortestPathContext ctx) { final ArrayDeque<OrientVertex> nextLevelQueue = new ArrayDeque<OrientVertex>(); while (!ctx.queueRight.isEmpty()) { ctx.currentRight = ctx.queueRight.poll(); Iterable<Vertex> neighbors; if (ctx.edgeType == null) { neighbors = ctx.currentRight.getVertices(ctx.directionRight); } else { neighbors = ctx.currentRight.getVertices(ctx.directionRight, ctx.edgeTypeParam); } for (Vertex neighbor : neighbors) { final OrientVertex v = (OrientVertex) neighbor; final ORID neighborIdentity = v.getIdentity(); if (ctx.leftVisited.contains(neighborIdentity)) { ctx.nexts.put(neighborIdentity, ctx.currentRight.getIdentity()); return computePath(ctx.previouses, ctx.nexts, neighborIdentity); } if (!ctx.rightVisited.contains(neighborIdentity)) { ctx.nexts.put(neighborIdentity, ctx.currentRight.getIdentity()); nextLevelQueue.offer(v); ctx.rightVisited.add(neighborIdentity); } } } ctx.queueRight = nextLevelQueue; return null; }
protected List<ORID> walkLeft(final OSQLFunctionShortestPath.OShortestPathContext ctx) { ArrayDeque<OrientVertex> nextLevelQueue = new ArrayDeque<OrientVertex>(); while (!ctx.queueLeft.isEmpty()) { ctx.current = ctx.queueLeft.poll(); Iterable<Vertex> neighbors; if (ctx.edgeType == null) { neighbors = ctx.current.getVertices(ctx.directionLeft); } else { neighbors = ctx.current.getVertices(ctx.directionLeft, ctx.edgeTypeParam); } for (Vertex neighbor : neighbors) { final OrientVertex v = (OrientVertex) neighbor; final ORID neighborIdentity = v.getIdentity(); if (ctx.rightVisited.contains(neighborIdentity)) { ctx.previouses.put(neighborIdentity, ctx.current.getIdentity()); return computePath(ctx.previouses, ctx.nexts, neighborIdentity); } if (!ctx.leftVisited.contains(neighborIdentity)) { ctx.previouses.put(neighborIdentity, ctx.current.getIdentity()); nextLevelQueue.offer(v); ctx.leftVisited.add(neighborIdentity); } } } ctx.queueLeft = nextLevelQueue; return null; }
protected void manageNeedRetryException(OBaseWorkLoadContext context, ONeedRetryException e) { if (((OWorkLoadContext) context).lastVertexToConnect.getIdentity().isPersistent()) ((OWorkLoadContext) context).lastVertexToConnect.reload(); }
String pmRID = ""; OrientGraph graphTwo = new OrientGraph(URL, USER, USER); try { ODocument pokemon = new ODocument("Pokemon"); pokemon.field("name", "Pikachu"); Map<String,ODocument> foo = new HashMap(); foo.put("pikachu", pokemon); OrientVertex v = graphTwo.addVertex("class:PokemonMaster", "name", "Sacha", "age", "42", "pokemons", foo); graphTwo.commit(); pmRID = v.getIdentity().toString(); } catch (Exception e) { // ... } finally { graphTwo.shutdown(); }
public String getEntityRid(String entityType, String entityId) { String entityRid = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex entity = (OrientVertex)graph.getVertexByKey(entityType + ".entityId", entityId); entityRid = entity.getIdentity().toString(); } catch (Exception e) { logger.error("Exception:", e); } finally { graph.shutdown(); } return entityRid; }
distance = new HashMap<ORID, Float>(); predecessors = new HashMap<ORID, OrientVertex>(); distance.put(paramSourceVertex.getIdentity(), MIN); unSettledNodes.add(paramSourceVertex); maxPredecessors = predecessors.size(); if (!isVariableEdgeWeight() && distance.containsKey(paramDestinationVertex.getIdentity()))
if (current.getIdentity().equals(goal.getIdentity()) || currentDepth >= paramMaxDepth) {
jsonMap = new HashMap<String, Object>(); jsonMap.put("type", entity.getLabel()); jsonMap.put("rid", entity.getIdentity().toString()); jsonMap.put("createDate", entity.getProperty("createDate")); OrientElementIterable iterable = entity.getProperty("in_Create"); if(iterator.hasNext()) { OrientVertex vertex = (OrientVertex)iterator.next(); jsonMap.put("createRid", vertex.getIdentity().toString()); jsonMap.put("createUserId", vertex.getProperty("userId")); jsonMap.put("gravatar", vertex.getProperty("gravatar")); if(iterator.hasNext()) { OrientVertex vertex = (OrientVertex)iterator.next(); jsonMap.put("parentRid", vertex.getIdentity().toString()); jsonMap.put("parentId", vertex.getProperty("categoryId")); jsonMap.put("parentType", vertex.getLabel()); if(iterator.hasNext()) { OrientVertex vertex = (OrientVertex)iterator.next(); jsonMap.put("parentRid", vertex.getIdentity().toString()); jsonMap.put("parentId", vertex.getProperty("categoryId")); jsonMap.put("parentType", vertex.getLabel());
if (lastVertex.getIdentity().isPersistent()) lastVertex.reload(); if (((OWorkLoadContext) context).lastVertexToConnect.getIdentity().isPersistent()) ((OWorkLoadContext) context).lastVertexToConnect.reload();
@Override public OrientEdge createWrapper(final Object iObject) { if (iObject instanceof OrientEdge) return (OrientEdge) iObject; final OIdentifiable rec = (OIdentifiable) iObject; final ODocument value = rec.getRecord(); if (value == null || value.getSchemaClass() == null) return null; final OrientEdge edge; if (value.getSchemaClass().isSubClassOf(OrientVertex.CLASS_NAME)) { // DIRECT VERTEX, CREATE DUMMY EDGE if (connection.getKey() == Direction.OUT) edge = new OrientEdge(this.vertex.graph, this.vertex.getIdentity(), rec.getIdentity(), connection.getValue()); else edge = new OrientEdge(this.vertex.graph, rec.getIdentity(), this.vertex.getIdentity(), connection.getValue()); } else if (value.getSchemaClass().isSubClassOf(OrientEdge.CLASS_NAME)) { // EDGE edge = new OrientEdge(this.vertex.graph, rec.getIdentity()); } else throw new IllegalStateException("Invalid content found between connections:" + value); if (this.vertex.graph.isUseVertexFieldsForEdgeLabels() || edge.isLabeled(labels)) return edge; return null; }
OrientEdge addEdgeInternal(final OrientVertex currentVertex, String label, final OrientVertex inVertex, final String iClassName, final String iClusterName, final Object... fields) { if (currentVertex.checkDeletedInTx()) throw new ORecordNotFoundException(currentVertex.getIdentity(), "The vertex " + currentVertex.getIdentity() + " has been deleted"); throw new ORecordNotFoundException(inVertex.getIdentity(), "The vertex " + inVertex.getIdentity() + " has been deleted"); throw new IllegalArgumentException("source vertex is invalid (rid=" + currentVertex.getIdentity() + ")"); throw new IllegalArgumentException("destination vertex is invalid (rid=" + inVertex.getIdentity() + ")");
sourceVertex != null ? sourceVertex.getIdentity() : null, targetVertex != null ? targetVertex.getIdentity() : null, record.getDatabase().getURL()); return null; edge = this.sourceVertex.getGraph().getEdgeInstance( this.sourceVertex.getIdentity(), rec.getIdentity(), connection.getValue()); else edge = this.sourceVertex.getGraph().getEdgeInstance( rec.getIdentity(), this.sourceVertex.getIdentity(), connection.getValue()); } else if (immutableSchema.isEdgeType()) {
graph.throwRecordNotFoundException(getIdentity(), "The vertex " + getIdentity() + " has been deleted"); final ORID oldIdentity = getIdentity().copy(); graph.throwRecordNotFoundException(getIdentity(), "The vertex " + getIdentity() + " has been deleted");
json.beginObject(0, false, null); json.beginObject(1, false, "an"); json.beginObject(2, false, vertex.getIdentity());
continue; final ORID oldVertex = fromVertex.getIdentity().copy(); final ORID newVertex = fromVertex.moveTo(className, clusterName);