Query DSL with Parameters - Wolfgang-Schuetzelhofer/jcypher GitHub Wiki

Previous Next Table of Contents

Query DSL with Parameters

You can use parameters (JcQueryParameter) with Query DSL expressions. This allows to reuse Query DSL Expressions with different values for the specified parameters.

Note: Don't confuse this with 'Parameterized CYPHER Expressions'. 'Parameterized CYPHER Expressions' are generated in the background whenever the use of parameters with CYPHER is possible. This allows Neo4J to optimize queries.

Here is a code snippet about how to use parameters with Query DSL Expressions.

// specify a query parameter
JcQueryParameter memberName = new JcQueryParameter("memberName");
// set the parameter value
memberName.setValue("John");

// specify the query
JcNode n = new JcNode("n");
IClause[] clauses = new IClause[] {
   // match nodes
   MATCH.node(n).label("Member").property("name").value(memberName),
   RETURN.value(n)
};
JcQuery query = new JcQuery();
query.setClauses(clauses);

// execute the query
JcQueryResult result = dbAccess.execute(query);

// modify the parameter value
memberName.setValue("Angelina");

// execute the query again
result = dbAccess.execute(query);

Previous Next Table of Contents
⚠️ **GitHub.com Fallback** ⚠️