org.h2.command.dml
Class SelectUnion

java.lang.Object
  extended by org.h2.command.Prepared
      extended by org.h2.command.dml.Query
          extended by org.h2.command.dml.SelectUnion

public class SelectUnion
extends Query

Represents a union SELECT statement.


Field Summary
static int EXCEPT
          The type of an EXCEPT statement.
static int INTERSECT
          The type of an INTERSECT statement.
static int UNION
          The type of a UNION statement.
static int UNION_ALL
          The type of a UNION ALL statement.
 
Fields inherited from class org.h2.command.dml.Query
limitExpr, offsetExpr, sampleSize
 
Fields inherited from class org.h2.command.Prepared
headPos, parameters, prepareAlways, session, sqlStatement
 
Constructor Summary
SelectUnion(Session session, Query query)
           
 
Method Summary
 void addGlobalCondition(Parameter param, int columnId, int comparisonType)
          Add a condition to the query.
 int getColumnCount()
          Get the column count of this query.
 double getCost()
          Calculate the cost to execute this query.
 ObjectArray<Expression> getExpressions()
          The the list of select expressions.
 java.lang.String getFirstColumnAlias(Session s)
          Get the alias (or column name) of the first column.
 java.lang.String getPlanSQL()
          Get the SQL statement with the execution plan.
 java.util.HashSet<Table> getTables()
          Get all tables that are involved in this query.
 void init()
          Initialize the query.
 boolean isEverything(ExpressionVisitor visitor)
          Check if this expression and all sub-expressions can fulfill a criteria.
 boolean isReadOnly()
          Check if this command is read only.
 void mapColumns(ColumnResolver resolver, int level)
          Map the columns to the given column resolver.
 void prepare()
          Prepare this statement.
 LocalResult query(int limit)
          Execute the query.
 LocalResult queryMeta()
          Get an empty result set containing the meta data.
protected  LocalResult queryWithoutCache(int maxrows)
          Execute the query without checking the cache.
 void setDistinct(boolean b)
          Set the distinct flag.
 void setEvaluatable(TableFilter tableFilter, boolean b)
          Change the evaluatable flag.
 void setForUpdate(boolean forUpdate)
          Set the 'for update' flag.
 void setOrder(ObjectArray<SelectOrderBy> order)
          Set the order by list.
 void setRight(Query select)
           
 void setSQL(java.lang.String sql)
          Set the SQL statement.
 void setUnionType(int type)
           
 void updateAggregate(Session s)
          Update all aggregate function values.
 
Methods inherited from class org.h2.command.dml.Query
getMaxDataModificationId, getParameterValues, isEverything, isQuery, isTransactional, prepareOrder, setLimit, setOffset, setSampleSize
 
Methods inherited from class org.h2.command.Prepared
checkCanceled, checkParameters, getCurrentObjectId, getCurrentRowNumber, getObjectId, getParameters, getSQL, getSQL, getSQL, needRecompile, setCommand, setCurrentRowNumber, setHeadPos, setObjectId, setParameterList, setPrepareAlways, setRow, setSession, toString, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNION

public static final int UNION
The type of a UNION statement.

See Also:
Constant Field Values

UNION_ALL

public static final int UNION_ALL
The type of a UNION ALL statement.

See Also:
Constant Field Values

EXCEPT

public static final int EXCEPT
The type of an EXCEPT statement.

See Also:
Constant Field Values

INTERSECT

public static final int INTERSECT
The type of an INTERSECT statement.

See Also:
Constant Field Values
Constructor Detail

SelectUnion

public SelectUnion(Session session,
                   Query query)
Method Detail

setUnionType

public void setUnionType(int type)

setRight

public void setRight(Query select)

setSQL

public void setSQL(java.lang.String sql)
Description copied from class: Prepared
Set the SQL statement.

Overrides:
setSQL in class Prepared
Parameters:
sql - the SQL statement

setOrder

