use of org.opencypher.gremlin.client.CypherGremlinClient 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");
}
use of org.opencypher.gremlin.client.CypherGremlinClient in project cypher-for-gremlin by opencypher.
the class CypherGremlinServerClient method inMemory.
@Test
public void inMemory() {
// freshReadmeSnippet: inMemory
TinkerGraph graph = TinkerFactory.createModern();
GraphTraversalSource traversal = graph.traversal();
CypherGremlinClient cypherGremlinClient = CypherGremlinClient.inMemory(traversal);
String cypher = "MATCH (p:person) WHERE p.age > 25 RETURN p.name";
List<Map<String, Object>> results = cypherGremlinClient.submit(cypher).all();
// freshReadmeSnippet: inMemory
assertThat(results).extracting("p.name").containsExactly("marko", "vadas", "josh", "peter");
}
use of org.opencypher.gremlin.client.CypherGremlinClient in project cypher-for-gremlin by opencypher.
the class CypherGremlinServerClient method workingWithCypherGremlinClient.
@Test
public void workingWithCypherGremlinClient() {
String cypher = "MATCH (p:person) WHERE p.age > 25 RETURN p.name";
CypherGremlinClient cypherGremlinClient = gremlinServer.cypherGremlinClient();
// freshReadmeSnippet: workingWithCypherGremlinClient
// as a list
List<Map<String, Object>> list = cypherGremlinClient.submit(cypher).all();
// as a stream
Stream<Map<String, Object>> stream = cypherGremlinClient.submit(cypher).stream();
// as an iterator
Iterator<Map<String, Object>> iterator = cypherGremlinClient.submit(cypher).iterator();
// also an iterable
Iterable<Map<String, Object>> iterable = cypherGremlinClient.submit(cypher);
// freshReadmeSnippet: workingWithCypherGremlinClient
assertThat(list).isEqualTo(stream.collect(Collectors.toList())).isEqualTo(Lists.newArrayList(iterator)).isEqualTo(Lists.newArrayList(iterable)).extracting("p.name").containsExactly("marko", "vadas", "josh", "peter");
}
use of org.opencypher.gremlin.client.CypherGremlinClient in project cypher-for-gremlin by opencypher.
the class GremlinServerDriver method session.
@Override
public Session session() {
Client gremlinClient = cluster.connect();
CypherGremlinClient cypherGremlinClient = config.translationEnabled() ? CypherGremlinClient.translating(gremlinClient, config.flavor()) : CypherGremlinClient.plugin(gremlinClient);
return new GremlinServerSession(serverInfo, cypherGremlinClient);
}
use of org.opencypher.gremlin.client.CypherGremlinClient in project cypher-for-gremlin by opencypher.
the class CypherGremlinServerClient method translating.
@Test
public void translating() {
BaseConfiguration configuration = new BaseConfiguration();
configuration.setProperty("port", gremlinServer.getPort());
configuration.setProperty("hosts", Arrays.asList("localhost"));
Cluster cluster = Cluster.open(configuration);
Client gremlinClient = cluster.connect();
// freshReadmeSnippet: translating
CypherGremlinClient cypherGremlinClient = CypherGremlinClient.translating(gremlinClient);
// freshReadmeSnippet: translating
List<Map<String, Object>> results = cypherGremlinClient.submit("MATCH (p:person) WHERE p.age > 25 RETURN p.name").all();
assertThat(results).extracting("p.name").containsExactly("marko", "vadas", "josh", "peter");
}
Aggregations