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 java.lang.Object implements ArgumentFactory.Preparable
AnArgumentFactorybase class for arguments of typeT. For values of typeT, factories produces arguments from thebuild(Object, ConfigRegistry)method. For null values with a known expected type ofT, produces null arguments for thesqlTypepassed 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 overrideObject.toString()in yourArgumentinstances if you want to be able to log their values with anSqlLogger.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceAbstractArgumentFactory.ArgumentPredicate-
Nested classes/interfaces inherited from interface org.jdbi.v3.core.argument.ArgumentFactory
ArgumentFactory.Preparable
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.TypeargumentTypeprivate AbstractArgumentFactory.ArgumentPredicateisInstanceprivate intsqlType
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractArgumentFactory(int sqlType)Constructs anArgumentFactoryfor typeT.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.Optional<Argument>build(java.lang.reflect.Type type, java.lang.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(java.lang.reflect.Type type, java.lang.Object value, ConfigRegistry config)java.util.Optional<java.util.function.Function<java.lang.Object,Argument>>prepare(java.lang.reflect.Type type, ConfigRegistry config)java.util.Collection<java.lang.reflect.Type>prePreparedTypes()
-
-
-
Field Detail
-
sqlType
private final int sqlType
-
isInstance
private final AbstractArgumentFactory.ArgumentPredicate isInstance
-
argumentType
private final java.lang.reflect.Type argumentType
-
-
Constructor Detail
-
AbstractArgumentFactory
protected AbstractArgumentFactory(int sqlType)
Constructs anArgumentFactoryfor typeT.- Parameters:
sqlType- theTypesconstant to use when the argument value isnull.
-
-
Method Detail
-
prepare
public java.util.Optional<java.util.function.Function<java.lang.Object,Argument>> prepare(java.lang.reflect.Type type, ConfigRegistry config)
- Specified by:
preparein interfaceArgumentFactory.Preparable
-
prePreparedTypes
public java.util.Collection<java.lang.reflect.Type> prePreparedTypes()
- Specified by:
prePreparedTypesin interfaceArgumentFactory.Preparable
-
build
public final java.util.Optional<Argument> build(java.lang.reflect.Type type, java.lang.Object value, ConfigRegistry config)
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:
StatementContext.findArgumentFor(Type, Object),Arguments.findFor(Type, Object)
-
innerBuild
private Argument innerBuild(java.lang.reflect.Type type, java.lang.Object value, ConfigRegistry config)
-
build
protected abstract Argument build(T value, ConfigRegistry config)
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!
-
-