private void checkExecutionEngine() { if ( queryEngine == null ) { queryEngine = new ExecutionEngine( graph ); } }
public static Node getReferenceNode(GraphDatabaseService db, String name) { if (engine == null || db != dbRef) { engine = new ExecutionEngine(db); ReferenceNodes.dbRef = db; } ExecutionResult result = engine.execute("MERGE (ref:ReferenceNode {name:{name}}) RETURN ref", map("name", name)); return IteratorUtil.single(result.<Node>columnAs("ref")); } }
static void writeResults(Appender appender, GraphDatabaseService dbService, List<String> queries, HashMap<String, Object> params, boolean includeHeader) throws IOException { for (String query : queries) { ExecutionResult rows = new ExecutionEngine(dbService).execute(query, params); List<String> columns = rows.columns(); if (includeHeader && queries.indexOf(query) == 0) { final String[] values = columns.toArray(new String[columns.size()]); appender.append(Stream.of(values)); } appendRow(appender, rows, columns); } }
@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 ) ) ); // END SNIPPET: JavaQuery }
private boolean contains(Atom atom, Transaction transaction) { String query = containsAtomIntoCypherQuery(atom, true); if (LOGGER.isDebugEnabled()) { LOGGER.debug(query); } ResourceIterator<Node> result = this.cypherEngine.execute(query).columnAs("atom"); boolean res = result.hasNext(); result.close(); return res; }
@Test public void testColumnAreInTheRightOrder() throws Exception { createTenNodes(); String q = "start one=node(1), two=node(2), three=node(3), four=node(4), five=node(5), six=node(6), " + "seven=node(7), eight=node(8), nine=node(9), ten=node(10) " + "return one, two, three, four, five, six, seven, eight, nine, ten"; ExecutionResult result = engine.execute( q ); assertThat( result.dumpToString(), matchesPattern( "one.*two.*three.*four.*five.*six.*seven.*eight.*nine.*ten" ) ); }
GraphDatabaseService db = ...; // from version 2.2.x onwards db.execute("your cypher statement"); // before version 2.2.x ExecutionEngine engine = new ExecutionEngine(db) engine.execute("your cypher statement");
private <T> List<T> toList( ExecutionResult result, String column ) { List<T> results = new ArrayList<T>(); IteratorUtil.addToCollection( result.<T>columnAs( column ), results ); return results; }
@Test public void shouldBeAbleToEmitJavaIterables() throws Exception { makeFriends( michaelaNode, andreasNode ); makeFriends( michaelaNode, johanNode ); ExecutionEngine engine = new ExecutionEngine( db ); ExecutionResult result = engine.execute( "START n=node(0) MATCH n-->friend RETURN collect(friend)" ); Iterable<Node> friends = (Iterable<Node>) result.columnAs( "collect(friend)" ).next(); assertThat( friends, hasItems( andreasNode, johanNode ) ); assertThat( friends, instanceOf( Iterable.class ) ); }
public Neo4jSingleInsertion(GraphDatabaseService neo4jGraph, File resultsPath) { super(GraphDatabaseType.NEO4J, resultsPath); this.neo4jGraph = neo4jGraph; engine = new ExecutionEngine(this.neo4jGraph); }
@Override public void clear() { this.checkTransaction(); this.cypherEngine .execute("MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r"); this.successTransaction(); this.reloadTransaction(); }
@Produces public ExecutionEngine createQueryEngine(GraphDatabaseService service) { return new ExecutionEngine(service); }
@Before public void setup() throws IOException { graphdb = new ImpermanentGraphDatabase(); graphdb.cleanContent(true); engine = new ExecutionEngine( graphdb ); }
@Override public CloseableIterator<Atom> match(Atom atom) { String query = matchAtomIntoCypherQuery(atom); if (LOGGER.isDebugEnabled()) { LOGGER.debug(query); } ResourceIterator<Map<String, Object>> result = this.cypherEngine.execute(query).iterator(); return new Neo4jAtomIterator(this.getTransaction(), result); }
@Before public void setup() throws IOException { graphdb = new ImpermanentGraphDatabase(); graphdb.cleanContent( false ); engine = new ExecutionEngine( graphdb ); }
@Override public CloseableIterator<Term> termsByPredicatePosition(Predicate p, int position) throws AtomSetException { StringBuilder sb = new StringBuilder(); sb.append("MATCH "); predicateToCypher(sb, p); sb.append("<-[rel_predicate:PREDICATE]-(atom)-[:TERM { index: ").append(position).append(" }]->(term) "); sb.append("RETURN DISTINCT term"); String query = sb.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(query); } ResourceIterator<Map<String, Object>> result = this.cypherEngine.execute(query).iterator(); return new Neo4jTermIterator(this.getTransaction(), result); }