Class Query
- java.lang.Object
-
- com.feedzai.commons.sql.abstraction.dml.Expression
-
- com.feedzai.commons.sql.abstraction.dml.Query
-
- All Implemented Interfaces:
Serializable
public class Query extends Expression
Represents a SQL Query.- Since:
- 2.0.0
- Author:
- Rui Vilao (rui.vilao@feedzai.com)
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.feedzai.commons.sql.abstraction.dml.Expression
alias, enclosed, joins, ordering, properties, quotes, translator, withNoLock
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description QueryandWhere(Expression where)The WHERE clause.Querydistinct()Sets the SELECT expression as DISTINCT.QueryforUpdate(boolean forUpdate)Sets whether query is FOR UPDATE or not.Queryfrom(Expression... fromColumns)Adds the FROM columns.Queryfrom(Collection<? extends Expression> fromColumns)Adds the FROM columns.List<Expression>getFromColumns()Gets the FROM columns.List<Expression>getGroupbyColumns()Gets the GROUP BY expressions.ExpressiongetHaving()Gets the HAVING expression.IntegergetLimit()Gets the limit.IntegergetOffset()Gets the offset.List<Expression>getOrderbyColumns()Gets the ORDER BY expressions.List<Expression>getSelectColumns()Gets the SELECT columns.ExpressiongetWhere()Gets the WHERE expression.Querygroupby(Expression... groupbyColumns)Adds the GROUP BY columns.Querygroupby(Collection<? extends Expression> groupbyColumns)Adds the GROUP BY columns.Queryhaving(Expression having)Adds the HAVING expression.booleanisDistinct()Checks if the SELECT expression is distinct.booleanisForUpdate()Checks if query is a FOR UPDATE.Querylimit(Integer limit)Sets the limit.Queryoffset(Integer offset)Sets the offset.Queryorderby(Expression... orderbyColumns)Adds the ORDER BY columns.Queryorderby(Collection<? extends Expression> orderbyColumns)Adds the ORDER BY columns.Queryselect(Expression... selectColumns)Adds the SELECT columns.Queryselect(Collection<? extends Expression> selectColumns)Adds the SELECT columns.Stringtranslate()Translates the expression.Querywhere(Expression where)The where clause.-
Methods inherited from class com.feedzai.commons.sql.abstraction.dml.Expression
alias, asc, desc, enclose, fullOuterJoin, getAlias, getJoins, getOrdering, innerJoin, isAliased, isEnclosed, isQuote, isQuotes, isWithNoLock, leftOuterJoin, rightOuterJoin, unquote, withNoLock
-
-
-
-
Constructor Detail
-
Query
public Query()
Creates a new instance ofQuery.
-
-
Method Detail
-
translate
public String translate()
Description copied from class:ExpressionTranslates the expression.- Specified by:
translatein classExpression- Returns:
- A translation of the implementing expression.
-
getSelectColumns
public List<Expression> getSelectColumns()
Gets the SELECT columns.- Returns:
- The SELECT columns.
-
getFromColumns
public List<Expression> getFromColumns()
Gets the FROM columns.- Returns:
- The FROM columns.
-
getWhere
public Expression getWhere()
Gets the WHERE expression.- Returns:
- The WHERE expression.
-
getGroupbyColumns
public List<Expression> getGroupbyColumns()
Gets the GROUP BY expressions.- Returns:
- The GROUP BY expressions.
-
getHaving
public Expression getHaving()
Gets the HAVING expression.- Returns:
- The HAVING expression.
-
getOrderbyColumns
public List<Expression> getOrderbyColumns()
Gets the ORDER BY expressions.- Returns:
- The ORDER BY expressions.
-
getLimit
public Integer getLimit()
Gets the limit.nullis returned when not applicable.- Returns:
- The limit.
-
getOffset
public Integer getOffset()
Gets the offset.nullis returned when not applicable.- Returns:
- The offset.
-
isDistinct
public boolean isDistinct()
Checks if the SELECT expression is distinct.- Returns:
trueis the SELECT expression is distinct,falseotherwise.
-
isForUpdate
public boolean isForUpdate()
Checks if query is a FOR UPDATE. If it is set as true the database will block reads from another transactions also using SELECT FOR UPDATE.- Returns:
- true if it is for update; false otherwise.
- Since:
- 2.8.4
-
distinct
public Query distinct()
Sets the SELECT expression as DISTINCT.- Returns:
- This expression.
-
select
public Query select(Expression... selectColumns)
Adds the SELECT columns.- Parameters:
selectColumns- The columns.- Returns:
- This expression.
-
select
public Query select(Collection<? extends Expression> selectColumns)
Adds the SELECT columns.- Parameters:
selectColumns- The columns.- Returns:
- This expression.
-
from
public Query from(Expression... fromColumns)
Adds the FROM columns.- Parameters:
fromColumns- The columns.- Returns:
- This expression.
-
from
public Query from(Collection<? extends Expression> fromColumns)
Adds the FROM columns.- Parameters:
fromColumns- The columns.- Returns:
- This expression.
-
andWhere
public Query andWhere(Expression where)
The WHERE clause. If there is no where clause already defined, sets to the defined value. If there is already an expression for where defined, defines anandexpression between old and new clauses. Example:query.where(eq(column("col1"),k(1)).andWhere(eq(column("col2"),k(2)) will be translated to ("col1" = 1) AND ("col2" = 2)- Parameters:
where- The WHERE expression.- Returns:
- This expression.
-
where
public Query where(Expression where)
The where clause. Note:This method replaces anywhereclauses previously defined.- Parameters:
where- The object.- Returns:
- This expression.
-
groupby
public Query groupby(Expression... groupbyColumns)
Adds the GROUP BY columns.- Parameters:
groupbyColumns- The columns.- Returns:
- This expression.
-
groupby
public Query groupby(Collection<? extends Expression> groupbyColumns)
Adds the GROUP BY columns.- Parameters:
groupbyColumns- The columns.- Returns:
- This expression.
-
having
public Query having(Expression having)
Adds the HAVING expression.- Parameters:
having- The having expression.- Returns:
- This expression.
-
orderby
public Query orderby(Expression... orderbyColumns)
Adds the ORDER BY columns.- Parameters:
orderbyColumns- The columns.- Returns:
- This expression.
-
orderby
public Query orderby(Collection<? extends Expression> orderbyColumns)
Adds the ORDER BY columns.- Parameters:
orderbyColumns- The columns.- Returns:
- This expression.
-
limit
public Query limit(Integer limit)
Sets the limit.- Parameters:
limit- The number of rows that the query returns.- Returns:
- This expression.
-
offset
public Query offset(Integer offset)
Sets the offset.- Parameters:
offset- The start position- Returns:
- This expression.
-
forUpdate
public Query forUpdate(boolean forUpdate)
Sets whether query is FOR UPDATE or not. If it is set as true the database will block reads from another transactions also using SELECT FOR UPDATE.- Parameters:
forUpdate- If it is FOR UPDATE or not.- Returns:
- This expression.
- Since:
- 2.8.4
-
-