Class ConfigRegistry
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a copy of this config registry.<C extends JdbiConfig<C>>
CReturns this registry's instance of the given config class.booleanReturns true ifcreateCopy()copies all config objects immediately.voidsetEagerCopies(boolean eagerCopies) Controls whencreateCopy()copies the config objects.
-
Constructor Details
-
ConfigRegistry
public ConfigRegistry()Creates a new config registry.
-
-
Method Details
-
get
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
Returns a copy of this config registry.- Returns:
- a copy of this config registry
- See Also:
-
setEagerCopies
Controls whencreateCopy()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 atcreateCopy()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 theJdbiregistry before handles or extensions are created.- Parameters:
eagerCopies- true to copy config objects atcreateCopy()time
-
isEagerCopies
Returns true ifcreateCopy()copies all config objects immediately.- Returns:
- true if
createCopy()copies all config objects immediately
-