Search in sources :

Example 1 with CypherResultSet

use of org.opencypher.gremlin.client.CypherResultSet in project cypher-for-gremlin by opencypher.

the class CypherGremlinServerClient method gremlinStyle.

@Test
public void gremlinStyle() throws Exception {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty("port", gremlinServer.getPort());
    configuration.setProperty("hosts", Arrays.asList("localhost"));
    // freshReadmeSnippet: gremlinStyle
    Cluster cluster = Cluster.open(configuration);
    Client gremlinClient = cluster.connect();
    CypherGremlinClient cypherGremlinClient = CypherGremlinClient.plugin(gremlinClient);
    String cypher = "MATCH (p:person) WHERE p.age > 25 RETURN p.name";
    CypherResultSet resultSet = cypherGremlinClient.submit(cypher);
    List<Map<String, Object>> results = resultSet.all();
    // freshReadmeSnippet: gremlinStyle
    assertThat(results).extracting("p.name").containsExactly("marko", "vadas", "josh", "peter");
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CypherResultSet(org.opencypher.gremlin.client.CypherResultSet) Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) Client(org.apache.tinkerpop.gremlin.driver.Client) Map(java.util.Map) Test(org.junit.Test)

Example 2 with CypherResultSet

use of org.opencypher.gremlin.client.CypherResultSet in project cypher-for-gremlin by opencypher.

the class CypherRemoteAcceptor method send.

private List<Result> send(String query) throws Exception {
    CompletableFuture<CypherResultSet> resultsFuture = client.submitAsync(query);
    CypherResultSet resultSet = (timeout > NO_TIMEOUT) ? resultsFuture.get(timeout, TimeUnit.MILLISECONDS) : resultsFuture.get();
    return resultSet.stream().map(Result::new).collect(toList());
}
Also used : CypherResultSet(org.opencypher.gremlin.client.CypherResultSet)

Example 3 with CypherResultSet

use of org.opencypher.gremlin.client.CypherResultSet in project cypher-for-gremlin by opencypher.

the class CypherGremlinServerClient method async.

@Test
public void async() {
    CypherGremlinClient cypherGremlinClient = gremlinServer.cypherGremlinClient();
    // freshReadmeSnippet: async
    String cypher = "MATCH (p:person) WHERE p.age > 25 RETURN p.name";
    CompletableFuture<CypherResultSet> future = cypherGremlinClient.submitAsync(cypher);
    future.thenApply(CypherResultSet::all).thenAccept(resultSet -> {
    // ...
    });
// freshReadmeSnippet: async
}
Also used : CypherResultSet(org.opencypher.gremlin.client.CypherResultSet) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) Test(org.junit.Test)

Aggregations

CypherResultSet (org.opencypher.gremlin.client.CypherResultSet)3 Test (org.junit.Test)2 CypherGremlinClient (org.opencypher.gremlin.client.CypherGremlinClient)2 Map (java.util.Map)1 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)1 Client (org.apache.tinkerpop.gremlin.driver.Client)1 Cluster (org.apache.tinkerpop.gremlin.driver.Cluster)1