Package org.dalesbred

Class Database


  • public final class Database
    extends java.lang.Object

    The main abstraction of the library: represents a configured connection to database and provides a way to execute callbacks in transactions.

    Usually you'll need only single instance of this in your application, unless you need to connect several different databases or need different default settings for different use cases.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T executeQuery​(@NotNull ResultSetProcessor<T> processor, @NotNull java.lang.String sql, java.lang.Object... args)
      Executes a query and processes the results with given ResultSetProcessor.
      <T> T executeQuery​(@NotNull ResultSetProcessor<T> processor, @NotNull SqlQuery query)
      Executes a query and processes the results with given ResultSetProcessor.
      <T> @NotNull java.util.List<T> findAll​(@NotNull java.lang.Class<T> cl, @NotNull java.lang.String sql, java.lang.Object... args)
      Executes a query and converts the results to instances of given class using default mechanisms.
      <T> @NotNull java.util.List<T> findAll​(@NotNull java.lang.Class<T> cl, @NotNull SqlQuery query)
      Executes a query and converts the results to instances of given class using default mechanisms.
      <T> @NotNull java.util.List<T> findAll​(@NotNull RowMapper<T> rowMapper, @NotNull java.lang.String sql, java.lang.Object... args)
      Executes a query and processes each row of the result with given RowMapper to produce a list of results.
      <T> @NotNull java.util.List<T> findAll​(@NotNull RowMapper<T> rowMapper, @NotNull SqlQuery query)
      Executes a query and processes each row of the result with given RowMapper to produce a list of results.
      <K,​V>
      @NotNull java.util.Map<K,​V>
      findMap​(@NotNull java.lang.Class<K> keyType, @NotNull java.lang.Class<V> valueType, @NotNull java.lang.String sql, java.lang.Object... args)
      Executes a query that returns at least two values and creates a map from the results, using the first value as the key and rest of the values for instantiating V.
      <K,​V>
      @NotNull java.util.Map<K,​V>
      findMap​(@NotNull java.lang.Class<K> keyType, @NotNull java.lang.Class<V> valueType, @NotNull SqlQuery query)
      Executes a query that returns at least two values and creates a map from the results, using the first value as the key and rest of the values for instantiating V.
      <T> @NotNull java.util.Optional<T> findOptional​(@NotNull java.lang.Class<T> cl, @NotNull java.lang.String sql, java.lang.Object... args)
      Finds a unique result from database, converting the database row to given class using default mechanisms.
      <T> @NotNull java.util.Optional<T> findOptional​(@NotNull java.lang.Class<T> cl, @NotNull SqlQuery query)
      Finds a unique result from database, converting the database row to given class using default mechanisms.
      <T> @NotNull java.util.Optional<T> findOptional​(@NotNull RowMapper<T> rowMapper, @NotNull java.lang.String sql, java.lang.Object... args)
      Find a unique result from database, using given RowMapper to convert row.
      <T> @NotNull java.util.Optional<T> findOptional​(@NotNull RowMapper<T> rowMapper, @NotNull SqlQuery query)
      Find a unique result from database, using given RowMapper to convert row.
      @NotNull java.util.OptionalDouble findOptionalDouble​(@NotNull java.lang.String sql, java.lang.Object... args)
      Finds a unique result from database, converting the database row to double using default mechanisms.
      @NotNull java.util.OptionalDouble findOptionalDouble​(@NotNull SqlQuery query)
      Finds a unique result from database, converting the database row to double using default mechanisms.
      @NotNull java.util.OptionalInt findOptionalInt​(@NotNull java.lang.String sql, java.lang.Object... args)
      Finds a unique result from database, converting the database row to int using default mechanisms.
      @NotNull java.util.OptionalInt findOptionalInt​(@NotNull SqlQuery query)
      Finds a unique result from database, converting the database row to int using default mechanisms.
      @NotNull java.util.OptionalLong findOptionalLong​(@NotNull java.lang.String sql, java.lang.Object... args)
      Finds a unique result from database, converting the database row to long using default mechanisms.
      @NotNull java.util.OptionalLong findOptionalLong​(@NotNull SqlQuery query)
      Finds a unique result from database, converting the database row to long using default mechanisms.
      @NotNull ResultTable findTable​(@NotNull java.lang.String sql, java.lang.Object... args)
      Executes a query and creates a ResultTable from the results.
      @NotNull ResultTable findTable​(@NotNull SqlQuery query)
      Executes a query and creates a ResultTable from the results.
      <T> T findUnique​(@NotNull java.lang.Class<T> cl, @NotNull java.lang.String sql, java.lang.Object... args)
      Finds a unique result from database, converting the database row to given class using default mechanisms.
      <T> T findUnique​(@NotNull java.lang.Class<T> cl, @NotNull SqlQuery query)
      Finds a unique result from database, converting the database row to given class using default mechanisms.
      <T> T findUnique​(@NotNull RowMapper<T> mapper, @NotNull java.lang.String sql, java.lang.Object... args)
      Finds a unique result from database, using given RowMapper to convert the row.
      <T> T findUnique​(@NotNull RowMapper<T> mapper, @NotNull SqlQuery query)
      Finds a unique result from database, using given RowMapper to convert the row.
      boolean findUniqueBoolean​(@NotNull java.lang.String sql, java.lang.Object... args)
      A convenience method for retrieving a single non-null boolean.
      boolean findUniqueBoolean​(@NotNull SqlQuery query)
      A convenience method for retrieving a single non-null boolean.
      int findUniqueInt​(@NotNull java.lang.String sql, java.lang.Object... args)
      A convenience method for retrieving a single non-null integer.
      int findUniqueInt​(@NotNull SqlQuery query)
      A convenience method for retrieving a single non-null integer.
      long findUniqueLong​(@NotNull java.lang.String sql, java.lang.Object... args)
      A convenience method for retrieving a single non-null long.
      long findUniqueLong​(@NotNull SqlQuery query)
      A convenience method for retrieving a single non-null long.
      <T> T findUniqueOrNull​(@NotNull java.lang.Class<T> cl, @NotNull java.lang.String sql, java.lang.Object... args)
      Alias for findOptional(cl, sql, args).orElse(null).
      <T> T findUniqueOrNull​(@NotNull java.lang.Class<T> cl, @NotNull SqlQuery query)
      Alias for findOptional(cl, query).orElse(null).
      <T> T findUniqueOrNull​(@NotNull RowMapper<T> rowMapper, @NotNull java.lang.String sql, java.lang.Object... args)
      Alias for {findUniqueOrNull(rowMapper, SqlQuery.query(sql, args))}.
      <T> T findUniqueOrNull​(@NotNull RowMapper<T> rowMapper, @NotNull SqlQuery query)
      Alias for findOptional(rowMapper, query).orElse(null).
      static @NotNull Database forDataSource​(@NotNull javax.sql.DataSource dataSource)
      Returns a new Database that uses given DataSource to retrieve connections.
      static @NotNull Database forJndiDataSource​(@NotNull java.lang.String jndiName)
      Returns a new Database that uses DataSource with given JNDI-name.
      static @NotNull Database forUrlAndCredentials​(@NotNull java.lang.String url, @Nullable java.lang.String username, @Nullable java.lang.String password)
      Returns a new Database that uses given connection options to open connection.
      @Nullable java.time.Duration getDefaultTimeout()
      If default timeout is set to non null (by default it's null) all queries will have this timeout value as default, unless is specified directly on SqlQuery or is set directly on JDBC Connection parameters.
      @NotNull TypeConversionRegistry getTypeConversionRegistry()
      Returns TypeConversionRegistry that can be used to register new type-conversions.
      boolean hasActiveTransaction()
      Returns true if and only if the current thread has an active transaction for this database.
      boolean isAllowImplicitTransactions()
      If flag is set to true (by default it's false) queries without active transaction will not throw exception but will start a fresh transaction.
      void setAllowImplicitTransactions​(boolean allowImplicitTransactions)
      If flag is set to true (by default it's false) queries without active transaction will not throw exception but will start a fresh transaction.
      void setDefaultTimeout​(@NotNull java.time.Duration timeout)
      If default timeout is set to non null (by default it's null) all queries will have this timeout value as default, unless is specified directly on SqlQuery or is set directly on JDBC Connection parameters.
      @NotNull java.lang.String toString()
      Returns a string containing useful debug information about the state of this object.
      int update​(@NotNull java.lang.String sql, java.lang.Object... args)
      Executes an update against the database and returns the amount of affected rows.
      int update​(@NotNull SqlQuery query)
      Executes an update against the database and returns the amount of affected rows.
      <T> T updateAndProcessGeneratedKeys​(@NotNull ResultSetProcessor<T> generatedKeysProcessor, @NotNull java.util.List<java.lang.String> columnNames, @NotNull java.lang.String sql, java.lang.Object... args)  
      <T> T updateAndProcessGeneratedKeys​(@NotNull ResultSetProcessor<T> generatedKeysProcessor, @NotNull java.util.List<java.lang.String> columnNames, @NotNull SqlQuery query)
      Executes an update against the database and return generated keys as extracted by generatedKeysProcessor.
      int[] updateBatch​(@NotNull java.lang.String sql, @NotNull java.util.List<? extends java.util.List<?>> argumentLists)
      Executes a batch update against the database, returning an array of modification counts for each argument list.
      <T> T updateBatchAndProcessGeneratedKeys​(@NotNull ResultSetProcessor<T> generatedKeysProcessor, @NotNull java.util.List<java.lang.String> columnNames, @NotNull java.lang.String sql, @NotNull java.util.List<? extends java.util.List<?>> argumentLists)
      Executes batch of updates against the database and return generated keys as extracted by generatedKeysProcessor.
      void updateUnique​(@NotNull java.lang.String sql, java.lang.Object... args)
      Execute an update against the database and assert that a single row will be modified.
      void updateUnique​(@NotNull SqlQuery query)
      Execute an update against the database and assert that a single row will be modified.
      <T> T withTransaction​(@NotNull Isolation isolation, @NotNull TransactionCallback<T> callback)
      Executes a block of code with given isolation.
      <T> T withTransaction​(@NotNull Propagation propagation, @NotNull Isolation isolation, @NotNull TransactionCallback<T> callback)
      Executes a block of code with given propagation and isolation.
      <T> T withTransaction​(@NotNull Propagation propagation, @NotNull TransactionCallback<T> callback)
      Executes a block of code with given propagation and configuration default isolation.
      <T> T withTransaction​(@NotNull TransactionCallback<T> callback)
      Executes a block of code within a context of a transaction, using Propagation.REQUIRED propagation.
      <T> T withTransaction​(@NotNull TransactionSettings settings, @NotNull TransactionCallback<T> callback)
      Executes a block of code with given transaction settings.
      void withVoidTransaction​(@NotNull Isolation isolation, @NotNull VoidTransactionCallback callback)
      Executes a block of code with given isolation.
      void withVoidTransaction​(@NotNull Propagation propagation, @NotNull Isolation isolation, @NotNull VoidTransactionCallback callback)
      Executes a block of code with given propagation and isolation.
      void withVoidTransaction​(@NotNull Propagation propagation, @NotNull VoidTransactionCallback callback)
      Executes a block of code with given propagation and configuration default isolation.
      void withVoidTransaction​(@NotNull TransactionSettings settings, @NotNull VoidTransactionCallback callback)
      Executes a block of code with given transaction settings.
      void withVoidTransaction​(@NotNull VoidTransactionCallback callback)
      Executes a block of code within a context of a transaction, using Propagation.REQUIRED propagation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Database

        public Database​(@NotNull
                        @NotNull ConnectionProvider connectionProvider)
        Constructs a new Database that uses given ConnectionProvider and auto-detects the dialect to use.
      • Database

        public Database​(@NotNull
                        @NotNull TransactionManager transactionManager)
        Constructs a new Database that uses given TransactionManager and auto-detects the dialect to use.
      • Database

        public Database​(@NotNull
                        @NotNull javax.sql.DataSource dataSource)
        Constructs a new Database that uses given DataSource and auto-detects the dialect to use.
      • Database

        public Database​(@NotNull
                        @NotNull javax.sql.DataSource dataSource,
                        @NotNull
                        @NotNull Dialect dialect)
        Constructs a new Database that uses given DataSource and Dialect.
    • Method Detail

      • forDataSource

        @NotNull
        public static @NotNull Database forDataSource​(@NotNull
                                                      @NotNull javax.sql.DataSource dataSource)
        Returns a new Database that uses given DataSource to retrieve connections.
      • forJndiDataSource

        @NotNull
        public static @NotNull Database forJndiDataSource​(@NotNull
                                                          @NotNull java.lang.String jndiName)
        Returns a new Database that uses DataSource with given JNDI-name.
      • forUrlAndCredentials

        @NotNull
        public static @NotNull Database forUrlAndCredentials​(@NotNull
                                                             @NotNull java.lang.String url,
                                                             @Nullable
                                                             @Nullable java.lang.String username,
                                                             @Nullable
                                                             @Nullable java.lang.String password)
        Returns a new Database that uses given connection options to open connection. The database opens connections directly from DriverManager without performing connection pooling.
        See Also:
        DriverManagerConnectionProvider
      • withTransaction

        public <T> T withTransaction​(@NotNull
                                     @NotNull TransactionCallback<T> callback)
        Executes a block of code within a context of a transaction, using Propagation.REQUIRED propagation.
      • withTransaction

        public <T> T withTransaction​(@NotNull
                                     @NotNull Propagation propagation,
                                     @NotNull
                                     @NotNull TransactionCallback<T> callback)
        Executes a block of code with given propagation and configuration default isolation.
      • withTransaction

        public <T> T withTransaction​(@NotNull
                                     @NotNull Isolation isolation,
                                     @NotNull
                                     @NotNull TransactionCallback<T> callback)
        Executes a block of code with given isolation.
      • withTransaction

        public <T> T withTransaction​(@NotNull
                                     @NotNull Propagation propagation,
                                     @NotNull
                                     @NotNull Isolation isolation,
                                     @NotNull
                                     @NotNull TransactionCallback<T> callback)
        Executes a block of code with given propagation and isolation.
      • withVoidTransaction

        public void withVoidTransaction​(@NotNull
                                        @NotNull Propagation propagation,
                                        @NotNull
                                        @NotNull VoidTransactionCallback callback)
        Executes a block of code with given propagation and configuration default isolation.
      • withVoidTransaction

        public void withVoidTransaction​(@NotNull
                                        @NotNull Isolation isolation,
                                        @NotNull
                                        @NotNull VoidTransactionCallback callback)
        Executes a block of code with given isolation.
      • withVoidTransaction

        public void withVoidTransaction​(@NotNull
                                        @NotNull Propagation propagation,
                                        @NotNull
                                        @NotNull Isolation isolation,
                                        @NotNull
                                        @NotNull VoidTransactionCallback callback)
        Executes a block of code with given propagation and isolation.
      • hasActiveTransaction

        public boolean hasActiveTransaction()
        Returns true if and only if the current thread has an active transaction for this database.
      • executeQuery

        public <T> T executeQuery​(@NotNull
                                  @NotNull ResultSetProcessor<T> processor,
                                  @NotNull
                                  @NotNull SqlQuery query)
        Executes a query and processes the results with given ResultSetProcessor. All other findXXX-methods are just convenience methods for this one.
      • findAll

        @NotNull
        public <T> @NotNull java.util.List<T> findAll​(@NotNull
                                                      @NotNull RowMapper<T> rowMapper,
                                                      @NotNull
                                                      @NotNull SqlQuery query)
        Executes a query and processes each row of the result with given RowMapper to produce a list of results.
      • findAll

        @NotNull
        public <T> @NotNull java.util.List<T> findAll​(@NotNull
                                                      @NotNull RowMapper<T> rowMapper,
                                                      @NotNull
                                                      @NotNull java.lang.String sql,
                                                      java.lang.Object... args)
        Executes a query and processes each row of the result with given RowMapper to produce a list of results.
      • findAll

        @NotNull
        public <T> @NotNull java.util.List<T> findAll​(@NotNull
                                                      @NotNull java.lang.Class<T> cl,
                                                      @NotNull
                                                      @NotNull SqlQuery query)
        Executes a query and converts the results to instances of given class using default mechanisms.
      • findAll

        @NotNull
        public <T> @NotNull java.util.List<T> findAll​(@NotNull
                                                      @NotNull java.lang.Class<T> cl,
                                                      @NotNull
                                                      @NotNull java.lang.String sql,
                                                      java.lang.Object... args)
        Executes a query and converts the results to instances of given class using default mechanisms.
      • findUnique

        public <T> T findUnique​(@NotNull
                                @NotNull RowMapper<T> mapper,
                                @NotNull
                                @NotNull java.lang.String sql,
                                java.lang.Object... args)
        Finds a unique result from database, using given RowMapper to convert the row.
        Throws:
        NonUniqueResultException - if there is more then one row
        EmptyResultException - if there are no rows
      • findUnique

        public <T> T findUnique​(@NotNull
                                @NotNull java.lang.Class<T> cl,
                                @NotNull
                                @NotNull SqlQuery query)
        Finds a unique result from database, converting the database row to given class using default mechanisms.
        Throws:
        NonUniqueResultException - if there is more then one row
        EmptyResultException - if there are no rows
      • findUnique

        public <T> T findUnique​(@NotNull
                                @NotNull java.lang.Class<T> cl,
                                @NotNull
                                @NotNull java.lang.String sql,
                                java.lang.Object... args)
        Finds a unique result from database, converting the database row to given class using default mechanisms.
        Throws:
        NonUniqueResultException - if there is more then one row
        EmptyResultException - if there are no rows
      • findOptional

        @NotNull
        public <T> @NotNull java.util.Optional<T> findOptional​(@NotNull
                                                               @NotNull RowMapper<T> rowMapper,
                                                               @NotNull
                                                               @NotNull SqlQuery query)
        Find a unique result from database, using given RowMapper to convert row. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptional

        @NotNull
        public <T> @NotNull java.util.Optional<T> findOptional​(@NotNull
                                                               @NotNull RowMapper<T> rowMapper,
                                                               @NotNull
                                                               @NotNull java.lang.String sql,
                                                               java.lang.Object... args)
        Find a unique result from database, using given RowMapper to convert row. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptional

        @NotNull
        public <T> @NotNull java.util.Optional<T> findOptional​(@NotNull
                                                               @NotNull java.lang.Class<T> cl,
                                                               @NotNull
                                                               @NotNull SqlQuery query)
        Finds a unique result from database, converting the database row to given class using default mechanisms. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptional

        @NotNull
        public <T> @NotNull java.util.Optional<T> findOptional​(@NotNull
                                                               @NotNull java.lang.Class<T> cl,
                                                               @NotNull
                                                               @NotNull java.lang.String sql,
                                                               java.lang.Object... args)
        Finds a unique result from database, converting the database row to given class using default mechanisms. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptionalInt

        @NotNull
        public @NotNull java.util.OptionalInt findOptionalInt​(@NotNull
                                                              @NotNull java.lang.String sql,
                                                              java.lang.Object... args)
        Finds a unique result from database, converting the database row to int using default mechanisms. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptionalInt

        @NotNull
        public @NotNull java.util.OptionalInt findOptionalInt​(@NotNull
                                                              @NotNull SqlQuery query)
        Finds a unique result from database, converting the database row to int using default mechanisms. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptionalLong

        @NotNull
        public @NotNull java.util.OptionalLong findOptionalLong​(@NotNull
                                                                @NotNull java.lang.String sql,
                                                                java.lang.Object... args)
        Finds a unique result from database, converting the database row to long using default mechanisms. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptionalLong

        @NotNull
        public @NotNull java.util.OptionalLong findOptionalLong​(@NotNull
                                                                @NotNull SqlQuery query)
        Finds a unique result from database, converting the database row to long using default mechanisms. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptionalDouble

        @NotNull
        public @NotNull java.util.OptionalDouble findOptionalDouble​(@NotNull
                                                                    @NotNull java.lang.String sql,
                                                                    java.lang.Object... args)
        Finds a unique result from database, converting the database row to double using default mechanisms. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findOptionalDouble

        @NotNull
        public @NotNull java.util.OptionalDouble findOptionalDouble​(@NotNull
                                                                    @NotNull SqlQuery query)
        Finds a unique result from database, converting the database row to double using default mechanisms. Returns empty if there are no results or if single null result is returned.
        Throws:
        NonUniqueResultException - if there are multiple result rows
      • findUniqueOrNull

        @Nullable
        public <T> T findUniqueOrNull​(@NotNull
                                      @NotNull RowMapper<T> rowMapper,
                                      @NotNull
                                      @NotNull SqlQuery query)
        Alias for findOptional(rowMapper, query).orElse(null).
      • findUniqueOrNull

        @Nullable
        public <T> T findUniqueOrNull​(@NotNull
                                      @NotNull RowMapper<T> rowMapper,
                                      @NotNull
                                      @NotNull java.lang.String sql,
                                      java.lang.Object... args)
        Alias for {findUniqueOrNull(rowMapper, SqlQuery.query(sql, args))}.
      • findUniqueOrNull

        @Nullable
        public <T> T findUniqueOrNull​(@NotNull
                                      @NotNull java.lang.Class<T> cl,
                                      @NotNull
                                      @NotNull SqlQuery query)
        Alias for findOptional(cl, query).orElse(null).
      • findUniqueOrNull

        @Nullable
        public <T> T findUniqueOrNull​(@NotNull
                                      @NotNull java.lang.Class<T> cl,
                                      @NotNull
                                      @NotNull java.lang.String sql,
                                      java.lang.Object... args)
        Alias for findOptional(cl, sql, args).orElse(null).
      • findUniqueBoolean

        public boolean findUniqueBoolean​(@NotNull
                                         @NotNull SqlQuery query)
        A convenience method for retrieving a single non-null boolean.
        Throws:
        NonUniqueResultException - if there is more then one row
        EmptyResultException - if there are no rows
      • findUniqueBoolean

        public boolean findUniqueBoolean​(@NotNull
                                         @NotNull java.lang.String sql,
                                         java.lang.Object... args)
        A convenience method for retrieving a single non-null boolean.
        Throws:
        NonUniqueResultException - if there is more then one row
        EmptyResultException - if there are no rows
      • findUniqueInt

        public int findUniqueInt​(@NotNull
                                 @NotNull java.lang.String sql,
                                 java.lang.Object... args)
        A convenience method for retrieving a single non-null integer.
        Throws:
        NonUniqueResultException - if there is more then one row
        EmptyResultException - if there are no rows
      • findUniqueLong

        public long findUniqueLong​(@NotNull
                                   @NotNull java.lang.String sql,
                                   java.lang.Object... args)
        A convenience method for retrieving a single non-null long.
        Throws:
        NonUniqueResultException - if there is more then one row
        EmptyResultException - if there are no rows
      • findMap

        @NotNull
        public <K,​V> @NotNull java.util.Map<K,​V> findMap​(@NotNull
                                                                     @NotNull java.lang.Class<K> keyType,
                                                                     @NotNull
                                                                     @NotNull java.lang.Class<V> valueType,
                                                                     @NotNull
                                                                     @NotNull SqlQuery query)
        Executes a query that returns at least two values and creates a map from the results, using the first value as the key and rest of the values for instantiating V.

        If the keys of the result are not distinct, the result contains the last binding of given key.

      • findMap

        @NotNull
        public <K,​V> @NotNull java.util.Map<K,​V> findMap​(@NotNull
                                                                     @NotNull java.lang.Class<K> keyType,
                                                                     @NotNull
                                                                     @NotNull java.lang.Class<V> valueType,
                                                                     @NotNull
                                                                     @NotNull java.lang.String sql,
                                                                     java.lang.Object... args)
        Executes a query that returns at least two values and creates a map from the results, using the first value as the key and rest of the values for instantiating V.

        If the keys of the result are not distinct, the result contains the last binding of given key.

      • findTable

        @NotNull
        public @NotNull ResultTable findTable​(@NotNull
                                              @NotNull SqlQuery query)
        Executes a query and creates a ResultTable from the results.
      • findTable

        @NotNull
        public @NotNull ResultTable findTable​(@NotNull
                                              @NotNull java.lang.String sql,
                                              java.lang.Object... args)
        Executes a query and creates a ResultTable from the results.
      • update

        public int update​(@NotNull
                          @NotNull SqlQuery query)
        Executes an update against the database and returns the amount of affected rows.
      • update

        public int update​(@NotNull
                          @NotNull java.lang.String sql,
                          java.lang.Object... args)
        Executes an update against the database and returns the amount of affected rows.
      • updateUnique

        public void updateUnique​(@NotNull
                                 @NotNull SqlQuery query)
        Execute an update against the database and assert that a single row will be modified.
        Throws:
        NonUniqueUpdateException - if zero or more then one rows were updated
      • updateUnique

        public void updateUnique​(@NotNull
                                 @NotNull java.lang.String sql,
                                 java.lang.Object... args)
        Execute an update against the database and assert that a single row will be modified.
        Throws:
        NonUniqueUpdateException - if zero or more then one rows were updated
      • updateAndProcessGeneratedKeys

        public <T> T updateAndProcessGeneratedKeys​(@NotNull
                                                   @NotNull ResultSetProcessor<T> generatedKeysProcessor,
                                                   @NotNull
                                                   @NotNull java.util.List<java.lang.String> columnNames,
                                                   @NotNull
                                                   @NotNull SqlQuery query)
        Executes an update against the database and return generated keys as extracted by generatedKeysProcessor.
        Parameters:
        generatedKeysProcessor - processor for handling the generated keys
        columnNames - names of columns that contain the generated keys. Can be empty, in which case the returned columns depend on the database
        query - to execute
        Returns:
        Result of processing the results with generatedKeysProcessor.
      • updateBatch

        public int[] updateBatch​(@NotNull
                                 @NotNull java.lang.String sql,
                                 @NotNull
                                 @NotNull java.util.List<? extends java.util.List<?>> argumentLists)
        Executes a batch update against the database, returning an array of modification counts for each argument list.
      • updateBatchAndProcessGeneratedKeys

        public <T> T updateBatchAndProcessGeneratedKeys​(@NotNull
                                                        @NotNull ResultSetProcessor<T> generatedKeysProcessor,
                                                        @NotNull
                                                        @NotNull java.util.List<java.lang.String> columnNames,
                                                        @NotNull
                                                        @NotNull java.lang.String sql,
                                                        @NotNull
                                                        @NotNull java.util.List<? extends java.util.List<?>> argumentLists)
        Executes batch of updates against the database and return generated keys as extracted by generatedKeysProcessor.
        Parameters:
        generatedKeysProcessor - processor for handling the generated keys
        columnNames - names of columns that contain the generated keys. Can be empty, in which case the returned columns depend on the database
        sql - to execute
        argumentLists - List of argument lists for items of batch
        Returns:
        Result of processing the results with generatedKeysProcessor.
      • isAllowImplicitTransactions

        public boolean isAllowImplicitTransactions()
        If flag is set to true (by default it's false) queries without active transaction will not throw exception but will start a fresh transaction.
      • setAllowImplicitTransactions

        public void setAllowImplicitTransactions​(boolean allowImplicitTransactions)
        If flag is set to true (by default it's false) queries without active transaction will not throw exception but will start a fresh transaction.
      • getDefaultTimeout

        @Nullable
        public @Nullable java.time.Duration getDefaultTimeout()
        If default timeout is set to non null (by default it's null) all queries will have this timeout value as default, unless is specified directly on SqlQuery or is set directly on JDBC Connection parameters.
      • setDefaultTimeout

        public void setDefaultTimeout​(@NotNull
                                      @NotNull java.time.Duration timeout)
        If default timeout is set to non null (by default it's null) all queries will have this timeout value as default, unless is specified directly on SqlQuery or is set directly on JDBC Connection parameters.
        Throws:
        java.lang.IllegalArgumentException - if timeout is negative
        See Also:
        Statement.setQueryTimeout(int)
      • toString

        @NotNull
        public @NotNull java.lang.String toString()
        Returns a string containing useful debug information about the state of this object.
        Overrides:
        toString in class java.lang.Object