Package org.jdbi.v3.core.mapper
Class ColumnMappers
- java.lang.Object
-
- org.jdbi.v3.core.mapper.ColumnMappers
-
- All Implemented Interfaces:
JdbiConfig<ColumnMappers>
public class ColumnMappers extends java.lang.Object implements JdbiConfig<ColumnMappers>
Configuration registry forColumnMapperFactoryinstances.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<QualifiedType<?>,java.util.Optional<? extends ColumnMapper<?>>>cacheprivate booleancoalesceNullPrimitivesToDefaultsprivate java.util.List<QualifiedColumnMapperFactory>factoriesprivate JdbiInterceptionChainHolder<ColumnMapper<?>,QualifiedColumnMapperFactory>inferenceInterceptorsprivate ConfigRegistryregistry
-
Constructor Summary
Constructors Modifier Constructor Description ColumnMappers()privateColumnMappers(ColumnMappers that)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ColumnMapperscreateCopy()Returns a copy of this configuration object.<T> java.util.Optional<ColumnMapper<T>>findFor(java.lang.Class<T> type)Obtain a column mapper for the given type.java.util.Optional<ColumnMapper<?>>findFor(java.lang.reflect.Type type)Obtain a column mapper for the given type.<T> java.util.Optional<ColumnMapper<T>>findFor(GenericType<T> type)Obtain a column mapper for the given type.<T> java.util.Optional<ColumnMapper<T>>findFor(QualifiedType<T> type)Obtain a column mapper for the given qualified type.booleangetCoalesceNullPrimitivesToDefaults()Returns true if databasenullvalues should be transformed to the default value for primitives.JdbiInterceptionChainHolder<ColumnMapper<?>,QualifiedColumnMapperFactory>getInferenceInterceptors()Returns theJdbiInterceptionChainHolderfor the ColumnMapper inference.ColumnMappersregister(java.lang.reflect.Type type, ColumnMapper<?> mapper)Register a column mapper for a given explicitTypeColumn mappers may be reused byRowMapperto map individual columns.<T> ColumnMappersregister(GenericType<T> type, ColumnMapper<T> mapper)Register a column mapper for a given explicitGenericTypeColumn mappers may be reused byRowMapperto map individual columns.ColumnMappersregister(ColumnMapper<?> mapper)Register a column mapper which will have its parameterized type inspected to determine what it maps to.ColumnMappersregister(ColumnMapperFactory factory)Register a column mapper factory.ColumnMappersregister(QualifiedColumnMapperFactory factory)Register a qualified column mapper factory.<T> ColumnMappersregister(QualifiedType<T> type, ColumnMapper<T> mapper)Register a column mapper for a givenQualifiedTypeColumn mappers may be reused byRowMapperto map individual columns.voidsetCoalesceNullPrimitivesToDefaults(boolean coalesceNullPrimitivesToDefaults)voidsetRegistry(ConfigRegistry registry)The registry will inject itself into the configuration object.
-
-
-
Field Detail
-
inferenceInterceptors
private final JdbiInterceptionChainHolder<ColumnMapper<?>,QualifiedColumnMapperFactory> inferenceInterceptors
-
factories
private final java.util.List<QualifiedColumnMapperFactory> factories
-
cache
private final java.util.Map<QualifiedType<?>,java.util.Optional<? extends ColumnMapper<?>>> cache
-
coalesceNullPrimitivesToDefaults
private boolean coalesceNullPrimitivesToDefaults
-
registry
private ConfigRegistry registry
-
-
Constructor Detail
-
ColumnMappers
public ColumnMappers()
-
ColumnMappers
private ColumnMappers(ColumnMappers that)
-
-
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<ColumnMappers>- Parameters:
registry- the registry that owns this configuration object
-
getInferenceInterceptors
@Alpha public JdbiInterceptionChainHolder<ColumnMapper<?>,QualifiedColumnMapperFactory> getInferenceInterceptors()
Returns theJdbiInterceptionChainHolderfor the ColumnMapper inference. This chain allows registration of custom interceptors to change the standard type inference for theregister(ColumnMapper)method.
-
register
public ColumnMappers register(ColumnMapper<?> mapper)
Register a column mapper which will have its parameterized type inspected to determine what it maps to. Column mappers may be reused byRowMapperto map individual columns.The parameter must be concretely parameterized, we use the type argument T to determine if it applies to a given type.
- Parameters:
mapper- the column mapper- Returns:
- this
- Throws:
java.lang.UnsupportedOperationException- if the ColumnMapper is not a concretely parameterized type
-
register
public <T> ColumnMappers register(GenericType<T> type, ColumnMapper<T> mapper)
Register a column mapper for a given explicitGenericTypeColumn mappers may be reused byRowMapperto map individual columns.- Type Parameters:
T- the type- Parameters:
type- the generic type to match with equals.mapper- the column mapper- Returns:
- this
-
register
public ColumnMappers register(java.lang.reflect.Type type, ColumnMapper<?> mapper)
Register a column mapper for a given explicitTypeColumn mappers may be reused byRowMapperto map individual columns.- Parameters:
type- the type to match with equals.mapper- the column mapper- Returns:
- this
-
register
public <T> ColumnMappers register(QualifiedType<T> type, ColumnMapper<T> mapper)
Register a column mapper for a givenQualifiedTypeColumn mappers may be reused byRowMapperto map individual columns.- Parameters:
type- the type to match with equals.mapper- the column mapper- Returns:
- this
-
register
public ColumnMappers register(ColumnMapperFactory factory)
Register a column mapper factory.Column mappers may be reused by
RowMapperto map individual columns.- Parameters:
factory- the column mapper factory- Returns:
- this
-
register
public ColumnMappers register(QualifiedColumnMapperFactory factory)
Register a qualified column mapper factory.Column mappers may be reused by
RowMapperto map individual columns.- Parameters:
factory- the qualified column mapper factory- Returns:
- this
-
findFor
public <T> java.util.Optional<ColumnMapper<T>> findFor(java.lang.Class<T> type)
Obtain a column mapper for the given type.- Type Parameters:
T- the type to map- Parameters:
type- the target type to map to- Returns:
- a ColumnMapper for the given type, or empty if no column mapper is registered for the given type.
-
findFor
public <T> java.util.Optional<ColumnMapper<T>> findFor(GenericType<T> type)
Obtain a column mapper for the given type.- Type Parameters:
T- the type to map- Parameters:
type- the target type to map to- Returns:
- a ColumnMapper for the given type, or empty if no column mapper is registered for the given type.
-
findFor
public java.util.Optional<ColumnMapper<?>> findFor(java.lang.reflect.Type type)
Obtain a column mapper for the given type.- Parameters:
type- the target type to map to- Returns:
- a ColumnMapper for the given type, or empty if no column mapper is registered for the given type.
-
findFor
public <T> java.util.Optional<ColumnMapper<T>> findFor(QualifiedType<T> type)
Obtain a column mapper for the given qualified type.- Parameters:
type- the qualified target type to map to- Returns:
- a ColumnMapper for the given type, or empty if no column mapper is registered for the given type.
-
getCoalesceNullPrimitivesToDefaults
public boolean getCoalesceNullPrimitivesToDefaults()
Returns true if databasenullvalues should be transformed to the default value for primitives.- Returns:
trueif databasenulls should translate to the Java defaults for primitives, or throw an exception otherwise. Default value is true: nulls will be coalesced to defaults.
-
setCoalesceNullPrimitivesToDefaults
public void setCoalesceNullPrimitivesToDefaults(boolean coalesceNullPrimitivesToDefaults)
-
createCopy
public ColumnMappers 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<ColumnMappers>- Returns:
- a copy of this configuration object.
-
-