gjrwebber / spring-data-gremlin

Spring data gremlin makes it easier to implement Graph based repositories. This module extends Spring Data to allow support for potentially any Graph database that implements the Tinkerpop Blueprints 2.x API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EdgeRepository - update Edge

clepelli opened this issue · comments

Hello again,

Updating an edge via the SimpleGremlinRepository always fails, throwing "Schema is neither EDGE nor VERTEX!".

Actually there is a typo there:

Best regards,
Clément.

Then, we should remove the cascade when the Edge is updated as the vertices may not be loaded. Below is my quick local rewriting of the method discussed above.

@Transactional(readOnly = false)
public T save(Graph graph, T object) {

    String id = schema.getObjectId(object);
    if (StringUtils.isEmpty(id)) {
        create(graph, object);
    } else {
        Element element;
        if (schema.isVertexSchema()) {
            element = graph.getVertex(schema.decodeId(id));
            schema.copyToGraph(graphAdapter, element, object);
        } else if (schema.isEdgeSchema()) {
            element = graph.getEdge(schema.decodeId(id));
            Object outObject = ((GremlinEdgeSchema) schema).getOutProperty().getAccessor().get(object);
            Object inObject = ((GremlinEdgeSchema) schema).getInProperty().getAccessor().get(object);
            schema.copyToGraph(graphAdapter, element, object, outObject, inObject);
        } else {
            throw new IllegalStateException("Schema is neither EDGE nor VERTEX!");
        }
        if (element == null) {
            throw new IllegalStateException(String.format("Could not save %s with id %s, as it does not exist.", object, id));
        }
    }
    return object;
}

Fixed in 11ee40b. Thanks clepelli!