Class SqlStatement<This extends 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 between Query and Update. It defines most of the argument binding functions used by its subclasses.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String sql  
      (package private) java.sql.PreparedStatement stmt  
    • 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) void afterExecution()  
      (package private) void beforeBinding()  
      (package private) void beforeExecution()  
      (package private) void beforeTemplating()  
      This bind​(int position, boolean value)
      Bind an argument positionally
      This bind​(int position, byte value)
      Bind an argument positionally
      This bind​(int position, byte[] value)
      Bind an argument positionally
      This bind​(int position, char value)
      Bind an argument positionally
      This bind​(int position, double value)
      Bind an argument positionally
      This bind​(int position, float value)
      Bind an argument positionally
      This bind​(int position, int value)
      Bind an argument positionally
      This bind​(int position, long value)
      Bind an argument positionally
      This bind​(int position, short value)
      Bind an argument positionally
      This bind​(int position, java.io.Reader value, int length)
      Bind an argument positionally
      This bind​(int position, java.lang.Boolean value)
      Bind an argument positionally
      This bind​(int position, java.lang.Byte value)
      Bind an argument positionally
      This bind​(int position, java.lang.Character value)
      Bind an argument positionally
      private This bind​(int position, java.lang.Class<?> type, java.lang.Object value)  
      This bind​(int position, java.lang.Double value)
      Bind an argument positionally
      This bind​(int position, java.lang.Float value)
      Bind an argument positionally
      This bind​(int position, java.lang.Integer value)
      Bind an argument positionally
      This bind​(int position, java.lang.Long value)
      Bind an argument positionally
      This bind​(int position, java.lang.Object value)
      Bind an argument positionally
      This bind​(int position, java.lang.Short value)
      Bind an argument positionally
      This bind​(int position, java.lang.String value)
      Bind an argument positionally
      This bind​(int position, java.math.BigDecimal value)
      Bind an argument positionally
      This bind​(int position, java.net.URI value)
      Bind an argument positionally
      This bind​(int position, java.net.URL value)
      Bind an argument positionally
      This bind​(int position, java.sql.Blob value)
      Bind an argument positionally
      This bind​(int position, java.sql.Clob value)
      Bind an argument positionally
      This bind​(int position, java.sql.Date value)
      Bind an argument positionally
      This bind​(int position, java.sql.Time value)
      Bind an argument positionally
      This bind​(int position, java.sql.Timestamp value)
      Bind an argument positionally
      This bind​(int position, java.util.Date value)
      Bind an argument positionally
      This bind​(int position, java.util.UUID value)
      Bind an argument positionally
      This bind​(int position, Argument argument)
      Used if you need to have some exotic parameter bound.
      This bind​(java.lang.String name, boolean value)
      Bind an argument by name
      This bind​(java.lang.String name, byte value)
      Bind an argument by name
      This bind​(java.lang.String name, byte[] value)
      Bind an argument by name
      This bind​(java.lang.String name, char value)
      Bind an argument by name
      This bind​(java.lang.String name, double value)
      Bind an argument by name
      This bind​(java.lang.String name, float value)
      Bind an argument by name
      This bind​(java.lang.String name, int value)
      Bind an argument by name
      This bind​(java.lang.String name, long value)
      Bind an argument by name
      This bind​(java.lang.String name, short value)
      Bind an argument by name
      This bind​(java.lang.String name, java.io.Reader value, int length)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.Boolean value)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.Byte value)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.Character value)
      Bind an argument by name
      private This bind​(java.lang.String name, java.lang.Class<?> type, java.lang.Object value)  
      This bind​(java.lang.String name, java.lang.Double value)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.Float value)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.Integer value)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.Long value)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.Object value)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.Short value)
      Bind an argument by name
      This bind​(java.lang.String name, java.lang.String value)
      Bind an argument by name
      This bind​(java.lang.String name, java.math.BigDecimal value)
      Bind an argument by name
      This bind​(java.lang.String name, java.net.URI value)
      Bind an argument by name
      This bind​(java.lang.String name, java.net.URL value)
      Bind an argument by name
      This bind​(java.lang.String name, java.sql.Blob value)
      Bind an argument by name
      This bind​(java.lang.String name, java.sql.Clob value)
      Bind an argument by name
      This bind​(java.lang.String name, java.sql.Date value)
      Bind an argument by name
      This bind​(java.lang.String name, java.sql.Time value)
      Bind an argument by name
      This bind​(java.lang.String name, java.sql.Timestamp value)
      Bind an argument by name
      This bind​(java.lang.String name, java.util.Date value)
      Bind an argument by name
      This bind​(java.lang.String name, java.util.UUID value)
      Bind an argument by name
      This bind​(java.lang.String name, Argument argument)
      Used if you need to have some exotic parameter bound.
      This bindArray​(int pos, java.lang.reflect.Type elementType, java.lang.Iterable<?> iterable)
      Bind an Iterable as a SQL array.
      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.
      This bindArray​(int pos, java.lang.reflect.Type elementType, java.util.Iterator<?> iterator)
      Bind an Iterator as a SQL array.
      <T> This bindArray​(int pos, T... array)
      Bind a Java array as a SQL array.
      This bindArray​(java.lang.String name, java.lang.reflect.Type elementType, java.lang.Iterable<?> iterable)
      Bind an Iterable as a SQL array.
      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.
      This bindArray​(java.lang.String name, java.lang.reflect.Type elementType, java.util.Iterator<?> iterator)
      Bind an Iterator as a SQL array.
      <T> This bindArray​(java.lang.String name, T... array)
      Bind a Java array as a SQL array.
      This bindASCIIStream​(int position, java.io.InputStream value, int length)
      Bind an argument positionally
      This bindASCIIStream​(java.lang.String name, java.io.InputStream value, int length)
      Bind an argument by name
      This bindBean​(java.lang.Object bean)
      Binds named parameters from JavaBean properties on the argument.
      This bindBean​(java.lang.String prefix, java.lang.Object bean)
      Binds named parameters from JavaBean properties on the bean argument, with the given prefix.
      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).
      This bindBinaryStream​(int position, java.io.InputStream value, int length)
      Bind an argument positionally
      This bindBinaryStream​(java.lang.String name, java.io.InputStream value, int length)
      Bind an argument by name
      This bindBySqlType​(int position, java.lang.Object value, int sqlType)
      Bind a value using a specific type from java.sql.Types via PreparedStatement#setObject(int, Object, int)
      This bindBySqlType​(java.lang.String name, java.lang.Object value, int sqlType)
      Bind a value using a specific type from java.sql.Types via PreparedStatement#setObject(int, Object, int)
      This bindByType​(int position, java.lang.Object value, java.lang.reflect.Type argumentType)
      Bind an argument dynamically by the type passed in.
      This bindByType​(int position, java.lang.Object value, GenericType<?> argumentType)
      Bind an argument dynamically by the generic type passed in.
      This bindByType​(int position, java.lang.Object value, QualifiedType<?> argumentType)
      Bind an argument dynamically by the qualified type passed in.
      This bindByType​(java.lang.String name, java.lang.Object value, java.lang.reflect.Type argumentType)
      Bind an argument dynamically by the type passed in.
      This bindByType​(java.lang.String name, java.lang.Object value, GenericType<?> argumentType)
      Bind an argument dynamically by the generic type passed in.
      This bindByType​(java.lang.String name, java.lang.Object value, QualifiedType<?> argumentType)
      Bind an argument dynamically by the type passed in.
      This bindFields​(java.lang.Object object)
      Binds public fields of the specified object as arguments for the query.
      This bindFields​(java.lang.String prefix, java.lang.Object object)
      Binds public fields of the specified object as arguments for the query.
      This bindList​(java.lang.String key, java.lang.Iterable<?> values)
      This bindList​(java.lang.String key, java.lang.Object... values)
      This bindList​(java.lang.String key, java.util.Iterator<?> values)
      This bindList​(java.util.function.BiConsumer<SqlStatement,​java.lang.String> onEmpty, java.lang.String key, java.lang.Iterable<?> values)
      This bindList​(java.util.function.BiConsumer<SqlStatement,​java.lang.String> onEmpty, java.lang.String key, java.lang.Object... values)
      This bindList​(java.util.function.BiConsumer<SqlStatement,​java.lang.String> onEmpty, java.lang.String key, java.util.Iterator<?> values)
      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).
      This bindMap​(java.util.Map<java.lang.String,​?> map)
      Binds named parameters from a map of String to Object instances
      This bindMethods​(java.lang.Object object)
      Binds methods with no parameters on the argument.
      This bindMethods​(java.lang.String prefix, java.lang.Object object)
      Binds methods with no parameters on the argument, with the given prefix.
      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 a VALUES (...) format insert clause.
      (package private) This bindNamedArgumentFinder​(NamedArgumentFinderFactory factory, java.lang.String prefix, java.lang.Object value, java.lang.reflect.Type type, java.util.function.Supplier<NamedArgumentFinder> namedArgumentFinder)  
      This bindNamedArgumentFinder​(NamedArgumentFinder namedArgumentFinder)
      Binds a new NamedArgumentFinder.
      This bindNull​(int position, int sqlType)
      Bind NULL to be set for a given argument.
      This bindNull​(java.lang.String name, int sqlType)
      Bind NULL to be set for a given argument.
      This bindNVarchar​(int position, java.lang.String value)
      Bind a String argument positionally, as NVARCHAR type.
      This bindNVarchar​(java.lang.String name, java.lang.String value)
      Bind a String argument by name, as NVARCHAR type.
      This bindPojo​(java.lang.Object pojo)
      Binds named parameters from object properties on the argument.
      This bindPojo​(java.lang.Object pojo, java.lang.reflect.Type type)
      Binds named parameters from object properties on the argument.
      This bindPojo​(java.lang.Object pojo, GenericType<?> type)
      Binds named parameters from object properties on the argument.
      This bindPojo​(java.lang.String prefix, java.lang.Object pojo)
      Binds named parameters from object properties on the bean argument, with the given prefix.
      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.
      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.
      private This cleanupHandle​(java.util.function.Consumer<Handle> action)  
      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.
      This cleanupHandleRollback()
      When the statement is closed, roll it back then close the owning Handle.
      (package private) void cleanupStatement​(java.sql.PreparedStatement statement)  
      (package private) java.sql.PreparedStatement createStatement​(java.lang.String parsedSql)  
      This defineList​(java.lang.String key, java.lang.Object... values)
      Define an attribute as the comma-separated String from the elements of the values argument.
      This defineList​(java.lang.String key, java.util.List<?> values)
      Define an attribute as the comma-separated String from the elements of the values argument.
      This defineNamedBindings()
      Define all bound arguments that don't already have a definition with a boolean indicating their presence.
      protected Binding getBinding()  
      protected java.lang.String getSql()
      Returns the un-translated SQL used to create this statement.
      (package private) java.sql.PreparedStatement internalExecute()  
      (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) ParsedSql parseSql()  
      This setQueryTimeout​(int seconds)
      Set the query timeout, in seconds, on the prepared statement.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • sql

        private final java.lang.String sql
      • stmt

        java.sql.PreparedStatement stmt
    • 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
      • cleanupHandle

        private This cleanupHandle​(java.util.function.Consumer<Handle> action)
      • 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 0
        argument - 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 argument
        argument - 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 prefix foo applied to a bean property bar will be bound as foo.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 arguments
        type - 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 arguments
        type - 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 arguments
        type - 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 arguments
        type - 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 new NamedArgumentFinder.
        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 0
        value - 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 to
        value - 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 0
        value - 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 to
        value - to bind
        Returns:
        the same Query instance
      • bindNVarchar

        public final This bindNVarchar​(int position,
                                       java.lang.String value)
        Bind a String argument positionally, as NVARCHAR type.
        Parameters:
        position - position to bind the parameter at, starting at 0
        value - to bind
        Returns:
        the same Query instance
      • bindNVarchar

        public final This bindNVarchar​(java.lang.String name,
                                       java.lang.String value)
        Bind a String argument by name, as NVARCHAR type.
        Parameters:
        name - token name to bind the parameter to
        value - 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 0
        value - 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 0
        value - 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 to
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - to bind
        length - 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 to
        value - to bind
        length - 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 0
        value - 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 to
        value - 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 0
        value - to bind
        length - 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 to
        value - to bind
        length - 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 0
        value - 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 to
        value - 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 0
        value - 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 0
        value - 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 to
        value - 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 to
        value - 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 0
        value - 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 0
        value - 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 to
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - to bind
        length - 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 to
        value - to bind
        length - 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 0
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - 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 0
        value - 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 to
        value - 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 to
        value - 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 0
        value - 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 0
        value - 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 to
        value - 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 to
        value - 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 0
        value - 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 0
        value - 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 to
        value - 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 to
        value - 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 0
        value - 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 0
        value - 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 to
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - 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 to
        value - 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 0
        value - to bind
        argumentType - 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 0
        value - to bind
        argumentType - 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 0
        value - to bind
        argumentType - 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 to
        value - to bind
        argumentType - 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 to
        value - to bind
        argumentType - 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 to
        value - to bind
        argumentType - 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 just bind(int, Object) an array, but this method allows varargs.
        Type Parameters:
        T - the array element type
        Parameters:
        name - the name of the parameter to bind
        array - 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 just bind(int, Object) an array, but this method allows varargs.
        Type Parameters:
        T - the array element type
        Parameters:
        pos - the position of the parameter to bind
        array - 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 bind
        elementType - the array element type
        array - 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 bind
        elementType - the array element type
        array - 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 bind
        elementType - the element type of the Iterable
        iterable - 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 bind
        elementType - the element type of the Iterable
        iterable - 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 bind
        elementType - the element type of the Iterable
        iterator - 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 bind
        elementType - the element type of the Iterator
        iterator - 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 to
        sqlType - The sqlType must be set and is a value from java.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 0
        sqlType - The sqlType must be set and is a value from java.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 from java.sql.Types via PreparedStatement#setObject(int, Object, int)
        Parameters:
        name - Named parameter to bind at
        value - Value to bind
        sqlType - 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 from java.sql.Types via PreparedStatement#setObject(int, Object, int)
        Parameters:
        position - position to bind NULL to, starting at 0
        value - Value to bind
        sqlType - The sqlType from java.sql.Types
        Returns:
        self
      • bindList

        public final This bindList​(java.lang.String key,
                                   java.lang.Object... values)
        Parameters:
        key - attribute name
        values - 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 array
        key - attribute name
        values - 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 name
        values - 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 list
        key - attribute name
        values - 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 name
        values - 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 list
        key - attribute name
        values - 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 using Handle.prepareBatch(String) or the PreparedBatch SQL 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 list
        key - attribute name
        values - 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 name
        values - 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 a VALUES (...) format insert clause.
        Parameters:
        key - attribute name
        values - list of values that will be comma-spliced into the defined attribute value
        methodNames - 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-separated String from the elements of the values argument.

        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 name
        values - 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-separated String from the elements of the values argument.

        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 name
        values - 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:
        toString in class java.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
      • mapperForType

        <T> RowMapper<T> mapperForType​(java.lang.Class<T> type)
      • mapperForType

        RowMapper<?> mapperForType​(java.lang.reflect.Type type)
      • beforeTemplating

        void beforeTemplating()
      • beforeBinding

        void beforeBinding()
      • beforeExecution

        void beforeExecution()
      • afterExecution

        void afterExecution()