public interface StatementRunner
StatementRunner are guaranteed
to execute in order, meaning changes made by one statement will be seen
by all subsequent statements in the same StatementRunner.
However, to allow handling very large results, and to improve performance,
result streams are retrieved lazily from the network. This means that when
any of the blocking run(Statement) or async runAsync(Statement)
methods return a result, the statement has only started executing - it may not
have completed yet. Most of the time, you will not notice this, because the
driver automatically waits for statements to complete at specific points to
fulfill its contracts.
Specifically, the driver will ensure all outstanding statements are completed
whenever you:
StatementResult.next(), StatementResult.consume() or async
StatementResultCursor.nextAsync(), StatementResultCursor.consumeAsync()Transaction.close()
or async Transaction.commitAsync(), Transaction.rollbackAsync()Session.close() or
async Session.closeAsync()transactions or close the session you used using Session.close().
While these semantics introduce some complexity, it gives the driver the ability
to handle infinite result streams (like subscribing to events), significantly lowers
the memory overhead for your application and improves performance.
runAsync(Statement) execute queries in async fashion and return CompletionStage of
a new StatementResultCursor. Stage can be completed exceptionally when error happens, e.g. connection can't
be acquired from the pool.
Note: Returned stage can be completed by an IO thread which should never block. Otherwise IO operations on
this and potentially other network connections might deadlock. Please do not chain blocking operations like
run(String) on the returned stage. Driver will throw IllegalStateException when blocking API
call is executed in IO thread. Consider using asynchronous calls throughout the chain or offloading blocking
operation to a different Executor. This can be done using methods with "Async" suffix like
CompletionStage.thenApplyAsync(Function) or CompletionStage.thenApplyAsync(Function, Executor).
Session,
Transaction| Modifier and Type | Method and Description |
|---|---|
StatementResult |
run(Statement statement)
Run a statement and return a result stream.
|
StatementResult |
run(String statementTemplate)
Run a statement and return a result stream.
|
StatementResult |
run(String statementTemplate,
Map<String,Object> statementParameters)
Run a statement and return a result stream.
|
StatementResult |
run(String statementTemplate,
Record statementParameters)
Run a statement and return a result stream.
|
StatementResult |
run(String statementTemplate,
Value parameters)
Run a statement and return a result stream.
|
CompletionStage<StatementResultCursor> |
runAsync(Statement statement)
Run a statement asynchronously and return a
CompletionStage with a
result cursor. |
CompletionStage<StatementResultCursor> |
runAsync(String statementTemplate)
Run a statement asynchronously and return a
CompletionStage with a
result cursor. |
CompletionStage<StatementResultCursor> |
runAsync(String statementTemplate,
Map<String,Object> statementParameters)
Run a statement asynchronously and return a
CompletionStage with a
result cursor. |
CompletionStage<StatementResultCursor> |
runAsync(String statementTemplate,
Record statementParameters)
Run a statement asynchronously and return a
CompletionStage with a
result cursor. |
CompletionStage<StatementResultCursor> |
runAsync(String statementTemplate,
Value parameters)
Run a statement asynchronously and return a
CompletionStage with a
result cursor. |
TypeSystem |
typeSystem() |
StatementResult run(String statementTemplate, Value parameters)
Value as its input. This is useful
if you want to take a map-like value that you've gotten from a prior result
and send it back as parameters.
If you are creating parameters programmatically, run(String, Map)
might be more helpful, it converts your map to a Value for you.
StatementResult cursor = session.run( "MATCH (n) WHERE n.name = {myNameParam} RETURN (n)",
Values.parameters( "myNameParam", "Bob" ) );
statementTemplate - text of a Neo4j statementparameters - input parameters, should be a map Value, see Values.parameters(Object...).CompletionStage<StatementResultCursor> runAsync(String statementTemplate, Value parameters)
CompletionStage with a
result cursor.
This method takes a set of parameters that will be injected into the statement by Neo4j. Using parameters is highly encouraged, it helps avoid dangerous cypher injection attacks and improves database performance as Neo4j can re-use query plans more often.
This particular method takes a Value as its input. This is useful
if you want to take a map-like value that you've gotten from a prior result
and send it back as parameters.
If you are creating parameters programmatically, runAsync(String, Map)
might be more helpful, it converts your map to a Value for you.
CompletionStage<StatementResultCursor> cursorStage = session.runAsync(
"MATCH (n) WHERE n.name = {myNameParam} RETURN (n)",
Values.parameters("myNameParam", "Bob"));
It is not allowed to chain blocking operations on the returned CompletionStage. See class javadoc for
more information.statementTemplate - text of a Neo4j statementparameters - input parameters, should be a map Value, see Values.parameters(Object...).CompletionStage that gets completed with a result cursor when query execution is successful.
Stage can be completed exceptionally when error happens, e.g. connection can't be acquired from the pool.StatementResult run(String statementTemplate, Map<String,Object> statementParameters)
Map of parameters. The values in the map
must be values that can be converted to Neo4j types. See Values.parameters(Object...) for
a list of allowed types.
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("myNameParam", "Bob");
StatementResult cursor = session.run( "MATCH (n) WHERE n.name = {myNameParam} RETURN (n)",
parameters );
statementTemplate - text of a Neo4j statementstatementParameters - input data for the statementCompletionStage<StatementResultCursor> runAsync(String statementTemplate, Map<String,Object> statementParameters)
CompletionStage with a
result cursor.
This method takes a set of parameters that will be injected into the statement by Neo4j. Using parameters is highly encouraged, it helps avoid dangerous cypher injection attacks and improves database performance as Neo4j can re-use query plans more often.
This version of runAsync takes a Map of parameters. The values in the map
must be values that can be converted to Neo4j types. See Values.parameters(Object...) for
a list of allowed types.
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("myNameParam", "Bob");
CompletionStage<StatementResultCursor> cursorStage = session.runAsync(
"MATCH (n) WHERE n.name = {myNameParam} RETURN (n)",
parameters);
It is not allowed to chain blocking operations on the returned CompletionStage. See class javadoc for
more information.statementTemplate - text of a Neo4j statementstatementParameters - input data for the statementCompletionStage that gets completed with a result cursor when query execution is successful.
Stage can be completed exceptionally when error happens, e.g. connection can't be acquired from the pool.StatementResult run(String statementTemplate, Record statementParameters)
Record of parameters, which can be useful
if you want to use the output of one statement as input for another.statementTemplate - text of a Neo4j statementstatementParameters - input data for the statementCompletionStage<StatementResultCursor> runAsync(String statementTemplate, Record statementParameters)
CompletionStage with a
result cursor.
This method takes a set of parameters that will be injected into the statement by Neo4j. Using parameters is highly encouraged, it helps avoid dangerous cypher injection attacks and improves database performance as Neo4j can re-use query plans more often.
This version of runAsync takes a Record of parameters, which can be useful
if you want to use the output of one statement as input for another.
It is not allowed to chain blocking operations on the returned CompletionStage. See class javadoc for
more information.
statementTemplate - text of a Neo4j statementstatementParameters - input data for the statementCompletionStage that gets completed with a result cursor when query execution is successful.
Stage can be completed exceptionally when error happens, e.g. connection can't be acquired from the pool.StatementResult run(String statementTemplate)
statementTemplate - text of a Neo4j statementCompletionStage<StatementResultCursor> runAsync(String statementTemplate)
CompletionStage with a
result cursor.
It is not allowed to chain blocking operations on the returned CompletionStage. See class javadoc for
more information.
statementTemplate - text of a Neo4j statementCompletionStage that gets completed with a result cursor when query execution is successful.
Stage can be completed exceptionally when error happens, e.g. connection can't be acquired from the pool.StatementResult run(Statement statement)
Statement statement = new Statement( "MATCH (n) WHERE n.name=$myNameParam RETURN n.age" );
StatementResult cursor = session.run( statement.withParameters( Values.parameters( "myNameParam", "Bob" ) ) );
statement - a Neo4j statementCompletionStage<StatementResultCursor> runAsync(Statement statement)
CompletionStage with a
result cursor.
This method takes a set of parameters that will be injected into the statement by Neo4j. Using parameters is highly encouraged, it helps avoid dangerous cypher injection attacks and improves database performance as Neo4j can re-use query plans more often.
This version of runAsync takes a Map of parameters. The values in the map
must be values that can be converted to Neo4j types. See Values.parameters(Object...) for
a list of allowed types.
Statement statement = new Statement( "MATCH (n) WHERE n.name=$myNameParam RETURN n.age" );
CompletionStage<StatementResultCursor> cursorStage = session.runAsync(statement);
It is not allowed to chain blocking operations on the returned CompletionStage. See class javadoc for
more information.statement - a Neo4j statementCompletionStage that gets completed with a result cursor when query execution is successful.
Stage can be completed exceptionally when error happens, e.g. connection can't be acquired from the pool.@Experimental TypeSystem typeSystem()
Copyright © 2018. All rights reserved.