This class is a collection of static functions to create different types of select expressions within a database query. This includes selecting DTO fields, database expressions, or counting rows in a query.
This class cannot be instantiated.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ProtoNestableTOExpr<Number> ABS(): Absolute value of a number.static ProtoNestableTOExpr<Number> abs(ExpressionSpec expressionSpec) ABS(): Absolute value of a number.static ExpressionSpecSelects a DTO field by name for the specified DTO type that is selected/joined in the query, and aliases it with the specified alias.static <DTO> DtoAliasSpec<DTO> Aliases the specified entity/mapped DTO class.static ExpressionSpecSelects a database column by name and aliases it with the specified alias.static ExpressionSpecSelects a database column by name and alias.static SqlFromTargetSpecalias(Function<SelectApi, SelectTerminal<?>> query, String alias) Aliases the specified subquery.static ExpressionSpecSelects a database column by name and aliases it with the specified alias.static AliasReferenceSpecReferences an aliased column in the query.static AliasReferenceSpecReferences an aliased column in the query in the context of a parent table/subquery.static AliasReferenceSpecaliasRef(String tableAlias, ExpressionSpec expression) References an aliased column in the query in the context of a parent table/subquery.static SqlFromTargetSpecaliasTable(String table, String alias) Aliases the specified table.static TypeOverrideExpressionSpec<Number> AVG(): Returns the average value of a column/field.static TypeOverrideExpressionSpec<Number> avg(ExpressionSpec expressionSpec) AVG(): Returns the average value of a column/field.static ExpressionSpecSelects a database column by name.static ExpressionSpecSelects a database column by its table and simple column name.static ExpressionSpecSelects a database column by name.static ExpressionSpecSelects a database column by name and aliases it with the specified alias.static ExpressionSpecSelects a database column by name and alias.static ExpressionSpecSelects a database column by name and aliases it with the specified alias.static ExpressionSpecSelects a database column by name.static ExpressionSpecSelects a database column by its table and simple column name.static ExpressionSpecSelects a database column by name.static <T> ConvertIntent<T> convert(Class<T> returnType, ExpressionSpec... expressions) Converts the results of multiple expressions into a single Java object of the specified type.static <T> ConvertSpec<T> convert(ExpressionSpec expression, Class<T> returnType) Converts a database result into the specified Java type.static TypeOverrideExpressionSpec<Long> count()COUNT(): Selects the count of rows matching the query.static CurrentTimestampSpecCURRENT_TIMESTAMP: Returns the current date and time.static QueryAlteringExpressionSpec<Boolean> exists()Execute an existence check and return a true/false response to the query.static ExistsExpressionSpecexists(Function<SelectApi, SelectTerminal<?>> query) EXISTS: Checks if the provided query returned any resultsstatic ExpressionSpecSelects a DTO field by name for the specified DTO type that is selected/joined in the query.static ExpressionSpecSelects a DTO field by name for the DTO class selected in the query.static ExpressionSpecSelects a DTO field by name for the specified DTO type that is selected/joined in the query.static ExpressionSpecSelects a DTO field by name for the entity/DTO class selected in the query.static <T> LiteralExpressionSpec<T> literal(@Nullable T value) Specifies a literal value.static <T> LiteralExpressionSpec<T> Specifies a literal value.static ProtoNestableTOExpr<String> LOWER(): Returns the lowercase value of a column's text.static ProtoNestableTOExpr<String> lower(ExpressionSpec expressionSpec) LOWER(): Returns the lowercase value of a column's text.static TypeOverrideExpressionSpec<Number> MAX(): Returns the highest or largest value within a specified column/field.static TypeOverrideExpressionSpec<Number> max(ExpressionSpec expressionSpec) MAX(): Returns the highest or largest value within a specified expression.static TypeOverrideExpressionSpec<Number> MIN(): Returns the lowest or smallest value within a specified column or expressionstatic TypeOverrideExpressionSpec<Number> min(ExpressionSpec expressionSpec) MIN(): Returns the lowest or smallest value within a specified column or expressionstatic ConvertIntent<Row> row(ExpressionSpec... expressions) Converts the results of multiple expressions into a single databaseRowobject.static ProtoNestableTOExpr<String> SUBSTRING(): Returns the lowercase value of a column's text.static ProtoNestableTOExpr<String> SUBSTRING(): Returns the lowercase value of a column's text.static ProtoNestableTOExpr<String> substring(ExpressionSpec expressionSpec, int start) SUBSTRING(): Returns the lowercase value of a column's text.static ProtoNestableTOExpr<String> substring(ExpressionSpec expressionSpec, int start, int length) SUBSTRING(): Returns the lowercase value of a column's text.static ProtoNestableTOExpr<String> UPPER(): Returns the uppercase value of a column's text.static ProtoNestableTOExpr<String> upper(ExpressionSpec expressionSpec) UPPER(): Returns the uppercase value of a column's text.static ValuesSpecCreates a SQLVALUESclause for multiple columns of hardcoded data spanning one or more rows.static ValuesSpecCreates a SQLVALUESclause for a single column of hardcoded data.static ValuesSpecCreates a SQLVALUESclause for multiple columns of hardcoded data.static ValuesSpecvalues(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2, String l3, @Nullable Object v3) Creates a SQLVALUESclause for multiple columns of hardcoded data.static ValuesSpecvalues(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2, String l3, @Nullable Object v3, String l4, @Nullable Object v4) Creates a SQLVALUESclause for multiple columns of hardcoded data.static ValuesSpecvalues(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2, String l3, @Nullable Object v3, String l4, @Nullable Object v4, String l5, @Nullable Object v5) Creates a SQLVALUESclause for multiple columns of hardcoded data.static ValuesSpecvalues(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2, String l3, @Nullable Object v3, String l4, @Nullable Object v4, String l5, @Nullable Object v5, String l6, @Nullable Object v6) Creates a SQLVALUESclause for multiple columns of hardcoded data.static ValuesSpecCreates a SQLVALUESclause for multiple columns of hardcoded data spanning one or more rows.static ValuesSpecCreates a SQLVALUESclause for multiple row, each containing multiple columns of hardcoded data.static ValuesSpecCreates a SQLVALUESclause for multiple columns of hardcoded data.
-
Method Details
-
alias
Aliases the specified entity/mapped DTO class.The result can be used as a target for a `FROM` or `JOIN` clause.
- Type Parameters:
DTO- The entity or mapped DTO class to alias.- Parameters:
dtoClass- The DTO class to alias.alias- The alias to use for the DTO class.- Returns:
- a target specification for the specified DTO class and alias.
-
aliasTable
Aliases the specified table.The result can be used as a target for a `FROM` or `JOIN` clause.
- Parameters:
table- Name of the table to alias.alias- The alias to use for the table.- Returns:
- a target specification for the specified table and alias.
-
alias
Aliases the specified subquery.This allows the results from the subquery to be referenced in the parent query. It can be used as a target for a `FROM` or `JOIN` clause.
- Parameters:
query- The subquery to alias.alias- The alias to use for the subquery.- Returns:
- a target specification for the specified subquery and alias.
-
values
Creates a SQLVALUESclause for a single column of hardcoded data.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.- Parameters:
tableAlias- the alias of the virtual table to which the values belonglabel- the value's column labelvalue- the value; can benull- Returns:
- a new
ValuesSpecinstance containing the specified table alias, label, and value
-
values
public static ValuesSpec values(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2) Creates a SQLVALUESclause for multiple columns of hardcoded data.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.- Parameters:
tableAlias- the alias of the virtual table to which the values belongl1- the first value's column labelv1- the first value; can benulll2- the second value's column labelv2- the second value; can benull- Returns:
- a new
ValuesSpecinstance containing the specified table alias, label, and value
-
values
public static ValuesSpec values(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2, String l3, @Nullable Object v3) Creates a SQLVALUESclause for multiple columns of hardcoded data.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.- Parameters:
tableAlias- the alias of the virtual table to which the values belongl1- the first value's column labelv1- the first value; can benulll2- the second value's column labelv2- the second value; can benulll3- the third value's column labelv3- the third value; can benull- Returns:
- a new
ValuesSpecinstance containing the specified table alias, label, and value
-
values
public static ValuesSpec values(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2, String l3, @Nullable Object v3, String l4, @Nullable Object v4) Creates a SQLVALUESclause for multiple columns of hardcoded data.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.- Parameters:
tableAlias- the alias of the virtual table to which the values belongl1- the first value's column labelv1- the first value; can benulll2- the second value's column labelv2- the second value; can benulll3- the third value's column labelv3- the third value; can benulll4- the fourth value's column labelv4- the fourth value; can benull- Returns:
- a new
ValuesSpecinstance containing the specified table alias, label, and value
-
values
public static ValuesSpec values(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2, String l3, @Nullable Object v3, String l4, @Nullable Object v4, String l5, @Nullable Object v5) Creates a SQLVALUESclause for multiple columns of hardcoded data.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.- Parameters:
tableAlias- the alias of the virtual table to which the values belongl1- the first value's column labelv1- the first value; can benulll2- the second value's column labelv2- the second value; can benulll3- the third value's column labelv3- the third value; can benulll4- the fourth value's column labelv4- the fourth value; can benulll5- the fifth value's column labelv5- the fifth value; can benull- Returns:
- a new
ValuesSpecinstance containing the specified table alias, label, and value
-
values
public static ValuesSpec values(String tableAlias, String l1, @Nullable Object v1, String l2, @Nullable Object v2, String l3, @Nullable Object v3, String l4, @Nullable Object v4, String l5, @Nullable Object v5, String l6, @Nullable Object v6) Creates a SQLVALUESclause for multiple columns of hardcoded data.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.- Parameters:
tableAlias- the alias of the virtual table to which the values belongl1- the first value's column labelv1- the first value; can benulll2- the second value's column labelv2- the second value; can benulll3- the third value's column labelv3- the third value; can benulll4- the fourth value's column labelv4- the fourth value; can benulll5- the fifth value's column labelv5- the fifth value; can benulll6- the sixth value's column labelv6- the sixth value; can benull- Returns:
- a new
ValuesSpecinstance containing the specified table alias, label, and value
-
values
Creates a SQLVALUESclause for multiple columns of hardcoded data spanning one or more rows.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.For a single row of
VALUESdata, thelabelsandvaluesarrays should contain the same number of elements. For multiple rows ofVALUESdata, thevaluesarray size should be a multiple of thelabelsarray size.- Parameters:
tableAlias- The alias of the virtual table to which the values belong.labels- Array of column labels.values- Array of nullable values. Must be the same length aslabels, or a multiple of it.- Returns:
- A new
ValuesSpecinstance containing the specified table alias, label, and value. - See Also:
-
values
public static ValuesSpec values(String tableAlias, List<String> labels, List<@Nullable Object> values) Creates a SQLVALUESclause for multiple columns of hardcoded data spanning one or more rows.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.For a single row of
VALUESdata, thelabelsandvalueslists should contain the same number of elements. For multiple rows ofVALUESdata, thevalueslist size should be a multiple of thelabelslist size.- Parameters:
tableAlias- The alias of the virtual table to which the values belong.labels- List of column labelsvalues- List of nullable values. Must be the same length aslabels, or a multiple of it.- Returns:
- A new
ValuesSpecinstance containing the specified table alias, label, and value. - See Also:
-
values
Creates a SQLVALUESclause for multiple columns of hardcoded data.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.- Parameters:
tableAlias- the alias of the virtual table to which the values belongvalues- A map of column labels to nullable values. To preserve ordering, consider using aLinkedHashMap.- Returns:
- a new
ValuesSpecinstance containing the specified table alias, label, and value
-
values
Creates a SQLVALUESclause for multiple row, each containing multiple columns of hardcoded data.The
VALUESclause be used inSELECTorMERGEstatements to construct a temporary, inline virtual table of hardcoded data without needing a physical database table.- Parameters:
tableAlias- the alias of the virtual table to which the values belongrows- List of rows, each row consisting of a map of column labels to nullable values. To preserve ordering, consider using aLinkedHashMap.- Returns:
- a new
ValuesSpecinstance containing the specified table alias, label, and value - See Also:
-
f
Selects a DTO field by name for the DTO class selected in the query.Shorthand for
field(String).This infers the source entity/mapped DTO class from the available `FROM`/`JOIN` clauses.
- Parameters:
field- The name of the DTO field to select.- Returns:
- a query expression selecting the target entity/DTO field
- See Also:
-
f
Selects a DTO field by name for the specified DTO type that is selected/joined in the query.Shorthand for
field(Class, String).- Parameters:
dtoClass- The DTO class to select from.field- The name of the DTO field to select.- Returns:
- a query expression selecting the target entity/DTO field
-
field
Selects a DTO field by name for the entity/DTO class selected in the query.This infers the source entity/mapped DTO class from the available `FROM`/`JOIN` clauses.
- Parameters:
field- The name of the DTO field to select.- Returns:
- a query expression selecting the target entity/DTO field
- See Also:
-
field
Selects a DTO field by name for the specified DTO type that is selected/joined in the query.- Parameters:
dtoClass- The DTO class.field- The name of the DTO field to select.- Returns:
- a query expression selecting the target entity/DTO field
- See Also:
-
alias
Selects a DTO field by name for the specified DTO type that is selected/joined in the query, and aliases it with the specified alias.- Parameters:
dtoClass- The DTO class to select from.field- The name of the DTO field to select.alias- The alias to use for the field.- Returns:
- a query expression selecting the aliased target entity/DTO field
-
c
Selects a database column by name.This is shorthand for
column(String).Column names can be qualified with a table name, e.g. "table.column".
- Parameters:
column- The name of the column to select.- Returns:
- a query expression selecting the target column.
-
column
Selects a database column by name.Column names can be qualified with a table name, e.g. "table.column".
- Parameters:
column- The name of the column to select.- Returns:
- a query expression selecting the target column.
- See Also:
-
c
Selects a database column by its table and simple column name.Shorthand for
column(String, String).- Parameters:
table- The table to select the column from.column- The name of the column to select.- Returns:
- a query expression selecting the target column.
- See Also:
-
column
Selects a database column by its table and simple column name.- Parameters:
table- The table to select the column from.column- The name of the column to select.- Returns:
- a query expression selecting the target column.
- See Also:
-
c
Selects a database column by name.Shorthand for
column(Table, String)The returned
ProtoColumnExpressionSpecvalue has no context of the table it is selecting from yet.- Parameters:
table- The table to select the column from.column- The name of the column to select.- Returns:
- a query expression selecting the target column.
-
column
Selects a database column by name.- Parameters:
table- The table to select the column from.column- The name of the column to select.- Returns:
- a query expression selecting the target column.
-
ca
Selects a database column by name and aliases it with the specified alias.Shorthand for
alias(Table, String, String).- Parameters:
table- The table to select the column from.column- The simple name of the column to select.columnAlias- The alias to use for the column; may benull.- Returns:
- a query expression selecting the target column.
-
alias
Selects a database column by name and aliases it with the specified alias.- Parameters:
table- The table to select the column from.column- The simple name of the column to select.columnAlias- The alias to use for the column; may benull.- Returns:
- a query expression selecting the target column.
- See Also:
-
ca
Selects a database column by name and aliases it with the specified alias.Shorthand for
alias(String, String)Column names can be qualified with a table name, e.g. "table.column".
- Parameters:
column- The name of the column to select.alias- The alias to use for the column.- Returns:
- a query expression selecting the target column.
-
alias
Selects a database column by name and aliases it with the specified alias.Column names can be qualified with a table name, e.g. "table.column".
- Parameters:
column- The name of the column to select.alias- The alias to use for the column.- Returns:
- a query expression selecting the target column.
- See Also:
-
ca
Selects a database column by name and alias.Shorthand for
alias(Table, String, String)- Parameters:
table- The table to select the column from.column- The simple name of the column to select.columnAlias- The alias to use for the column.- Returns:
- a query expression selecting the target column.
-
alias
Selects a database column by name and alias.The returned
ProtoColumnExpressionSpecvalue has no context of the table it is selecting from yet.- Parameters:
table- The table to select the column from.column- The name of the column to select.columnAlias- The alias to use for the column.- Returns:
- a query expression selecting the target column.
-
aliasRef
References an aliased column in the query.This is used to provide aliases as part of conditional statements in various SQL clauses.
- Parameters:
alias- The alias/label of the column in the query.- Returns:
- A reference to an aliased column in the query.
-
aliasRef
References an aliased column in the query in the context of a parent table/subquery.This is used to provide aliases as part of conditional statements in various SQL clauses.
- Parameters:
tableAlias- The alias/label of the parent table/subquery.columnLabel- The label (alias or column name) of the column to reference.- Returns:
- A reference to an aliased column in the query.
- See Also:
-
aliasRef
References an aliased column in the query in the context of a parent table/subquery.This is used to provide aliases as part of conditional statements in various SQL clauses.
- Parameters:
tableAlias- The alias/label of the parent table/subquery.expression- Query expression targeting a column in the parent table/subquery.- Returns:
- A reference to an aliased column in the query.
- See Also:
-
literal
Specifies a literal value.This is used to specify a literal value in a query expression.
- Type Parameters:
T- The type of the literal value.- Parameters:
value- The literal value to wrap.- Returns:
- A literal expression specification.
-
literal
Specifies a literal value.This is used to specify a literal value in a query expression.
- Type Parameters:
T- The type of the literal value.- Parameters:
value- The literal value to wrap.- Returns:
- A literal expression specification.
-
convert
Converts a database result into the specified Java type.This uses Litebridge's registered type converter to perform the conversion; it is not a database operation.
It can be used to ensure that the return value of a nested expression is converted to the specified Java type on the ORM side; e.g.
avg(ExpressionSpec)returns a @{Number} instance by default, with the actual return type being determined by the database. To convert the return type to aLong,convert()can be used to convert it before returning:litebridge.select(Fn.convert(Fn.avg(column), Long.class));- Type Parameters:
T- The type to convert the expression result to- Parameters:
expression- The target expression result to convertreturnType- The type to convert the expression result to- Returns:
- a
ProtoColumnExpressionSpecexpression instance to convert the return value of the nested expression
-
convert
Converts the results of multiple expressions into a single Java object of the specified type.- Type Parameters:
T- The target type.- Parameters:
returnType- The target type class.expressions- The expressions to convert.- Returns:
- a
ConvertIntentinstance.
-
row
Converts the results of multiple expressions into a single databaseRowobject.- Parameters:
expressions- The expressions to convert.- Returns:
- a
ConvertIntentinstance forRow.
-
avg
AVG(): Returns the average value of a column/field.- Parameters:
column- Name of the target column/field to calculate the average value of.- Returns:
- a
ProtoNestableTOExprexpression instance to select the average value of a column/field.
-
avg
AVG(): Returns the average value of a column/field.- Parameters:
expressionSpec- Target nested expression to calculate the average value of.- Returns:
- a
ProtoNestableTOExprexpression instance to select the average value of a column/field.
-
max
MAX(): Returns the highest or largest value within a specified column/field.- Parameters:
column- Name of the target column/field to calculate the maximum value of.- Returns:
- a
ProtoNestableTOExprexpression instance to select the maximum value of a column/field.
-
max
MAX(): Returns the highest or largest value within a specified expression.- Parameters:
expressionSpec- Target nested expression to calculate the maximum value of.- Returns:
- a
ProtoNestableTOExprexpression instance to select the maximum value of a column/field.
-
min
MIN(): Returns the lowest or smallest value within a specified column or expression- Parameters:
column- Name of the target column/field to calculate the maximum value of.- Returns:
- a
ProtoNestableTOExprexpression instance to select the maximum value of a column/field.
-
min
MIN(): Returns the lowest or smallest value within a specified column or expression- Parameters:
expressionSpec- Target nested expression to calculate the maximum value of.- Returns:
- a
ProtoNestableTOExprexpression instance to select the maximum value of a column/field.
-
count
COUNT(): Selects the count of rows matching the query.- Returns:
- a
CountSpecexpression instance to select the count of rows.
-
upper
UPPER(): Returns the uppercase value of a column's text.- Parameters:
column- Target column/field name- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column.
-
upper
UPPER(): Returns the uppercase value of a column's text.- Parameters:
expressionSpec- Target nested expression- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column.
-
lower
LOWER(): Returns the lowercase value of a column's text.- Parameters:
column- Target column/field name- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column.
-
lower
LOWER(): Returns the lowercase value of a column's text.- Parameters:
expressionSpec- Target nested expression- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column.
-
substring
SUBSTRING(): Returns the lowercase value of a column's text.This shorthand version omits the "length" parameter and thus extracts everything from the start position to the end of the text.
- Parameters:
column- Target column to extract characters from.start- The starting position. The first character of a database string is always 1.- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column. - See Also:
-
substring
SUBSTRING(): Returns the lowercase value of a column's text.This shorthand version omits the "length" parameter and thus extracts everything from the start position to the end of the text.
- Parameters:
expressionSpec- Target nested expression to extract characters from.start- The starting position. The first character of a database string is always 1.- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column. - See Also:
-
substring
SUBSTRING(): Returns the lowercase value of a column's text.- Parameters:
column- Target column to extract characters from.start- The starting position. The first character of a database string is always 1.length- The number of characters to return.- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column. - See Also:
-
substring
public static ProtoNestableTOExpr<String> substring(ExpressionSpec expressionSpec, int start, int length) SUBSTRING(): Returns the lowercase value of a column's text.- Parameters:
expressionSpec- Target nested expression to extract characters from.start- The starting position. The first character of a database string is always 1.length- The number of characters to return.- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column. - See Also:
-
abs
ABS(): Absolute value of a number.- Parameters:
column- Target column/field.- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column.
-
abs
ABS(): Absolute value of a number.- Parameters:
expressionSpec- Target nested expression.- Returns:
- a
ProtoNestableTOExprexpression instance to select a specific column.
-
currentTimestamp
CURRENT_TIMESTAMP: Returns the current date and time.- Returns:
- a
CurrentTimestampSpecinstance.
-
exists
EXISTS: Checks if the provided query returned any results- Returns:
- An
EXISTSexpression.
-
exists
Execute an existence check and return a true/false response to the query.This should be used as the only expression in the query.
It alters the query return type toBoolean.The resulting expression causes the query to be optimised for a basic existence check, e.g. a variant of:
SELECT 1 FROM users WHERE user_id = ? LIMIT 1- Returns:
- A top-level existence-checking expression.
-