org.h2.command.dml
Class Query

java.lang.Object
  extended by org.h2.command.Prepared
      extended by org.h2.command.dml.Query
Direct Known Subclasses:
Select, SelectUnion

public abstract class Query
extends Prepared

Represents a SELECT statement (simple, or union).


Field Summary
protected  Expression limitExpr
          The limit expression as specified in the LIMIT or TOP clause.
protected  Expression offsetExpr
          The offset expression as specified in the LIMIT ..
protected  int sampleSize
          The sample size
 
Fields inherited from class org.h2.command.Prepared
headPos, parameters, prepareAlways, session, sqlStatement
 
Constructor Summary
Query(Session session)
           
 
Method Summary
abstract  void addGlobalCondition(Parameter param, int columnId, int comparisonType)
          Add a condition to the query.
abstract  int getColumnCount()
          Get the column count of this query.
abstract  double getCost()
          Calculate the cost to execute this query.
abstract  ObjectArray<Expression> getExpressions()
          The the list of select expressions.
abstract  java.lang.String getFirstColumnAlias(Session s)
          Get the alias (or column name) of the first column.
 long getMaxDataModificationId()
           
 Value[] getParameterValues()
           
abstract  java.util.HashSet<Table> getTables()
          Get all tables that are involved in this query.
abstract  void init()
          Initialize the query.
abstract  boolean isEverything(ExpressionVisitor visitor)
          Check if this expression and all sub-expressions can fulfill a criteria.
 boolean isEverything(int expressionVisitorType)
          Visit all expressions and subqueries in this query using the visitor pattern.
 boolean isQuery()
          Check if this object is a query.
 boolean isTransactional()
          Check if this command is transactional.
abstract  void mapColumns(ColumnResolver resolver, int level)
          Map the columns to the given column resolver.
 SortOrder prepareOrder(ObjectArray<SelectOrderBy> orderList, int expressionCount)
          Create a SortOrder object given the list of SelectOrderBy objects.
 LocalResult query(int limit)
          Execute the query.
protected abstract  LocalResult queryWithoutCache(int limit)
          Execute the query without checking the cache.
abstract  void setDistinct(boolean b)
          Set the distinct flag.
abstract  void setEvaluatable(TableFilter tableFilter, boolean b)
          Change the evaluatable flag.
abstract  void setForUpdate(boolean forUpdate)
          Set the 'for update' flag.
 void setLimit(Expression limit)
           
 void setOffset(Expression offset)
           
abstract  void setOrder(ObjectArray<SelectOrderBy> order)
          Set the order by list.
 void setSampleSize(int sampleSize)
           
abstract  void updateAggregate(Session s)
          Update all aggregate function values.
 
Methods inherited from class org.h2.command.Prepared
checkCanceled, checkParameters, getCurrentObjectId, getCurrentRowNumber, getObjectId, getParameters, getPlanSQL, getSQL, getSQL, getSQL, isReadOnly, needRecompile, prepare, queryMeta, setCommand, setCurrentRowNumber, setHeadPos, setObjectId, setParameterList, setPrepareAlways, setRow, setSession, setSQL, toString, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

limitExpr

protected Expression limitExpr
The limit expression as specified in the LIMIT or TOP clause.


offsetExpr

protected Expression offsetExpr
The offset expression as specified in the LIMIT .. OFFSET clause.


sampleSize

protected int sampleSize
The sample size

Constructor Detail

Query

public Query(Session session)
Method Detail

queryWithoutCache

protected abstract LocalResult queryWithoutCache(int limit)
                                          throws java.sql.SQLException
Execute the query without checking the cache.

Parameters:
limit - the limit as specified in the JDBC method call
Returns:
the result
Throws:
java.sql.SQLException

init

public abstract void init()
                   throws java.sql.SQLException
Initialize the query.

Throws:
java.sql.SQLException

getExpressions

public abstract ObjectArray<Expression> getExpressions()
The the list of select expressions. This may include invisible expressions such as order by expressions.

