Package org.h2.result
Class LocalResult
- java.lang.Object
-
- org.h2.result.LocalResult
-
- All Implemented Interfaces:
java.lang.AutoCloseable,ResultInterface,ResultTarget
public class LocalResult extends java.lang.Object implements 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
Fields Modifier and Type Field Description private booleanclosedprivate booleancontainsLobsprivate java.lang.BooleancontainsNullprivate Value[]currentRowprivate booleandistinctprivate int[]distinctIndexesprivate java.util.TreeMap<ValueRow,Value[]>distinctRowsprivate Expression[]expressionsprivate ResultExternalexternalprivate booleanfetchPercentprivate booleanforDataChangeDeltaTableprivate longlimitprivate booleanlimitsWereAppliedprivate intmaxMemoryRowsprivate longoffsetprivate intresultColumnCountprivate longrowCountprivate longrowIdprivate java.util.ArrayList<Value[]>rowsprivate SessionLocalsessionprivate SortOrdersortprivate intvisibleColumnCountprivate SortOrderwithTiesSortOrder
-
Constructor Summary
Constructors Modifier Constructor Description LocalResult()Construct a local result object.privateLocalResult(SessionLocal session)LocalResult(SessionLocal session, Expression[] expressions, int visibleColumnCount, int resultColumnCount)Construct a local result object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRow(Value... values)Add a row to this object.voidaddRowForTable(Row row)Add a row for a table.private voidaddRowInternal(Value... values)private voidaddRowsToDisk()private voidapplyOffsetAndLimit()private voidcloneLobs(Value[] values)voidclose()Close the result and delete any temporary filesbooleancontainsDistinct(Value[] values)Check if this result set contains the given row.booleancontainsNull()Check if this result set contains a NULL value.private voidcreateExternalResult()LocalResultcreateShallowCopy(Session targetSession)Create a shallow copy of the result set.Value[]currentRow()Get the current row.RowcurrentRowForTable()Retrieve the current rowvoiddone()This method is called after all rows have been added.static LocalResultforTable(SessionLocal session, Table table)Constructs a new local result object for the specified table.java.lang.StringgetAlias(int i)Get the column alias name for the column.java.lang.StringgetColumnName(int i)Get the column name.TypeInfogetColumnType(int i)Get the column data type.private ValueRowgetDistinctRow(Value[] values)intgetFetchSize()Get the current fetch size for this result set.intgetNullable(int i)Check if this column is nullable.longgetRowCount()Get the number of rows in this object.longgetRowId()Get the current row id, starting with 0.java.lang.StringgetSchemaName(int i)Get the schema name for the column, if one exists.java.lang.StringgetTableName(int i)Get the table name for the column, if one exists.intgetVisibleColumnCount()Get the number of visible columns.booleanhasNext()Check if this result has more rows to fetch.booleanisAfterLast()Check if the current position is after last row.private booleanisAnyDistinct()booleanisClosed()Check if this result set is closed.booleanisIdentity(int i)Check if this is an identity column.booleanisLazy()Check if this a lazy execution result.voidlimitsWereApplied()A hint that sorting, offset and limit may be ignored by this result because they were applied during the query.booleanneedToClose()Check if this result set should be closed, for example because it is buffered using a temporary file.booleannext()Go to the next row.voidremoveDistinct(Value[] values)Remove the row from the result set if it exists.voidreset()Go to the beginning of the result, that means before the first row.voidsetDistinct()Remove duplicate rows.voidsetDistinct(int[] distinctIndexes)Remove rows with duplicates in columns with specified indexes.voidsetFetchPercent(boolean fetchPercent)voidsetFetchSize(int fetchSize)Set the fetch size for this result set.voidsetForDataChangeDeltaTable()Sets value collection mode for data change delta tables.voidsetLimit(long limit)Set the number of rows that this result will return at the maximum.voidsetMaxMemoryRows(int maxValue)Redefine count of maximum rows holds in memory for the result.voidsetOffset(long offset)Set the offset of the first row to return.voidsetSortOrder(SortOrder sort)Sets sort order to be used by this result.voidsetWithTies(SortOrder withTiesSortOrder)Enables inclusion of tied rows to result and sets the sort order for tied rows.java.lang.StringtoString()private voidtrimExternal(long offset, long limit)
-
-
-
Field Detail
-
maxMemoryRows
private int maxMemoryRows
-
session
private final SessionLocal session
-
visibleColumnCount
private int visibleColumnCount
-
resultColumnCount
private int resultColumnCount
-
expressions
private Expression[] expressions
-
forDataChangeDeltaTable
private boolean forDataChangeDeltaTable
-
rowId
private long rowId
-
rowCount
private long rowCount
-
rows
private java.util.ArrayList<Value[]> rows
-
sort
private SortOrder sort
-
currentRow
private Value[] currentRow
-
offset
private long offset
-
limit
private long limit
-
fetchPercent
private boolean fetchPercent
-
withTiesSortOrder
private SortOrder withTiesSortOrder
-
limitsWereApplied
private boolean limitsWereApplied
-
external
private ResultExternal external
-
distinct
private boolean distinct
-
distinctIndexes
private int[] distinctIndexes
-
closed
private boolean closed
-
containsLobs
private boolean containsLobs
-
containsNull
private java.lang.Boolean containsNull
-
-
Constructor Detail
-
LocalResult
public LocalResult()
Construct a local result object.
-
LocalResult
private LocalResult(SessionLocal session)
-
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 Detail
-
forTable
public static LocalResult forTable(SessionLocal session, Table table)
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:ResultInterfaceCheck if this a lazy execution result.- Specified by:
isLazyin 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:
SysProperties.MAX_MEMORY_ROWS
-
setForDataChangeDeltaTable
public void setForDataChangeDeltaTable()
Sets value collection mode for data change delta tables.
-
createShallowCopy
public LocalResult createShallowCopy(Session targetSession)
Create a shallow copy of the result set. The data and a temporary table (if there is any) is not copied.- Specified by:
createShallowCopyin interfaceResultInterface- Parameters:
targetSession- the session of the copy- Returns:
- the copy if possible, or null if copying is not possible
-
setSortOrder
public void setSortOrder(SortOrder sort)
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
public boolean containsDistinct(Value[] values)
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
public void removeDistinct(Value[] values)
Remove the row from the result set if it exists.- Parameters:
values- the row
-
reset
public void reset()
Description copied from interface:ResultInterfaceGo to the beginning of the result, that means before the first row.- Specified by:
resetin interfaceResultInterface
-
currentRowForTable
public Row currentRowForTable()
Retrieve the current row- Returns:
- row
-
currentRow
public Value[] currentRow()
Description copied from interface:ResultInterfaceGet the current row.- Specified by:
currentRowin interfaceResultInterface- Returns:
- the row
-
next
public boolean next()
Description copied from interface:ResultInterfaceGo to the next row.- Specified by:
nextin interfaceResultInterface- Returns:
- true if a row exists
-
getRowId
public long getRowId()
Description copied from interface:ResultInterfaceGet the current row id, starting with 0. -1 is returned when next() was not called yet.- Specified by:
getRowIdin interfaceResultInterface- Returns:
- the row id
-
isAfterLast
public boolean isAfterLast()
Description copied from interface:ResultInterfaceCheck if the current position is after last row.- Specified by:
isAfterLastin interfaceResultInterface- Returns:
- true if after last
-
cloneLobs
private void cloneLobs(Value[] values)
-
createExternalResult
private void createExternalResult()
-
addRowForTable
public void addRowForTable(Row row)
Add a row for a table.- Parameters:
row- the row to add
-
addRow
public void addRow(Value... values)
Add a row to this object.- Specified by:
addRowin interfaceResultTarget- Parameters:
values- the row to add
-
addRowInternal
private void addRowInternal(Value... values)
-
addRowsToDisk
private void addRowsToDisk()
-
getVisibleColumnCount
public int getVisibleColumnCount()
Description copied from interface:ResultInterfaceGet the number of visible columns. More columns may exist internally for sorting or grouping.- Specified by:
getVisibleColumnCountin 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:ResultInterfaceGet the number of rows in this object.- Specified by:
getRowCountin interfaceResultInterface- Specified by:
getRowCountin interfaceResultTarget- Returns:
- the number of rows
-
limitsWereApplied
public void limitsWereApplied()
Description copied from interface:ResultTargetA 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:
limitsWereAppliedin interfaceResultTarget
-
hasNext
public boolean hasNext()
Description copied from interface:ResultInterfaceCheck if this result has more rows to fetch.- Specified by:
hasNextin 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
public void setWithTies(SortOrder withTiesSortOrder)
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:ResultInterfaceCheck if this result set should be closed, for example because it is buffered using a temporary file.- Specified by:
needToClosein interfaceResultInterface- Returns:
- true if close should be called.
-
close
public void close()
Description copied from interface:ResultInterfaceClose the result and delete any temporary files- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceResultInterface
-
getAlias
public java.lang.String getAlias(int i)
Description copied from interface:ResultInterfaceGet the column alias name for the column.- Specified by:
getAliasin interfaceResultInterface- Parameters:
i- the column number (starting with 0)- Returns:
- the alias name
-
getTableName
public java.lang.String getTableName(int i)
Description copied from interface:ResultInterfaceGet the table name for the column, if one exists.- Specified by:
getTableNamein interfaceResultInterface- Parameters:
i- the column number (starting with 0)- Returns:
- the table name or null
-
getSchemaName
public java.lang.String getSchemaName(int i)
Description copied from interface:ResultInterfaceGet the schema name for the column, if one exists.- Specified by:
getSchemaNamein interfaceResultInterface- Parameters:
i- the column number (starting with 0)- Returns:
- the schema name or null
-
getColumnName
public java.lang.String getColumnName(int i)
Description copied from interface:ResultInterfaceGet the column name.- Specified by:
getColumnNamein interfaceResultInterface- Parameters:
i- the column number (starting with 0)- Returns:
- the column name
-
getColumnType
public TypeInfo getColumnType(int i)
Description copied from interface:ResultInterfaceGet the column data type.- Specified by:
getColumnTypein interfaceResultInterface- Parameters:
i- the column number (starting with 0)- Returns:
- the column data type
-
getNullable
public int getNullable(int i)
Description copied from interface:ResultInterfaceCheck if this column is nullable.- Specified by:
getNullablein interfaceResultInterface- Parameters:
i- the column number (starting with 0)- Returns:
- Column.NULLABLE_*
-
isIdentity
public boolean isIdentity(int i)
Description copied from interface:ResultInterfaceCheck if this is an identity column.- Specified by:
isIdentityin 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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isClosed
public boolean isClosed()
Check if this result set is closed.- Specified by:
isClosedin interfaceResultInterface- Returns:
- true if it is
-
getFetchSize
public int getFetchSize()
Description copied from interface:ResultInterfaceGet the current fetch size for this result set.- Specified by:
getFetchSizein interfaceResultInterface- Returns:
- the fetch size
-
setFetchSize
public void setFetchSize(int fetchSize)
Description copied from interface:ResultInterfaceSet the fetch size for this result set.- Specified by:
setFetchSizein interfaceResultInterface- Parameters:
fetchSize- the new fetch size
-
-