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() . |
default ReactiveSession |
reactiveSession()
Create a new general purpose
ReactiveSession with default session configuration . |
ReactiveSession |
reactiveSession(SessionConfig sessionConfig)
Create a new
ReactiveSession with a specified session configuration . |
default RxSession |
rxSession()
Deprecated.
superseded by
reactiveSession() . |
RxSession |
rxSession(SessionConfig sessionConfig)
Deprecated.
superseded by
reactiveSession(SessionConfig) . |
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.SessionConfig
@Deprecated default RxSession rxSession()
reactiveSession()
.RxSession
with default session configuration
. The RxSession
provides a reactive way to
run queries and process results.
Alias to rxSession(SessionConfig)
}.
RxSession
object.@Deprecated RxSession rxSession(SessionConfig sessionConfig)
reactiveSession(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.default ReactiveSession reactiveSession()
ReactiveSession
with default session configuration
. The ReactiveSession
provides a
reactive way to run queries and process results.
Alias to rxSession(SessionConfig)
}.
ReactiveSession
object.ReactiveSession reactiveSession(SessionConfig sessionConfig)
ReactiveSession
with a specified session configuration
. Use SessionConfig.forDatabase(String)
to
obtain a general purpose session configuration for the specified database. The ReactiveSession
provides a reactive way to run queries and process
results.sessionConfig
- used to customize the session.ReactiveSession
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.
close
in interface AutoCloseable
CompletionStage<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.
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.