Class ConfigRegistry

java.lang.Object
org.jdbi.v3.core.config.ConfigRegistry

public final class ConfigRegistry extends Object
A registry of JdbiConfig instances by type.

A registry returned by createCopy() materializes each config object lazily: the first get(Class) for a config type copies the source registry's instance at that moment. Once materialized, the copy is private to this registry, so changes to it do not modify the source and vice-versa. If the source does not hold the config type yet, the first access creates a default instance in the source and then copies it. Configuration is expected to be finalized before Jdbi is used; a source registry that is reconfigured between createCopy() and the copy's first access of the changed config type is observed with the new value. Call setEagerCopies(boolean) to restore copy-at-creation timing instead.

See Also:
  • Constructor Details

    • ConfigRegistry

      public ConfigRegistry()
      Creates a new config registry.
  • Method Details

    • get

      public <C extends JdbiConfig<C>> C get(Class<C> configClass)
      Returns this registry's instance of the given config class. Creates an instance on-demand if this registry does not have one of the given type yet, copying the source registry's instance if this registry is a copy.
      Type Parameters:
      C - the config class type.
      Parameters:
      configClass - the config class type.
      Returns:
      the given config class instance that belongs to this registry.
    • createCopy

      public ConfigRegistry createCopy()
      Returns a copy of this config registry.
      Returns:
      a copy of this config registry
      See Also:
    • setEagerCopies

      @Alpha public void setEagerCopies(boolean eagerCopies)
      Controls when createCopy() copies the config objects. The default (false) materializes each config object on its first access in the copy. Set true to copy every config object at createCopy() time, the behavior of Jdbi releases before 3.55.0. Use this only if code depends on the exact moment a copy is taken; it restores the old allocation cost on every copy.

      Copies inherit the mode this registry has when createCopy() runs. Set the flag on the Jdbi registry before handles or extensions are created.

      Parameters:
      eagerCopies - true to copy config objects at createCopy() time
    • isEagerCopies

      @Alpha public boolean isEagerCopies()
      Returns true if createCopy() copies all config objects immediately.
      Returns:
      true if createCopy() copies all config objects immediately