/** * Add a plain edge to the graph. * * Note: this is not an eventable vertex. * * @param id The id of the edge to set, if null, new id will be generated. * @return plain created edge. */ private Edge addPlainEdgeToGraph(Object id, Vertex out, Vertex in, String label) { validateNewId(id, Edge.class); final Edge edge; // TODO: Ensure we get raw vertices here. Object idVal = id == null ? edgeIdFactory.createId() : id; if (isNaturalIds()) { // we create an id just in case the underline doesn't ignore // supplied ids // and cannot recieve null but we ignore this id in the logic. edge = getUneventableGraph().addEdge(edgeIdFactory.createId(), out, in, label); edge.setProperty(VEProps.NATURAL_EDGE_ID_PROP_KEY, idVal); } else { edge = getUneventableGraph().addEdge(idVal, out, in, label); } return edge; }
/** * Add an edge to the graph. The added edges requires a recommended identifier, a tail vertex, an head vertex, and a * label. * * @param id the identifier of the edge * @param outVertex the vertex on the tail of the edge * @param inVertex the vertex on the head of the edge * @param label the label associated with the edge * @param mappingFunc the function to create a new dedicated edge from another * @param <E> the type of the edge after mapping * * @return the newly created edge * * @see #addEdge(Object, Vertex, Vertex, String) */ @Nonnull public <E extends Edge> E addEdge(@Nullable Object id, Vertex outVertex, Vertex inVertex, String label, BiFunction<Edge, G, E> mappingFunc) { checkNativeElement(outVertex); checkNativeElement(inVertex); Edge base = baseGraph.addEdge(null, getBaseElement(outVertex), getBaseElement(inVertex), label); if (supportEdgeIds) { Object v = checkNotNull(id, "id"); base.setProperty(ID, v); } return mappingFunc.apply(base, me()); }
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); }
/** * Add the historical vertex in the vertex versions chain * * @param latestGraphVersion The latest graph version * @param newVersion The new version to be committed * @param activeModifiedVertex The active vertex that was modified. * @param latestHistoricVertex Latest historical vertex (the previous * version of the newly created historic vertex) * @param newHistoricVertex The new historic vertex to be added in the chain */ private void addHistoricalVertexInChain(V latestGraphVersion, V newVersion, ActiveVersionedVertex<V> activeModifiedVertex, HistoricVersionedVertex<V> latestHistoricVertex, HistoricVersionedVertex newHistoricVertex) { newHistoricVertex.getRaw().setProperty(VEProps.REF_TO_LATEST_HISTORIC_ID_KEY, latestHistoricVertex.getHardId()); newHistoricVertex.getRaw().setProperty(VEProps.VALID_MAX_VERSION_PROP_KEY, latestGraphVersion); Edge prevEdge = ElementUtils.getSingleElement(latestHistoricVertex.getRaw().getEdges(Direction.OUT, VEProps.PREV_VERSION_LABEL)); if (prevEdge != null) { Vertex inVertex = prevEdge.getVertex(Direction.IN); getUneventableGraph().removeEdge(prevEdge); getBaseGraph().addEdge(edgeIdFactory.createId(), (Vertex) newHistoricVertex.getRaw(), inVertex, VEProps.PREV_VERSION_LABEL); } getBaseGraph().addEdge(edgeIdFactory.createId(), latestHistoricVertex.getRaw(), (Vertex) newHistoricVertex.getRaw(), VEProps.PREV_VERSION_LABEL); }