- All Superinterfaces:
AutoCloseable
Driver implementations are typically thread-safe, act as a template for session creation and host a connection pool. All configuration and authentication settings are held immutably by the Driver. Should different settings be required, a new Driver instance should be created.
A driver maintains a connection pool for each remote Neo4j server. Therefore, the most efficient way to make use of a Driver is to use the same instance across the application.
To construct a new Driver, use one of the
GraphDatabase.driver methods.
The URI passed to
this method determines the type of Driver created.
| URI Scheme | Driver |
|---|---|
bolt |
Direct driver: connects directly to the host and port specified in the URI. |
neo4j |
Routing driver: can automatically discover members of a Causal Cluster and route sessions based on AccessMode. |
-
Method Summary
Modifier and TypeMethodDescriptiondefault AsyncSessionDeprecated.default AsyncSessionasyncSession(SessionConfig sessionConfig) Deprecated.superseded bysession(Class, SessionConfig)voidclose()Close all the resources assigned to this driver, including open connections and IO threads.Close all the resources assigned to this driver, including open connections and IO threads.Deprecated.superseded byTypeSystem.getDefault()executableQuery(String query) Creates a newExecutableQueryinstance that executes a query in a managed transaction with automatic retries on retryable errors.Returns an instance ofBookmarkManagerused byExecutableQueryinstances by default.booleanReturn a flag to indicate whether encryption is used for this driver.booleanReturns true if the driver metrics reporting is enabled viaConfig.ConfigBuilder.withDriverMetrics(), otherwise false.metrics()Returns the driver metrics if metrics reporting is enabled viaConfig.ConfigBuilder.withDriverMetrics().default ReactiveSessionDeprecated.superseded bysession(Class)default ReactiveSessionreactiveSession(SessionConfig sessionConfig) Deprecated.superseded bysession(Class, SessionConfig)default RxSessionDeprecated.superseded bysession(Class)default RxSessionrxSession(SessionConfig sessionConfig) Deprecated.superseded bysession(Class, SessionConfig)default Sessionsession()Create a new general purposeSessionwith defaultsession configuration.default <T extends BaseSession>
TInstantiate a new session of supported type with defaultsession configuration.default <T extends BaseSession>
TInstantiate a new session of a supported type with the suppliedAuthToken.default <T extends BaseSession>
Tsession(Class<T> sessionClass, SessionConfig sessionConfig) Create a new session of supported type with a specifiedsession configuration.<T extends BaseSession>
Tsession(Class<T> sessionClass, SessionConfig sessionConfig, AuthToken sessionAuthToken) Instantiate a new session of a supported type with the suppliedsession configurationandAuthToken.default Sessionsession(SessionConfig sessionConfig) Instantiate a newSessionwith a specifiedsession configuration.booleanReturns true if the server or cluster the driver connects to supports multi-databases, otherwise false.Asynchronous check if the server or cluster the driver connects to supports multi-databases.booleanChecks if session auth is supported.booleanverifyAuthentication(AuthToken authToken) Verifies if the givenAuthTokenis valid.voidThis verifies if the driver can connect to a remote server or a cluster by establishing a network connection with the remote and possibly exchanging a few data before closing the connection.This verifies if the driver can connect to a remote server or cluster by establishing a network connection with the remote and possibly exchanging a few data before closing the connection.
-
Method Details
-
executableQuery
Creates a newExecutableQueryinstance that executes a query in a managed transaction with automatic retries on retryable errors.- Parameters:
query- query string- Returns:
- new executable query instance
- Since:
- 5.7
-
executableQueryBookmarkManager
BookmarkManager executableQueryBookmarkManager()Returns an instance ofBookmarkManagerused byExecutableQueryinstances by default.- Returns:
- bookmark manager, must not be
null - Since:
- 5.7
-
isEncrypted
boolean isEncrypted()Return a flag to indicate whether encryption is used for this driver.- Returns:
- true if the driver requires encryption, false otherwise
-
session
Create a new general purposeSessionwith defaultsession configuration.Alias to
session(SessionConfig)}.- Returns:
- a new
Sessionobject.
-
session
Instantiate a newSessionwith a specifiedsession configuration. UseSessionConfig.forDatabase(String)to obtain a general purpose session configuration for the specified database.- Parameters:
sessionConfig- specifies session configurations for this session.- Returns:
- a new
Sessionobject. - See Also:
-
session
Instantiate a new session of supported type with defaultsession configuration.Supported types are:
Session- synchronous sessionAsyncSession- asynchronous sessionReactiveSession- reactive session using Flow APIReactiveSession- reactive session using Reactive Streams APIRxSession- deprecated reactive session using Reactive Streams API, superseded byReactiveSession
Sample usage:
var session = driver.session(AsyncSession.class);- Type Parameters:
T- session type- Parameters:
sessionClass- session type class, must not be null- Returns:
- session instance
- Throws:
IllegalArgumentException- for unsupported session types- Since:
- 5.2
-
session
@Preview(name="AuthToken rotation and session auth support") default <T extends BaseSession> T session(Class<T> sessionClass, AuthToken sessionAuthToken) Instantiate a new session of a supported type with the suppliedAuthToken.This method allows creating a session with a different
AuthTokento the one used on the driver level. The minimum Bolt protocol version is 5.1. AnIllegalStateExceptionwill be emitted on session interaction for previous Bolt versions.Supported types are:
Session- synchronous sessionAsyncSession- asynchronous sessionReactiveSession- reactive session using Flow APIReactiveSession- reactive session using Reactive Streams APIRxSession- deprecated reactive session using Reactive Streams API, superseded byReactiveSession
Sample usage:
var session = driver.session(AsyncSession.class);- Type Parameters:
T- session type- Parameters:
sessionClass- session type class, must not be nullsessionAuthToken- a token, null will result in driver-level configuration being used- Returns:
- session instance
- Throws:
IllegalArgumentException- for unsupported session types- Since:
- 5.8
-
session
Create a new session of supported type with a specifiedsession configuration.Supported types are:
Session- synchronous sessionAsyncSession- asynchronous sessionReactiveSession- reactive session using Flow APIReactiveSession- reactive session using Reactive Streams APIRxSession- deprecated reactive session using Reactive Streams API, superseded byReactiveSession
Sample usage:
var session = driver.session(AsyncSession.class);- Type Parameters:
T- session type- Parameters:
sessionClass- session type class, must not be nullsessionConfig- session config, must not be null- Returns:
- session instance
- Throws:
IllegalArgumentException- for unsupported session types- Since:
- 5.2
-
session
@Preview(name="AuthToken rotation and session auth support") <T extends BaseSession> T session(Class<T> sessionClass, SessionConfig sessionConfig, AuthToken sessionAuthToken) Instantiate a new session of a supported type with the suppliedsession configurationandAuthToken.This method allows creating a session with a different
AuthTokento the one used on the driver level. The minimum Bolt protocol version is 5.1. AnIllegalStateExceptionwill be emitted on session interaction for previous Bolt versions.Supported types are:
Session- synchronous sessionAsyncSession- asynchronous sessionReactiveSession- reactive session using Flow APIReactiveSession- reactive session using Reactive Streams APIRxSession- deprecated reactive session using Reactive Streams API, superseded byReactiveSession
Sample usage:
var session = driver.session(AsyncSession.class);- Type Parameters:
T- session type- Parameters:
sessionClass- session type class, must not be nullsessionConfig- session config, must not be nullsessionAuthToken- a token, null will result in driver-level configuration being used- Returns:
- session instance
- Throws:
IllegalArgumentException- for unsupported session types- Since:
- 5.8
-
rxSession
Deprecated.superseded bysession(Class)Create a new general purposeRxSessionwith defaultsession configuration. TheRxSessionprovides a reactive way to run queries and process results.Alias to
rxSession(SessionConfig)}.- Returns:
- a new
RxSessionobject.
-
rxSession
Deprecated.superseded bysession(Class, SessionConfig)Create a newRxSessionwith a specifiedsession configuration. UseSessionConfig.forDatabase(String)to obtain a general purpose session configuration for the specified database. TheRxSessionprovides a reactive way to run queries and process results.- Parameters:
sessionConfig- used to customize the session.- Returns:
- a new
RxSessionobject.
-
reactiveSession
Deprecated.superseded bysession(Class)Create a new general purposeReactiveSessionwith defaultsession configuration. TheReactiveSessionprovides a reactive way to run queries and process results.Alias to
rxSession(SessionConfig)}.- Returns:
- a new
ReactiveSessionobject.
-
reactiveSession
Deprecated.superseded bysession(Class, SessionConfig)Create a newReactiveSessionwith a specifiedsession configuration. UseSessionConfig.forDatabase(String)to obtain a general purpose session configuration for the specified database. TheReactiveSessionprovides a reactive way to run queries and process results.- Parameters:
sessionConfig- used to customize the session.- Returns:
- a new
ReactiveSessionobject.
-
asyncSession
Deprecated.superseded bysession(Class)Create a new general purposeAsyncSessionwith defaultsession configuration. TheAsyncSessionprovides an asynchronous way to run queries and process results.Alias to
asyncSession(SessionConfig)}.- Returns:
- a new
AsyncSessionobject.
-
asyncSession
Deprecated.superseded bysession(Class, SessionConfig)Create a newAsyncSessionwith a specifiedsession configuration. UseSessionConfig.forDatabase(String)to obtain a general purpose session configuration for the specified database. TheAsyncSessionprovides an asynchronous way to run queries and process results.- Parameters:
sessionConfig- used to customize the session.- Returns:
- a new
AsyncSessionobject.
-
close
void close()Close all the resources assigned to this driver, including open connections and IO threads.This operation works the same way as
closeAsync()but blocks until all resources are closed.- Specified by:
closein interfaceAutoCloseable
-
closeAsync
CompletionStage<Void> closeAsync()Close all the resources assigned to this driver, including open connections and IO threads.This operation is asynchronous and returns a
CompletionStage. This stage is completed withnullwhen all resources are closed. It is completed exceptionally if termination fails.- Returns:
- a
completion stagethat represents the asynchronous close.
-
metrics
Metrics metrics()Returns the driver metrics if metrics reporting is enabled viaConfig.ConfigBuilder.withDriverMetrics(). Otherwise, aClientExceptionwill be thrown.- Returns:
- the driver metrics if enabled.
- Throws:
ClientException- if the driver metrics reporting is not enabled.
-
isMetricsEnabled
boolean isMetricsEnabled()Returns true if the driver metrics reporting is enabled viaConfig.ConfigBuilder.withDriverMetrics(), otherwise false.- Returns:
- true if the metrics reporting is enabled.
-
defaultTypeSystem
Deprecated.superseded byTypeSystem.getDefault()This will return the type system supported by the driver. The types supported on a particular server a session is connected against might not contain all of the types defined here.- Returns:
- type system used by this query runner for classifying values
-
verifyConnectivity
void verifyConnectivity()This verifies if the driver can connect to a remote server or a cluster by establishing a network connection with the remote and possibly exchanging a few data before closing the connection.It throws exception if fails to connect. Use the exception to further understand the cause of the connectivity problem. Note: Even if this method throws an exception, the driver still need to be closed via
close()to free up all resources. -
verifyConnectivityAsync
CompletionStage<Void> verifyConnectivityAsync()This verifies if the driver can connect to a remote server or cluster by establishing a network connection with the remote and possibly exchanging a few data before closing the connection.This operation is asynchronous and returns a
CompletionStage. This stage is completed withnullwhen the driver connects to the remote server or cluster successfully. It is completed exceptionally if the driver failed to connect the remote server or cluster. This exception can be used to further understand the cause of the connectivity problem. Note: Even if this method complete exceptionally, the driver still need to be closed viacloseAsync()to free up all resources.- Returns:
- a
completion stagethat represents the asynchronous verification.
-
verifyAuthentication
Verifies if the givenAuthTokenis valid.This check works on Bolt 5.1 version or above only.
- Parameters:
authToken- the token- Returns:
- the verification outcome
- Since:
- 5.8
-
supportsSessionAuth
boolean supportsSessionAuth()Checks if session auth is supported.- Returns:
- the check outcome
- Since:
- 5.8
- See Also:
-
supportsMultiDb
boolean supportsMultiDb()Returns true if the server or cluster the driver connects to supports multi-databases, otherwise false.- Returns:
- true if the server or cluster the driver connects to supports multi-databases, otherwise false.
-
supportsMultiDbAsync
CompletionStage<Boolean> supportsMultiDbAsync()Asynchronous check if the server or cluster the driver connects to supports multi-databases.- Returns:
- a
completion stagethat returns true if the server or cluster the driver connects to supports multi-databases, otherwise false.
-
session(Class)