Package org.apache.torque.sql
Class Query
java.lang.Object
org.apache.torque.sql.Query
Contains the various parts of a SQL statement (select, update or delete).
Attributes exist for the sections of these statements:
modifiers, columns, from clause, where clause, and order by clause.
Most parts of the query are appended to buffers which only accept
unique entries.
- Version:
- $Id: Query.java 1867515 2019-09-25 15:02:03Z gk $ TODO rename to SqlStatement
- Author:
- John D. McNally, Sam Joseph, Martin Poeschl, Thomas Fischer
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a String to display this query.Returns the JDBC statement fetch size to use for queries.Returns the FOR UPDATE clause which should be added to the query.Retrieve the from buffer in order to specify which tables are involved in this query.Retrieve the group by columns buffer in order to specify which columns are used to group the results of the query.Get the having clause.getLimit()Get the limit number.Get the offset number.Retrieve the order by columns buffer in order to specify which columns are used to sort the results of the query.Returns the operator connecting the query parts.getParts()Returns the parts of this query.Get the Post limit String.Get the Pre limit String.Returns all preparedStatementReplacements in the query.Get the rowcount number.Retrieve the columns buffer in order to specify which columns are returned in this query.Retrieve the modifier buffer in order to add modifiers to this query.getType()Returns the type of this SQL statement.Retrieve the values to update to in case of an update statement.Retrieve the where buffer in order to specify the selection criteria E.g. column_a=?.Retrieves the replacements which are inserted into prepared statement placeholders in the where clause.booleanhasLimit()True if this query has a limit clause registered.voidsetFetchSize(Integer fetchSize) Sets the JDBC statement fetch size to use for queries.voidsetForUpdate(String forUpdate) Sets the FOR UPDATE clause which should be added to the query.voidSet the having clause.voidSet the limit number.voidSet the offset number.voidsetPartOperator(String partOperator) Sets the operator connecting the query parts.voidsetPostLimit(String postLimit) Set the Post limit String.voidsetPreLimit(String preLimit) Get the Pre limit String.voidsetRowcount(String rowcount) Set the rowcount number.voidsetType(Query.Type type) Sets the type of this SQL statement.toString()Outputs the query statement.toStringBuilder(StringBuilder stringBuilder) Appends the query to a string builder.
-
Constructor Details
-
Query
public Query()
-
-
Method Details
-
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.
-
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.
-
getUpdateValues
Retrieve the values to update to in case of an update statement.- Returns:
- A modifiable ColumnValues object containing the current update values.
-
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.
-
getWhereClause
Retrieve the where buffer in order to specify the selection criteria E.g. column_a=?. Expressions added to the buffer will be separated using AND.- Returns:
- An UniqueList used to add selection criteria.
-
getWhereClausePreparedStatementReplacements
Retrieves the replacements which are inserted into prepared statement placeholders in the where clause. The number and order of the elements in the list must correspond to the order of the placeholders in the where clause string.- Returns:
- A List containing all the replacements for the prepared statement placeholders, not null.
-
getPreparedStatementReplacements
Returns all preparedStatementReplacements in the query.- Returns:
- an unmodifiable list of all preparedStatementReplacements.
-
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
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.
-
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.
-
setHaving
Set the having clause. This is used to restrict which rows are returned.- Parameters:
having- A 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.
-
setLimit
Set the limit number. This is used to limit the number of rows returned by a query.- Parameters:
limit- A 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.
-
setPreLimit
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.
-
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.
-
setPostLimit
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.
-
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.
-
setOffset
Set the offset number. This is used to set the row where the resultset starts.- Parameters:
offset- A 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.
-
setRowcount
Set the rowcount number. This is used to limit the number of rows returned by Sybase and MS SQL/Server.- Parameters:
rowcount- A String.
-
setForUpdate
Sets the FOR UPDATE clause which should be added to the query.- Parameters:
forUpdate- the FOR UPDATE clause which should be added, null if no FOR UPDATE clause should be used.
-
getForUpdate
Returns the FOR UPDATE clause which should be added to the query.- Returns:
- the FOR UPDATE clause, or null if none should be added.
-
hasLimit
public boolean hasLimit()True if this query has a limit clause registered.- Returns:
- true if a limit clause exists.
-
getType
Returns the type of this SQL statement.- Returns:
- type the new type, not null.
-
setType
Sets the type of this SQL statement.- Parameters:
type- the new type, not null.- Throws:
NullPointerException- iftypeis null.
-
getFetchSize
Returns the JDBC statement fetch size to use for queries.- Returns:
- the fetch size, or null if none is set.
-
setFetchSize
Sets the JDBC statement fetch size to use for queries.- Parameters:
fetchSize- the fetch size, or null for not set.
-
getParts
Returns the parts of this query.- Returns:
- a modifiable list containing the parts of this query, not null.
-
getPartOperator
Returns the operator connecting the query parts.- Returns:
- the operator connecting the parts, or null.
-
setPartOperator
Sets the operator connecting the query parts.- Parameters:
partOperator- the operator connecting the parts, or null.
-
toString
Outputs the query statement. -
toStringBuilder
Appends the query to a string builder.- Parameters:
stringBuilder- the stringBuilder to append to, not null.- Returns:
- the modified passed in string builder.
-
getDisplayString
Returns a String to display this query.- Returns:
- the SQL query for display.
- Throws:
TorqueException- Trouble creating the query string.
-