Package org.jdbi.v3.core.mapper
Class ColumnMappers
java.lang.Object
org.jdbi.v3.core.mapper.ColumnMappers
- All Implemented Interfaces:
JdbiConfig<ColumnMappers>
Configuration registry for
ColumnMapperFactory
instances.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns a copy of this configuration object.<T> Optional
<ColumnMapper<T>> Obtain a column mapper for the given type.Optional
<ColumnMapper<?>> Obtain a column mapper for the given type.<T> Optional
<ColumnMapper<T>> findFor
(GenericType<T> type) Obtain a column mapper for the given type.<T> Optional
<ColumnMapper<T>> findFor
(QualifiedType<T> type) Obtain a column mapper for the given qualified type.boolean
Returns true if databaseNULL
values should be transformed to the default value for primitives.Returns theJdbiInterceptionChainHolder
for the ColumnMapper inference.register
(Type type, ColumnMapper<?> mapper) <T> ColumnMappers
register
(GenericType<T> type, ColumnMapper<T> mapper) Register a column mapper for a given explicitGenericType
Column mappers may be reused byRowMapper
to map individual columns.register
(ColumnMapper<?> mapper) Register a column mapper which will have its parameterized type inspected to determine what it maps to.register
(ColumnMapperFactory factory) Register a column mapper factory.register
(QualifiedColumnMapperFactory factory) Register a qualified column mapper factory.<T> ColumnMappers
register
(QualifiedType<T> type, ColumnMapper<T> mapper) Register a column mapper for a givenQualifiedType
Column mappers may be reused byRowMapper
to map individual columns.void
setCoalesceNullPrimitivesToDefaults
(boolean coalesceNullPrimitivesToDefaults) Use the JDBC default value for primitive types if a SQL NULL value was returned by the database.void
setRegistry
(ConfigRegistry registry) The registry will inject itself into the configuration object.
-
Constructor Details
-
ColumnMappers
public ColumnMappers()
-
-
Method Details
-
setRegistry
Description copied from interface:JdbiConfig
The 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:
setRegistry
in interfaceJdbiConfig<ColumnMappers>
- Parameters:
registry
- the registry that owns this configuration object
-
getInferenceInterceptors
@Alpha public JdbiInterceptionChainHolder<ColumnMapper<?>,QualifiedColumnMapperFactory> getInferenceInterceptors()Returns theJdbiInterceptionChainHolder
for the ColumnMapper inference. This chain allows registration of custom interceptors to change the standard type inference for theregister(ColumnMapper)
method. -
register
Register a column mapper which will have its parameterized type inspected to determine what it maps to. Column mappers may be reused byRowMapper
to 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:
UnsupportedOperationException
- if the ColumnMapper is not a concretely parameterized type
-
register
Register a column mapper for a given explicitGenericType
Column mappers may be reused byRowMapper
to map individual columns.- Type Parameters:
T
- the type- Parameters:
type
- the generic type to match with equals.mapper
- the column mapper- Returns:
- this
-
register
-
register
Register a column mapper for a givenQualifiedType
Column mappers may be reused byRowMapper
to map individual columns.- Parameters:
type
- the type to match with equals.mapper
- the column mapper- Returns:
- this
-
register
Register a column mapper factory.Column mappers may be reused by
RowMapper
to map individual columns.- Parameters:
factory
- the column mapper factory- Returns:
- this
-
register
Register a qualified column mapper factory.Column mappers may be reused by
RowMapper
to map individual columns.- Parameters:
factory
- the qualified column mapper factory- Returns:
- this
-
findFor
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
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
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
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 databaseNULL
values should be transformed to the default value for primitives.- Returns:
true
if databaseNULL
s should translate to the JDBC defaults for primitives, or throw an exception otherwise. Default value is true: nulls will be coalesced to defaults.
-
setCoalesceNullPrimitivesToDefaults
public void setCoalesceNullPrimitivesToDefaults(boolean coalesceNullPrimitivesToDefaults) Use the JDBC default value for primitive types if a SQL NULL value was returned by the database. If this property is set tofalse
, Jdbi will throw an exception when trying to map a SQLNULL
value to a primitive type.- Parameters:
coalesceNullPrimitivesToDefaults
- If true, then use the JDBC default value, otherwise throw an exception.
-
createCopy
Description copied from interface:JdbiConfig
Returns a copy of this configuration object. Changes to the copy should not modify the original, and vice-versa.- Specified by:
createCopy
in interfaceJdbiConfig<ColumnMappers>
- Returns:
- a copy of this configuration object.
-