Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy#detach()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy#detach() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddEdgeStep.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
protected Edge map(final Traverser.Admin<S> traverser) {
    Vertex toVertex = this.parameters.get(traverser, TO, () -> (Vertex) traverser.get()).get(0);
    Vertex fromVertex = this.parameters.get(traverser, FROM, () -> (Vertex) traverser.get()).get(0);
    if (toVertex instanceof Attachable)
        toVertex = ((Attachable<Vertex>) toVertex)
                .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
    if (fromVertex instanceof Attachable)
        fromVertex = ((Attachable<Vertex>) fromVertex)
                .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
    final String edgeLabel = this.parameters.get(traverser, T.label, () -> Edge.DEFAULT_LABEL).get(0);

    final Edge edge = fromVertex.addEdge(edgeLabel, toVertex, this.parameters.getKeyValues(traverser, TO, FROM, T.label));
    if (callbackRegistry != null) {
        final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get();
        final Event.EdgeAddedEvent vae = new Event.EdgeAddedEvent(eventStrategy.detach(edge));
        callbackRegistry.getCallbacks().forEach(c -> c.accept(vae));
    }
    return edge;
}
 
Example 2
Source File: SqlgAddVertexStartStep.java    From sqlg with MIT License 6 votes vote down vote up
@Override
protected Traverser.Admin<Vertex> processNextStart() {
    if (this.first) {
        this.first = false;
        final SqlgTraverserGenerator generator = SqlgTraverserGenerator.instance();
        final Vertex vertex = this.getTraversal().getGraph().get().addVertex(
                this.parameters.getKeyValues(
                        generator.generate(false, (Step)this, 1L, false, false)
                ));
        if (this.callbackRegistry != null && !this.callbackRegistry.getCallbacks().isEmpty()) {
            final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get();
            final Event.VertexAddedEvent vae = new Event.VertexAddedEvent(eventStrategy.detach(vertex));
            this.callbackRegistry.getCallbacks().forEach(c -> c.accept(vae));
        }
        return generator.generate(vertex, (Step)this, 1L, false, false);
    } else
        throw FastNoSuchElementException.instance();
}
 
Example 3
Source File: AddEdgeStartStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
protected Traverser.Admin<Edge> processNextStart() {
    if (this.first) {
        this.first = false;
        final TraverserGenerator generator = this.getTraversal().getTraverserGenerator();
        final Traverser.Admin traverser = generator.generate(1, (Step) this, 1); // a dead traverser to trigger the traversal
        Vertex toVertex = (Vertex) this.parameters.get(traverser, TO, Collections::emptyList).get(0);
        Vertex fromVertex = (Vertex) this.parameters.get(traverser, FROM, Collections::emptyList).get(0);
        if (toVertex instanceof Attachable)
            toVertex = ((Attachable<Vertex>) toVertex)
                    .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
        if (fromVertex instanceof Attachable)
            fromVertex = ((Attachable<Vertex>) fromVertex)
                    .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
        final String edgeLabel = (String) this.parameters.get(traverser, T.label, () -> Edge.DEFAULT_LABEL).get(0);
        final Edge edge = fromVertex.addEdge(edgeLabel, toVertex, this.parameters.getKeyValues(traverser, TO, FROM, T.label));
        if (callbackRegistry != null) {
            final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get();
            final Event.EdgeAddedEvent vae = new Event.EdgeAddedEvent(eventStrategy.detach(edge));
            callbackRegistry.getCallbacks().forEach(c -> c.accept(vae));
        }
        return generator.generate(edge, this, 1L);
    } else
        throw FastNoSuchElementException.instance();


}
 
Example 4
Source File: AddVertexStartStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
protected Traverser.Admin<Vertex> processNextStart() {
    if (this.first) {
        this.first = false;
        final TraverserGenerator generator = this.getTraversal().getTraverserGenerator();
        final Vertex vertex = this.getTraversal().getGraph().get().addVertex(this.parameters.getKeyValues(generator.generate(false, (Step) this, 1L)));
        if (this.callbackRegistry != null) {
            final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get();
            final Event.VertexAddedEvent vae = new Event.VertexAddedEvent(eventStrategy.detach(vertex));
            this.callbackRegistry.getCallbacks().forEach(c -> c.accept(vae));
        }
        return generator.generate(vertex, this, 1L);
    } else
        throw FastNoSuchElementException.instance();
}
 
Example 5
Source File: AddVertexStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
protected Vertex map(final Traverser.Admin<S> traverser) {
    final Vertex vertex = this.getTraversal().getGraph().get().addVertex(this.parameters.getKeyValues(traverser));
    if (this.callbackRegistry != null) {
        final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get();
        final Event.VertexAddedEvent vae = new Event.VertexAddedEvent(eventStrategy.detach(vertex));
        this.callbackRegistry.getCallbacks().forEach(c -> c.accept(vae));
    }
    return vertex;
}