public void setOrder(ObjectArray<SelectOrderBy> order)
Description copied from class: Query
Set the order by list.

Specified by:
setOrder in class Query
Parameters:
order - the order by list

queryMeta

public LocalResult queryMeta()
                      throws java.sql.SQLException
Description copied from class: Prepared
Get an empty result set containing the meta data.

Specified by:
queryMeta in class Prepared
Returns:
an empty result set
Throws:
java.sql.SQLException

queryWithoutCache

protected LocalResult queryWithoutCache(int maxrows)
                                 throws java.sql.SQLException
Description copied from class: Query
Execute the query without checking the cache.

Specified by:
queryWithoutCache in class Query
Parameters:
maxrows - the limit as specified in the JDBC method call
Returns:
the result
Throws:
java.sql.SQLException

init

public void init()
          throws java.sql.SQLException
Description copied from class: Query
Initialize the query.

Specified by:
init in class Query
Throws:
java.sql.SQLException

prepare

public void prepare()
             throws java.sql.SQLException
Description copied from class: Prepared
Prepare this statement.

Overrides:
prepare in class Prepared
Throws:
java.sql.SQLException

getCost

public double getCost()
Description copied from class: Query
Calculate the cost to execute this query.

Specified by:
getCost in class Query
Returns:
the cost

getTables

public java.util.HashSet<Table> getTables()
Description copied from class: Query
Get all tables that are involved in this query.

Specified by:
getTables in class Query
Returns:
the set of tables

setDistinct

public void setDistinct(boolean b)
Description copied from class: Query
Set the distinct flag.

Specified by:
setDistinct in class Query
Parameters:
b - the new value

getExpressions

public ObjectArray<Expression> getExpressions()
Description copied from class: Query
The the list of select expressions. This may include invisible expressions such as order by expressions.

Specified by:
getExpressions in class Query
Returns:
the list of expressions

setForUpdate

public void setForUpdate(boolean forUpdate)
Description copied from class: Query
Set the 'for update' flag.

Specified by:
setForUpdate in class Query
Parameters:
forUpdate - the new setting

getColumnCount

public int getColumnCount()
Description copied from class: Query
Get the column count of this query.

Specified by:
getColumnCount in class Query
Returns:
the column count

mapColumns

public void mapColumns(ColumnResolver resolver,
                       int level)
                throws java.sql.SQLException
Description copied from class: Query
Map the columns to the given column resolver.

Specified by:
mapColumns in class Query
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 void setEvaluatable(TableFilter tableFilter,
                           boolean b)
Description copied from class: Query
Change the evaluatable flag. This is used when building the execution plan.

Specified by:
setEvaluatable in class Query
Parameters:
tableFilter - the table filter
b - the new value

addGlobalCondition

public void addGlobalCondition(Parameter param,
                               int columnId,
                               int comparisonType)
                        throws java.sql.SQLException
Description copied from class: Query
Add a condition to the query. This is used for views.

Specified by:
addGlobalCondition in class Query
Parameters:
param - the parameter
columnId - the column index (0 meaning the first column)
comparisonType - the comparison type
Throws:
java.sql.SQLException

getPlanSQL

public java.lang.String getPlanSQL()
Description copied from class: Prepared
Get the SQL statement with the execution plan.

Overrides:
getPlanSQL in class Prepared
Returns:
the execution plan

query

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

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

isEverything

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

Specified by:
isEverything in class Query
Parameters:
visitor - the visitor
Returns:
if the criteria can be fulfilled

isReadOnly

public boolean isReadOnly()
Description copied from class: Prepared
Check if this command is read only.

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

updateAggregate

public void updateAggregate(Session s)
                     throws java.sql.SQLException
Description copied from class: Query
Update all aggregate function values.

Specified by:
updateAggregate in class Query
Parameters:
s - the session
Throws:
java.sql.SQLException

getFirstColumnAlias

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

Specified by:
getFirstColumnAlias in class Query
Parameters:
s - the session
Returns:
the alias or column name