Package org.jdbi.v3.core.argument
Class AbstractArgumentFactory<T>
java.lang.Object
org.jdbi.v3.core.argument.AbstractArgumentFactory<T>
- Type Parameters:
T- the type of argument supported by this factory.
- All Implemented Interfaces:
ArgumentFactory,ArgumentFactory.Preparable
- Direct Known Subclasses:
BlobInputStreamArgumentFactory,CharSequenceArgumentFactory,ClobReaderArgumentFactory,DateTimeArgumentFactory,DurationArgumentFactory,HStoreArgumentFactory,InetArgumentFactory,JavaTimeZoneIdArgumentFactory,JsonArgumentFactory,MacAddrArgumentFactory,NVarcharArgumentFactory,PeriodArgumentFactory,PGobjectArgumentFactory,TypedEnumArgumentFactory,URLArgumentFactory
public abstract class AbstractArgumentFactory<T>
extends Object
implements ArgumentFactory.Preparable
An
ArgumentFactory base class for arguments of type T. For values of type T, factories
produces arguments from the build(Object, ConfigRegistry) method. For null values with a known expected type
of T, produces null arguments for the sqlType passed to the constructor.
class ValueType {
String value;
}
class ValueTypeArgumentFactory extends AbstractArgumentFactory<ValueType> {
ValueTypeArgumentFactory() {
super(Types.VARCHAR);
}
@Override
protected Argument build(ValueType valueType, ConfigRegistry config) {
return (pos, stmt, ctx) -> stmt.setString(pos, valueType.value);
}
}
Don't forget to override Object.toString() in your Argument instances if you want to be able to log their values with an SqlLogger.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceNested classes/interfaces inherited from interface org.jdbi.v3.core.argument.ArgumentFactory
ArgumentFactory.Preparable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Typeprivate final AbstractArgumentFactory.ArgumentPredicateprivate final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractArgumentFactory(int sqlType) Constructs anArgumentFactoryfor typeT. -
Method Summary
Modifier and TypeMethodDescriptionbuild(Type type, Object value, ConfigRegistry config) Returns anArgumentfor the given value if the factory supports it; empty otherwise.protected abstract Argumentbuild(T value, ConfigRegistry config) Produce an argument object for the given value.private ArgumentinnerBuild(Type type, Object value, ConfigRegistry config) prepare(Type type, ConfigRegistry config)
-
Field Details
-
sqlType
private final int sqlType -
isInstance
-
argumentType
-
-
Constructor Details
-
AbstractArgumentFactory
protected AbstractArgumentFactory(int sqlType) Constructs anArgumentFactoryfor typeT.- Parameters:
sqlType- theTypesconstant to use when the argument value isnull.
-
-
Method Details
-
prepare
- Specified by:
preparein interfaceArgumentFactory.Preparable
-
prePreparedTypes
- Specified by:
prePreparedTypesin interfaceArgumentFactory.Preparable
-
build
Description copied from interface:ArgumentFactoryReturns anArgumentfor the given value if the factory supports it; empty otherwise.- Specified by:
buildin interfaceArgumentFactory- Specified by:
buildin interfaceArgumentFactory.Preparable- Parameters:
type- the known 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:
-
innerBuild
-
build
Produce an argument object for the given value. When the implementation class has accepted a given type, it must then produce an argument instance or throw an exception.- Parameters:
value- the value to convert to an argumentconfig- the config registry- Returns:
- An
Argumentfor the givenvalue. Must not be null!
-