Package org.jdbi.v3.core.codec
Class CodecFactory
- java.lang.Object
-
- org.jdbi.v3.core.codec.CodecFactory
-
- All Implemented Interfaces:
QualifiedArgumentFactory,QualifiedArgumentFactory.Preparable,QualifiedColumnMapperFactory
- Direct Known Subclasses:
TypeResolvingCodecFactory
@ThreadSafe @Alpha public class CodecFactory extends java.lang.Object implements QualifiedColumnMapperFactory, QualifiedArgumentFactory.Preparable
CodecFactory provides column mappers and arguments for bidirectional mapping types to database columns.This class is immutable and thread safe.
Alpha: this class as public API is redundant with the existing way of managing mappers: we should try to combine them to make the new public API as small as possible
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCodecFactory.BuilderFluent Builder forCodecFactory.-
Nested classes/interfaces inherited from interface org.jdbi.v3.core.argument.QualifiedArgumentFactory
QualifiedArgumentFactory.Preparable
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentMap<QualifiedType<?>,Codec<?>>codecMapMap of all known codecs in this factory.
-
Constructor Summary
Constructors Constructor Description CodecFactory(java.util.Map<QualifiedType<?>,Codec<?>> codecMap)Create a new CodecFactory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<Argument>build(QualifiedType<?> type, java.lang.Object value, ConfigRegistry config)Returns anArgumentfor the given value if the factory supports it; empty otherwise.java.util.Optional<ColumnMapper<?>>build(QualifiedType<?> type, ConfigRegistry config)Supplies a column mapper which will map columns to type if the factory supports it; empty otherwise.static CodecFactory.Builderbuilder()Returns a builder for fluent API.static CodecFactoryforSingleCodec(QualifiedType<?> type, Codec<?> codec)java.util.Optional<java.util.function.Function<java.lang.Object,Argument>>prepare(QualifiedType<?> type, ConfigRegistry config)java.util.Collection<QualifiedType<?>>prePreparedTypes()protected Codec<?>resolveType(QualifiedType<?> qualifiedType)Extension point for type resolution.
-
-
-
Field Detail
-
codecMap
protected final java.util.concurrent.ConcurrentMap<QualifiedType<?>,Codec<?>> codecMap
Map of all known codecs in this factory. ALPHA: the fact that this is a Map from type to Codec makes it hard to implement Codecs that target wildcard or varying types e.g. mapping bothSub<T>andSuper<T>with one codec. It might be nice to re-imagine this as itself a JdbiPlugin and have it do all registration through the existing flows.
-
-
Constructor Detail
-
CodecFactory
public CodecFactory(java.util.Map<QualifiedType<?>,Codec<?>> codecMap)
Create a new CodecFactory.
-
-
Method Detail
-
builder
public static CodecFactory.Builder builder()
Returns a builder for fluent API.
-
forSingleCodec
public static CodecFactory forSingleCodec(QualifiedType<?> type, Codec<?> codec)
-
prepare
public final java.util.Optional<java.util.function.Function<java.lang.Object,Argument>> prepare(QualifiedType<?> type, ConfigRegistry config)
- Specified by:
preparein interfaceQualifiedArgumentFactory.Preparable
-
prePreparedTypes
public final java.util.Collection<QualifiedType<?>> prePreparedTypes()
- Specified by:
prePreparedTypesin interfaceQualifiedArgumentFactory.Preparable
-
build
public final java.util.Optional<Argument> build(QualifiedType<?> type, java.lang.Object value, ConfigRegistry config)
Description copied from interface:QualifiedArgumentFactoryReturns anArgumentfor the given value if the factory supports it; empty otherwise.- Specified by:
buildin interfaceQualifiedArgumentFactory- Parameters:
type- the known qualified type of value. Depending on the situation this may be a full generic signature e.g.ParameterizedType, aClass, or Object.class if no type information is known.value- the value to convert into anArgumentconfig- the config registry, for composition- Returns:
- an argument for the given value if this factory supports it, or
Optional.empty()otherwise. - See Also:
StatementContext.findArgumentFor(QualifiedType, Object),Arguments.findFor(QualifiedType, Object),QualifiedType
-
build
public final java.util.Optional<ColumnMapper<?>> build(QualifiedType<?> type, ConfigRegistry config)
Description copied from interface:QualifiedColumnMapperFactorySupplies a column mapper which will map columns to type if the factory supports it; empty otherwise.- Specified by:
buildin interfaceQualifiedColumnMapperFactory- Parameters:
type- the target qualified type to map toconfig- the config registry, for composition- Returns:
- a column mapper for the given type if this factory supports it, or
Optional.empty()otherwise. - See Also:
for composition,QualifiedType
-
resolveType
protected Codec<?> resolveType(QualifiedType<?> qualifiedType)
Extension point for type resolution.- Parameters:
qualifiedType- Requested type- Returns:
- A
Codecfor the requested type or null if no codec is suitable.
-
-