@@ -224,16 +224,40 @@ public Builder withDefaultAccessMode(AccessMode mode) {
224
224
}
225
225
226
226
/**
227
- * Set the database that the newly created session is going to connect to .
227
+ * Sets target database name for queries executed within session .
228
228
* <p>
229
- * For connecting to servers that support multi-databases,
230
- * it is highly recommended to always set the database explicitly in the {@link SessionConfig} for each session.
231
- * If the database name is not set, then session defaults to connecting to the default database configured in server configuration.
229
+ * This option has no explicit value by default, as such it is recommended to set a value if the target database
230
+ * is known in advance. This has the benefit of ensuring a consistent target database name throughout the
231
+ * session in a straightforward way and potentially simplifies driver logic, which reduces network communication
232
+ * and might result in better performance.
232
233
* <p>
233
- * For servers that do not support multi-databases, leave this database value unset. The only database will be used instead.
234
+ * Cypher clauses such as USE are not a replacement for this option as Cypher is handled by the server and not
235
+ * the driver.
236
+ * <p>
237
+ * When no explicit name is set, the driver behavior depends on the connection URI scheme supplied to the driver
238
+ * on instantiation and Bolt protocol version.
239
+ * <p>
240
+ * Specifically, the following applies:
241
+ * <ul>
242
+ * <li><b>bolt schemes</b> - queries are dispatched to the server for execution without explicit database name
243
+ * supplied, meaning that the target database name for query execution is determined by the server. It is
244
+ * important to note that the target database may change (even within the same session), for instance if the
245
+ * user's home database is changed on the server.</li>
246
+ * <li><b>neo4j schemes</b> - providing that Bolt protocol version 4.4, which was introduced with Neo4j server
247
+ * 4.4, or above is available, the driver fetches the user's home database name from the server on first query
248
+ * execution within the session and uses the fetched database name explicitly for all queries executed within
249
+ * the session. This ensures that the database name remains consistent within the given session. For instance,
250
+ * if the user's home database name is 'movies' and the server supplies it to the driver upon database name
251
+ * fetching for the session, all queries within that session are executed with the explicit database name
252
+ * 'movies' supplied. Any change to the user’s home database is reflected only in sessions created after such
253
+ * change takes effect. This behavior requires additional network communication. In clustered environments, it
254
+ * is strongly recommended to avoid a single point of failure. For instance, by ensuring that the connection URI
255
+ * resolves to multiple endpoints. For older Bolt protocol versions the behavior is the same as described for
256
+ * the <b>bolt</b> schemes above.</li>
257
+ * </ul>
234
258
*
235
- * @param database the database the session going to connect to. Provided value should not be {@code null}.
236
- * @return this builder.
259
+ * @param database the target database name, must not be {@code null}
260
+ * @return this builder
237
261
*/
238
262
public Builder withDatabase (String database ) {
239
263
requireNonNull (database , "Database name should not be null." );
0 commit comments