Search in sources :

Example 1 with CypherGremlinClient

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");
}
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 CypherGremlinClient

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");
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) TinkerGraph(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) Map(java.util.Map) Test(org.junit.Test)

Example 3 with CypherGremlinClient

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");
}
Also used : CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) Map(java.util.Map) Test(org.junit.Test)

Example 4 with CypherGremlinClient

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);
}
Also used : CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) Client(org.apache.tinkerpop.gremlin.driver.Client)

Example 5 with 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");
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) 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)

Aggregations

CypherGremlinClient (org.opencypher.gremlin.client.CypherGremlinClient)6 Test (org.junit.Test)5 Map (java.util.Map)4 Client (org.apache.tinkerpop.gremlin.driver.Client)3 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)2 Cluster (org.apache.tinkerpop.gremlin.driver.Cluster)2 CypherResultSet (org.opencypher.gremlin.client.CypherResultSet)2 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)1 TinkerGraph (org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph)1