Class GenericQuery<T>

  • Direct Known Subclasses:
    CachingGenericQuery, DebugQuery, HistoryInsertQuery

    public class GenericQuery<T>
    extends Object
    Handy class to overcome JDBC verbosity. Provides vararg params, compact result set processing and batch operations, etc. Typicaly used as static object. Completely threadsafe.
    Author:
    Pavel.Sher Date: 27.03.2006
    • Constructor Detail

      • GenericQuery

        public GenericQuery​(@NotNull
                            String sqlStatement)
        Creates instance parametrized by given SQL statement.
        Parameters:
        sqlStatement - SQL statement
      • GenericQuery

        public GenericQuery​(@NotNull
                            String sqlStatement,
                            @Nullable
                            GenericQuery.ResultSetProcessor<T> processor)
        Creates instance parametrized by given SQL statement and result set processor instance.
        Parameters:
        sqlStatement - SQL statement
        processor - default result set processor instance for this query
    • Method Detail

      • setOptions

        public void setOptions​(@Nullable
                               QueryOptions options)
      • getOriginalSqlStatement

        @NotNull
        protected String getOriginalSqlStatement()
      • execute

        public T execute​(@NotNull
                         DBFunctions dbf,
                         @Nullable
                         Object... params)
        Executes statement as query with given parameters
        Parameters:
        dbf - database access object
        params - parameters
        Returns:
        result as declared
        Throws:
        org.springframework.dao.DataAccessException - underlying JDBC exceptions are wrapped with extra details
        Since:
        7.0
      • execute

        public T execute​(@NotNull
                         DBFunctions dbf,
                         @NotNull
                         GenericQuery.ResultSetProcessor<T> processor,
                         @Nullable
                         Object... params)
        Executes statement as query with given parameters and specific result set processor instance.
        Parameters:
        dbf - database access object
        params - parameters
        processor - result set processor instance
        Returns:
        result as declared
        Throws:
        org.springframework.dao.DataAccessException - underlying JDBC exceptions are wrapped with extra details
        Since:
        7.0
      • execute

        public T execute​(@NotNull
                         SQLRunnerEx runner,
                         @Nullable
                         Object... params)
        Executes statement as query with given parameters and specific result set processor instance.
        Parameters:
        runner - SQL runner
        params - parameters
        Returns:
        result as declared
        Throws:
        org.springframework.dao.DataAccessException - underlying JDBC exceptions are wrapped with extra details
      • execute

        public T execute​(@NotNull
                         SQLRunnerEx runner,
                         @NotNull
                         GenericQuery.ResultSetProcessor<T> processor,
                         @Nullable
                         Object... params)
        Executes statement as query with given parameters and specific result set processor instance.
        Parameters:
        runner - SQL runner
        params - parameters
        processor - result set processor instance
        Returns:
        result as declared
        Throws:
        org.springframework.dao.DataAccessException - underlying JDBC exceptions are wrapped with extra details
      • executeUpdate

        public int executeUpdate​(@NotNull
                                 DBFunctions dbf,
                                 Object... params)
        Executes an update statement and returns number of affected rows. Use this for updates, inserts and deletes.
        Parameters:
        dbf - database access session.
        params - parameters.
        Returns:
        affected rows count.
        Throws:
        DBException
        Since:
        7.0
      • executeBatch

        public void executeBatch​(SQLRunnerEx runner,
                                 Iterator<Object[]> paramsIterator)
        Executes (same) SQL statement in a batch, parametrizing it by provided iterator.
        Parameters:
        runner - SQL runner
        paramsIterator - parameter arrays generator
      • executeBatch

        public void executeBatch​(@NotNull
                                 DBFunctions dbf,
                                 @NotNull
                                 Iterator<Object[]> paramsIterator)
        Executes (same) SQL statement in a batch, parametrizing it by provided iterator.
        Parameters:
        dbf - database functions instance
        paramsIterator - parameter arrays generator