Package org.jdbi.v3.core.statement
Class SqlStatement<This extends SqlStatement<This>>
- java.lang.Object
-
- org.jdbi.v3.core.statement.BaseStatement<This>
-
- org.jdbi.v3.core.statement.SqlStatement<This>
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,Configurable<This>
- Direct Known Subclasses:
Call,PreparedBatch,Query,Script,Update
public abstract class SqlStatement<This extends SqlStatement<This>> extends BaseStatement<This>
This class provides the common functions betweenQueryandUpdate. It defines most of the argument binding functions used by its subclasses.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jdbi.v3.core.statement.BaseStatement
BaseStatement.StatementCustomizerInvocation
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringsql(package private) java.sql.PreparedStatementstmt-
Fields inherited from class org.jdbi.v3.core.statement.BaseStatement
typedThis
-
-
Constructor Summary
Constructors Constructor Description SqlStatement(Handle handle, java.lang.CharSequence sql)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidafterExecution()(package private) voidbeforeBinding()(package private) voidbeforeExecution()(package private) voidbeforeTemplating()Thisbind(int position, boolean value)Bind an argument positionallyThisbind(int position, byte value)Bind an argument positionallyThisbind(int position, byte[] value)Bind an argument positionallyThisbind(int position, char value)Bind an argument positionallyThisbind(int position, double value)Bind an argument positionallyThisbind(int position, float value)Bind an argument positionallyThisbind(int position, int value)Bind an argument positionallyThisbind(int position, long value)Bind an argument positionallyThisbind(int position, short value)Bind an argument positionallyThisbind(int position, java.io.Reader value, int length)Bind an argument positionallyThisbind(int position, java.lang.Boolean value)Bind an argument positionallyThisbind(int position, java.lang.Byte value)Bind an argument positionallyThisbind(int position, java.lang.Character value)Bind an argument positionallyprivate Thisbind(int position, java.lang.Class<?> type, java.lang.Object value)Thisbind(int position, java.lang.Double value)Bind an argument positionallyThisbind(int position, java.lang.Float value)Bind an argument positionallyThisbind(int position, java.lang.Integer value)Bind an argument positionallyThisbind(int position, java.lang.Long value)Bind an argument positionallyThisbind(int position, java.lang.Object value)Bind an argument positionallyThisbind(int position, java.lang.Short value)Bind an argument positionallyThisbind(int position, java.lang.String value)Bind an argument positionallyThisbind(int position, java.math.BigDecimal value)Bind an argument positionallyThisbind(int position, java.net.URI value)Bind an argument positionallyThisbind(int position, java.net.URL value)Bind an argument positionallyThisbind(int position, java.sql.Blob value)Bind an argument positionallyThisbind(int position, java.sql.Clob value)Bind an argument positionallyThisbind(int position, java.sql.Date value)Bind an argument positionallyThisbind(int position, java.sql.Time value)Bind an argument positionallyThisbind(int position, java.sql.Timestamp value)Bind an argument positionallyThisbind(int position, java.util.Date value)Bind an argument positionallyThisbind(int position, java.util.UUID value)Bind an argument positionallyThisbind(int position, Argument argument)Used if you need to have some exotic parameter bound.Thisbind(java.lang.String name, boolean value)Bind an argument by nameThisbind(java.lang.String name, byte value)Bind an argument by nameThisbind(java.lang.String name, byte[] value)Bind an argument by nameThisbind(java.lang.String name, char value)Bind an argument by nameThisbind(java.lang.String name, double value)Bind an argument by nameThisbind(java.lang.String name, float value)Bind an argument by nameThisbind(java.lang.String name, int value)Bind an argument by nameThisbind(java.lang.String name, long value)Bind an argument by nameThisbind(java.lang.String name, short value)Bind an argument by nameThisbind(java.lang.String name, java.io.Reader value, int length)Bind an argument by nameThisbind(java.lang.String name, java.lang.Boolean value)Bind an argument by nameThisbind(java.lang.String name, java.lang.Byte value)Bind an argument by nameThisbind(java.lang.String name, java.lang.Character value)Bind an argument by nameprivate Thisbind(java.lang.String name, java.lang.Class<?> type, java.lang.Object value)Thisbind(java.lang.String name, java.lang.Double value)Bind an argument by nameThisbind(java.lang.String name, java.lang.Float value)Bind an argument by nameThisbind(java.lang.String name, java.lang.Integer value)Bind an argument by nameThisbind(java.lang.String name, java.lang.Long value)Bind an argument by nameThisbind(java.lang.String name, java.lang.Object value)Bind an argument by nameThisbind(java.lang.String name, java.lang.Short value)Bind an argument by nameThisbind(java.lang.String name, java.lang.String value)Bind an argument by nameThisbind(java.lang.String name, java.math.BigDecimal value)Bind an argument by nameThisbind(java.lang.String name, java.net.URI value)Bind an argument by nameThisbind(java.lang.String name, java.net.URL value)Bind an argument by nameThisbind(java.lang.String name, java.sql.Blob value)Bind an argument by nameThisbind(java.lang.String name, java.sql.Clob value)Bind an argument by nameThisbind(java.lang.String name, java.sql.Date value)Bind an argument by nameThisbind(java.lang.String name, java.sql.Time value)Bind an argument by nameThisbind(java.lang.String name, java.sql.Timestamp value)Bind an argument by nameThisbind(java.lang.String name, java.util.Date value)Bind an argument by nameThisbind(java.lang.String name, java.util.UUID value)Bind an argument by nameThisbind(java.lang.String name, Argument argument)Used if you need to have some exotic parameter bound.ThisbindArray(int pos, java.lang.reflect.Type elementType, java.lang.Iterable<?> iterable)Bind an Iterable as a SQL array.ThisbindArray(int pos, java.lang.reflect.Type elementType, java.lang.Object... array)Bind a Java array as a SQL array, casting each element to a new type.ThisbindArray(int pos, java.lang.reflect.Type elementType, java.util.Iterator<?> iterator)Bind an Iterator as a SQL array.<T> ThisbindArray(int pos, T... array)Bind a Java array as a SQL array.ThisbindArray(java.lang.String name, java.lang.reflect.Type elementType, java.lang.Iterable<?> iterable)Bind an Iterable as a SQL array.ThisbindArray(java.lang.String name, java.lang.reflect.Type elementType, java.lang.Object... array)Bind a Java array as a SQL array, casting each element to a new type.ThisbindArray(java.lang.String name, java.lang.reflect.Type elementType, java.util.Iterator<?> iterator)Bind an Iterator as a SQL array.<T> ThisbindArray(java.lang.String name, T... array)Bind a Java array as a SQL array.ThisbindASCIIStream(int position, java.io.InputStream value, int length)Bind an argument positionallyThisbindASCIIStream(java.lang.String name, java.io.InputStream value, int length)Bind an argument by nameThisbindBean(java.lang.Object bean)Binds named parameters from JavaBean properties on the argument.ThisbindBean(java.lang.String prefix, java.lang.Object bean)Binds named parameters from JavaBean properties on the bean argument, with the given prefix.ThisbindBeanList(java.lang.String key, java.util.List<?> values, java.util.List<java.lang.String> propertyNames)Bind a parameter for each value in the given list * number of property names, and defines an attribute as the comma-separated list of parameter references (using colon prefix).ThisbindBinaryStream(int position, java.io.InputStream value, int length)Bind an argument positionallyThisbindBinaryStream(java.lang.String name, java.io.InputStream value, int length)Bind an argument by nameThisbindBySqlType(int position, java.lang.Object value, int sqlType)Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)ThisbindBySqlType(java.lang.String name, java.lang.Object value, int sqlType)Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)ThisbindByType(int position, java.lang.Object value, java.lang.reflect.Type argumentType)Bind an argument dynamically by the type passed in.ThisbindByType(int position, java.lang.Object value, GenericType<?> argumentType)Bind an argument dynamically by the generic type passed in.ThisbindByType(int position, java.lang.Object value, QualifiedType<?> argumentType)Bind an argument dynamically by the qualified type passed in.ThisbindByType(java.lang.String name, java.lang.Object value, java.lang.reflect.Type argumentType)Bind an argument dynamically by the type passed in.ThisbindByType(java.lang.String name, java.lang.Object value, GenericType<?> argumentType)Bind an argument dynamically by the generic type passed in.ThisbindByType(java.lang.String name, java.lang.Object value, QualifiedType<?> argumentType)Bind an argument dynamically by the type passed in.ThisbindFields(java.lang.Object object)Binds public fields of the specified object as arguments for the query.ThisbindFields(java.lang.String prefix, java.lang.Object object)Binds public fields of the specified object as arguments for the query.ThisbindList(java.lang.String key, java.lang.Iterable<?> values)ThisbindList(java.lang.String key, java.lang.Object... values)ThisbindList(java.lang.String key, java.util.Iterator<?> values)ThisbindList(java.util.function.BiConsumer<SqlStatement,java.lang.String> onEmpty, java.lang.String key, java.lang.Iterable<?> values)ThisbindList(java.util.function.BiConsumer<SqlStatement,java.lang.String> onEmpty, java.lang.String key, java.lang.Object... values)ThisbindList(java.util.function.BiConsumer<SqlStatement,java.lang.String> onEmpty, java.lang.String key, java.util.Iterator<?> values)ThisbindList(java.util.function.BiConsumer<SqlStatement,java.lang.String> onEmpty, java.lang.String key, java.util.List<?> values)Bind a parameter for each value in the given list, and defines an attribute as the comma-separated list of parameter references (using colon prefix).ThisbindMap(java.util.Map<java.lang.String,?> map)Binds named parameters from a map of String to Object instancesThisbindMethods(java.lang.Object object)Binds methods with no parameters on the argument.ThisbindMethods(java.lang.String prefix, java.lang.Object object)Binds methods with no parameters on the argument, with the given prefix.ThisbindMethodsList(java.lang.String key, java.lang.Iterable<?> values, java.util.List<java.lang.String> methodNames)For each value given, create a tuple by invoking each given method in order, and bind the tuple into aVALUES (...)format insert clause.(package private) ThisbindNamedArgumentFinder(NamedArgumentFinderFactory factory, java.lang.String prefix, java.lang.Object value, java.lang.reflect.Type type, java.util.function.Supplier<NamedArgumentFinder> namedArgumentFinder)ThisbindNamedArgumentFinder(NamedArgumentFinder namedArgumentFinder)Binds a newNamedArgumentFinder.ThisbindNull(int position, int sqlType)Bind NULL to be set for a given argument.ThisbindNull(java.lang.String name, int sqlType)Bind NULL to be set for a given argument.ThisbindNVarchar(int position, java.lang.String value)Bind aStringargument positionally, asNVARCHARtype.ThisbindNVarchar(java.lang.String name, java.lang.String value)Bind aStringargument by name, asNVARCHARtype.ThisbindPojo(java.lang.Object pojo)Binds named parameters from object properties on the argument.ThisbindPojo(java.lang.Object pojo, java.lang.reflect.Type type)Binds named parameters from object properties on the argument.ThisbindPojo(java.lang.Object pojo, GenericType<?> type)Binds named parameters from object properties on the argument.ThisbindPojo(java.lang.String prefix, java.lang.Object pojo)Binds named parameters from object properties on the bean argument, with the given prefix.ThisbindPojo(java.lang.String prefix, java.lang.Object pojo, java.lang.reflect.Type type)Binds named parameters from object properties on the bean argument, with the given prefix.ThisbindPojo(java.lang.String prefix, java.lang.Object pojo, GenericType<?> type)Binds named parameters from object properties on the bean argument, with the given prefix.private ThiscleanupHandle(java.util.function.Consumer<Handle> action)ThiscleanupHandleCommit()Transfer ownership of the handle to the statement: when the statement is closed, commit the handle's transaction (if one exists) and close the handle.ThiscleanupHandleRollback()When the statement is closed, roll it back then close the owning Handle.(package private) voidcleanupStatement(java.sql.PreparedStatement statement)(package private) java.sql.PreparedStatementcreateStatement(java.lang.String parsedSql)ThisdefineList(java.lang.String key, java.lang.Object... values)Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.ThisdefineList(java.lang.String key, java.util.List<?> values)Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.ThisdefineNamedBindings()Define all bound arguments that don't already have a definition with a boolean indicating their presence.protected BindinggetBinding()protected java.lang.StringgetSql()Returns the un-translated SQL used to create this statement.(package private) java.sql.PreparedStatementinternalExecute()(package private) <T> RowMapper<T>mapperForType(java.lang.Class<T> type)(package private) RowMapper<?>mapperForType(java.lang.reflect.Type type)(package private) <T> RowMapper<T>mapperForType(GenericType<T> type)(package private) ParsedSqlparseSql()ThissetQueryTimeout(int seconds)Set the query timeout, in seconds, on the prepared statement.java.lang.StringtoString()-
Methods inherited from class org.jdbi.v3.core.statement.BaseStatement
addCustomizers, attachToHandleForCleanup, callCustomizers, cleanUpForException, close, equals, getConfig, getContext, getHandle, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jdbi.v3.core.config.Configurable
addCustomizer, configure, define, getConfig, registerArgument, registerArgument, registerArrayType, registerArrayType, registerArrayType, registerArrayType, registerCodecFactory, registerCollector, registerCollector, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerExtension, registerRowMapper, registerRowMapper, registerRowMapper, registerRowMapper, setMapKeyColumn, setMapValueColumn, setSqlArrayArgumentStrategy, setSqlLogger, setSqlParser, setTemplateEngine, setTimingCollector
-
-
-
-
Constructor Detail
-
SqlStatement
SqlStatement(Handle handle, java.lang.CharSequence sql)
-
-
Method Detail
-
getBinding
protected Binding getBinding()
-
getSql
protected java.lang.String getSql()
Returns the un-translated SQL used to create this statement.- Returns:
- the un-translated SQL used to create this statement.
-
setQueryTimeout
public This setQueryTimeout(int seconds)
Set the query timeout, in seconds, on the prepared statement.- Parameters:
seconds- number of seconds before timing out- Returns:
- the same Query instance
-
cleanupHandleCommit
public This cleanupHandleCommit()
Transfer ownership of the handle to the statement: when the statement is closed, commit the handle's transaction (if one exists) and close the handle.- Returns:
- this
-
cleanupHandleRollback
public This cleanupHandleRollback()
When the statement is closed, roll it back then close the owning Handle.- Returns:
- this
-
bind
public This bind(int position, Argument argument)
Used if you need to have some exotic parameter bound.- Parameters:
position- position to bindBinaryStream this argument, starting at 0argument- exotic argument factory- Returns:
- the same Query instance
-
bind
public This bind(java.lang.String name, Argument argument)
Used if you need to have some exotic parameter bound.- Parameters:
name- name to bindBinaryStream this argumentargument- exotic argument factory- Returns:
- the same Query instance
-
bindBean
public This bindBean(java.lang.Object bean)
Binds named parameters from JavaBean properties on the argument.- Parameters:
bean- source of named parameter values to use as arguments- Returns:
- modified statement
-
bindBean
public This bindBean(java.lang.String prefix, java.lang.Object bean)
Binds named parameters from JavaBean properties on the bean argument, with the given prefix. Example: the prefixfooapplied to a bean propertybarwill be bound asfoo.bar.- Parameters:
prefix- a prefix to apply to all property names.bean- source of named parameter values to use as arguments- Returns:
- modified statement
-
bindPojo
@Beta public This bindPojo(java.lang.Object pojo)
Binds named parameters from object properties on the argument. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
pojo- source of named parameter values to use as arguments- Returns:
- modified statement
- See Also:
an example method of registering a type
-
bindPojo
@Beta public This bindPojo(java.lang.String prefix, java.lang.Object pojo)
Binds named parameters from object properties on the bean argument, with the given prefix. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
prefix- a prefix to apply to all property names.pojo- source of named parameter values to use as arguments- Returns:
- modified statement
- See Also:
an example method of registering a type
-
bindPojo
@Beta public This bindPojo(java.lang.Object pojo, java.lang.reflect.Type type)
Binds named parameters from object properties on the argument. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
pojo- source of named parameter values to use as argumentstype- the static, possibly generic type of the pojo- Returns:
- modified statement
- See Also:
an example method of registering a type
-
bindPojo
@Beta public This bindPojo(java.lang.String prefix, java.lang.Object pojo, java.lang.reflect.Type type)
Binds named parameters from object properties on the bean argument, with the given prefix. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
prefix- a prefix to apply to all property names.pojo- source of named parameter values to use as argumentstype- the static, possibly generic type of the pojo- Returns:
- modified statement
- See Also:
an example method of registering a type
-
bindPojo
@Beta public This bindPojo(java.lang.Object pojo, GenericType<?> type)
Binds named parameters from object properties on the argument. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
pojo- source of named parameter values to use as argumentstype- the static generic type of the pojo- Returns:
- modified statement
- See Also:
an example method of registering a type
-
bindPojo
@Beta public This bindPojo(java.lang.String prefix, java.lang.Object pojo, GenericType<?> type)
Binds named parameters from object properties on the bean argument, with the given prefix. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
prefix- a prefix to apply to all property names.pojo- source of named parameter values to use as argumentstype- the static generic type of the pojo- Returns:
- modified statement
- See Also:
an example method of registering a type
-
bindFields
public This bindFields(java.lang.Object object)
Binds public fields of the specified object as arguments for the query.- Parameters:
object- source of the public fields to bind.- Returns:
- modified statement
-
bindFields
public This bindFields(java.lang.String prefix, java.lang.Object object)
Binds public fields of the specified object as arguments for the query.- Parameters:
prefix- a prefix to apply to all field names.object- source of the public fields to bind.- Returns:
- modified statement
-
bindMethods
public This bindMethods(java.lang.Object object)
Binds methods with no parameters on the argument.- Parameters:
object- source of methods to use as arguments- Returns:
- modified statement
-
bindMethods
public This bindMethods(java.lang.String prefix, java.lang.Object object)
Binds methods with no parameters on the argument, with the given prefix.- Parameters:
prefix- a prefix to apply to all property names.object- source of methods to use as arguments- Returns:
- modified statement
-
bindMap
public This bindMap(java.util.Map<java.lang.String,?> map)
Binds named parameters from a map of String to Object instances- Parameters:
map- map where keys are matched to named parameters in order to bind arguments. Can be null, in which case the binding has no effect.- Returns:
- modified statement
-
bindNamedArgumentFinder
public This bindNamedArgumentFinder(NamedArgumentFinder namedArgumentFinder)
Binds a newNamedArgumentFinder.- Parameters:
namedArgumentFinder- A NamedArgumentFinder to bind. Can be null.- Returns:
- the same Query instance
-
bindNamedArgumentFinder
This bindNamedArgumentFinder(NamedArgumentFinderFactory factory, java.lang.String prefix, java.lang.Object value, java.lang.reflect.Type type, java.util.function.Supplier<NamedArgumentFinder> namedArgumentFinder)
-
bind
public final This bind(int position, java.lang.Character value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Character value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.String value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.String value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bindNVarchar
public final This bindNVarchar(int position, java.lang.String value)
Bind aStringargument positionally, asNVARCHARtype.- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bindNVarchar
public final This bindNVarchar(java.lang.String name, java.lang.String value)
Bind aStringargument by name, asNVARCHARtype.- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, int value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.Integer value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, int value)
Bind an argument by name- Parameters:
name- name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Integer value)
Bind an argument by name- Parameters:
name- name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, char value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, char value)
Bind an argument by name- Parameters:
name- name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bindASCIIStream
public final This bindASCIIStream(int position, java.io.InputStream value, int length)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bindlength- how long is the stream being bound?- Returns:
- the same Query instance
-
bindASCIIStream
public final This bindASCIIStream(java.lang.String name, java.io.InputStream value, int length)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bindlength- bytes to read from value- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.math.BigDecimal value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.math.BigDecimal value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bindBinaryStream
public final This bindBinaryStream(int position, java.io.InputStream value, int length)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bindlength- the number of bytes in the stream.- Returns:
- the same Query instance
-
bindBinaryStream
public final This bindBinaryStream(java.lang.String name, java.io.InputStream value, int length)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bindlength- bytes to read from value- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.sql.Blob value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.sql.Blob value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, boolean value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.Boolean value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
private This bind(int position, java.lang.Class<?> type, java.lang.Object value)
-
bind
private This bind(java.lang.String name, java.lang.Class<?> type, java.lang.Object value)
-
bind
public final This bind(java.lang.String name, boolean value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Boolean value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, byte value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.Byte value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, byte value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Byte value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, byte[] value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, byte[] value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.io.Reader value, int length)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bindlength- number of characters to read- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.io.Reader value, int length)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bindlength- number of characters to read- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.sql.Clob value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.sql.Clob value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.sql.Date value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.sql.Date value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.util.Date value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.util.Date value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, double value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.Double value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, double value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Double value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, float value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.Float value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, float value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Float value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, long value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.Long value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, long value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Long value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.Short value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, short value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, short value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Short value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.lang.Object value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.lang.Object value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.sql.Time value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.sql.Time value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.sql.Timestamp value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.sql.Timestamp value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.net.URL value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.net.URL value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.net.URI value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.net.URI value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
public final This bind(int position, java.util.UUID value)
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
public final This bind(java.lang.String name, java.util.UUID value)
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bindByType
public final This bindByType(int position, java.lang.Object value, java.lang.reflect.Type argumentType)
Bind an argument dynamically by the type passed in.- Parameters:
position- position to bind the parameter at, starting at 0value- to bindargumentType- type for value argument- Returns:
- the same Query instance
-
bindByType
public final This bindByType(int position, java.lang.Object value, GenericType<?> argumentType)
Bind an argument dynamically by the generic type passed in.- Parameters:
position- position to bind the parameter at, starting at 0value- to bindargumentType- type token for value argument- Returns:
- the same Query instance
-
bindByType
public final This bindByType(int position, java.lang.Object value, QualifiedType<?> argumentType)
Bind an argument dynamically by the qualified type passed in.- Parameters:
position- position to bind the parameter at, starting at 0value- to bindargumentType- type token for value argument- Returns:
- the same Query instance
-
bindByType
public final This bindByType(java.lang.String name, java.lang.Object value, java.lang.reflect.Type argumentType)
Bind an argument dynamically by the type passed in.- Parameters:
name- token name to bind the parameter tovalue- to bindargumentType- type for value argument- Returns:
- the same Query instance
-
bindByType
public final This bindByType(java.lang.String name, java.lang.Object value, GenericType<?> argumentType)
Bind an argument dynamically by the generic type passed in.- Parameters:
name- token name to bind the parameter tovalue- to bindargumentType- type token for value argument- Returns:
- the same Query instance
-
bindByType
public final This bindByType(java.lang.String name, java.lang.Object value, QualifiedType<?> argumentType)
Bind an argument dynamically by the type passed in.- Parameters:
name- token name to bind the parameter tovalue- to bindargumentType- type for value argument- Returns:
- the same Query instance
-
bindArray
@SafeVarargs public final <T> This bindArray(java.lang.String name, T... array)
Bind a Java array as a SQL array. Usually you can justbind(int, Object)an array, but this method allows varargs.- Type Parameters:
T- the array element type- Parameters:
name- the name of the parameter to bindarray- the array to bind- Returns:
- this Query
-
bindArray
@SafeVarargs public final <T> This bindArray(int pos, T... array)
Bind a Java array as a SQL array. Usually you can justbind(int, Object)an array, but this method allows varargs.- Type Parameters:
T- the array element type- Parameters:
pos- the position of the parameter to bindarray- the array to bind- Returns:
- this Query
-
bindArray
public final This bindArray(java.lang.String name, java.lang.reflect.Type elementType, java.lang.Object... array)
Bind a Java array as a SQL array, casting each element to a new type.- Parameters:
name- the name of the parameter to bindelementType- the array element typearray- the array to bind- Returns:
- this Query
-
bindArray
public final This bindArray(int pos, java.lang.reflect.Type elementType, java.lang.Object... array)
Bind a Java array as a SQL array, casting each element to a new type.- Parameters:
pos- the position of the parameter to bindelementType- the array element typearray- the array to bind- Returns:
- this Query
-
bindArray
public final This bindArray(java.lang.String name, java.lang.reflect.Type elementType, java.lang.Iterable<?> iterable)
Bind an Iterable as a SQL array.- Parameters:
name- the name of the parameter to bindelementType- the element type of the Iterableiterable- the iterable to bind as an array- Returns:
- this Query
-
bindArray
public final This bindArray(int pos, java.lang.reflect.Type elementType, java.lang.Iterable<?> iterable)
Bind an Iterable as a SQL array.- Parameters:
pos- the position of the parameter to bindelementType- the element type of the Iterableiterable- the iterable to bind as an array- Returns:
- this Query
-
bindArray
public final This bindArray(java.lang.String name, java.lang.reflect.Type elementType, java.util.Iterator<?> iterator)
Bind an Iterator as a SQL array.- Parameters:
name- the name of the parameter to bindelementType- the element type of the Iterableiterator- the iterator to bind as an array- Returns:
- this Query
-
bindArray
public final This bindArray(int pos, java.lang.reflect.Type elementType, java.util.Iterator<?> iterator)
Bind an Iterator as a SQL array.- Parameters:
pos- the position of the parameter to bindelementType- the element type of the Iteratoriterator- the Iterator to bind as an array- Returns:
- this Query
-
bindNull
public final This bindNull(java.lang.String name, int sqlType)
Bind NULL to be set for a given argument.- Parameters:
name- Named parameter to bind tosqlType- The sqlType must be set and is a value fromjava.sql.Types- Returns:
- the same statement instance
-
bindNull
public final This bindNull(int position, int sqlType)
Bind NULL to be set for a given argument.- Parameters:
position- position to bind NULL to, starting at 0sqlType- The sqlType must be set and is a value fromjava.sql.Types- Returns:
- the same statement instance
-
bindBySqlType
public final This bindBySqlType(java.lang.String name, java.lang.Object value, int sqlType)
Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)- Parameters:
name- Named parameter to bind atvalue- Value to bindsqlType- The sqlType from java.sql.Types- Returns:
- self
-
bindBySqlType
public final This bindBySqlType(int position, java.lang.Object value, int sqlType)
Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)- Parameters:
position- position to bind NULL to, starting at 0value- Value to bindsqlType- The sqlType from java.sql.Types- Returns:
- self
-
bindList
public final This bindList(java.lang.String key, java.lang.Object... values)
- Parameters:
key- attribute namevalues- vararg values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the vararg array is empty.- See Also:
bindList(BiConsumer, String, List)
-
bindList
public final This bindList(java.util.function.BiConsumer<SqlStatement,java.lang.String> onEmpty, java.lang.String key, java.lang.Object... values)
- Parameters:
onEmpty- handler for null/empty vararg arraykey- attribute namevalues- vararg values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the vararg array is empty.- See Also:
EmptyHandling,bindList(BiConsumer, String, List)
-
bindList
public final This bindList(java.lang.String key, java.lang.Iterable<?> values)
- Parameters:
key- attribute namevalues- iterable values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the iterable is empty.- See Also:
bindList(BiConsumer, String, List)
-
bindList
public final This bindList(java.util.function.BiConsumer<SqlStatement,java.lang.String> onEmpty, java.lang.String key, java.lang.Iterable<?> values)
- Parameters:
onEmpty- handler for null/empty listkey- attribute namevalues- iterable values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the iterable is empty.- See Also:
EmptyHandling,bindList(BiConsumer, String, List)
-
bindList
public final This bindList(java.lang.String key, java.util.Iterator<?> values)
- Parameters:
key- attribute namevalues- iterator of values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the iterator is empty.- See Also:
bindList(BiConsumer, String, List)
-
bindList
public final This bindList(java.util.function.BiConsumer<SqlStatement,java.lang.String> onEmpty, java.lang.String key, java.util.Iterator<?> values)
- Parameters:
onEmpty- handler for null/empty listkey- attribute namevalues- iterator of values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the iterator is empty.- See Also:
EmptyHandling,bindList(BiConsumer, String, List)
-
bindList
public final This bindList(java.util.function.BiConsumer<SqlStatement,java.lang.String> onEmpty, java.lang.String key, java.util.List<?> values)
Bind a parameter for each value in the given list, and defines an attribute as the comma-separated list of parameter references (using colon prefix).Examples:
List<String> columnNames = Arrays.asList("id", "name", "created_on"); List<Object> values = Arrays.asList(1, "Alice", LocalDate.now()); handle.createUpdate("insert into things (<columnNames>) values (<values>)") .defineList("columnNames", columnNames) .bindList("values", values) .execute(); List<Integer> ids = Arrays.asList(1, 2, 3); List<Thing> things = handle.createQuery("select * from things where id in (<ids>)") .bindList("ids", ids) .mapTo(Contact.class) .list();Note that using this method modifies the SQL statement by using a defined attribute. This is problematic when usingHandle.prepareBatch(String)or thePreparedBatchSQL operation as those evaluate the SQL statement only once. When binding lists of different size, the number of placeholders will not match the number of elements in the list which will lead to errors.- Parameters:
onEmpty- handler for null/empty listkey- attribute namevalues- list of values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the list is empty.- See Also:
EmptyHandling
-
bindBeanList
public final This bindBeanList(java.lang.String key, java.util.List<?> values, java.util.List<java.lang.String> propertyNames)
Bind a parameter for each value in the given list * number of property names, and defines an attribute as the comma-separated list of parameter references (using colon prefix). Used to create query similar to: select * from things where (id, foo) in ((1,'abc'),(2,'def'),(3,'ghi'))Examples:
List<ThingKey> thingKeys = ... List<Thing> things = handle.createQuery("select * from things where (id, foo) in (<thingKeys>)") .bindBeanList("thingKeys", thingKeys, Arrays.asList("id", "foo")) .mapTo(Contact.class) .list();- Parameters:
key- attribute namevalues- list of values that will be comma-spliced into the defined attribute value.propertyNames- list of properties that will be invoked on the values.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the list of values or properties is empty.UnableToCreateStatementException- If a property can't be found on an value or we can't find a Argument for it.- See Also:
bindList(BiConsumer, String, List)
-
bindMethodsList
public final This bindMethodsList(java.lang.String key, java.lang.Iterable<?> values, java.util.List<java.lang.String> methodNames)
For each value given, create a tuple by invoking each given method in order, and bind the tuple into aVALUES (...)format insert clause.- Parameters:
key- attribute namevalues- list of values that will be comma-spliced into the defined attribute valuemethodNames- list of methods that will be invoked on the values- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the list of values or properties is empty.UnableToCreateStatementException- if the method cannot be found- See Also:
bindList(BiConsumer, String, List)
-
defineList
public final This defineList(java.lang.String key, java.lang.Object... values)
Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.Examples:
handle.createUpdate("insert into things (<columnNames>) values (<values>)") .defineList("columnNames", "id", "name", "created_on") .bindList("values", 1, "Alice", LocalDate.now()) .execute(); List<Thing> things = handle.createQuery("select <columnNames> from things") .bindList("columnNames", "id", "name", "created_on") .mapTo(Contact.class) .list();- Parameters:
key- attribute namevalues- vararg values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the vararg array is empty, or contains any null elements.
-
defineList
public final This defineList(java.lang.String key, java.util.List<?> values)
Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.Examples:
List<String> columnNames = Arrays.asList("id", "name", "created_on"); List<Object> values = Arrays.asList(1, "Alice", LocalDate.now()); handle.createUpdate("insert into things (<columnNames>) values (<values>)") .defineList("columnNames", columnNames) .bindList("values", 1, values) .execute(); List<String> columnNames = Arrays.asList("id", "name", "created_on"); List<Thing> things = handle.createQuery("select <columnNames> from things") .bindList("columnNames", columnNames) .mapTo(Contact.class) .list();- Parameters:
key- attribute namevalues- list of values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if the list is empty, or contains any null elements.
-
defineNamedBindings
@Beta public This defineNamedBindings()
Define all bound arguments that don't already have a definition with a boolean indicating their presence. Useful to easily template optional properties of pojos or beans like<if(property)>property = :property<endif>.- Returns:
- this
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
internalExecute
java.sql.PreparedStatement internalExecute()
-
createStatement
java.sql.PreparedStatement createStatement(java.lang.String parsedSql) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
cleanupStatement
void cleanupStatement(java.sql.PreparedStatement statement) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
parseSql
ParsedSql parseSql()
-
mapperForType
<T> RowMapper<T> mapperForType(java.lang.Class<T> type)
-
mapperForType
<T> RowMapper<T> mapperForType(GenericType<T> type)
-
mapperForType
RowMapper<?> mapperForType(java.lang.reflect.Type type)
-
beforeTemplating
void beforeTemplating()
-
beforeBinding
void beforeBinding()
-
beforeExecution
void beforeExecution()
-
afterExecution
void afterExecution()
-
-