|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.query.Expressions
public class Expressions
A factory class to create expressions.
Field Summary | |
---|---|
static Pattern |
PARAMETER_REGEXP
A parameter name can only contain the characters a-z, A-Z or 0-9. |
Constructor Summary | |
---|---|
Expressions()
|
Method Summary | |
---|---|
static Expression |
abs(Expression e)
Calculate the absolute value of an expression: new expression = abs(e). |
static Expression |
add(Expression e1,
Expression e2)
Add two expressions: new expression = e1 + e2. |
static Expression |
aFloat(float value)
Create a constant expression from a float. |
static Expression |
all(Query subquery)
Create a subquery expression: ANY (subquery) . |
static Expression |
any(Query subquery)
Create a subquery expression: ANY (subquery) . |
static Expression |
caseWhen(Expression elseExpression,
WhenStatement... whenStatements)
Create a conditional CASE-WHEN expression:
CASE WHEN r1 THEN e1 WHEN r2 THEN e2 ... |
static Expression |
divide(Expression e1,
Expression e2)
Divide one expression by another: new expression = e1 / e2. |
static Expression |
exp(Expression e)
Calculate the exponential of an expression: new expression = exp(e). |
private static int |
getFirstNull(Object[] array)
Test if there is null in the array. |
static Expression |
integer(int value)
Create a constant expression from an integer. |
static Expression |
ln(Expression e)
Calculate the natural logarithm of an expression: new expression = ln(e). |
static Expression |
log(double n,
Expression e)
Calculate the n-based logarithm of an expression: new expression = log(n, e). |
static Expression |
log10(Expression e)
Calculate the 10-based logarithm of an expression: new expression = log10(e). |
static Expression |
log2(Expression e)
Calculate the 2-based logarithm of an expression: new expression = log2(e). |
static Expression |
multiply(Expression e1,
Expression e2)
Multiply two expressions: new expression = e1 * e2. |
static Expression |
negate(Expression e)
Negate an expression: new expression = -e1. |
static Expression |
parameter(String name)
Create an expression for a parameter without a default value or type. |
static Expression |
parameter(String name,
Object value)
Create an expression for a parameter with a default value but no type. |
static Expression |
parameter(String name,
Object value,
Type valueType)
Create an expression for a parameter with a default value and type. |
static Expression |
parameter(String name,
Type valueType)
Create an expression for a typed parameter without a default value. |
static Expression |
power(Expression e1,
Expression e2)
Calculate the first expression raised to the power of the second expression: new expression = e1 ^ e2 |
static Expression |
selected(Select select)
Create an expression for an already selected query element. |
static Expression |
sqrt(Expression e)
Calculate the square root of an expression: new expression = sqrt(e). |
static Expression |
string(String value)
Create a constant expression from a string. |
static Expression |
subtract(Expression e1,
Expression e2)
Subtract one expression from another: new expression = e1 - e2. |
static Expression |
toDate(Expression e)
Get the date part from a date or timestamp expression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Pattern PARAMETER_REGEXP
Constructor Detail |
---|
public Expressions()
Method Detail |
---|
public static Expression add(Expression e1, Expression e2) throws InvalidDataException
e1
- The left valuee2
- The right value
InvalidDataException
- If any of the arguments are nullpublic static Expression subtract(Expression e1, Expression e2) throws InvalidDataException
e1
- The left valuee2
- The right value
InvalidDataException
- If any of the arguments are nullpublic static Expression divide(Expression e1, Expression e2) throws InvalidDataException
e1
- The numeratore2
- The denominator
InvalidDataException
- If any of the arguments are nullpublic static Expression multiply(Expression e1, Expression e2) throws InvalidDataException
e1
- The left valuee2
- The right value
InvalidDataException
- If any of the arguments are nullpublic static Expression negate(Expression e) throws InvalidDataException
e
- The expression to negate
InvalidDataException
- If the argument is nullpublic static Expression integer(int value)
value
- The value to create an expression for
public static Expression aFloat(float value)
value
- The value to create an expression for
public static Expression string(String value) throws InvalidDataException
parameter(String, Object)
.
In most cases it is better to use that method instead of this.
value
- The string value
InvalidDataException
- If the value is nullpublic static Expression parameter(String name) throws InvalidDataException
name
- Name of the parameter. Can not be null.
InvalidDataException
- If the parameter is null.parameter(String, Object, Type)
,
Query.setParameter(String, Object, Type)
public static Expression parameter(String name, Type valueType) throws InvalidDataException
name
- Name of the parameter. Can not be nullvalueType
- Type of value the parameter holds.
InvalidDataException
- If required argument is null.parameter(String, Object, Type)
,
Query.setParameter(String, Object, Type)
public static Expression parameter(String name, Object value) throws InvalidDataException
name
- Name of the parameter. Can not be null.value
- Value of the parameter.
InvalidDataException
- If required parameter is null.parameter(String, Object, Type)
public static Expression parameter(String name, Object value, Type valueType) throws InvalidDataException
name
- The name of the parameter. Can not be nullvalue
- The default value of the parameter, or null if no default is neededvalueType
- The type of the parameter, or null if not used
InvalidDataException
- If the argument 'name' is null
or contains invalid charactersQuery.setParameter(String, Object, Type)
,
PARAMETER_REGEXP
public static Expression selected(Select select) throws InvalidDataException
select
- A selected query element. Can not be null.
InvalidDataException
- If the argument is nullpublic static Expression log10(Expression e) throws InvalidDataException
e
- The expression to take the logarithm of
InvalidDataException
- If the argument is nullpublic static Expression log2(Expression e) throws InvalidDataException
e
- The expression to take the logarithm of
InvalidDataException
- If the argument is nullpublic static Expression ln(Expression e) throws InvalidDataException
e
- The expression to take the logarithm of
InvalidDataException
- If the argument is nullpublic static Expression log(double n, Expression e) throws InvalidDataException
n
- The log base, must be > 0e
- The expression to take the logarithm of
InvalidDataException
- If the expression is null or if the base is 0 or
belowpublic static Expression exp(Expression e) throws InvalidDataException
e
- The expression to take the exponential of
InvalidDataException
- If the argument is nullpublic static Expression power(Expression e1, Expression e2)
e1
- The base expressione2
- The exponent expression
InvalidDataException
- If some of the arguments are nullpublic static Expression sqrt(Expression e) throws InvalidDataException
e
- The expression to take the square root of
InvalidDataException
- If the argument is nullpublic static Expression abs(Expression e) throws InvalidDataException
e
- The expression to take the absolute value of
InvalidDataException
- If the argument is nullpublic static Expression toDate(Expression e)
e
- An expression which should evaluate to a date or timestamp
public static Expression caseWhen(Expression elseExpression, WhenStatement... whenStatements) throws InvalidDataException
CASE-WHEN
expression:
CASE WHEN r1 THEN e1 WHEN r2 THEN e2 ... ELSE elseExpression END
elseExpression
- The optional else part of the expressionwhenStatements
- An array of WhenStatement
:s
InvalidDataException
- If any of the when statements are null or
if no when statements have been specifiedpublic static Expression any(Query subquery)
ANY (subquery)
.
The expression is useful in the WHERE part of a query only.
For example, to find all users that are members of a group
having a name starting with A.
Query groupFilter = User.getQuery(); groupFilter.join(Hql.innerJoin("groups", "grp")); groupFilter.restrict(Restrictions.like(Hql.property("grp", "name"), Expressions.string("A%"))); Query userQuery = User.getQuery(); userQuery.restrict(Restrictions.eq(Hql.property("id"), Expressions.any(groupFilter)));
subquery
- The subquery
InvalidDataException
- If the subquery is nullpublic static Expression all(Query subquery)
ANY (subquery)
.
subquery
- The subquery
InvalidDataException
- If the subquery is nullany(Query)
private static int getFirstNull(Object[] array)
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |