Package org.h2.result
Class LocalResult
java.lang.Object
org.h2.result.LocalResult
- All Implemented Interfaces:
AutoCloseable
,ResultInterface
,ResultTarget
A local result set contains all row data of a result set.
This is the object generated by engine,
and it is also used directly by the ResultSet class in the embedded mode.
If the result does not fit in memory, it is written to a temporary file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private Boolean
private Value[]
private boolean
private int[]
private Expression[]
private ResultExternal
private boolean
private boolean
private long
private boolean
private int
private long
private int
private long
private long
private final SessionLocal
private SortOrder
private int
private SortOrder
-
Constructor Summary
ConstructorsModifierConstructorDescriptionConstruct a local result object.private
LocalResult
(SessionLocal session) LocalResult
(SessionLocal session, Expression[] expressions, int visibleColumnCount, int resultColumnCount) Construct a local result object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a row to this object.void
addRowForTable
(Row row) Add a row for a table.private void
addRowInternal
(Value... values) private void
private void
private void
void
close()
Close the result and delete any temporary filesboolean
containsDistinct
(Value[] values) Check if this result set contains the given row.boolean
Check if this result set contains a NULL value.private void
createShallowCopy
(Session targetSession) Create a shallow copy of the result set.Value[]
Get the current row.Retrieve the current rowvoid
done()
This method is called after all rows have been added.static LocalResult
forTable
(SessionLocal session, Table table) Constructs a new local result object for the specified table.getAlias
(int i) Get the column alias name for the column.getColumnName
(int i) Get the column name.getColumnType
(int i) Get the column data type.private ValueRow
getDistinctRow
(Value[] values) int
Get the current fetch size for this result set.int
getNullable
(int i) Check if this column is nullable.long
Get the number of rows in this object.long
getRowId()
Get the current row id, starting with 0.getSchemaName
(int i) Get the schema name for the column, if one exists.getTableName
(int i) Get the table name for the column, if one exists.int
Get the number of visible columns.boolean
hasNext()
Check if this result has more rows to fetch.boolean
Check if the current position is after last row.private boolean
boolean
isClosed()
Check if this result set is closed.boolean
isIdentity
(int i) Check if this is an identity column.boolean
isLazy()
Check if this a lazy execution result.void
A hint that sorting, offset and limit may be ignored by this result because they were applied during the query.boolean
Check if this result set should be closed, for example because it is buffered using a temporary file.boolean
next()
Go to the next row.void
removeDistinct
(Value[] values) Remove the row from the result set if it exists.void
reset()
Go to the beginning of the result, that means before the first row.void
Remove duplicate rows.void
setDistinct
(int[] distinctIndexes) Remove rows with duplicates in columns with specified indexes.void
setFetchPercent
(boolean fetchPercent) void
setFetchSize
(int fetchSize) Set the fetch size for this result set.void
Sets value collection mode for data change delta tables.void
setLimit
(long limit) Set the number of rows that this result will return at the maximum.void
setMaxMemoryRows
(int maxValue) Redefine count of maximum rows holds in memory for the result.void
setOffset
(long offset) Set the offset of the first row to return.void
setSortOrder
(SortOrder sort) Sets sort order to be used by this result.void
setWithTies
(SortOrder withTiesSortOrder) Enables inclusion of tied rows to result and sets the sort order for tied rows.toString()
private void
trimExternal
(long offset, long limit)
-
Field Details
-
maxMemoryRows
private int maxMemoryRows -
session
-
visibleColumnCount
private int visibleColumnCount -
resultColumnCount
private int resultColumnCount -
expressions
-
forDataChangeDeltaTable
private boolean forDataChangeDeltaTable -
rowId
private long rowId -
rowCount
private long rowCount -
rows
-
sort
-
distinctRows
-
currentRow
-
offset
private long offset -
limit
private long limit -
fetchPercent
private boolean fetchPercent -
withTiesSortOrder
-
limitsWereApplied
private boolean limitsWereApplied -
external
-
distinct
private boolean distinct -
distinctIndexes
private int[] distinctIndexes -
closed
private boolean closed -
containsLobs
private boolean containsLobs -
containsNull
-
-
Constructor Details
-
LocalResult
public LocalResult()Construct a local result object. -
LocalResult
-
LocalResult
public LocalResult(SessionLocal session, Expression[] expressions, int visibleColumnCount, int resultColumnCount) Construct a local result object.- Parameters:
session
- the sessionexpressions
- the expression arrayvisibleColumnCount
- the number of visible columnsresultColumnCount
- the number of columns including visible columns and additional virtual columns for ORDER BY and DISTINCT ON clauses
-
-
Method Details
-
forTable
Constructs a new local result object for the specified table.- Parameters:
session
- the sessiontable
- the table- Returns:
- the local result
-
isLazy
public boolean isLazy()Description copied from interface:ResultInterface
Check if this a lazy execution result.- Specified by:
isLazy
in interfaceResultInterface
- Returns:
- true if it is a lazy result
-
setMaxMemoryRows
public void setMaxMemoryRows(int maxValue) Redefine count of maximum rows holds in memory for the result.- Parameters:
maxValue
- Maximum rows count in memory.- See Also:
-
setForDataChangeDeltaTable
public void setForDataChangeDeltaTable()Sets value collection mode for data change delta tables. -
createShallowCopy
Create a shallow copy of the result set. The data and a temporary table (if there is any) is not copied.- Specified by:
createShallowCopy
in interfaceResultInterface
- Parameters:
targetSession
- the session of the copy- Returns:
- the copy if possible, or null if copying is not possible
-
setSortOrder
Sets sort order to be used by this result. When rows are presorted by the query this method should not be used.- Parameters:
sort
- the sort order
-
setDistinct
public void setDistinct()Remove duplicate rows. -
setDistinct
public void setDistinct(int[] distinctIndexes) Remove rows with duplicates in columns with specified indexes.- Parameters:
distinctIndexes
- distinct indexes
-
isAnyDistinct
private boolean isAnyDistinct()- Returns:
- whether this result is a distinct result
-
containsDistinct
Check if this result set contains the given row.- Parameters:
values
- the row- Returns:
- true if the row exists
-
containsNull
public boolean containsNull()Check if this result set contains a NULL value. This method may reset this result.- Returns:
- true if there is a NULL value
-
removeDistinct
Remove the row from the result set if it exists.- Parameters:
values
- the row
-
reset
public void reset()Description copied from interface:ResultInterface
Go to the beginning of the result, that means before the first row.- Specified by:
reset
in interfaceResultInterface
-
currentRowForTable
Retrieve the current row- Returns:
- row
-
currentRow
Description copied from interface:ResultInterface
Get the current row.- Specified by:
currentRow
in interfaceResultInterface
- Returns:
- the row
-
next
public boolean next()Description copied from interface:ResultInterface
Go to the next row.- Specified by:
next
in interfaceResultInterface
- Returns:
- true if a row exists
-
getRowId
public long getRowId()Description copied from interface:ResultInterface
Get the current row id, starting with 0. -1 is returned when next() was not called yet.- Specified by:
getRowId
in interfaceResultInterface
- Returns:
- the row id
-
isAfterLast
public boolean isAfterLast()Description copied from interface:ResultInterface
Check if the current position is after last row.- Specified by:
isAfterLast
in interfaceResultInterface
- Returns:
- true if after last
-
cloneLobs
-
getDistinctRow
-
createExternalResult
private void createExternalResult() -
addRowForTable
Add a row for a table.- Parameters:
row
- the row to add
-
addRow
Add a row to this object.- Specified by:
addRow
in interfaceResultTarget
- Parameters:
values
- the row to add
-
addRowInternal
-
addRowsToDisk
private void addRowsToDisk() -
getVisibleColumnCount
public int getVisibleColumnCount()Description copied from interface:ResultInterface
Get the number of visible columns. More columns may exist internally for sorting or grouping.- Specified by:
getVisibleColumnCount
in interfaceResultInterface
- Returns:
- the number of columns
-
done
public void done()This method is called after all rows have been added. -
applyOffsetAndLimit
private void applyOffsetAndLimit() -
trimExternal
private void trimExternal(long offset, long limit) -
getRowCount
public long getRowCount()Description copied from interface:ResultInterface
Get the number of rows in this object.- Specified by:
getRowCount
in interfaceResultInterface
- Specified by:
getRowCount
in interfaceResultTarget
- Returns:
- the number of rows
-
limitsWereApplied
public void limitsWereApplied()Description copied from interface:ResultTarget
A hint that sorting, offset and limit may be ignored by this result because they were applied during the query. This is useful for WITH TIES clause because result may contain tied rows above limit.- Specified by:
limitsWereApplied
in interfaceResultTarget
-
hasNext
public boolean hasNext()Description copied from interface:ResultInterface
Check if this result has more rows to fetch.- Specified by:
hasNext
in interfaceResultInterface
- Returns:
- true if it has
-
setLimit
public void setLimit(long limit) Set the number of rows that this result will return at the maximum.- Parameters:
limit
- the limit (-1 means no limit, 0 means no rows)
-
setFetchPercent
public void setFetchPercent(boolean fetchPercent) - Parameters:
fetchPercent
- whether limit expression specifies percentage of rows
-
setWithTies
Enables inclusion of tied rows to result and sets the sort order for tied rows. The specified sort order must be the same as sort order if sort order was set. Passed value will be used if sort order was not set that is possible when rows are presorted.- Parameters:
withTiesSortOrder
- the sort order for tied rows
-
needToClose
public boolean needToClose()Description copied from interface:ResultInterface
Check if this result set should be closed, for example because it is buffered using a temporary file.- Specified by:
needToClose
in interfaceResultInterface
- Returns:
- true if close should be called.
-
close
public void close()Description copied from interface:ResultInterface
Close the result and delete any temporary files- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceResultInterface
-
getAlias
Description copied from interface:ResultInterface
Get the column alias name for the column.- Specified by:
getAlias
in interfaceResultInterface
- Parameters:
i
- the column number (starting with 0)- Returns:
- the alias name
-
getTableName
Description copied from interface:ResultInterface
Get the table name for the column, if one exists.- Specified by:
getTableName
in interfaceResultInterface
- Parameters:
i
- the column number (starting with 0)- Returns:
- the table name or null
-
getSchemaName
Description copied from interface:ResultInterface
Get the schema name for the column, if one exists.- Specified by:
getSchemaName
in interfaceResultInterface
- Parameters:
i
- the column number (starting with 0)- Returns:
- the schema name or null
-
getColumnName
Description copied from interface:ResultInterface
Get the column name.- Specified by:
getColumnName
in interfaceResultInterface
- Parameters:
i
- the column number (starting with 0)- Returns:
- the column name
-
getColumnType
Description copied from interface:ResultInterface
Get the column data type.- Specified by:
getColumnType
in interfaceResultInterface
- Parameters:
i
- the column number (starting with 0)- Returns:
- the column data type
-
getNullable
public int getNullable(int i) Description copied from interface:ResultInterface
Check if this column is nullable.- Specified by:
getNullable
in interfaceResultInterface
- Parameters:
i
- the column number (starting with 0)- Returns:
- Column.NULLABLE_*
-
isIdentity
public boolean isIdentity(int i) Description copied from interface:ResultInterface
Check if this is an identity column.- Specified by:
isIdentity
in interfaceResultInterface
- Parameters:
i
- the column number (starting with 0)- Returns:
- true for identity columns
-
setOffset
public void setOffset(long offset) Set the offset of the first row to return.- Parameters:
offset
- the offset
-
toString
-
isClosed
public boolean isClosed()Check if this result set is closed.- Specified by:
isClosed
in interfaceResultInterface
- Returns:
- true if it is
-
getFetchSize
public int getFetchSize()Description copied from interface:ResultInterface
Get the current fetch size for this result set.- Specified by:
getFetchSize
in interfaceResultInterface
- Returns:
- the fetch size
-
setFetchSize
public void setFetchSize(int fetchSize) Description copied from interface:ResultInterface
Set the fetch size for this result set.- Specified by:
setFetchSize
in interfaceResultInterface
- Parameters:
fetchSize
- the new fetch size
-