Package org.jdbi.v3.core.extension
Class Extensions
- java.lang.Object
-
- org.jdbi.v3.core.extension.Extensions
-
- All Implemented Interfaces:
JdbiConfig<Extensions>
public class Extensions extends java.lang.Object implements JdbiConfig<Extensions>
Configuration class for definingJdbiextensions viaExtensionFactoryinstances.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowProxyprivate java.util.List<ConfigCustomizerFactory>configCustomizerFactoriesprivate java.util.List<ExtensionFactoryDelegate>extensionFactoriesprivate java.util.List<ExtensionHandlerCustomizer>extensionHandlerCustomizersprivate java.util.List<ExtensionHandlerFactory>extensionHandlerFactoriesprivate java.util.Map<java.lang.Class<?>,ExtensionMetadata>extensionMetadataCacheprivate ConfigRegistryregistry
-
Constructor Summary
Constructors Modifier Constructor Description Extensions()Creates a new instance.privateExtensions(Extensions that)Create an extension configuration by cloning another.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExtensionscreateCopy()Returns a copy of this configuration object.private java.util.function.Function<java.lang.Class<?>,ExtensionMetadata>createMetadata(ExtensionFactory extensionFactory)java.util.Optional<ExtensionFactory>findFactory(java.lang.Class<? extends ExtensionFactory> factoryType)Find the registered factory of the given type.private java.util.Optional<ExtensionFactory>findFactoryFor(java.lang.Class<?> extensionType)<E> java.util.Optional<E>findFor(java.lang.Class<E> extensionType, HandleSupplier handleSupplier)Create an extension instance if a factory accepts the extension type.ExtensionMetadatafindMetadata(java.lang.Class<?> extensionType, ExtensionFactory extensionFactory)Retrieves all extension metadata for a specific extension type.booleanhasExtensionFor(java.lang.Class<?> extensionType)Returns true if an extension is registered for the given extension type.private ExtensionsinternalRegisterHandlerFactory(ExtensionHandlerFactory extensionHandlerFactory)booleanisAllowProxy()Returns whether Proxy classes are allowed to be used.voidonCreateProxy()Throw if proxy creation is disallowed.Extensionsregister(ExtensionFactory factory)Register aExtensionFactoryinstance with the extension framework.ExtensionsregisterConfigCustomizerFactory(ConfigCustomizerFactory configCustomizerFactory)Registers a globalConfigCustomizerFactoryinstance.ExtensionsregisterHandlerCustomizer(ExtensionHandlerCustomizer extensionHandlerCustomizer)Registers a globalExtensionHandlerCustomizerinstance.ExtensionsregisterHandlerFactory(ExtensionHandlerFactory extensionHandlerFactory)Registers a globalExtensionHandlerFactoryinstance.ExtensionssetAllowProxy(boolean allowProxy)Allow usingProxyto implement extensions.voidsetRegistry(ConfigRegistry registry)The registry will inject itself into the configuration object.
-
-
-
Field Detail
-
extensionFactories
private final java.util.List<ExtensionFactoryDelegate> extensionFactories
-
extensionMetadataCache
private final java.util.Map<java.lang.Class<?>,ExtensionMetadata> extensionMetadataCache
-
extensionHandlerCustomizers
private final java.util.List<ExtensionHandlerCustomizer> extensionHandlerCustomizers
-
extensionHandlerFactories
private final java.util.List<ExtensionHandlerFactory> extensionHandlerFactories
-
configCustomizerFactories
private final java.util.List<ConfigCustomizerFactory> configCustomizerFactories
-
allowProxy
private boolean allowProxy
-
registry
private ConfigRegistry registry
-
-
Constructor Detail
-
Extensions
public Extensions()
Creates a new instance.- registers extension handlers factories for bridge and interface default methods and for the
UseExtensionHandlerannotation. - registers extension handler customizers for the
UseExtensionHandlerCustomizerannotation. - registers extension configurer factories for
UseExtensionConfigurerannotation.
- registers extension handlers factories for bridge and interface default methods and for the
-
Extensions
private Extensions(Extensions that)
Create an extension configuration by cloning another.- Parameters:
that- the configuration to clone
-
-
Method Detail
-
setRegistry
public void setRegistry(ConfigRegistry registry)
Description copied from interface:JdbiConfigThe registry will inject itself into the configuration object. This can be useful if you need to look up dependencies. You will get a new registry after being copied.- Specified by:
setRegistryin interfaceJdbiConfig<Extensions>- Parameters:
registry- the registry that owns this configuration object
-
register
public Extensions register(ExtensionFactory factory)
Register aExtensionFactoryinstance with the extension framework.- Parameters:
factory- the factory to register- Returns:
- This instance
-
registerHandlerFactory
@Alpha public Extensions registerHandlerFactory(ExtensionHandlerFactory extensionHandlerFactory)
Registers a globalExtensionHandlerFactoryinstance. This factory is registered globally and will be used with all registeredExtensionFactoryinstances.- Parameters:
extensionHandlerFactory- TheExtensionHandlerFactoryto register- Returns:
- This instance
- Since:
- 3.38.0
-
registerHandlerCustomizer
@Alpha public Extensions registerHandlerCustomizer(ExtensionHandlerCustomizer extensionHandlerCustomizer)
Registers a globalExtensionHandlerCustomizerinstance. This customizer is registered globally and will be used with all registeredExtensionFactoryinstances.- Parameters:
extensionHandlerCustomizer- TheExtensionHandlerCustomizerto register- Returns:
- This instance
- Since:
- 3.38.0
-
registerConfigCustomizerFactory
@Alpha public Extensions registerConfigCustomizerFactory(ConfigCustomizerFactory configCustomizerFactory)
Registers a globalConfigCustomizerFactoryinstance. This factory is registered globally and will be used with all registeredExtensionFactoryinstances.- Parameters:
configCustomizerFactory- TheConfigCustomizerFactoryto register- Returns:
- This instance
- Since:
- 3.38.0
-
hasExtensionFor
public boolean hasExtensionFor(java.lang.Class<?> extensionType)
Returns true if an extension is registered for the given extension type.- Parameters:
extensionType- the type to query. Must not be null- Returns:
- true if a registered extension factory handles the type
-
findFor
public <E> java.util.Optional<E> findFor(java.lang.Class<E> extensionType, HandleSupplier handleSupplier)Create an extension instance if a factory accepts the extension type. This method requires access to aHandleSupplier, which is only useful either from within an extension implementation of inside the Jdbi code. It should rarely be called by user code.- Type Parameters:
E- the extension type to create- Parameters:
extensionType- the extension type to createhandleSupplier- A handle supplier object- Returns:
- an attached extension instance if a factory is found,
Optional.empty()otherwise
-
findFactoryFor
private java.util.Optional<ExtensionFactory> findFactoryFor(java.lang.Class<?> extensionType)
-
findFactory
public java.util.Optional<ExtensionFactory> findFactory(java.lang.Class<? extends ExtensionFactory> factoryType)
Find the registered factory of the given type. The factory returned from this call may not be the same instance that was registered withregister(ExtensionFactory).- Parameters:
factoryType- the factory's type to find- Returns:
- the found factory, if any or
Optional.empty()otherwise
-
findMetadata
@Alpha public ExtensionMetadata findMetadata(java.lang.Class<?> extensionType, ExtensionFactory extensionFactory)
Retrieves all extension metadata for a specific extension type.- Parameters:
extensionType- The extension typeextensionFactory- The extension factory for this extension type- Returns:
- A
ExtensionMetadataobject describing the extension handlers and customizers for this extension type - Since:
- 3.38.0
-
internalRegisterHandlerFactory
private Extensions internalRegisterHandlerFactory(ExtensionHandlerFactory extensionHandlerFactory)
-
createMetadata
private java.util.function.Function<java.lang.Class<?>,ExtensionMetadata> createMetadata(ExtensionFactory extensionFactory)
-
setAllowProxy
@Beta public Extensions setAllowProxy(boolean allowProxy)
Allow usingProxyto implement extensions.- Parameters:
allowProxy- whether to allow use of Proxy types- Returns:
- this
-
isAllowProxy
@Beta public boolean isAllowProxy()
Returns whether Proxy classes are allowed to be used.- Returns:
- whether Proxy classes are allowed to be used.
-
createCopy
public Extensions createCopy()
Description copied from interface:JdbiConfigReturns a copy of this configuration object. Changes to the copy should not modify the original, and vice-versa.- Specified by:
createCopyin interfaceJdbiConfig<Extensions>- Returns:
- a copy of this configuration object.
-
onCreateProxy
@Beta public void onCreateProxy()
Throw if proxy creation is disallowed.
-
-