public interface Driver extends 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. |
AsyncSession and RxSession since 2.0)| Modifier and Type | Method and Description |
|---|---|
AsyncSession |
asyncSession()
Create a new general purpose
AsyncSession with default session configuration. |
AsyncSession |
asyncSession(SessionConfig sessionConfig)
Create a new
AsyncSession with a specified session configuration. |
void |
close()
Close all the resources assigned to this driver, including open connections and IO threads.
|
CompletionStage<Void> |
closeAsync()
Close all the resources assigned to this driver, including open connections and IO threads.
|
TypeSystem |
defaultTypeSystem()
This will return the type system supported by the driver.
|
boolean |
isEncrypted()
Return a flag to indicate whether or not encryption is used for this driver.
|
boolean |
isMetricsEnabled()
Returns true if the driver metrics reporting is enabled via
Config.ConfigBuilder.withDriverMetrics(), otherwise false. |
Metrics |
metrics()
Returns the driver metrics if metrics reporting is enabled via
Config.ConfigBuilder.withDriverMetrics(). |
RxSession |
rxSession()
Create a new general purpose
RxSession with default session configuration. |
RxSession |
rxSession(SessionConfig sessionConfig)
Create a new
RxSession with a specified session configuration. |
Session |
session()
Create a new general purpose
Session with default session configuration. |
Session |
session(SessionConfig sessionConfig)
Create a new
Session with a specified session configuration. |
boolean |
supportsMultiDb()
Returns true if the server or cluster the driver connects to supports multi-databases, otherwise false.
|
CompletionStage<Boolean> |
supportsMultiDbAsync()
Asynchronous check if the server or cluster the driver connects to supports multi-databases.
|
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.
|
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.
|
boolean isEncrypted()
Session session()
Session with default session configuration.
Alias to session(SessionConfig)}.
Session object.Session session(SessionConfig sessionConfig)
Session with a specified session configuration.
Use SessionConfig.forDatabase(String) to obtain a general purpose session configuration for the specified database.sessionConfig - specifies session configurations for this session.Session object.SessionConfigRxSession rxSession()
RxSession with default session configuration.
The RxSession provides a reactive way to run queries and process results.
Alias to rxSession(SessionConfig)}.
RxSession object.RxSession rxSession(SessionConfig sessionConfig)
RxSession with a specified session configuration.
Use SessionConfig.forDatabase(String) to obtain a general purpose session configuration for the specified database.
The RxSession provides a reactive way to run queries and process results.sessionConfig - used to customize the session.RxSession object.AsyncSession asyncSession()
AsyncSession with default session configuration.
The AsyncSession provides an asynchronous way to run queries and process results.
Alias to asyncSession(SessionConfig)}.
AsyncSession object.AsyncSession asyncSession(SessionConfig sessionConfig)
AsyncSession with a specified session configuration.
Use SessionConfig.forDatabase(String) to obtain a general purpose session configuration for the specified database.
The AsyncSession provides an asynchronous way to run queries and process results.sessionConfig - used to customize the session.AsyncSession object.void close()
This operation works the same way as closeAsync() but blocks until all resources are closed.
Please note that this method is intended for graceful shutdown only and expects that all driver interactions have either been finished or no longer awaited for. Pending driver API calls may not be completed after this method is invoked.
close in interface AutoCloseableCompletionStage<Void> closeAsync()
This operation is asynchronous and returns a CompletionStage. This stage is completed with
null when all resources are closed. It is completed exceptionally if termination fails.
Please note that this method is intended for graceful shutdown only and expects that all driver interactions have either been finished or no longer awaited for. Pending driver API calls may not be completed after this method is invoked.
completion stage that represents the asynchronous close.Metrics metrics()
Config.ConfigBuilder.withDriverMetrics().
Otherwise, a ClientException will be thrown.ClientException - if the driver metrics reporting is not enabled.boolean isMetricsEnabled()
Config.ConfigBuilder.withDriverMetrics(), otherwise false.@Experimental TypeSystem defaultTypeSystem()
void verifyConnectivity()
close() to free up all resources.CompletionStage<Void> verifyConnectivityAsync()
CompletionStage. This stage is completed with
null when 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 via closeAsync() to free up all resources.completion stage that represents the asynchronous verification.boolean supportsMultiDb()
CompletionStage<Boolean> supportsMultiDbAsync()
completion stage that returns true if the server or cluster
the driver connects to supports multi-databases, otherwise false.