Package org.mariadb.jdbc.client.result
Class StreamingResult
- java.lang.Object
-
- org.mariadb.jdbc.client.result.Result
-
- org.mariadb.jdbc.client.result.StreamingResult
-
- All Implemented Interfaces:
AutoCloseable
,ResultSet
,Wrapper
,org.mariadb.jdbc.client.Completion
,org.mariadb.jdbc.message.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 bufferThe 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 Summary
-
Fields inherited from class org.mariadb.jdbc.client.result.Result
closed, context, data, dataSize, exceptionFactory, loaded, maxRows, metadataList, outputParameter, reader, resultSetType, row, rowPointer, statement
-
Fields inherited from interface java.sql.ResultSet
CLOSE_CURSORS_AT_COMMIT, CONCUR_READ_ONLY, CONCUR_UPDATABLE, FETCH_FORWARD, FETCH_REVERSE, FETCH_UNKNOWN, HOLD_CURSORS_OVER_COMMIT, TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE
-
-
Constructor Summary
Constructors Constructor Description StreamingResult(Statement stmt, boolean binaryProtocol, long maxRows, org.mariadb.jdbc.client.Column[] metadataList, Reader reader, org.mariadb.jdbc.client.Context context, int fetchSize, ReentrantLock lock, int resultSetType, boolean closeOnCompletion, boolean traceEnable)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
absolute(int idx)
void
afterLast()
void
beforeFirst()
void
fetchRemaining()
When protocol has a current Streaming result (this) fetch all to permit another query is executing.boolean
first()
int
getFetchSize()
int
getRow()
boolean
isAfterLast()
boolean
isFirst()
boolean
isLast()
boolean
last()
boolean
next()
Position resultset to next rowboolean
previous()
boolean
relative(int rows)
void
setFetchSize(int fetchSize)
boolean
streaming()
Indicate of current result-set is a streaming result-set-
Methods inherited from class org.mariadb.jdbc.client.result.Result
abort, addRowData, cancelRowUpdates, checkClose, checkNotForwardOnly, clearWarnings, close, closeFromStmtClose, deleteRow, findColumn, getArray, getArray, getAsciiStream, getAsciiStream, getBigDecimal, getBigDecimal, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBinaryStream, getBinaryStream, getBlob, getBlob, getBoolean, getBoolean, getByte, getByte, getBytes, getBytes, getCharacterStream, getCharacterStream, getClob, getClob, getConcurrency, getCurrentRowData, getCursorName, getDate, getDate, getDate, getDate, getDouble, getDouble, getFetchDirection, getFloat, getFloat, getHoldability, getInt, getInt, getLong, getLong, getMetaData, getNCharacterStream, getNCharacterStream, getNClob, getNClob, getNString, getNString, getObject, getObject, getObject, getObject, getObject, getObject, getRef, getRef, getRowId, getRowId, getShort, getShort, getSQLXML, getSQLXML, getStatement, getString, getString, getTime, getTime, getTime, getTime, getTimestamp, getTimestamp, getTimestamp, getTimestamp, getType, getUnicodeStream, getUnicodeStream, getURL, getURL, getWarnings, insertRow, isBeforeFirst, isClosed, isOutputParameter, isWrapperFor, loaded, moveToCurrentRow, moveToInsertRow, readNext, refreshRow, rowDeleted, rowInserted, rowUpdated, setFetchDirection, setStatement, skipRemaining, unwrap, updateArray, updateArray, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateAsciiStream, updateBigDecimal, updateBigDecimal, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBinaryStream, updateBlob, updateBlob, updateBlob, updateBlob, updateBlob, updateBlob, updateBoolean, updateBoolean, updateByte, updateByte, updateBytes, updateBytes, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateCharacterStream, updateClob, updateClob, updateClob, updateClob, updateClob, updateClob, updateDate, updateDate, updateDouble, updateDouble, updateFloat, updateFloat, updateInt, updateInt, updateLong, updateLong, updateNCharacterStream, updateNCharacterStream, updateNCharacterStream, updateNCharacterStream, updateNClob, updateNClob, updateNClob, updateNClob, updateNClob, updateNClob, updateNString, updateNString, updateNull, updateNull, updateObject, updateObject, updateObject, updateObject, updateObject, updateObject, updateObject, updateObject, updateRef, updateRef, updateRow, updateRowData, updateRowId, updateRowId, updateShort, updateShort, updateSQLXML, updateSQLXML, updateString, updateString, updateTime, updateTime, updateTimestamp, updateTimestamp, useAliasAsName, wasNull
-
-
-
-
Constructor Detail
-
StreamingResult
public StreamingResult(Statement stmt, boolean binaryProtocol, long maxRows, org.mariadb.jdbc.client.Column[] metadataList, Reader reader, org.mariadb.jdbc.client.Context context, int fetchSize, ReentrantLock lock, int resultSetType, boolean closeOnCompletion, boolean traceEnable) throws SQLException
Constructor- Parameters:
stmt
- statement that initiate this resultbinaryProtocol
- is result-set binary encodedmaxRows
- maximum row numbermetadataList
- column metadatareader
- packet readercontext
- connection contextfetchSize
- fetch sizelock
- thread safe lockerresultSetType
- result-set typecloseOnCompletion
- close statement on completiontraceEnable
- can network log be logged- Throws:
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
-
fetchRemaining
public void fetchRemaining() throws SQLException
When protocol has a current Streaming result (this) fetch all to permit another query is executing.- Specified by:
fetchRemaining
in classResult
- Throws:
SQLException
- if any error occur
-
next
public boolean next() throws SQLException
Description copied from class:Result
Position resultset to next row- Specified by:
next
in interfaceResultSet
- Specified by:
next
in classResult
- Returns:
- true if next row exists
- Throws:
SQLException
- if any error occurs
-
isAfterLast
public boolean isAfterLast() throws SQLException
- Specified by:
isAfterLast
in interfaceResultSet
- Specified by:
isAfterLast
in classResult
- Throws:
SQLException
-
isFirst
public boolean isFirst() throws SQLException
- Specified by:
isFirst
in interfaceResultSet
- Specified by:
isFirst
in classResult
- Throws:
SQLException
-
isLast
public boolean isLast() throws SQLException
- Specified by:
isLast
in interfaceResultSet
- Specified by:
isLast
in classResult
- Throws:
SQLException
-
beforeFirst
public void beforeFirst() throws SQLException
- Specified by:
beforeFirst
in interfaceResultSet
- Specified by:
beforeFirst
in classResult
- Throws:
SQLException
-
afterLast
public void afterLast() throws SQLException
- Specified by:
afterLast
in interfaceResultSet
- Specified by:
afterLast
in classResult
- Throws:
SQLException
-
first
public boolean first() throws SQLException
- Specified by:
first
in interfaceResultSet
- Specified by:
first
in classResult
- Throws:
SQLException
-
last
public boolean last() throws SQLException
- Specified by:
last
in interfaceResultSet
- Specified by:
last
in classResult
- Throws:
SQLException
-
getRow
public int getRow() throws SQLException
- Specified by:
getRow
in interfaceResultSet
- Specified by:
getRow
in classResult
- Throws:
SQLException
-
absolute
public boolean absolute(int idx) throws SQLException
- Specified by:
absolute
in interfaceResultSet
- Specified by:
absolute
in classResult
- Throws:
SQLException
-
relative
public boolean relative(int rows) throws SQLException
- Specified by:
relative
in interfaceResultSet
- Specified by:
relative
in classResult
- Throws:
SQLException
-
previous
public boolean previous() throws SQLException
- Specified by:
previous
in interfaceResultSet
- Specified by:
previous
in classResult
- Throws:
SQLException
-
getFetchSize
public int getFetchSize()
-
setFetchSize
public void setFetchSize(int fetchSize) throws SQLException
- Throws:
SQLException
-
-