Class SessionConfig.Builder

java.lang.Object
org.neo4j.driver.SessionConfig.Builder
Enclosing class:
SessionConfig

public static final class SessionConfig.Builder extends Object
Builder used to configure SessionConfig which will be used to create a session.
  • Method Details

    • withBookmarks

      public SessionConfig.Builder withBookmarks(Bookmark... bookmarks)
      Set the initial bookmarks to be used in a session.

      First transaction in a session will ensure that server hosting is at least as up-to-date as the latest transaction referenced by the supplied bookmarks. The bookmarks can be obtained via Session.lastBookmarks(), AsyncSession.lastBookmarks(), and/or ReactiveSession.lastBookmarks().

      Parameters:
      bookmarks - a series of initial bookmarks. Both null value and empty array are permitted, and indicate that the bookmarks do not exist or are unknown.
      Returns:
      this builder.
    • withBookmarks

      public SessionConfig.Builder withBookmarks(Iterable<Bookmark> bookmarks)
      Set the initial bookmarks to be used in a session. First transaction in a session will ensure that server hosting is at least as up-to-date as the latest transaction referenced by the supplied bookmarks. The bookmarks can be obtained via Session.lastBookmarks(), AsyncSession.lastBookmarks(), and/or ReactiveSession.lastBookmarks().

      Multiple immutable sets of bookmarks may be joined in the following way:

       
       Set<Bookmark> bookmarks = new HashSet<>();
       bookmarks.addAll( session1.lastBookmarks() );
       bookmarks.addAll( session2.lastBookmarks() );
       bookmarks.addAll( session3.lastBookmarks() );
       
       
      Parameters:
      bookmarks - initial references to some previous transactions. Both null value and empty iterable are permitted, and indicate that the bookmarks do not exist or are unknown.
      Returns:
      this builder
    • withDefaultAccessMode

      public SessionConfig.Builder withDefaultAccessMode(AccessMode mode)
      Set the type of access required by units of work in this session, e.g. read access or write access. This access mode is used to route transactions in the session to the server who has the right to carry out the specified operations.
      Parameters:
      mode - access mode.
      Returns:
      this builder.
    • withDatabase

      public SessionConfig.Builder withDatabase(String database)
      Sets target database name for queries executed within session.

      This option has no explicit value by default, as such it is recommended to set a value if the target database is known in advance. This has the benefit of ensuring a consistent target database name throughout the session in a straightforward way and potentially simplifies driver logic, which reduces network communication and might result in better performance.

      Cypher clauses such as USE are not a replacement for this option as Cypher is handled by the server and not the driver.

      When no explicit name is set, the driver behavior depends on the connection URI scheme supplied to the driver on instantiation and Bolt protocol version.

      Specifically, the following applies:

      • bolt schemes - queries are dispatched to the server for execution without explicit database name supplied, meaning that the target database name for query execution is determined by the server. It is important to note that the target database may change (even within the same session), for instance if the user's home database is changed on the server.
      • neo4j schemes - providing that Bolt protocol version 4.4, which was introduced with Neo4j server 4.4, or above is available, the driver fetches the user's home database name from the server on first query execution within the session and uses the fetched database name explicitly for all queries executed within the session. This ensures that the database name remains consistent within the given session. For instance, if the user's home database name is 'movies' and the server supplies it to the driver upon database name fetching for the session, all queries within that session are executed with the explicit database name 'movies' supplied. Any change to the user’s home database is reflected only in sessions created after such change takes effect. This behavior requires additional network communication. In clustered environments, it is strongly recommended to avoid a single point of failure. For instance, by ensuring that the connection URI resolves to multiple endpoints. For older Bolt protocol versions the behavior is the same as described for the bolt schemes above.
      Parameters:
      database - the target database name, must not be null
      Returns:
      this builder
    • withFetchSize

      public SessionConfig.Builder withFetchSize(long size)
      Specify how many records to fetch in each batch for this session. This config will overrides the default value set on Config.fetchSize(). This config is only valid when the driver is used with servers that support Bolt V4 (Server version 4.0 and later).

      Bolt V4 enables pulling records in batches to allow client to take control of data population and apply back pressure to server. This config specifies the default fetch size for all query runs using Session and AsyncSession. By default, the value is set to 1000. Use -1 to disables back pressure and config client to pull all records at once after each run.

      This config only applies to run result obtained via Session and AsyncSession. As with the reactive sessions the batch size is managed by the subscription requests instead.

      Parameters:
      size - the default record fetch size when pulling records in batches using Bolt V4.
      Returns:
      this builder
    • withImpersonatedUser

      public SessionConfig.Builder withImpersonatedUser(String impersonatedUser)
      Set the impersonated user that the newly created session is going to use for query execution.

      The principal provided to the driver on creation must have the necessary permissions to impersonate and run queries as the impersonated user.

      When withDatabase(String) is not used, the driver will discover the default database name of the impersonated user on first session usage. From that moment, the discovered database name will be used as the default database name for the whole lifetime of the new session.

      Compatible with 4.4+ only. You MUST have all servers running 4.4 version or above and communicating over Bolt 4.4 or above.

      Parameters:
      impersonatedUser - the user to impersonate. Provided value should not be null.
      Returns:
      this builder
    • withBookmarkManager

      public SessionConfig.Builder withBookmarkManager(BookmarkManager bookmarkManager)
      Sets a BookmarkManager implementation for the session to use.

      By default, bookmark manager is effectively disabled.

      Parameters:
      bookmarkManager - bookmark manager implementation. Providing null effectively disables bookmark manager.
      Returns:
      this builder.
    • withNotificationConfig

      public SessionConfig.Builder withNotificationConfig(NotificationConfig notificationConfig)
      Sets notification config.

      Any configuration other than the NotificationConfig.defaultConfig() requires a minimum Bolt protocol version 5.2. Otherwise, an UnsupportedFeatureException will be emitted when the driver comes across a Bolt connection that does not support this feature. For instance, when running a query.

      Parameters:
      notificationConfig - the notification config
      Returns:
      this builder
      Since:
      5.7
    • withMinimumNotificationSeverity

      @Preview(name="GQL-status object") public SessionConfig.Builder withMinimumNotificationSeverity(NotificationSeverity minimumNotificationSeverity)
      Sets a minimum severity for notifications produced by the server.
      Parameters:
      minimumNotificationSeverity - the minimum notification severity
      Returns:
      this builder
      Since:
      5.22.0
    • withDisabledNotificationClassifications

      @Preview(name="GQL-status object") public SessionConfig.Builder withDisabledNotificationClassifications(Set<NotificationClassification> disabledNotificationClassifications)
      Sets a set of disabled classifications for notifications produced by the server.
      Parameters:
      disabledNotificationClassifications - the set of disabled notification classifications
      Returns:
      this builder
      Since:
      5.22.0
    • build

      public SessionConfig build()
      Builds the SessionConfig.
      Returns:
      the config