Search in sources :

Example 1 with JanusGraphBlueprintsGraph

use of org.janusgraph.graphdb.tinkerpop.JanusGraphBlueprintsGraph in project janusgraph by JanusGraph.

the class JanusGraphTraversalUtil method getTx.

public static JanusGraphTransaction getTx(Traversal.Admin<?, ?> traversal) {
    final JanusGraphTransaction tx;
    Optional<Graph> optGraph = TraversalHelper.getRootTraversal(traversal.asAdmin()).getGraph();
    if (traversal instanceof FulgoraElementTraversal) {
        tx = (JanusGraphTransaction) optGraph.get();
    } else {
        if (!optGraph.isPresent())
            throw new IllegalArgumentException("Traversal is not bound to a graph: " + traversal);
        Graph graph = optGraph.get();
        if (graph instanceof JanusGraphTransaction)
            tx = (JanusGraphTransaction) graph;
        else if (graph instanceof JanusGraphBlueprintsGraph)
            tx = ((JanusGraphBlueprintsGraph) graph).getCurrentThreadTx();
        else
            throw new IllegalArgumentException("Traversal is not bound to a JanusGraph Graph, but: " + graph);
    }
    if (tx == null)
        throw new IllegalArgumentException("Not a valid start step for a JanusGraph traversal: " + traversal);
    if (tx.isOpen())
        return tx;
    else
        return ((StandardJanusGraphTx) tx).getNextTx();
}
Also used : JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraphBlueprintsGraph(org.janusgraph.graphdb.tinkerpop.JanusGraphBlueprintsGraph) FulgoraElementTraversal(org.janusgraph.graphdb.olap.computer.FulgoraElementTraversal) JanusGraphBlueprintsGraph(org.janusgraph.graphdb.tinkerpop.JanusGraphBlueprintsGraph)

Aggregations

Graph (org.apache.tinkerpop.gremlin.structure.Graph)1 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)1 FulgoraElementTraversal (org.janusgraph.graphdb.olap.computer.FulgoraElementTraversal)1 JanusGraphBlueprintsGraph (org.janusgraph.graphdb.tinkerpop.JanusGraphBlueprintsGraph)1