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:
CharSequenceArgumentFactory,DateTimeArgumentFactory,DurationArgumentFactory,HStoreArgumentFactory,InetArgumentFactory,JavaTimeZoneIdArgumentFactory,PeriodArgumentFactory,TypedEnumArgumentFactory
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 classes/interfaces inherited from interface org.jdbi.v3.core.argument.ArgumentFactory
ArgumentFactory.Preparable -
Method Summary
Modifier and TypeMethodDescriptionbuild(Type type, Object value, ConfigRegistry config) Returns anArgumentfor the given value if the factory supports it; empty otherwise.prepare(Type type, ConfigRegistry config)
-
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:
-