public interface RxSession extends RxStatementRunner
Session except it provides a reactive API.Session,
RxStatementResult,
RxTransaction,
Publisher| Modifier and Type | Method and Description |
|---|---|
org.reactivestreams.Publisher<RxTransaction> |
beginTransaction()
Begin a new explicit transaction.
|
org.reactivestreams.Publisher<RxTransaction> |
beginTransaction(TransactionConfig config)
Begin a new explicit transaction with the specified
configuration. |
<T> org.reactivestreams.Publisher<T> |
close()
Signal that you are done using this session.
|
Bookmark |
lastBookmark()
Return the bookmark received following the last completed statement within this session.
|
<T> org.reactivestreams.Publisher<T> |
readTransaction(RxTransactionWork<org.reactivestreams.Publisher<T>> work)
Execute given unit of reactive work in a
read reactive transaction. |
<T> org.reactivestreams.Publisher<T> |
readTransaction(RxTransactionWork<org.reactivestreams.Publisher<T>> work,
TransactionConfig config)
Execute given unit of reactive work in a
read reactive transaction with
the specified configuration. |
RxStatementResult |
run(Statement statement,
TransactionConfig config)
Run a statement in an auto-commit transaction with specified
configuration and return a reactive result stream. |
RxStatementResult |
run(String statement,
Map<String,Object> parameters,
TransactionConfig config)
Run a statement with parameters in an auto-commit transaction with specified
TransactionConfig and return a reactive result stream. |
RxStatementResult |
run(String statement,
TransactionConfig config)
Run a statement with parameters in an auto-commit transaction with specified
TransactionConfig and return a reactive result stream. |
<T> org.reactivestreams.Publisher<T> |
writeTransaction(RxTransactionWork<org.reactivestreams.Publisher<T>> work)
Execute given unit of reactive work in a
write reactive transaction. |
<T> org.reactivestreams.Publisher<T> |
writeTransaction(RxTransactionWork<org.reactivestreams.Publisher<T>> work,
TransactionConfig config)
Execute given unit of reactive work in a
write reactive transaction with
the specified configuration. |
org.reactivestreams.Publisher<RxTransaction> beginTransaction()
It by default is executed in a Network IO thread, as a result no blocking operation is allowed in this thread.
RxTransactionorg.reactivestreams.Publisher<RxTransaction> beginTransaction(TransactionConfig config)
configuration.
At most one transaction may exist in a session at any point in time. To
maintain multiple concurrent transactions, use multiple concurrent sessions.
It by default is executed in a Network IO thread, as a result no blocking operation is allowed in this thread.
config - configuration for the new transaction.RxTransaction<T> org.reactivestreams.Publisher<T> readTransaction(RxTransactionWork<org.reactivestreams.Publisher<T>> work)
read reactive transaction.
Transaction will automatically be committed unless given unit of work fails or
transaction commit fails.
It will also not be committed if explicitly rolled back via RxTransaction.rollback().
Returned publisher and given RxTransactionWork is completed/executed 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 CompletableFuture.get() on the returned publisher and do not use them inside the
RxTransactionWork.
T - the return type of the given unit of work.work - the RxTransactionWork to be applied to a new read transaction.
Operation executed by the given work must NOT include any blocking operation.publisher completed with the same result as returned by the given unit of work.
publisher can be completed exceptionally if given work or commit fails.<T> org.reactivestreams.Publisher<T> readTransaction(RxTransactionWork<org.reactivestreams.Publisher<T>> work, TransactionConfig config)
read reactive transaction with
the specified configuration.
Transaction will automatically be committed unless given unit of work fails or
transaction commit fails.
It will also not be committed if explicitly rolled back via RxTransaction.rollback().
Returned publisher and given RxTransactionWork is completed/executed 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 CompletableFuture.get() on the returned publisher and do not use them inside the
RxTransactionWork.
T - the return type of the given unit of work.work - the RxTransactionWork to be applied to a new read transaction.
Operation executed by the given work must NOT include any blocking operation.config - the transaction configuration.publisher completed with the same result as returned by the given unit of work.
publisher can be completed exceptionally if given work or commit fails.<T> org.reactivestreams.Publisher<T> writeTransaction(RxTransactionWork<org.reactivestreams.Publisher<T>> work)
write reactive transaction.
Transaction will automatically be committed unless given unit of work fails or
transaction commit fails.
It will also not be committed if explicitly rolled back via RxTransaction.rollback().
Returned publisher and given RxTransactionWork is completed/executed 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 CompletableFuture.get() on the returned publisher and do not use them inside the
RxTransactionWork.
T - the return type of the given unit of work.work - the RxTransactionWork to be applied to a new read transaction.
Operation executed by the given work must NOT include any blocking operation.publisher completed with the same result as returned by the given unit of work.
publisher can be completed exceptionally if given work or commit fails.<T> org.reactivestreams.Publisher<T> writeTransaction(RxTransactionWork<org.reactivestreams.Publisher<T>> work, TransactionConfig config)
write reactive transaction with
the specified configuration.
Transaction will automatically be committed unless given unit of work fails or
transaction commit fails.
It will also not be committed if explicitly rolled back via RxTransaction.rollback().
Returned publisher and given RxTransactionWork is completed/executed 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 CompletableFuture.get() on the returned publisher and do not use them inside the
RxTransactionWork.
T - the return type of the given unit of work.work - the RxTransactionWork to be applied to a new read transaction.
Operation executed by the given work must NOT include any blocking operation.config - the transaction configuration.publisher completed with the same result as returned by the given unit of work.
publisher can be completed exceptionally if given work or commit fails.RxStatementResult run(String statement, TransactionConfig config)
TransactionConfig and return a reactive result stream.
The statement is not executed when the reactive result is returned.
Instead, the publishers in the result will actually start the execution of the statement.statement - text of a Neo4j statement.config - configuration for the new transaction.RxStatementResult run(String statement, Map<String,Object> parameters, TransactionConfig config)
TransactionConfig and return a reactive result stream.
The statement is not executed when the reactive result is returned.
Instead, the publishers in the result will actually start the execution of the statement.
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 run 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> metadata = new HashMap<>();
metadata.put("type", "update name");
TransactionConfig config = TransactionConfig.builder()
.withTimeout(Duration.ofSeconds(3))
.withMetadata(metadata)
.build();
Map<String, Object> parameters = new HashMap<>();
parameters.put("myNameParam", "Bob");
RxResult result = rxSession.run("MATCH (n) WHERE n.name = {myNameParam} RETURN (n)", parameters, config);
statement - text of a Neo4j statement.parameters - input data for the statement.config - configuration for the new transaction.RxStatementResult run(Statement statement, TransactionConfig config)
configuration and return a reactive result stream.
The statement is not executed when the reactive result is returned.
Instead, the publishers in the result will actually start the execution of the statement.
Map<String, Object> metadata = new HashMap<>();
metadata.put("type", "update name");
TransactionConfig config = TransactionConfig.builder()
.withTimeout(Duration.ofSeconds(3))
.withMetadata(metadata)
.build();
Statement statement = new Statement("MATCH (n) WHERE n.name=$myNameParam RETURN n.age");
RxResult result = rxSession.run(statement.withParameters(Values.parameters("myNameParam", "Bob")));
statement - a Neo4j statement.config - configuration for the new transaction.Bookmark lastBookmark()
run.<T> org.reactivestreams.Publisher<T> close()
This operation is not needed if 1) all results created in the session have been fully consumed and 2) all transactions opened by this session have been either committed or rolled back.
This method is a fallback if you failed to fulfill the two requirements above. This publisher is completed when all outstanding statements in the session have completed, meaning any writes you performed are guaranteed to be durably stored. It might be completed exceptionally when there are unconsumed errors from previous statements or transactions.
T - makes it easier to be chained.Copyright © 2019. All rights reserved.