Class StreamingResult
java.lang.Object
org.mariadb.jdbc.client.result.Result
org.mariadb.jdbc.client.result.StreamingResult
- All Implemented Interfaces:
AutoCloseable, ResultSet, Wrapper, Completion, ServerMessage
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 Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final ClosableLockprivate static final intprivate intFields inherited from class Result
closed, context, data, dataSize, exceptionFactory, fieldIndex, loaded, maxRows, metadataList, NULL_LENGTH, outputParameter, reader, resultSetType, rowBuf, rowDecoder, rowPointer, statement, traceEnableFields inherited from interface 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
ConstructorsConstructorDescriptionStreamingResult(Statement stmt, boolean binaryProtocol, long maxRows, ColumnDecoder[] metadataList, Reader reader, Context context, int fetchSize, ClosableLock lock, int resultSetType, boolean closeOnCompletion, boolean traceEnable) Constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleanabsolute(int idx) private voidvoidvoidvoidWhen protocol has a current Streaming result (this) fetch all to permit another query is executing.booleanfirst()intintgetRow()booleanbooleanIndicate if result-set is a bulk unitary resultbooleanisFirst()booleanisLast()booleanlast()booleannext()Position resultset to next rowprivate voidThis permit to replace current stream results by next ones.booleanprevious()booleanrelative(int rows) voidIndicate that result is a bulk resultvoidsetFetchSize(int fetchSize) booleanIndicate of current result-set is a streaming result-setMethods inherited from class Result
abort, addRowData, cancelRowUpdates, checkClose, checkNotForwardOnly, clearWarnings, close, closeFromStmtClose, closeOnCompletion, 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, setNullRowBuf, setRow, 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, wasNull
-
Field Details
-
MAX_FETCH_SIZE
private static final int MAX_FETCH_SIZE- See Also:
-
lock
-
dataFetchTime
private int dataFetchTime -
requestedFetchSize
private int requestedFetchSize
-
-
Constructor Details
-
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 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 Details
-
streaming
-
isBulkResult
public boolean isBulkResult()Description copied from class:ResultIndicate if result-set is a bulk unitary result- Specified by:
isBulkResultin classResult- Returns:
- true if unitary result-set
-
setBulkResult
public void setBulkResult()Description copied from class:ResultIndicate that result is a bulk result- Specified by:
setBulkResultin classResult
-
nextStreamingValue
This permit to replace current stream results by next ones.- Throws:
SQLException- if server return an unexpected error
-
addStreamingValue
- Throws:
SQLException
-
fetchRemaining
When protocol has a current Streaming result (this) fetch all to permit another query is executing.- Specified by:
fetchRemainingin classResult- Throws:
SQLException- if any error occur
-
next
-
isAfterLast
- Specified by:
isAfterLastin interfaceResultSet- Specified by:
isAfterLastin classResult- Throws:
SQLException
-
isFirst
- Specified by:
isFirstin interfaceResultSet- Specified by:
isFirstin classResult- Throws:
SQLException
-
isLast
- Specified by:
isLastin interfaceResultSet- Specified by:
isLastin classResult- Throws:
SQLException
-
beforeFirst
- Specified by:
beforeFirstin interfaceResultSet- Specified by:
beforeFirstin classResult- Throws:
SQLException
-
afterLast
- Specified by:
afterLastin interfaceResultSet- Specified by:
afterLastin classResult- Throws:
SQLException
-
first
- Specified by:
firstin interfaceResultSet- Specified by:
firstin classResult- Throws:
SQLException
-
last
- Specified by:
lastin interfaceResultSet- Specified by:
lastin classResult- Throws:
SQLException
-
getRow
- Specified by:
getRowin interfaceResultSet- Specified by:
getRowin classResult- Throws:
SQLException
-
absolute
- Specified by:
absolutein interfaceResultSet- Specified by:
absolutein classResult- Throws:
SQLException
-
relative
- Specified by:
relativein interfaceResultSet- Specified by:
relativein classResult- Throws:
SQLException
-
previous
- Specified by:
previousin interfaceResultSet- Specified by:
previousin classResult- Throws:
SQLException
-
getFetchSize
- Specified by:
getFetchSizein interfaceResultSet- Overrides:
getFetchSizein classResult- Throws:
SQLException
-
setFetchSize
- Specified by:
setFetchSizein interfaceResultSet- Overrides:
setFetchSizein classResult- Throws:
SQLException
-