Edge e = tialVertex.addEdge("temp",headVertex); e.setProperty("key1","value1"); e.setProperty("key2","value2");
private Edge createNewFieldEdge(Vertex container, Vertex binary, String fileName, String contentType, String dominantColor, String fieldKey) { Edge edge = getGraph().addEdge("class:BinaryGraphFieldImpl", container, binary, "HAS_FIELD"); edge.setProperty("ferma_type", "BinaryGraphFieldImpl"); edge.setProperty("uuid", randomUUID()); edge.setProperty(BINARY_FILENAME_PROPERTY_KEY, fileName); edge.setProperty(BINARY_CONTENT_TYPE_PROPERTY_KEY, contentType); if (dominantColor != null) { edge.setProperty(BINARY_IMAGE_DOMINANT_COLOR_PROPERTY_KEY, dominantColor); } edge.setProperty(FIELD_KEY_PROPERTY_KEY, fieldKey); return null; }
/** * Add the new properties to the schema and microschema version edges * * @param release */ private void processRelease(Vertex release) { for (Edge edge : release.getEdges(OUT, "HAS_SCHEMA_VERSION")) { edge.setProperty("active", true); edge.setProperty("migrationStatus", "COMPLETED"); } for (Edge edge : release.getEdges(OUT, "HAS_MICROSCHEMA_VERSION")) { edge.setProperty("active", true); edge.setProperty("migrationStatus", "COMPLETED"); } }
visitEdge.setProperty(PROP_VISIT_RATING, nextLine[2]); visitEdge.setProperty(PROP_VISIT_FOOD, nextLine[3]); visitEdge.setProperty(PROP_VISIT_SERVICE, nextLine[4]);
/** * Add an edge to the graph with specified id and provided properties. * * @param graph the graph to create the edge in * @param id the id of the edge to create * @param outVertex the outgoing/tail vertex of the edge * @param inVertex the incoming/head vertex of the edge * @param label the label of the edge * @param properties the properties of the edge to add (must be String,Object,String,Object,...) * @return the edge created in the graph with the provided properties set */ public static Edge addEdge(final Graph graph, final Object id, final Vertex outVertex, final Vertex inVertex, final String label, final Object... properties) { if ((properties.length % 2) != 0) throw new RuntimeException("There must be an equal number of keys and values"); final Edge edge = graph.addEdge(id, outVertex, inVertex, label); for (int i = 0; i < properties.length; i = i + 2) { edge.setProperty((String) properties[i], properties[i + 1]); } return edge; }
private void migrateProperty(Edge edge, String label, String oldPropertyKey, String newPropertyKey) { String value = edge.getProperty(oldPropertyKey); edge.removeProperty(oldPropertyKey); if (value != null) { edge.setProperty(newPropertyKey, value); } }
@Override public void setProperty(Edge edge, PrimitivePropertyMethodMetadata<TitanPropertyMetadata> metadata, Object value) { edge.setProperty(metadata.getDatastoreMetadata().getName(), value); }
/** * Creates an edge from GraphSON using settings supplied in the constructor. */ public Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in) throws IOException { final Map<String, Object> props = OGraphSONUtility.readProperties(json, true, this.hasEmbeddedTypes); final Object edgeId = getTypedValueFromJsonNode(json.get(GraphSONTokens._ID)); final JsonNode nodeLabel = json.get(GraphSONTokens._LABEL); // assigned an empty string edge label in cases where one does not exist. this gets around the requirement // that blueprints graphs have a non-null label while ensuring that GraphSON can stay flexible in parsing // partial bits from the JSON. Not sure if there is any gotchas developing out of this. final String label = nodeLabel == null ? EMPTY_STRING : nodeLabel.textValue(); final Edge e = factory.createEdge(edgeId, out, in, label); for (Map.Entry<String, Object> entry : props.entrySet()) { // if (this.edgePropertyKeys == null || this.edgePropertyKeys.contains(entry.getKey())) { if (includeKey(entry.getKey(), edgePropertyKeys, this.edgePropertiesRule)) { e.setProperty(entry.getKey(), entry.getValue()); } } return e; }
/** * Creates an edge from GraphSON using settings supplied in the constructor. */ public Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in) throws IOException { final Map<String, Object> props = GraphSONUtility.readProperties(json, true, this.hasEmbeddedTypes); final Object edgeId = getTypedValueFromJsonNode(json.get(GraphSONTokens._ID)); final JsonNode nodeLabel = json.get(GraphSONTokens._LABEL); // assigned an empty string edge label in cases where one does not exist. this gets around the requirement // that blueprints graphs have a non-null label while ensuring that GraphSON can stay flexible in parsing // partial bits from the JSON. Not sure if there is any gotchas developing out of this. final String label = nodeLabel == null ? EMPTY_STRING : nodeLabel.textValue(); final Edge e = factory.createEdge(edgeId, out, in, label); for (Map.Entry<String, Object> entry : props.entrySet()) { // if (this.edgePropertyKeys == null || this.edgePropertyKeys.contains(entry.getKey())) { if (includeKey(entry.getKey(), edgePropertyKeys, this.edgePropertiesRule)) { e.setProperty(entry.getKey(), entry.getValue()); } } return e; }
/** * Updates the containment identified by its {@code name} between the {@code parentVertex} and the {@code * childVertex}. * * @param localName the name of the property identifying the reference (parent -> child) * @param parentVertex the parent vertex * @param childVertex the child vertex */ private static void updateContainment(final String localName, final Vertex parentVertex, final Vertex childVertex) { for (Edge edge : childVertex.getEdges(Direction.OUT, CONTAINER)) { edge.remove(); } Edge edge = childVertex.addEdge(CONTAINER, parentVertex); edge.setProperty(CONTAINING_FEATURE, localName); }
@Override protected void transformEdge(final IEdge edge) { final com.tinkerpop.blueprints.Vertex mappedInVertex = this.mappedVertices.get(edge.getVertex(Direction.IN)); final com.tinkerpop.blueprints.Vertex mappedOutVertex = this.mappedVertices.get(edge.getVertex(Direction.OUT)); String label = edge.getProperty(LABEL_PROPERTY); if (label == null) { label = ""; } final com.tinkerpop.blueprints.Edge mappedEdge = this.transformedGraph.addEdge(edge.getId(), mappedOutVertex, mappedInVertex, label); for (final String propertyKey : edge.getPropertyKeys()) { mappedEdge.setProperty(propertyKey, edge.getProperty(propertyKey)); } }
public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label, final Object... properties) { if (!BatchVertex.class.isInstance(outVertex) || !BatchVertex.class.isInstance(inVertex)) throw new IllegalArgumentException("Given element was not created in this baseGraph"); nextElement(); final Vertex ov = getCachedVertex(outVertex.getId()); final Vertex iv = getCachedVertex(inVertex.getId()); previousOutVertexId = outVertex.getId(); //keep track of the previous out vertex id currentEdgeCached = baseGraph.addEdge(id, ov, iv, label); if (edgeIdKey != null && id != null) { currentEdgeCached.setProperty(edgeIdKey, id); } currentEdge = new BatchEdge(); setProperties(currentEdge, properties); return currentEdge; }
/** * Creates a new container edge between {@code parentVertex} and {@code childVertex}, and deletes any * container edge previously linked to {@code childVertex}. * * @param reference the containment {@link EReference}. This parameter is used to set the containing feature * property in the create edge. * @param parentVertex the {@link Vertex} representing the container element * @param childVertex the {@link Vertex} representing the contained element * * @see DirectWriteBlueprintsStore#CONTAINER * @see DirectWriteBlueprintsStore#CONTAINING_FEATURE */ private void updateContainment(EReference reference, Vertex parentVertex, Vertex childVertex) { for (Edge edge : childVertex.getEdges(Direction.OUT, CONTAINER)) { edge.remove(); } Edge edge = childVertex.addEdge(CONTAINER, parentVertex); edge.setProperty(CONTAINING_FEATURE, reference.getName()); }
/** * Add an active edge to the underline. * * @param id specify explicit id, if null id will be generated, id may be * ignored if underline ignores supplied ids. * @param out the out vertex of the edge. * @param in the in vrtex of the edge. * @param label the label of the edge. * @return the created active edge. */ private ActiveVersionedEdge addActiveEdgeInUnderline(Object id, ActiveVersionedVertex<V> out, ActiveVersionedVertex<V> in, String label) { Edge edge = addPlainEdgeToGraph(id, out.getRaw(), in.getRaw(), label); edge.setProperty(VEProps.HISTORIC_ELEMENT_PROP_KEY, false); return new ActiveVersionedEdge<V>(edge, this); }
public void run() { for (int i = 0; i < noNodes; i++) { Vertex v = bgraph.addVertex(i); v.setProperty("name", getName(i)); v.setProperty("uid", i); } for (int i = 0; i < noNodes; i++) { // Out vertex Vertex n = bgraph.getVertex(i); // Iterate over in vertices for (int e = 0; e < noEdgesPerNode; e++) { Vertex n2 = bgraph.getVertex(wrapAround(i + e, noNodes)); Edge edge = n.addEdge("knows", n2); edge.setProperty("uid", RandomGenerator.randomInt(0, Integer.MAX_VALUE)); edge.setProperty("weight", Math.random()); } } bgraph.commit(); }
public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) { if (uniqueIds && null != id && null != getEdge(id)) { throw new IllegalArgumentException("edge with given id already exists: " + id); } verifyNativeElement(outVertex); verifyNativeElement(inVertex); Edge base = baseGraph.addEdge(null, ((IdVertex) outVertex).getBaseVertex(), ((IdVertex) inVertex).getBaseVertex(), label); if (supportEdgeIds) { Object v = null == id ? edgeIdFactory.createId() : id; if (null != v) { base.setProperty(ID, v); } } return new IdEdge(base, this); }
@Override protected void addReference(final Id id, final String name, int index, final boolean many, final boolean containment, final Id idReference) { Vertex vertex = getVertex(id); Vertex referencedVertex = getVertex(idReference); // Update the containment reference if needed if (containment) { updateContainment(name, vertex, referencedVertex); } int size = getSize(vertex, name); if (index == PersistentStore.NO_INDEX) { index = size; } size++; setSize(vertex, name, size); Edge edge = vertex.addEdge(name, referencedVertex); edge.setProperty(POSITION, index); }
/** * Handles a statement. * * @param st The statement. * @throws org.openrdf.rio.RDFHandlerException If the RDF handler has encountered an unrecoverable error. */ @Override public void handleStatement(Statement st) throws RDFHandlerException { Vertex out = getOrCreateVertex(st.getSubject()); Vertex in = getOrCreateVertex(st.getObject()); Edge edge = graph.addEdge(null, out, in, st.getPredicate().stringValue()); if (null == edge.getProperty(CONTEXT_PROP)) { edge.setProperty(CONTEXT_PROP, valueToNative(st.getContext())); } triples ++; if(triples % 10000 == 0 && graph instanceof TransactionalGraph) { ((TransactionalGraph)graph).commit(); } }
@Override public boolean add(Atom atom) { Vertex atomVertex = graph.addVertex(null); atomVertex.setProperty("class", "atom"); atomVertex.setProperty("predicate", predicateToString(atom.getPredicate())); Vertex predicateVertex = this.add(atom.getPredicate()); this.graph.addEdge(null, atomVertex, predicateVertex, "predicate"); int i = 0; for (Term t : atom) { atomVertex.setProperty("term" + i, termToString(t)); Vertex termVertex = this.add(t); Edge e = graph.addEdge(null, atomVertex, termVertex, "term"); e.setProperty("index", i++); } return true; }
/** * Create new binary vertex and link it to the binary root. * * @param hash * @param binaryRoot * @return */ private Vertex createBinary(String hash, Long size, Integer height, Integer width, Vertex binaryRoot) { Vertex binary = getGraph().addVertex("class:BinaryImpl"); binary.setProperty("ferma_type", "BinaryImpl"); binary.setProperty("uuid", randomUUID()); if (height != null) { binary.setProperty(BINARY_IMAGE_HEIGHT_PROPERTY_KEY, height); } if (width != null) { binary.setProperty(BINARY_IMAGE_WIDTH_PROPERTY_KEY, width); } binary.setProperty(BINARY_FILESIZE_PROPERTY_KEY, size); binary.setProperty(NEW_HASH_KEY, hash); binaryRoot.addEdge("HAS_BINARY", binary).setProperty("uuid", randomUUID()); return binary; }