org.apache.torque.util
Class Query

java.lang.Object
  extended by org.apache.torque.util.Query

public class Query
extends java.lang.Object

Used to assemble an SQL SELECT query. Attributes exist for the sections of a SELECT: modifiers, columns, from clause, where clause, and order by clause. The various parts of the query are appended to buffers which only accept unique entries. This class is used primarily by BasePeer.

Version:
$Id: Query.java 522044 2007-03-24 16:00:57Z tfischer $
Author:
John D. McNally, Sam Joseph, Martin Poeschl, Thomas Fischer

Nested Class Summary
static class Query.FromElement
          This class describes an Element in the From-part of a SQL clause.
 
Constructor Summary
Query()
           
 
Method Summary
 UniqueList getFromClause()
          Retrieve the from buffer in order to specify which tables are involved in this query.
 UniqueList getGroupByClause()
          Retrieve the group by columns buffer in order to specify which columns are used to group the results of the query.
 java.lang.String getHaving()
          Get the having clause.
 java.lang.String getLimit()
          Get the limit number.
 java.lang.String getOffset()
          Get the offset number.
 UniqueList getOrderByClause()
          Retrieve the order by columns buffer in order to specify which columns are used to sort the results of the query.
 java.lang.String getPostLimit()
          Get the Post limit String.
 java.lang.String getPreLimit()
          Get the Pre limit String.
 java.lang.String getRowcount()
          Get the rowcount number.
 UniqueList getSelectClause()
          Retrieve the columns buffer in order to specify which columns are returned in this query.
 UniqueList getSelectModifiers()
          Retrieve the modifier buffer in order to add modifiers to this query.
 UniqueList getWhereClause()
          Retrieve the where buffer in order to specify the selection criteria E.g.
 boolean hasLimit()
          True if this query has a limit clause registered.
 void setFromClause(UniqueList tables)
          Set the from clause.
 void setHaving(java.lang.String having)
          Set the having clause.
 void setLimit(java.lang.String limit)
          Set the limit number.
 void setOffset(java.lang.String offset)
          Set the offset number.
 void setPostLimit(java.lang.String postLimit)
          Set the Post limit String.
 void setPreLimit(java.lang.String preLimit)
          Get the Pre limit String.
 void setRowcount(java.lang.String rowcount)
          Set the rowcount number.
 void setSelectClause(UniqueList columns)
          Set the columns.
 void setSelectModifiers(UniqueList modifiers)
          Set the modifiers.
 void setWhereClause(UniqueList where)
          Set the where clause.
 java.lang.String toString()
          Outputs the query statement.
 java.lang.StringBuffer toStringBuffer(java.lang.StringBuffer stmt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Query

public Query()
Method Detail

getSelectModifiers

public UniqueList getSelectModifiers()
Retrieve the modifier buffer in order to add modifiers to this query. E.g. DISTINCT and ALL.

Returns:
An UniqueList used to add modifiers.

setSelectModifiers

public void setSelectModifiers(UniqueList modifiers)
Set the modifiers. E.g. DISTINCT and ALL.

Parameters:
modifiers - the modifiers

getSelectClause

public UniqueList getSelectClause()
Retrieve the columns buffer in order to specify which columns are returned in this query.

Returns:
An UniqueList used to add columns to be selected.

setSelectClause

public void setSelectClause(UniqueList columns)
Set the columns.

Parameters:
columns - columns list

getFromClause

public UniqueList getFromClause()
Retrieve the from buffer in order to specify which tables are involved in this query.

Returns:
An UniqueList used to add tables involved in the query.

setFromClause

public void setFromClause(UniqueList tables)
Set the from clause.

Parameters:
tables - the tables

getWhereClause

public UniqueList getWhereClause()
Retrieve the where buffer in order to specify the selection criteria E.g. column_a=3. Expressions added to the buffer will be separated using AND.

Returns:
An UniqueList used to add selection criteria.

setWhereClause

public void setWhereClause(UniqueList where)
Set the where clause.

Parameters:
where - where clause

getOrderByClause

public UniqueList getOrderByClause()
Retrieve the order by columns buffer in order to specify which columns are used to sort the results of the query.

Returns:
An UniqueList used to add columns to sort on.

getGroupByClause

public UniqueList getGroupByClause()
Retrieve the group by columns buffer in order to specify which columns are used to group the results of the query.

Returns:
An UniqueList used to add columns to group on.

setHaving

public void setHaving(java.lang.String having)
Set the having clause. This is used to restrict which rows are returned.

Parameters:
having - A String.

setLimit

public void setLimit(java.lang.String limit)
Set the limit number. This is used to limit the number of rows returned by a query.

Parameters:
limit - A String.

setPreLimit

public void setPreLimit(java.lang.String preLimit)
Get the Pre limit String. Oracle and DB2 want to encapsulate a query into a subquery for limiting.

Parameters:
preLimit - A String with the preLimit.

setPostLimit

public void setPostLimit(java.lang.String postLimit)
Set the Post limit String. Oracle and DB2 want to encapsulate a query into a subquery for limiting.

Parameters:
postLimit - A String with the postLimit.

setOffset

public void setOffset(java.lang.String offset)
Set the offset number. This is used to set the row where the resultset starts.

Parameters:
offset - A String.

setRowcount

public void setRowcount(java.lang.String rowcount)
Set the rowcount number. This is used to limit the number of rows returned by Sybase and MS SQL/Server.

Parameters:
rowcount - A String.

getHaving

public java.lang.String getHaving()
Get the having clause. This is used to restrict which rows are returned based on some condition.

Returns:
A String that is the having clause.

getLimit

public java.lang.String getLimit()
Get the limit number. This is used to limit the number of returned by a query in Postgres.

Returns:
A String with the limit.

getPostLimit

public java.lang.String getPostLimit()
Get the Post limit String. Oracle and DB2 want to encapsulate a query into a subquery for limiting.

Returns:
A String with the preLimit.

getPreLimit

public java.lang.String getPreLimit()
Get the Pre limit String. Oracle and DB2 want to encapsulate a query into a subquery for limiting.

Returns:
A String with the preLimit.

getOffset

public java.lang.String getOffset()
Get the offset number. This is used to set the row where the resultset starts.

Returns:
A String with the offset, or null if no offset is set.

hasLimit

public boolean hasLimit()
True if this query has a limit clause registered.

Returns:
true if a limit clause exists.

getRowcount

public java.lang.String getRowcount()
Get the rowcount number. This is used to limit the number of returned by a query in Sybase and MS SQL/Server.

Returns:
A String with the row count.

toString

public java.lang.String toString()
Outputs the query statement.

Overrides:
toString in class java.lang.Object
Returns:
A String with the query statement.

toStringBuffer

public java.lang.StringBuffer toStringBuffer(java.lang.StringBuffer stmt)


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.