Returns:
the list of expressions

getCost

public abstract double getCost()
Calculate the cost to execute this query.

Returns:
the cost

getTables

public abstract java.util.HashSet<Table> getTables()
Get all tables that are involved in this query.

Returns:
the set of tables

setOrder

public abstract void setOrder(ObjectArray<SelectOrderBy> order)
Set the order by list.

Parameters:
order - the order by list

setForUpdate

public abstract void setForUpdate(boolean forUpdate)
Set the 'for update' flag.

Parameters:
forUpdate - the new setting

getColumnCount

public abstract int getColumnCount()
Get the column count of this query.

Returns:
the column count

mapColumns

public abstract void mapColumns(ColumnResolver resolver,
                                int level)
                         throws java.sql.SQLException
Map the columns to the given column resolver.

Parameters:
resolver - the resolver
level - the subquery level (0 is the top level query, 1 is the first subquery level)
Throws:
java.sql.SQLException

setEvaluatable

public abstract void setEvaluatable(TableFilter tableFilter,
                                    boolean b)
Change the evaluatable flag. This is used when building the execution plan.

Parameters:
tableFilter - the table filter
b - the new value

addGlobalCondition

public abstract void addGlobalCondition(Parameter param,
                                        int columnId,
                                        int comparisonType)
                                 throws java.sql.SQLException
Add a condition to the query. This is used for views.

Parameters:
param - the parameter
columnId - the column index (0 meaning the first column)
comparisonType - the comparison type
Throws:
java.sql.SQLException

setDistinct

public abstract void setDistinct(boolean b)
Set the distinct flag.

Parameters:
b - the new value

getFirstColumnAlias

public abstract java.lang.String getFirstColumnAlias(Session s)
Get the alias (or column name) of the first column. This is used to convert IN(SELECT ...) queries to inner joins.

Parameters:
s - the session
Returns:
the alias or column name

isEverything

public abstract boolean isEverything(ExpressionVisitor visitor)
Check if this expression and all sub-expressions can fulfill a criteria. If any part returns false, the result is false.

Parameters:
visitor - the visitor
Returns:
if the criteria can be fulfilled

updateAggregate

public abstract void updateAggregate(Session s)
                              throws java.sql.SQLException
Update all aggregate function values.

Parameters:
s - the session
Throws:
java.sql.SQLException

isQuery

public boolean isQuery()
Description copied from class: Prepared
Check if this object is a query.

Overrides:
isQuery in class Prepared
Returns:
true if it is

isTransactional

public boolean isTransactional()
Description copied from class: Prepared
Check if this command is transactional. If it is not, then it forces the current transaction to commit.

Specified by:
isTransactional in class Prepared
Returns:
true if it is

getParameterValues

public final Value[] getParameterValues()

query

public LocalResult query(int limit)
                  throws java.sql.SQLException
Description copied from class: Prepared
Execute the query.

Overrides:
query in class Prepared
Parameters:
limit - the maximum number of rows to return
Returns:
the result set
Throws:
java.sql.SQLException - if it is not a query

prepareOrder

public SortOrder prepareOrder(ObjectArray<SelectOrderBy> orderList,
                              int expressionCount)
                       throws java.sql.SQLException
Create a SortOrder object given the list of SelectOrderBy objects. The expression list is extended if necessary.

Parameters:
orderList - a list of SelectOrderBy elements
expressionCount - the number of columns in the query
Returns:
the SortOrder object
Throws:
java.sql.SQLException

setOffset

public void setOffset(Expression offset)

setLimit

public void setLimit(Expression limit)

setSampleSize

public void setSampleSize(int sampleSize)

getMaxDataModificationId

public final long getMaxDataModificationId()

isEverything

public final boolean isEverything(int expressionVisitorType)
Visit all expressions and subqueries in this query using the visitor pattern.

Parameters:
expressionVisitorType - the visitor type
Returns:
true if no component returned false