org.eobjects.metamodel.query
Class Query

java.lang.Object
  extended by org.eobjects.metamodel.util.BaseObject
      extended by org.eobjects.metamodel.query.Query
All Implemented Interfaces:
Serializable, Cloneable

public final class Query
extends BaseObject
implements Cloneable, Serializable

Represents a query to retrieve data by. A query is made up of six clauses, equivalent to the SQL standard:

In addition two properties are applied to queries to limit the resulting dataset: Queries are executed using the DataContext.executeQuery method or can alternatively be used directly in JDBC by using the toString() method.

See Also:
DataContext, Serialized Form

Constructor Summary
Query()
           
 
Method Summary
 Query clone()
           
protected  void decorateIdentity(List<Object> identifiers)
          Subclasses should implement this method and add all fields to the list that are to be included in equals(...) and hashCode() evaluation
 Query from(FromItem... items)
           
 Query from(String expression)
           
 Query from(Table table)
           
 Query from(Table table, String alias)
           
 Query from(Table leftTable, Table rightTable, JoinType joinType, Column leftOnColumn, Column rightOnColumn)
           
 Integer getFirstRow()
          Gets the first row (aka offset) of the query's result, or null if none is specified.
 FromClause getFromClause()
           
 GroupByClause getGroupByClause()
           
 FilterClause getHavingClause()
           
 Integer getMaxRows()
           
 OrderByClause getOrderByClause()
           
 SelectClause getSelectClause()
           
 FilterClause getWhereClause()
           
 Query groupBy(Column... columns)
           
 Query groupBy(GroupByItem... items)
           
 Query groupBy(String... groupByTokens)
           
 Query having(Column column, OperatorType operatorType, Object operand)
           
 Query having(FilterItem... items)
           
 Query having(FunctionType function, Column column, OperatorType operatorType, Object operand)
           
 Query having(String... havingItemTokens)
           
 Query orderBy(Column column)
           
 Query orderBy(Column column, boolean ascending)
          Deprecated. use orderBy(Column, Direction) instead
 Query orderBy(Column column, OrderByItem.Direction direction)
           
 Query orderBy(OrderByItem... items)
           
 Query orderBy(String... orderByTokens)
           
 Query select(Column... columns)
           
 Query select(Column column, FromItem fromItem)
           
 Query select(FunctionType functionType, Column column)
           
 Query select(SelectItem... items)
           
 Query select(String expression)
          Adds a selection to this query.
 Query select(String expression, String alias)
           
 Query selectAll()
          Select all available select items from all currently available FROM items.
 Query selectAll(FromItem fromItem)
           
 Query selectCount()
           
 Query selectDistinct()
           
 Query setFirstRow(Integer firstRow)
          Sets the first row (aka offset) of the query's result.
 Query setMaxRows(Integer maxRows)
          Sets the maximum number of rows to be queried.
 String toSql()
           
protected  String toSql(boolean includeSchemaInColumnPaths)
           
 String toString()
           
 Query where(Column column, OperatorType operatorType, Object operand)
           
 Query where(FilterItem... items)
           
 Query where(Iterable<FilterItem> items)
           
 Query where(SelectItem selectItem, OperatorType operatorType, Object operand)
           
 Query where(String... whereItemTokens)
           
 
Methods inherited from class org.eobjects.metamodel.util.BaseObject
classEquals, equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

public Query()
Method Detail

select

public Query select(Column column,
                    FromItem fromItem)

select

public Query select(Column... columns)

select

public Query select(SelectItem... items)

select

public Query select(FunctionType functionType,
                    Column column)

select

public Query select(String expression,
                    String alias)

select

public Query select(String expression)
Adds a selection to this query.

Parameters:
expression -
Returns:

selectAll

public Query selectAll()
Select all available select items from all currently available FROM items. Equivalent of the expression "SELECT * FROM ..." in SQL.

Returns:

selectAll

public Query selectAll(FromItem fromItem)

selectDistinct

public Query selectDistinct()

selectCount

public Query selectCount()

from

public Query from(FromItem... items)

from

public Query from(Table table)

from

public Query from(String expression)

from

public Query from(Table table,
                  String alias)

from

public Query from(Table leftTable,
                  Table rightTable,
                  JoinType joinType,
                  Column leftOnColumn,
                  Column rightOnColumn)

groupBy

public Query groupBy(String... groupByTokens)

groupBy

public Query groupBy(GroupByItem... items)

groupBy

public Query groupBy(Column... columns)

orderBy

public Query orderBy(OrderByItem... items)

orderBy

public Query orderBy(String... orderByTokens)

orderBy

public Query orderBy(Column column)

orderBy

@Deprecated
public Query orderBy(Column column,
                                boolean ascending)
Deprecated. use orderBy(Column, Direction) instead


orderBy

public Query orderBy(Column column,
                     OrderByItem.Direction direction)

where

public Query where(FilterItem... items)

where

public Query where(Iterable<FilterItem> items)

where

public Query where(String... whereItemTokens)

where

public Query where(SelectItem selectItem,
                   OperatorType operatorType,
                   Object operand)

where

public Query where(Column column,
                   OperatorType operatorType,
                   Object operand)

having

public Query having(FilterItem... items)

having

public Query having(FunctionType function,
                    Column column,
                    OperatorType operatorType,
                    Object operand)

having

public Query having(Column column,
                    OperatorType operatorType,
                    Object operand)

having

public Query having(String... havingItemTokens)

toString

public String toString()
Overrides:
toString in class BaseObject

toSql

public String toSql()

toSql

protected String toSql(boolean includeSchemaInColumnPaths)

getSelectClause

public SelectClause getSelectClause()

getFromClause

public FromClause getFromClause()

getWhereClause

public FilterClause getWhereClause()

getGroupByClause

public GroupByClause getGroupByClause()

getHavingClause

public FilterClause getHavingClause()

getOrderByClause

public OrderByClause getOrderByClause()

setMaxRows

public Query setMaxRows(Integer maxRows)
Sets the maximum number of rows to be queried. If the result of the query yields more rows they should be discarded.

Parameters:
maxRows - the number of desired maximum rows. Can be null (default) for no limits
Returns:
this query

getMaxRows

public Integer getMaxRows()
Returns:
the number of maximum rows to yield from executing this query or null if no maximum/limit is set.

setFirstRow

public Query setFirstRow(Integer firstRow)
Sets the first row (aka offset) of the query's result. The row number is 1-based, so setting a first row value of 1 is equivalent to not setting it at all..

Parameters:
firstRow - the first row, where 1 is the first row.
Returns:
this query

getFirstRow

public Integer getFirstRow()
Gets the first row (aka offset) of the query's result, or null if none is specified. The row number is 1-based, so setting a first row value of 1 is equivalent to not setting it at all..

Returns:
the first row (aka offset) of the query's result, or null if no offset is specified.

decorateIdentity

protected void decorateIdentity(List<Object> identifiers)
Description copied from class: BaseObject
Subclasses should implement this method and add all fields to the list that are to be included in equals(...) and hashCode() evaluation

Specified by:
decorateIdentity in class BaseObject

clone

public Query clone()
Overrides:
clone in class Object


Copyright © 2007-2013. All Rights Reserved.