Package org.jdbi.v3.core.argument
Class Arguments
- java.lang.Object
-
- org.jdbi.v3.core.argument.Arguments
-
- All Implemented Interfaces:
JdbiConfig<Arguments>
public class Arguments extends java.lang.Object implements JdbiConfig<Arguments>
A registry for ArgumentFactory instances. When a statement with bound parameters is executed, Jdbi consults the Arguments registry to obtain an Argument instance for each bound parameter (see #findFor(...)). The factories are consulted in reverse order of registration (i.e. last-registered wins).
-
-
Field Summary
Fields Modifier and Type Field Description private booleanbindingNullToPrimitivesPermittedprivate java.util.Set<QualifiedType<?>>didPrepareprivate java.util.List<QualifiedArgumentFactory>factoriesprivate booleanpreparedArgumentsEnabledprivate java.util.Map<QualifiedType<?>,java.util.function.Function<java.lang.Object,Argument>>preparedFactoriesprivate ConfigRegistryregistryprivate ArgumentuntypedNullArgument
-
Constructor Summary
Constructors Modifier Constructor Description privateArguments(Arguments that)Arguments(ConfigRegistry registry)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ArgumentscreateCopy()Returns a copy of this configuration object.java.util.Optional<Argument>findFor(java.lang.reflect.Type type, java.lang.Object value)Obtain an argument for given value in the given contextjava.util.Optional<Argument>findFor(QualifiedType<?> type, java.lang.Object value)Obtain an argument for given value in the given context.java.util.List<QualifiedArgumentFactory>getFactories()ArgumentgetUntypedNullArgument()Returns the untyped null argument.booleanisBindingNullToPrimitivesPermitted()Returns true if bindingnullto a variable declared as a primitive type is allowed.booleanisPreparedArgumentsEnabled()Returns true if prepared arguments binding is enabled.java.util.Optional<java.util.function.Function<java.lang.Object,Argument>>prepareFor(java.lang.reflect.Type type)Obtain a prepared argument function for given type in the given context.java.util.Optional<java.util.function.Function<java.lang.Object,Argument>>prepareFor(QualifiedType<?> type)Obtain a prepared argument function for given type in the given context.Argumentsregister(ArgumentFactory factory)Registers the given argument factory.Argumentsregister(QualifiedArgumentFactory factory)Registers the given qualified argument factory.voidsetBindingNullToPrimitivesPermitted(boolean bindingNullToPrimitivesPermitted)Whether bindingnullto a variable declared as a primitive type should be allowed.voidsetPreparedArgumentsEnabled(boolean preparedArgumentsEnabled)Configure whetherArgumentFactory.Preparablefactories will be processed before regularArgumentFactoryinstances are.voidsetRegistry(ConfigRegistry registry)The registry will inject itself into the configuration object.voidsetUntypedNullArgument(Argument untypedNullArgument)Configure theArgumentto use when binding a null we don't have a type for.
-
-
-
Field Detail
-
factories
private final java.util.List<QualifiedArgumentFactory> factories
-
preparedFactories
private final java.util.Map<QualifiedType<?>,java.util.function.Function<java.lang.Object,Argument>> preparedFactories
-
didPrepare
private final java.util.Set<QualifiedType<?>> didPrepare
-
registry
private ConfigRegistry registry
-
untypedNullArgument
private Argument untypedNullArgument
-
bindingNullToPrimitivesPermitted
private boolean bindingNullToPrimitivesPermitted
-
preparedArgumentsEnabled
private boolean preparedArgumentsEnabled
-
-
Constructor Detail
-
Arguments
public Arguments(ConfigRegistry registry)
-
Arguments
private Arguments(Arguments that)
-
-
Method Detail
-
setRegistry
public void setRegistry(ConfigRegistry registry)
Description copied from interface:JdbiConfigThe 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:
setRegistryin interfaceJdbiConfig<Arguments>- Parameters:
registry- the registry that owns this configuration object
-
register
public Arguments register(ArgumentFactory factory)
Registers the given argument factory. If more than one of the registered factories supports a given parameter type, the last-registered factory wins.- Parameters:
factory- the factory to add- Returns:
- this
-
register
public Arguments register(QualifiedArgumentFactory factory)
Registers the given qualified argument factory. If more than one of the registered factories supports a given parameter type, the last-registered factory wins.- Parameters:
factory- the qualified factory to add- Returns:
- this
-
findFor
public java.util.Optional<Argument> findFor(java.lang.reflect.Type type, java.lang.Object value)
Obtain an argument for given value in the given context- Parameters:
type- the type of the argument.value- the argument value.- Returns:
- an Argument for the given value.
-
findFor
public java.util.Optional<Argument> findFor(QualifiedType<?> type, java.lang.Object value)
Obtain an argument for given value in the given context.- Parameters:
type- the qualified type of the argument.value- the argument value.- Returns:
- an Argument for the given value.
-
prepareFor
public java.util.Optional<java.util.function.Function<java.lang.Object,Argument>> prepareFor(java.lang.reflect.Type type)
Obtain a prepared argument function for given type in the given context.- Parameters:
type- the type of the argument.- Returns:
- an Argument factory function for the given value.
-
prepareFor
@Beta public java.util.Optional<java.util.function.Function<java.lang.Object,Argument>> prepareFor(QualifiedType<?> type)
Obtain a prepared argument function for given type in the given context.- Parameters:
type- the qualified type of the argument.- Returns:
- an Argument factory function for the given value.
-
getFactories
public java.util.List<QualifiedArgumentFactory> getFactories()
-
setUntypedNullArgument
public void setUntypedNullArgument(Argument untypedNullArgument)
Configure theArgumentto use when binding a null we don't have a type for.- Parameters:
untypedNullArgument- the argument to bind
-
getUntypedNullArgument
public Argument getUntypedNullArgument()
Returns the untyped null argument.- Returns:
- the untyped null argument.
-
isBindingNullToPrimitivesPermitted
public boolean isBindingNullToPrimitivesPermitted()
Returns true if bindingnullto a variable declared as a primitive type is allowed.- Returns:
- true if binding
nullto a variable declared as a primitive type is allowed.
-
setBindingNullToPrimitivesPermitted
public void setBindingNullToPrimitivesPermitted(boolean bindingNullToPrimitivesPermitted)
Whether bindingnullto a variable declared as a primitive type should be allowed.- Parameters:
bindingNullToPrimitivesPermitted- if true,nullcan be bound to a variable declared as a primitive type.
-
isPreparedArgumentsEnabled
public boolean isPreparedArgumentsEnabled()
Returns true if prepared arguments binding is enabled. Settings this improves performance.- Returns:
- true if prepared arguments binding is enabled.
-
setPreparedArgumentsEnabled
public void setPreparedArgumentsEnabled(boolean preparedArgumentsEnabled)
Configure whetherArgumentFactory.Preparablefactories will be processed before regularArgumentFactoryinstances are. This improves speed at a small cost to backwards compatibility. Please disable it if you require the old semantics.- Parameters:
preparedArgumentsEnabled- whether to enable preparable argument factories
-
createCopy
public Arguments createCopy()
Description copied from interface:JdbiConfigReturns a copy of this configuration object. Changes to the copy should not modify the original, and vice-versa.- Specified by:
createCopyin interfaceJdbiConfig<Arguments>- Returns:
- a copy of this configuration object.
-
-