Search in sources :

Example 1 with StandardVertex

use of org.janusgraph.graphdb.vertices.StandardVertex in project janusgraph by JanusGraph.

the class StandardJanusGraphTx method addVertex.

@Override
public JanusGraphVertex addVertex(Long vertexId, VertexLabel label) {
    verifyWriteAccess();
    if (label == null)
        label = BaseVertexLabel.DEFAULT_VERTEXLABEL;
    if (vertexId != null && !graph.getConfiguration().allowVertexIdSetting()) {
        log.info("Provided vertex id [{}] is ignored because vertex id setting is not enabled", vertexId);
        vertexId = null;
    }
    Preconditions.checkArgument(vertexId != null || !graph.getConfiguration().allowVertexIdSetting(), "Must provide vertex id");
    Preconditions.checkArgument(vertexId == null || IDManager.VertexIDType.NormalVertex.is(vertexId), "Not a valid vertex id: %s", vertexId);
    Preconditions.checkArgument(vertexId == null || ((InternalVertexLabel) label).hasDefaultConfiguration(), "Cannot only use default vertex labels: %s", label);
    Preconditions.checkArgument(vertexId == null || !config.hasVerifyExternalVertexExistence() || !containsVertex(vertexId), "Vertex with given id already exists: %s", vertexId);
    StandardVertex vertex = new StandardVertex(this, IDManager.getTemporaryVertexID(IDManager.VertexIDType.NormalVertex, temporaryIds.nextID()), ElementLifeCycle.New);
    if (vertexId != null) {
        vertex.setId(vertexId);
    } else if (config.hasAssignIDsImmediately() || label.isPartitioned()) {
        graph.assignID(vertex, label);
    }
    addProperty(vertex, BaseKey.VertexExists, Boolean.TRUE);
    if (label != BaseVertexLabel.DEFAULT_VERTEXLABEL) {
        // Add label
        Preconditions.checkArgument(label instanceof VertexLabelVertex);
        addEdge(vertex, label, BaseLabel.VertexLabelEdge);
    }
    vertexCache.add(vertex, vertex.longId());
    return vertex;
}
Also used : StandardVertex(org.janusgraph.graphdb.vertices.StandardVertex)

Aggregations

StandardVertex (org.janusgraph.graphdb.vertices.StandardVertex)1