Search in sources :

Example 1 with StandardVertex

use of com.thinkaurelius.titan.graphdb.vertices.StandardVertex in project titan by thinkaurelius.

the class StandardTitanTx method addVertex.

@Override
public TitanVertex 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, (VertexLabelVertex) label, BaseLabel.VertexLabelEdge);
    }
    vertexCache.add(vertex, vertex.longId());
    return vertex;
}
Also used : StandardVertex(com.thinkaurelius.titan.graphdb.vertices.StandardVertex)

Aggregations

StandardVertex (com.thinkaurelius.titan.graphdb.vertices.StandardVertex)1