java.lang.Object
io.opentelemetry.instrumentation.jdbc.internal.parser.ParseContext

public final class ParseContext extends Object
Mutable context for building up connection info during JDBC URL parsing.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

  • Method Details

    • of

      public static ParseContext of(String type, @Nullable Properties props)
      Create a context with the JDBC type and optional properties.
    • type

      public String type()
      The JDBC type (e.g., "mysql", "postgresql").
    • system

      @Nullable public String system()
      The database system identifier (stable/new value, e.g., "postgresql", "h2database").
    • system

      public void system(String system)
      Set the database system identifier (stable/new value). For systems where old and new values differ, also call oldSemconvSystem(String).
    • oldSemconvSystem

      @Deprecated @Nullable public String oldSemconvSystem()
      Deprecated.
      The old semconv database system identifier (e.g., "mssql", "h2").
    • oldSemconvSystem

      @Deprecated public void oldSemconvSystem(@Nullable String oldSemconvSystem)
      Deprecated.
      Set the old semconv database system identifier (only required when different from system).
    • subtype

      @Nullable public String subtype()
      The optional subtype (e.g., "tcp", "aurora").
    • subtype

      public void subtype(@Nullable String subtype)
      Set the subtype value.
    • host

      @Nullable public String host()
      The host value accumulated so far.
    • host

      public void host(@Nullable String host)
      Set the host value.
    • port

      @Nullable public Integer port()
      The port value accumulated so far.
    • port

      public void port(@Nullable Integer port)
      Set the port value.
    • user

      @Deprecated @Nullable public String user()
      Deprecated.
      The user value accumulated so far.
    • user

      @Deprecated public void user(@Nullable String user)
      Deprecated.
      Set the user value.
    • databaseName

      @Nullable public String databaseName()
      The database name value accumulated so far.
    • databaseName

      public void databaseName(@Nullable String databaseName)
      Set the database name value.
    • namespace

      @Nullable public String namespace()
      The namespace value accumulated so far.
    • namespace

      public void namespace(@Nullable String namespace)
      Set the namespace value.
    • dbName

      @Deprecated @Nullable public String dbName()
      Deprecated.
      Override for the dbName field in the resulting DbInfo. When set, this value takes precedence over the databaseName-derived value. Used by SQL Server parsers to preserve old behavior where dbName is the instance name when both instance and database are present.
    • dbName

      @Deprecated public void dbName(@Nullable String dbName)
      Deprecated.
    • props

      @Nullable public Properties props()
      DataSource connection properties.
    • applyCommonParams

      public void applyCommonParams(String jdbcUrl, String startDelimiter, String splitSeparator)
      Apply common parameters from URL parameters to the context.

      Extracts the same properties as applyDataSourceProperties() but using lowercase keys (servername, portnumber, databasename, user) as URL params are typically lowercased.

      Parameters:
      jdbcUrl - the JDBC URL containing parameters
      startDelimiter - the delimiter marking the start of parameters (";" or "?")
      splitSeparator - the separator between individual parameters (";" or "&")
    • applyDataSourceProperties

      public void applyDataSourceProperties()
      Apply common DataSource properties to this context. These properties are defined by the JDBC specification (JSR 221, Section 9.4.1).

      Extracts serverName, portNumber, databaseName, and user from the properties if present.

    • applyUserProperty

      public void applyUserProperty()
      Apply only the user property from DataSource properties. Use this for drivers that don't support the standard serverName/portNumber/databaseName DataSource properties (e.g., SAP HANA, H2, HSQLDB, Derby).

      TODO: Currently delegates to applyDataSourceProperties() to avoid a behavioral change in this refactoring. In the future, this will be changed to only apply the user property.

    • parseUrl

      public void parseUrl(String jdbcUrl)
      Parse a URL-style JDBC connection string that uses semicolons for properties. Updates this context with extracted values (user, host, port, path).

      If the URL contains a database path, it is applied to this context and overrides any previously set database name.

      Parameters:
      jdbcUrl - the JDBC URL to parse
    • toDbInfo

      public DbInfo toDbInfo()
      Build the final DbInfo from the accumulated context values.
      Returns:
      the complete DbInfo