- All Implemented Interfaces:
AsyncQueryRunner
,AsyncSession
,BaseSession
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionBegin a new unmanaged transaction.Begin a new unmanaged transaction with the specifiedconfiguration
.Signal that you are done using this session.<T> CompletionStage<T>
executeReadAsync
(AsyncTransactionCallback<CompletionStage<T>> callback, TransactionConfig config) Execute a unit of work as a single, managed transaction withread
access mode and retry behaviour.<T> CompletionStage<T>
executeWriteAsync
(AsyncTransactionCallback<CompletionStage<T>> callback, TransactionConfig config) Execute a unit of work as a single, managed transaction withwrite
access mode and retry behaviour.Deprecated.Return a set of last bookmarks.<T> CompletionStage<T>
Deprecated.<T> CompletionStage<T>
readTransactionAsync
(AsyncTransactionWork<CompletionStage<T>> work, TransactionConfig config) Deprecated.Run a query asynchronously in an auto-commit transaction with the specifiedconfiguration
and return aCompletionStage
with a result cursor.runAsync
(String query, TransactionConfig config) Run a query asynchronously in an auto-commit transaction with the specifiedconfiguration
and return aCompletionStage
with a result cursor.Run a query asynchronously and return aCompletionStage
with a result cursor.runAsync
(Query query, TransactionConfig config) Run a query asynchronously in an auto-commit transaction with the specifiedconfiguration
and return aCompletionStage
with a result cursor.<T> CompletionStage<T>
Deprecated.<T> CompletionStage<T>
writeTransactionAsync
(AsyncTransactionWork<CompletionStage<T>> work, TransactionConfig config) Deprecated.Methods inherited from class org.neo4j.driver.internal.async.AsyncAbstractQueryRunner
runAsync, runAsync, runAsync, runAsync
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.neo4j.driver.async.AsyncQueryRunner
runAsync, runAsync, runAsync, runAsync
Methods inherited from interface org.neo4j.driver.async.AsyncSession
executeReadAsync, executeWriteAsync
-
Constructor Details
-
InternalAsyncSession
-
-
Method Details
-
runAsync
Description copied from interface:AsyncQueryRunner
Run a query asynchronously and return aCompletionStage
with a result cursor.Example
Query query = new Query( "MATCH (n) WHERE n.name = $myNameParam RETURN n.age" ); CompletionStage<ResultCursor> cursorStage = session.runAsync(query);
CompletionStage
. See class javadoc for more information.- Specified by:
runAsync
in interfaceAsyncQueryRunner
- Parameters:
query
- a Neo4j query- Returns:
- new
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.
-
runAsync
Description copied from interface:AsyncSession
Run a query asynchronously in an auto-commit transaction with the specifiedconfiguration
and return aCompletionStage
with a result cursor.It is not allowed to chain blocking operations on the returned
CompletionStage
. See class javadoc inAsyncQueryRunner
for more information.- Specified by:
runAsync
in interfaceAsyncSession
- Parameters:
query
- text of a Neo4j query.config
- configuration for the new transaction.- Returns:
- new
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.
-
runAsync
public CompletionStage<ResultCursor> runAsync(String query, Map<String, Object> parameters, TransactionConfig config) Description copied from interface:AsyncSession
Run a query asynchronously in an auto-commit transaction with the specifiedconfiguration
and return aCompletionStage
with a result cursor.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 runAsync takes a
Map
of 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.Example
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<String, Object>(); parameters.put("myNameParam", "Bob"); CompletionStage<ResultCursor> cursorStage = session.runAsync( "MATCH (n) WHERE n.name = $myNameParam RETURN (n)", parameters, config);
CompletionStage
. See class javadoc inAsyncQueryRunner
for more information.- Specified by:
runAsync
in interfaceAsyncSession
- Parameters:
query
- text of a Neo4j query.parameters
- input data for the query.config
- configuration for the new transaction.- Returns:
- new
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.
-
runAsync
Description copied from interface:AsyncSession
Run a query asynchronously in an auto-commit transaction with the specifiedconfiguration
and return aCompletionStage
with a result cursor.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" ); CompletionStage<ResultCursor> cursorStage = session.runAsync(query, config);
CompletionStage
. See class javadoc inAsyncQueryRunner
for more information.- Specified by:
runAsync
in interfaceAsyncSession
- Parameters:
query
- a Neo4j query.config
- configuration for the new transaction.- Returns:
- new
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.
-
closeAsync
Description copied from interface:AsyncSession
Signal that you are done using this session. In the default driver usage, closing and accessing sessions is very low cost.This operation is asynchronous and returns a
CompletionStage
. Stage 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:
closeAsync
in interfaceAsyncSession
- Returns:
- a
completion stage
that represents the asynchronous close.
-
beginTransactionAsync
Description copied from interface:AsyncSession
Begin a new unmanaged transaction. At most one transaction may exist in a session at any point in time. To maintain multiple concurrent transactions, use multiple concurrent sessions.This operation is asynchronous and returns a
CompletionStage
. This stage is completed with a newTransaction
object when begin operation is successful. It is completed exceptionally if transaction can't be started.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
CompletableFuture.get()
on the returned stage. Consider using asynchronous calls throughout the chain or offloading blocking operation to a differentExecutor
. This can be done using methods with "Async" suffix likeCompletionStage.thenApplyAsync(Function)
orCompletionStage.thenApplyAsync(Function, Executor)
.- Specified by:
beginTransactionAsync
in interfaceAsyncSession
- Returns:
- a
completion stage
that represents the asynchronous begin of a transaction.
-
beginTransactionAsync
Description copied from interface:AsyncSession
Begin 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.This operation is asynchronous and returns a
CompletionStage
. This stage is completed with a newAsyncTransaction
object when begin operation is successful. It is completed exceptionally if transaction can't be started.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
CompletableFuture.get()
on the returned stage. Consider using asynchronous calls throughout the chain or offloading blocking operation to a differentExecutor
. This can be done using methods with "Async" suffix likeCompletionStage.thenApplyAsync(Function)
orCompletionStage.thenApplyAsync(Function, Executor)
.- Specified by:
beginTransactionAsync
in interfaceAsyncSession
- Parameters:
config
- configuration for the new transaction.- Returns:
- a
completion stage
that represents the asynchronous begin of a transaction.
-
readTransactionAsync
@Deprecated public <T> CompletionStage<T> readTransactionAsync(AsyncTransactionWork<CompletionStage<T>> work) Deprecated.Description copied from interface:AsyncSession
Execute given unit of asynchronous work in aread
asynchronous transaction.Transaction will automatically be committed unless given unit of work fails or
async transaction commit
fails. It will also not be committed if explicitly rolled back viaAsyncTransaction.rollbackAsync()
.Returned stage and given
AsyncTransactionWork
can be 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 likeCompletableFuture.get()
on the returned stage and do not use them inside theAsyncTransactionWork
. Consider using asynchronous calls throughout the chain or offloading blocking operation to a differentExecutor
. This can be done using methods with "Async" suffix likeCompletionStage.thenApplyAsync(Function)
orCompletionStage.thenApplyAsync(Function, Executor)
.- Specified by:
readTransactionAsync
in interfaceAsyncSession
- Type Parameters:
T
- the return type of the given unit of work.- Parameters:
work
- theAsyncTransactionWork
to be applied to a new read transaction. Operation executed by the given work must be asynchronous.- Returns:
- a
completion stage
completed with the same result as returned by the given unit of work. Stage can be completed exceptionally if given work or commit fails.
-
readTransactionAsync
@Deprecated public <T> CompletionStage<T> readTransactionAsync(AsyncTransactionWork<CompletionStage<T>> work, TransactionConfig config) Deprecated.Description copied from interface:AsyncSession
Execute given unit of asynchronous work in aread
asynchronous transaction with the specifiedconfiguration
.Transaction will automatically be committed unless given unit of work fails or
async transaction commit
fails. It will also not be committed if explicitly rolled back viaAsyncTransaction.rollbackAsync()
.Returned stage and given
AsyncTransactionWork
can be 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 likeCompletableFuture.get()
on the returned stage and do not use them inside theAsyncTransactionWork
. Consider using asynchronous calls throughout the chain or offloading blocking operation to a differentExecutor
. This can be done using methods with "Async" suffix likeCompletionStage.thenApplyAsync(Function)
orCompletionStage.thenApplyAsync(Function, Executor)
.- Specified by:
readTransactionAsync
in interfaceAsyncSession
- Type Parameters:
T
- the return type of the given unit of work.- Parameters:
work
- theAsyncTransactionWork
to be applied to a new read transaction. Operation executed by the given work must be asynchronous.config
- configuration for all transactions started to execute the unit of work.- Returns:
- a
completion stage
completed with the same result as returned by the given unit of work. Stage can be completed exceptionally if given work or commit fails.
-
executeReadAsync
public <T> CompletionStage<T> executeReadAsync(AsyncTransactionCallback<CompletionStage<T>> callback, TransactionConfig config) Description copied from interface:AsyncSession
Execute a unit of work as a single, managed transaction withread
access 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
Result
object 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.- Specified by:
executeReadAsync
in interfaceAsyncSession
- 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 completion stage that completes successfully with the result of the unit of work on success or completes exceptionally otherwise.
-
writeTransactionAsync
@Deprecated public <T> CompletionStage<T> writeTransactionAsync(AsyncTransactionWork<CompletionStage<T>> work) Deprecated.Description copied from interface:AsyncSession
Execute given unit of asynchronous work in awrite
asynchronous transaction.Transaction will automatically be committed unless given unit of work fails or
async transaction commit
fails. It will also not be committed if explicitly rolled back viaAsyncTransaction.rollbackAsync()
.Returned stage and given
AsyncTransactionWork
can be 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 likeCompletableFuture.get()
on the returned stage and do not use them inside theAsyncTransactionWork
. Consider using asynchronous calls throughout the chain or offloading blocking operation to a differentExecutor
. This can be done using methods with "Async" suffix likeCompletionStage.thenApplyAsync(Function)
orCompletionStage.thenApplyAsync(Function, Executor)
.- Specified by:
writeTransactionAsync
in interfaceAsyncSession
- Type Parameters:
T
- the return type of the given unit of work.- Parameters:
work
- theAsyncTransactionWork
to be applied to a new write transaction. Operation executed by the given work must be asynchronous.- Returns:
- a
completion stage
completed with the same result as returned by the given unit of work. Stage can be completed exceptionally if given work or commit fails.
-
writeTransactionAsync
@Deprecated public <T> CompletionStage<T> writeTransactionAsync(AsyncTransactionWork<CompletionStage<T>> work, TransactionConfig config) Deprecated.Description copied from interface:AsyncSession
Execute given unit of asynchronous work in awrite
asynchronous transaction with the specifiedconfiguration
.Transaction will automatically be committed unless given unit of work fails or
async transaction commit
fails. It will also not be committed if explicitly rolled back viaAsyncTransaction.rollbackAsync()
.Returned stage and given
AsyncTransactionWork
can be 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 likeCompletableFuture.get()
on the returned stage and do not use them inside theAsyncTransactionWork
. Consider using asynchronous calls throughout the chain or offloading blocking operation to a differentExecutor
. This can be done using methods with "Async" suffix likeCompletionStage.thenApplyAsync(Function)
orCompletionStage.thenApplyAsync(Function, Executor)
.- Specified by:
writeTransactionAsync
in interfaceAsyncSession
- Type Parameters:
T
- the return type of the given unit of work.- Parameters:
work
- theAsyncTransactionWork
to be applied to a new write transaction. Operation executed by the given work must be asynchronous.config
- configuration for all transactions started to execute the unit of work.- Returns:
- a
completion stage
completed with the same result as returned by the given unit of work. Stage can be completed exceptionally if given work or commit fails.
-
executeWriteAsync
public <T> CompletionStage<T> executeWriteAsync(AsyncTransactionCallback<CompletionStage<T>> callback, TransactionConfig config) Description copied from interface:AsyncSession
Execute a unit of work as a single, managed transaction withwrite
access 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
Result
object 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.- Specified by:
executeWriteAsync
in interfaceAsyncSession
- 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 completion stage that completes successfully with the result of the unit of work on success or completes exceptionally otherwise.
-
lastBookmark
Deprecated.Description copied from interface:AsyncSession
Return the last bookmark of this session.When no new bookmark is received, the initial bookmarks are returned as a composite
Bookmark
containing all initial bookmarks. This may happen when no work has been done using the session. If no initial bookmarks have been provided, an emptyBookmark
is returned.- Specified by:
lastBookmark
in interfaceAsyncSession
- Returns:
- the last bookmark.
-
lastBookmarks
Description copied from interface:AsyncSession
Return 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
Bookmark
instances will be mapped to distinctBookmark
instances. If no initial bookmarks have been provided, an empty set is returned.- Specified by:
lastBookmarks
in interfaceAsyncSession
- Returns:
- the immutable set of last bookmarks.
-