Class InternalReactiveSession
- All Implemented Interfaces:
BaseSession,ReactiveQueryRunner,ReactiveSession
-
Field Summary
Fields inherited from class org.neo4j.driver.internal.reactive.AbstractReactiveSession
session -
Constructor Summary
ConstructorsConstructorDescriptionInternalReactiveSession(NetworkSession session, DriverObservationProvider observationProvider) -
Method Summary
Modifier and TypeMethodDescriptionorg.reactivestreams.Publisher<ReactiveTransaction> beginTransaction(TransactionConfig config) Begin a new unmanaged transaction with the specifiedconfiguration.org.reactivestreams.Publisher<ReactiveTransaction> beginTransaction(TransactionConfig config, String txType, ApiTelemetryWork apiTelemetryWork) <T> org.reactivestreams.Publisher<T> close()Signal that you are done using this session.org.reactivestreams.Publisher<Void> closeTransaction(ReactiveTransaction transaction, boolean commit, Observation parentObservation) createTransaction(UnmanagedTransaction unmanagedTransaction) <T> org.reactivestreams.Publisher<T> executeRead(ReactiveTransactionCallback<? extends org.reactivestreams.Publisher<T>> callback, TransactionConfig config) Execute a unit of work as a single, managed transaction withreadaccess mode and retry behaviour.<T> org.reactivestreams.Publisher<T> executeWrite(ReactiveTransactionCallback<? extends org.reactivestreams.Publisher<T>> callback, TransactionConfig config) Execute a unit of work as a single, managed transaction withwriteaccess mode and retry behaviour.Return a set of last bookmarks.default org.reactivestreams.Publisher<ReactiveResult> Register running of a query and return a publisher ofReactiveResult.default org.reactivestreams.Publisher<ReactiveResult> Register running of a query and return a publisher ofReactiveResult.default org.reactivestreams.Publisher<ReactiveResult> Register running of a query and return a publisher ofReactiveResult.default org.reactivestreams.Publisher<ReactiveResult> Register running of a query and return a publisher ofReactiveResult.org.reactivestreams.Publisher<ReactiveResult> Register running of a query and return a publisher ofReactiveResult.org.reactivestreams.Publisher<ReactiveResult> run(Query query, TransactionConfig config) Run a query in an auto-commit transaction with specifiedconfigurationand return a publisher ofReactiveResult.Methods inherited from class org.neo4j.driver.internal.reactive.AbstractReactiveSession
doBeginTransaction, doClose, run, runTransactionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.neo4j.driver.reactivestreams.ReactiveSession
beginTransaction, executeRead, executeWrite, run, run
-
Constructor Details
-
InternalReactiveSession
public InternalReactiveSession(NetworkSession session, DriverObservationProvider observationProvider)
-
-
Method Details
-
createTransaction
- Specified by:
createTransactionin classAbstractReactiveSession<ReactiveTransaction>
-
closeTransaction
public org.reactivestreams.Publisher<Void> closeTransaction(ReactiveTransaction transaction, boolean commit, Observation parentObservation) - Specified by:
closeTransactionin classAbstractReactiveSession<ReactiveTransaction>
-
beginTransaction
public org.reactivestreams.Publisher<ReactiveTransaction> beginTransaction(TransactionConfig config) Description copied from interface:ReactiveSessionBegin a new unmanaged transaction with the specifiedconfiguration. At most one transaction may exist in a session at any point in time. To maintain multiple concurrent transactions, use multiple concurrent sessions.It is by default is executed in a Network IO thread, as a result no blocking operation is allowed in this thread.
- Specified by:
beginTransactionin interfaceReactiveSession- Parameters:
config- configuration for the new transaction.- Returns:
- a new
ReactiveTransaction
-
beginTransaction
public org.reactivestreams.Publisher<ReactiveTransaction> beginTransaction(TransactionConfig config, String txType, ApiTelemetryWork apiTelemetryWork) -
executeRead
public <T> org.reactivestreams.Publisher<T> executeRead(ReactiveTransactionCallback<? extends org.reactivestreams.Publisher<T>> callback, TransactionConfig config) Description copied from interface:ReactiveSessionExecute a unit of work as a single, managed transaction withreadaccess mode and retry behaviour. The transaction allows for one or more statements to be run.The driver will attempt committing the transaction when the provided unit of work completes successfully. Any exception emitted by the unit of work will result in a rollback attempt and abortion of execution unless exception is considered to be valid for retry attempt by the driver.
The provided unit of work should not return
ReactiveResultobject as it won't be valid outside the scope of the transaction.It is prohibited to block the thread completing the returned
CompletionStage. Please avoid blocking operations or hand processing over to a different thread.The driver uses the provided
ReactiveTransactionCallbackto get a publisher and emits its signals via the resulting publisher. If the supplied publisher emits aRetryableExceptionand the driver is in a position to retry, it calls the provided callback again to get a new publisher and attempts to stream its signals. In case of retries, the resulting publisher contains the successfully emitted values from all retry attempts. For instance, if a retryable exception occurs after streaming values [v1, v2, v3] and a successful retry emits values [v1, v2, v3, v4] then the resulting publisher emits the following values: [v1, v2, v3, v1, v2, v3, v4].- Specified by:
executeReadin interfaceReactiveSession- Type Parameters:
T- the return type of the given unit of work.- Parameters:
callback- the callback representing the unit of work.config- configuration for all transactions started to execute the unit of work.- Returns:
- a publisher that emits the result of the unit of work and success signals on success or error otherwise.
-
executeWrite
public <T> org.reactivestreams.Publisher<T> executeWrite(ReactiveTransactionCallback<? extends org.reactivestreams.Publisher<T>> callback, TransactionConfig config) Description copied from interface:ReactiveSessionExecute a unit of work as a single, managed transaction withwriteaccess mode and retry behaviour. The transaction allows for one or more statements to be run.The driver will attempt committing the transaction when the provided unit of work completes successfully. Any exception emitted by the unit of work will result in a rollback attempt and abortion of execution unless exception is considered to be valid for retry attempt by the driver.
The provided unit of work should not return
ReactiveResultobject as it won't be valid outside the scope of the transaction.It is prohibited to block the thread completing the returned
CompletionStage. Please avoid blocking operations or hand processing over to a different thread.The driver uses the provided
ReactiveTransactionCallbackto get a publisher and emits its signals via the resulting publisher. If the supplied publisher emits aRetryableExceptionand the driver is in a position to retry, it calls the provided callback again to get a new publisher and attempts to stream its signals. In case of retries, the resulting publisher contains the successfully emitted values from all retry attempts. For instance, if a retryable exception occurs after streaming values [v1, v2, v3] and a successful retry emits values [v1, v2, v3, v4] then the resulting publisher emits the following values: [v1, v2, v3, v1, v2, v3, v4].- Specified by:
executeWritein interfaceReactiveSession- Type Parameters:
T- the return type of the given unit of work.- Parameters:
callback- the callback representing the unit of work.config- configuration for all transactions started to execute the unit of work.- Returns:
- a publisher that emits the result of the unit of work and success signals on success or error otherwise.
-
run
Description copied from interface:ReactiveQueryRunnerRegister running of a query and return a publisher ofReactiveResult.Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of
ReactiveResulton success or an error otherwise.- Specified by:
runin interfaceReactiveQueryRunner- Parameters:
query- a Neo4j query- Returns:
- a publisher of reactive result.
-
run
Description copied from interface:ReactiveSessionRun a query in an auto-commit transaction with specifiedconfigurationand return a publisher ofReactiveResult.Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of
ReactiveResulton success or an error otherwise.Example
Map<String, Object> metadata = new HashMap<>(); metadata.put("type", "update name"); TransactionConfig config = TransactionConfig.builder() .withTimeout(Duration.ofSeconds(3)) .withMetadata(metadata) .build(); Query query = new Query("MATCH (n) WHERE n.name = $myNameParam RETURN n.age"); reactiveSession.run(query.withParameters(Values.parameters("myNameParam", "Bob")));- Specified by:
runin interfaceReactiveSession- Parameters:
query- a Neo4j query.config- configuration for the new transaction.- Returns:
- a publisher of reactive result.
-
lastBookmarks
Description copied from interface:ReactiveSessionReturn a set of last bookmarks.When no new bookmark is received, the initial bookmarks are returned. This may happen when no work has been done using the session. Multivalued
Bookmarkinstances will be mapped to distinctBookmarkinstances. If no initial bookmarks have been provided, an empty set is returned.- Specified by:
lastBookmarksin interfaceReactiveSession- Overrides:
lastBookmarksin classAbstractReactiveSession<ReactiveTransaction>- Returns:
- the immutable set of last bookmarks.
-
close
public <T> org.reactivestreams.Publisher<T> close()Description copied from interface:ReactiveSessionSignal that you are done using this session. In the default driver usage, closing and accessing sessions is very low cost.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 queries 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 queries or transactions.
- Specified by:
closein interfaceReactiveSession- Type Parameters:
T- makes it easier to be chained.- Returns:
- an empty publisher that represents the reactive close.
-
run
Description copied from interface:ReactiveQueryRunnerRegister running of a query and return a publisher ofReactiveResult.Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of
ReactiveResulton success or an error otherwise.This method takes a set of parameters that will be injected into the query 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
Valueas 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,
ReactiveQueryRunner.run(String, Map)might be more helpful, it converts your map to aValuefor you.- Specified by:
runin interfaceReactiveQueryRunner- Parameters:
queryStr- text of a Neo4j queryparameters- input parameters, should be a map Value, seeValues.parameters(Object...).- Returns:
- a publisher of reactive result.
-
run
default org.reactivestreams.Publisher<ReactiveResult> run(String query, Map<String, Object> parameters) Description copied from interface:ReactiveQueryRunnerRegister running of a query and return a publisher ofReactiveResult.Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of
ReactiveResulton success or an error otherwise.This method takes a set of parameters that will be injected into the query 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
Mapof parameters. The values in the map must be values that can be converted to Neo4j types. SeeValues.parameters(Object...)for a list of allowed types.- Specified by:
runin interfaceReactiveQueryRunner- Parameters:
query- text of a Neo4j queryparameters- input data for the query- Returns:
- a publisher of reactive result.
-
run
Description copied from interface:ReactiveQueryRunnerRegister running of a query and return a publisher ofReactiveResult.Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of
ReactiveResulton success or an error otherwise.This method takes a set of parameters that will be injected into the query 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
Recordof parameters, which can be useful if you want to use the output of one query as input for another.- Specified by:
runin interfaceReactiveQueryRunner- Parameters:
query- text of a Neo4j queryparameters- input data for the query- Returns:
- a publisher of reactive result.
-
run
Description copied from interface:ReactiveQueryRunnerRegister running of a query and return a publisher ofReactiveResult.Invoking this method will result in a Bolt RUN message exchange with server and the returned publisher will either emit an instance of
ReactiveResulton success or an error otherwise.- Specified by:
runin interfaceReactiveQueryRunner- Parameters:
queryStr- text of a Neo4j query- Returns:
- a publisher of reactive result.
-