public static String edgeString(final Edge edge) { return "e[" + edge.getLabel() + "], [" + edge.getVertex(Direction.OUT) + " -> " + edge.getLabel() + " -> " + edge.getVertex(Direction.IN) + "]"; }
public void addOutEdge(final Edge edge) { boolean adding = false; String label = edge.getLabel(); // Set<String> outs = getOutEdges(); Set<String> outs = getOutEdgesSet(label); synchronized (outs) { if (!outs.contains((String) edge.getId())) { adding = true; outs.add((String) edge.getId()); } } if (adding) { getParent().startTransaction(this); Map map = getOutDirtyMap(); synchronized (map) { map.put(label, true); } Set<Edge> outLabelObjs = getOutEdgeCache(label); synchronized (outLabelObjs) { outLabelObjs.add(edge); } // outDirty_ = true; // Set<Edge> outObjs = getOutEdgeObjects(); // synchronized (outObjs) { // outObjs.add(edge); // } } // setProperty(DominoVertex.OUT_NAME, outEdges_); }
public void run2() { long testStartTime = System.nanoTime(); marktime = System.nanoTime(); try { timelog("Beginning graph2 test..."); for (Vertex v : graph.getVertices()) { System.out.println("RESULT: " + v.getId().toString()); } for (Edge e : graph.getEdges()) { System.out.println("RESULT: " + e.getId().toString() + ":" + e.getLabel()); } // lotus.domino.Session s = Factory.terminate(); // s.recycle(); graph = null; System.gc(); } catch (Throwable t) { t.printStackTrace(); } long testEndTime = System.nanoTime(); System.out.println( "Completed " + getClass().getSimpleName() + " run2 in " + ((testEndTime - testStartTime) / 1000000) + " ms"); }
public void addInEdge(final Edge edge) { boolean adding = false; String label = edge.getLabel(); // Set<String> ins = getInEdges(); Set<String> ins = getInEdgesSet(label); synchronized (ins) { if (!ins.contains((String) edge.getId())) { adding = true; ins.add((String) edge.getId()); } } if (adding) { getParent().startTransaction(this); Map map = getInDirtyMap(); synchronized (map) { map.put(label, true); } Set<Edge> inLabelObjs = getInEdgeCache(label); synchronized (inLabelObjs) { inLabelObjs.add(edge); } // inDirty_ = true; // Set<Edge> inObjs = getInEdgeObjects(); // synchronized (inObjs) { // inObjs.add(edge); // } } }
public void removeEdge(final Edge edge) { getParent().startTransaction(this); String label = edge.getLabel(); boolean inChanged = false; Set<String> ins = getInEdgesSet(label); if (ins != null) { // System.out.println("Removing an in edge from " + label + " with id " + edge.getId() + " // from a vertex of type " // + getProperty("Form")); synchronized (ins) { inChanged = ins.remove(edge.getId()); } } else { // System.out.println("in edges were null from a vertex of type " + getProperty("Form") + ": // " + getId()); } // Set<Edge> inObjs = getInEdgeObjects(); // synchronized (inObjs) { // inObjs.remove(edge); // } if (inChanged) { // System.out.println("Ins were changed so recording cache invalidation..."); Set<Edge> inObjsLabel = getInEdgeCache(label); synchronized (inObjsLabel) { inObjsLabel.remove(edge); } Map<String, Boolean> inDirtyMap = getInDirtyMap(); synchronized (inDirtyMap) { inDirtyMap.put(label, true); } } boolean outChanged = false; Set<String> outs = getOutEdgesSet(label); if (outs != null) { // System.out.println("Removing an out edge from " + label + " with id " + edge.getId() + " // from a vertex of type " // + getProperty("Form")); synchronized (outs) { outChanged = outs.remove(edge.getId()); } } else { // System.out.println("out edges were null from a vertex of type " + getProperty("Form") + // ": " + getId()); } if (outChanged) { // System.out.println("Out were changed so recording cache invalidation..."); Set<Edge> outObjsLabel = getOutEdgeCache(label); synchronized (outObjsLabel) { outObjsLabel.remove(edge); } Map<String, Boolean> outDirtyMap = getOutDirtyMap(); synchronized (outDirtyMap) { outDirtyMap.put(label, true); } } }
static Edge addEdge(Graph graph, Edge edge) { Edge newEdge = graph.getEdge(edge.getId()); if (null == newEdge) { Vertex outVertex = addNode(graph, edge.getVertex(Direction.OUT)); Vertex inVertex = addNode(graph, edge.getVertex(Direction.IN)); String label = edge.getLabel(); newEdge = graph.addEdge(edge.getId(), outVertex, inVertex, label); copyProperties(edge, edge); } return newEdge; }
private void writeEdgeProperties(Writer writer, Edge e, Integer source, Integer target) throws IOException { writer.write(TAB); writer.write(GMLTokens.EDGE); writer.write(OPEN_LIST); writeKey(writer, GMLTokens.SOURCE); writeNumberProperty(writer, source); writeKey(writer, GMLTokens.TARGET); writeNumberProperty(writer, target); writeKey(writer, GMLTokens.LABEL); writeStringProperty(writer, e.getLabel()); writeEdgeProperties(writer, e); writer.write(TAB); writer.write(CLOSE_LIST); }
protected void deleteEdge(Edge edge, boolean updateReverseAttribute, boolean force) throws AtlasException { // update reverse attribute if (updateReverseAttribute) { AttributeInfo attributeInfo = getAttributeForEdge(edge.getLabel()); if (attributeInfo.reverseAttributeName != null) { deleteEdgeBetweenVertices( edge.getVertex(Direction.IN), edge.getVertex(Direction.OUT), attributeInfo.reverseAttributeName); } } deleteEdge(edge, force); }
protected void deleteVertex(Vertex instanceVertex, boolean force) throws AtlasException { // Update external references(incoming edges) to this vertex LOG.debug( "Setting the external references to {} to null(removing edges)", string(instanceVertex)); Iterator<Edge> edges = instanceVertex.getEdges(Direction.IN).iterator(); while (edges.hasNext()) { Edge edge = edges.next(); Id.EntityState edgeState = GraphHelper.getState(edge); if (edgeState == Id.EntityState.ACTIVE) { // Delete only the active edge references AttributeInfo attribute = getAttributeForEdge(edge.getLabel()); // TODO use delete edge instead?? deleteEdgeBetweenVertices( edge.getVertex(Direction.OUT), edge.getVertex(Direction.IN), attribute.name); } } _deleteVertex(instanceVertex, force); }
/** * Creates a Jackson ObjectNode from a graph element. * * @param element the graph element to convert to JSON. * @param propertyKeys The property keys at the root of the element to serialize. If null, then * all keys are serialized. * @param showTypes Data types are written to the JSON explicitly if true. */ public static ObjectNode createJSONElementAsObjectNode( final Element element, final List<String> propertyKeys, final boolean showTypes) { ObjectNode jsonElement = createJSONMap(createPropertyMap(element, propertyKeys), propertyKeys, showTypes); putObject(jsonElement, GraphSONTokens._ID, element.getId()); if (element instanceof Vertex) { jsonElement.put(GraphSONTokens._TYPE, GraphSONTokens.VERTEX); } else if (element instanceof Edge) { final Edge edge = (Edge) element; jsonElement.put(GraphSONTokens._TYPE, GraphSONTokens.EDGE); putObject(jsonElement, GraphSONTokens._OUT_V, edge.getVertex(Direction.OUT).getId()); putObject(jsonElement, GraphSONTokens._IN_V, edge.getVertex(Direction.IN).getId()); jsonElement.put(GraphSONTokens._LABEL, edge.getLabel()); } return jsonElement; }
@Override public void outputGraph(Graph graph, OutputStream out) throws IOException { Iterable<Edge> iterable = graph.getEdges(); Iterator<Edge> it = iterable.iterator(); writeCSVField("SourceId", out, true, false); writeCSVField("SourceVirtual", out, false, false); writeCSVField("SourceFileType", out, false, false); writeCSVField("SourceName", out, false, false); writeCSVField("SourceAuthor", out, false, false); writeCSVField("SourceModified", out, false, false); writeCSVField("LinkType", out, false, false); writeCSVField("DestinationId", out, false, false); writeCSVField("DestinationVirtual", out, false, false); writeCSVField("DestinationFileType", out, false, false); writeCSVField("DestinationName", out, false, false); writeCSVField("DestinationAuthor", out, false, false); writeCSVField("DestinationModified", out, false, true); while (it.hasNext()) { Edge edge = it.next(); Vertex fromV = edge.getVertex(Direction.OUT); Vertex toV = edge.getVertex(Direction.IN); writeCSVField(fromV.getId(), out, true, false); writeCSVField(fromV.getProperty(DictionaryConst.NODE_VIRTUAL), out, false, false); writeCSVField(fromV.getProperty(DictionaryConst.PROPERTY_TYPE), out, false, false); writeCSVField(fromV.getProperty(DictionaryConst.PROPERTY_NAME), out, false, false); writeCSVField(fromV.getProperty(DictionaryConst.PROPERTY_AUTHOR), out, false, false); writeCSVField(fromV.getProperty(DictionaryConst.PROPERTY_LAST_MODIFIED), out, false, false); writeCSVField(edge.getLabel(), out, false, false); writeCSVField(toV.getId(), out, false, false); writeCSVField(toV.getProperty(DictionaryConst.NODE_VIRTUAL), out, false, false); writeCSVField(toV.getProperty(DictionaryConst.PROPERTY_TYPE), out, false, false); writeCSVField(toV.getProperty(DictionaryConst.PROPERTY_NAME), out, false, false); writeCSVField(toV.getProperty(DictionaryConst.PROPERTY_AUTHOR), out, false, false); writeCSVField(toV.getProperty(DictionaryConst.PROPERTY_LAST_MODIFIED), out, false, true); } }