Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#forEachRemaining()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#forEachRemaining() . 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: EdgesClient.java    From amazon-neptune-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void queryForMetadata(GraphElementHandler<Map<?, Object>> handler, Range range, LabelsFilter labelsFilter) {
    GraphTraversal<? extends Element, Map<Object, Object>> t = tokensOnly ?
            traversal(range, labelsFilter).valueMap(true, "~TOKENS-ONLY") :
            traversal(range, labelsFilter).valueMap(true);

    logger.info(GremlinQueryDebugger.queryAsString(t));

    t.forEachRemaining(m -> {
        try {
            handler.handle(m, false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example 2
Source File: NodesClient.java    From amazon-neptune-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void queryForMetadata(GraphElementHandler<Map<?, Object>> handler, Range range, LabelsFilter labelsFilter) {

    GraphTraversal<? extends Element, Map<Object, Object>> t = tokensOnly ?
            traversal(range, labelsFilter).valueMap(true, "~TOKENS-ONLY") :
            traversal(range, labelsFilter).valueMap(true);

    logger.info(GremlinQueryDebugger.queryAsString(t));

    t.forEachRemaining(m -> {
        try {
            handler.handle(m, false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example 3
Source File: NodesClient.java    From amazon-neptune-tools with Apache License 2.0 6 votes vote down vote up
@Override
public void queryForValues(GraphElementHandler<Map<String, Object>> handler,
                           Range range,
                           LabelsFilter labelsFilter,
                           PropertiesMetadata propertiesMetadata) {

    GraphTraversal<? extends Element, Map<String, Object>> t = traversal(range, labelsFilter).
            project("id", "label", "properties").
            by(T.id).
            by(label().fold()).
            by(tokensOnly ?
                    select("x") :
                    valueMap(labelsFilter.getPropertiesForLabels(propertiesMetadata))
            );

    logger.info(GremlinQueryDebugger.queryAsString(t));

    t.forEachRemaining(m -> {
        try {
            handler.handle(m, false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example 4
Source File: TinkerPopOperations.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addPid(UUID id, int rev, URI pidUri) throws NotFoundException {
  /*
   * EntityFetcher does not work here, because it does not return all the vertices with a certain id en revision. It
   * will only return the vertex with the revision with "isLatest" set to false.
   */
  GraphTraversal<Vertex, Vertex> vertices = traversal.V().has("tim_id", id.toString()).has("rev", rev);
  if (!vertices.hasNext()) {
    throw new NotFoundException();
  }
  vertices.forEachRemaining(vertex -> {
      LOG.info("Setting pid for " + vertex.id() + " to " + pidUri.toString());
      vertex.property("pid", pidUri.toString());
    }
  );
}
 
Example 5
Source File: EdgesClient.java    From amazon-neptune-tools with Apache License 2.0 5 votes vote down vote up
@Override
public void queryForValues(GraphElementHandler<Map<String, Object>> handler,
                           Range range,
                           LabelsFilter labelsFilter,
                           PropertiesMetadata propertiesMetadata) {

    GraphTraversal<Edge, Edge> t = tokensOnly ?
            g.withSideEffect("x", new HashMap<String, Object>()).E():
            g.E();


    GraphTraversal<? extends Element, Map<String, Object>> traversal =
            range.applyRange(labelsFilter.apply(t)).
                    project("id", "label", "properties", "from", "to").
                    by(T.id).
                    by(T.label).
                    by(tokensOnly ?
                            select("x"):
                            valueMap(labelsFilter.getPropertiesForLabels(propertiesMetadata))
                    ).
                    by(outV().id()).
                    by(inV().id());

    logger.info(GremlinQueryDebugger.queryAsString(t));

    traversal.forEachRemaining(p -> {
        try {
            handler.handle(p, false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example 6
Source File: App.java    From graph-examples with Apache License 2.0 5 votes vote down vote up
private void printTraversalResult(Terminal terminal, String title, GraphTraversal traversal) {
    if (title != null) {
        terminal.writer().println(new AttributedStringBuilder()
                .style(AttributedStyle.DEFAULT.foreground(AttributedStyle.GREEN))
                .append(title).append("\n")
                .style(AttributedStyle.DEFAULT).toAnsi());
    }
    traversal.forEachRemaining(r -> terminal.writer().println(formatResult(r)));
    terminal.writer().println();
}
 
Example 7
Source File: CoreTraversalTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void shouldHavePropertyForEachRemainingBehaviorEvenWithStrategyRewrite() {
    final GraphTraversal<Vertex, Map<Object, Long>> traversal = g.V().out().groupCount();
    traversal.forEachRemaining(Map.class, map -> assertTrue(map instanceof Map));
}