Class StreamingResult

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.sql.ResultSet, java.sql.Wrapper, Completion, ServerMessage

    public class StreamingResult
    extends Result
    Streaming result-set implementation. Implementation rely on reading as many rows than fetch size required, keeping remaining rows in TCP-IP buffer

    The server usually expects clients to read off the result set relatively quickly. The net_write_timeout server variable controls this behavior (defaults to 60s).

    If you don't expect results to be handled in this amount of time there is a different possibility:

    • With > MariaDB server, you can use the query "SET STATEMENT net_write_timeout=10000 FOR XXX" with XXX your "normal" query. This will indicate that specifically for this query, net_write_timeout will be set to a longer time (10000 in this example).
    • for non mariadb servers, a specific query will have to temporarily set net_write_timeout ("SET STATEMENT net_write_timeout=..."), and set it back afterward.
    • if your application usually uses a lot of long queries with fetch size, the connection can be set using option "sessionVariables=net_write_timeout=xxx"

    Even using setFetchSize, the server will send all results to the client.

    If another query is executed on the same connection when a streaming result-set has not been fully read, the connector will put the whole remaining streaming result-set in memory in order to execute the next query. This can lead to OutOfMemoryError if not handled.

    • Field Detail

      • dataFetchTime

        private int dataFetchTime
      • requestedFetchSize

        private int requestedFetchSize
    • Constructor Detail

      • StreamingResult

        public StreamingResult​(Statement stmt,
                               boolean binaryProtocol,
                               long maxRows,
                               ColumnDecoder[] metadataList,
                               Reader reader,
                               Context context,
                               int fetchSize,
                               ClosableLock lock,
                               int resultSetType,
                               boolean closeOnCompletion,
                               boolean traceEnable)
                        throws java.sql.SQLException
        Constructor
        Parameters:
        stmt - statement that initiate this result
        binaryProtocol - is result-set binary encoded
        maxRows - maximum row number
        metadataList - column metadata
        reader - packet reader
        context - connection context
        fetchSize - fetch size
        lock - thread safe locker
        resultSetType - result-set type
        closeOnCompletion - close statement on completion
        traceEnable - can network log be logged
        Throws:
        java.sql.SQLException - if any error occurs
    • Method Detail

      • streaming

        public boolean streaming()
        Description copied from class: Result
        Indicate of current result-set is a streaming result-set
        Specified by:
        streaming in class Result
        Returns:
        if streaming result-set
      • isBulkResult

        public boolean isBulkResult()
        Description copied from class: Result
        Indicate if result-set is a bulk unitary result
        Specified by:
        isBulkResult in class Result
        Returns:
        true if unitary result-set
      • setBulkResult

        public void setBulkResult()
        Description copied from class: Result
        Indicate that result is a bulk result
        Specified by:
        setBulkResult in class Result
      • nextStreamingValue

        private void nextStreamingValue()
                                 throws java.sql.SQLException
        This permit to replace current stream results by next ones.
        Throws:
        java.sql.SQLException - if server return an unexpected error
      • addStreamingValue

        private void addStreamingValue()
                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • fetchRemaining

        public void fetchRemaining()
                            throws java.sql.SQLException
        When protocol has a current Streaming result (this) fetch all to permit another query is executing.
        Specified by:
        fetchRemaining in class Result
        Throws:
        java.sql.SQLException - if any error occur
      • next

        public boolean next()
                     throws java.sql.SQLException
        Description copied from class: Result
        Position resultset to next row
        Specified by:
        next in interface java.sql.ResultSet
        Specified by:
        next in class Result
        Returns:
        true if next row exists
        Throws:
        java.sql.SQLException - if any error occurs
      • isAfterLast

        public boolean isAfterLast()
                            throws java.sql.SQLException
        Specified by:
        isAfterLast in interface java.sql.ResultSet
        Specified by:
        isAfterLast in class Result
        Throws:
        java.sql.SQLException
      • isFirst

        public boolean isFirst()
                        throws java.sql.SQLException
        Specified by:
        isFirst in interface java.sql.ResultSet
        Specified by:
        isFirst in class Result
        Throws:
        java.sql.SQLException
      • isLast

        public boolean isLast()
                       throws java.sql.SQLException
        Specified by:
        isLast in interface java.sql.ResultSet
        Specified by:
        isLast in class Result
        Throws:
        java.sql.SQLException
      • beforeFirst

        public void beforeFirst()
                         throws java.sql.SQLException
        Specified by:
        beforeFirst in interface java.sql.ResultSet
        Specified by:
        beforeFirst in class Result
        Throws:
        java.sql.SQLException
      • afterLast

        public void afterLast()
                       throws java.sql.SQLException
        Specified by:
        afterLast in interface java.sql.ResultSet
        Specified by:
        afterLast in class Result
        Throws:
        java.sql.SQLException
      • first

        public boolean first()
                      throws java.sql.SQLException
        Specified by:
        first in interface java.sql.ResultSet
        Specified by:
        first in class Result
        Throws:
        java.sql.SQLException
      • last

        public boolean last()
                     throws java.sql.SQLException
        Specified by:
        last in interface java.sql.ResultSet
        Specified by:
        last in class Result
        Throws:
        java.sql.SQLException
      • getRow

        public int getRow()
                   throws java.sql.SQLException
        Specified by:
        getRow in interface java.sql.ResultSet
        Specified by:
        getRow in class Result
        Throws:
        java.sql.SQLException
      • absolute

        public boolean absolute​(int idx)
                         throws java.sql.SQLException
        Specified by:
        absolute in interface java.sql.ResultSet
        Specified by:
        absolute in class Result
        Throws:
        java.sql.SQLException
      • relative

        public boolean relative​(int rows)
                         throws java.sql.SQLException
        Specified by:
        relative in interface java.sql.ResultSet
        Specified by:
        relative in class Result
        Throws:
        java.sql.SQLException
      • previous

        public boolean previous()
                         throws java.sql.SQLException
        Specified by:
        previous in interface java.sql.ResultSet
        Specified by:
        previous in class Result
        Throws:
        java.sql.SQLException
      • getFetchSize

        public int getFetchSize()
                         throws java.sql.SQLException
        Specified by:
        getFetchSize in interface java.sql.ResultSet
        Overrides:
        getFetchSize in class Result
        Throws:
        java.sql.SQLException
      • setFetchSize

        public void setFetchSize​(int fetchSize)
                          throws java.sql.SQLException
        Specified by:
        setFetchSize in interface java.sql.ResultSet
        Overrides:
        setFetchSize in class Result
        Throws:
        java.sql.SQLException