@Test public void exampleQuery() throws Exception { // START SNIPPET: JavaQuery ExecutionEngine engine = new ExecutionEngine(db); ExecutionResult result = engine.execute("start n=node(0) where 1=1 return n"); assertThat(result.columns(), hasItem("n")); Iterator<Node> n_column = result.columnAs("n"); assertThat(asIterable(n_column), hasItem(db.getNodeById(0))); assertThat(result.toString(), containsString("Node[0]")); // END SNIPPET: JavaQuery }
@Test public void exampleWithParameterForNodeObject() throws Exception { // START SNIPPET: exampleWithParameterForNodeObject Map<String, Object> params = new HashMap<String, Object>(); params.put("node", andreasNode); ExecutionResult result = engine.execute("start n=node({node}) return n.name", params); // END SNIPPET: exampleWithParameterForNodeObject assertThat(result.columns(), hasItem("n.name")); Iterator<Object> n_column = result.columnAs("n.name"); assertEquals("Andreas", n_column.next()); }
@Test public void exampleWithParameterRegularExpression() throws Exception { // START SNIPPET: exampleWithParameterRegularExpression Map<String, Object> params = new HashMap<String, Object>(); params.put("regex", ".*h.*"); ExecutionResult result = engine.execute("start n=node(0,1,2) where n.name =~ {regex} return n.name", params); // END SNIPPET: exampleWithParameterRegularExpression assertThat(result.columns(), hasItem("n.name")); Iterator<Object> n_column = result.columnAs("n.name"); assertEquals("Michaela", n_column.next()); assertEquals("Johan", n_column.next()); }
@Test public void exampleWithParameterForSkipAndLimit() throws Exception { // START SNIPPET: exampleWithParameterForSkipLimit Map<String, Object> params = new HashMap<String, Object>(); params.put("s", 1); params.put("l", 1); ExecutionResult result = engine.execute("start n=node(0,1,2) return n.name skip {s} limit {l}", params); // END SNIPPET: exampleWithParameterForSkipLimit assertThat(result.columns(), hasItem("n.name")); Iterator<Object> n_column = result.columnAs("n.name"); assertEquals("Andreas", n_column.next()); }
protected ResultSet toResultSet(ExecutionResult result) throws SQLException { return new IteratorResultSet(this, result.columns(), result.getResult()); }