Last update: 2011-06-23

org.proteios.core.query
Class Expressions

java.lang.Object
  extended by org.proteios.core.query.Expressions

public class Expressions
extends Object

A factory class to create expressions.

Version:
2.0
Author:
Samuel, Nicklas
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

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 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 divide(Expression e1, Expression e2)
          Divide one expression by another: new expression = e1 / e2.
static Expression integer(int value)
          Create a constant expression from an integer.
static Expression ln(Expression e)
          Take the natural logarithm of an expression: new expression = ln(e).
static Expression log(double n, Expression e)
          Take the n-based logarithm of an expression: new expression = log(n, e).
static Expression log10(Expression e)
          Take the 10-based logarithm of an expression: new expression = log10(e).
static Expression log2(Expression e)
          Take 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 expresson for a parameter without a default value or type.
static Expression parameter(String name, Object value)
          Create an expresson for a parameter with a default value but no type.
static Expression parameter(String name, Object value, Type valueType)
          Create an expresson for a parameter with a default value and type.
static Expression parameter(String name, Type valueType)
          Create an expresson for a typed parameter without a default value.
static Expression selected(Select select)
          Create an expression for an already selected query element.
static Expression sqrt(Expression e)
          Take 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARAMETER_REGEXP

public static final Pattern PARAMETER_REGEXP
A parameter name can only contain the characters a-z, A-Z or 0-9.

Constructor Detail

Expressions

public Expressions()
Method Detail

add

public static Expression add(Expression e1,
                             Expression e2)
                      throws InvalidDataException
Add two expressions: new expression = e1 + e2.

Parameters:
e1 - The left value
e2 - The right value
Returns:
The new expression
Throws:
InvalidDataException - If any of the arguments are null

subtract

public static Expression subtract(Expression e1,
                                  Expression e2)
                           throws InvalidDataException
Subtract one expression from another: new expression = e1 - e2.

Parameters:
e1 - The left value
e2 - The right value
Returns:
The new expression
Throws:
InvalidDataException - If any of the arguments are null

divide

public static Expression divide(Expression e1,
                                Expression e2)
                         throws InvalidDataException
Divide one expression by another: new expression = e1 / e2.

Parameters:
e1 - The numerator
e2 - The denominator
Returns:
The new expression
Throws:
InvalidDataException - If any of the arguments are null

multiply

public static Expression multiply(Expression e1,
                                  Expression e2)
                           throws InvalidDataException
Multiply two expressions: new expression = e1 * e2.

Parameters:
e1 - The left value
e2 - The right value
Returns:
The new expression
Throws:
InvalidDataException - If any of the arguments are null

negate

public static Expression negate(Expression e)
                         throws InvalidDataException
Negate an expression: new expression = -e1.

Parameters:
e - The expression to negate
Returns:
The new expression
Throws:
InvalidDataException - If the argument is null

integer

public static Expression integer(int value)
Create a constant expression from an integer.

Parameters:
value - The value to create an expression for
Returns:
The expression

aFloat

public static Expression aFloat(float value)
Create a constant expression from a float.

Parameters:
value - The value to create an expression for
Returns:
The expression

string

public static Expression string(String value)
                         throws InvalidDataException
Create a constant expression from a string. Internally this is implemented as parameter with a default value. Ie. parameter(String, Object). In most cases it is better to use that method instead of this.

Parameters:
value - The string value
Returns:
The expression
Throws:
InvalidDataException - If the value is null

parameter

public static Expression parameter(String name)
                            throws InvalidDataException
Create an expresson for a parameter without a default value or type.

Throws:
InvalidDataException
See Also:
parameter(String, Object, Type), Query.setParameter(String, Object, Type)

parameter

public static Expression parameter(String name,
                                   Type valueType)
                            throws InvalidDataException
Create an expresson for a typed parameter without a default value.

Throws:
InvalidDataException
See Also:
parameter(String, Object, Type), Query.setParameter(String, Object, Type)

parameter

public static Expression parameter(String name,
                                   Object value)
                            throws InvalidDataException
Create an expresson for a parameter with a default value but no type.

Throws:
InvalidDataException
See Also:
parameter(String, Object, Type)

parameter

public static Expression parameter(String name,
                                   Object value,
                                   Type valueType)
                            throws InvalidDataException
Create an expresson for a parameter with a default value and type.

Parameters:
name - The name of the parameter
value - The default value of the parameter, or null if no default is needed
valueType - The type of the parameter, or null if not used
Returns:
An expression representing the parameter
Throws:
InvalidUseOfNullException - If the argument is null or contains invalid characters
InvalidDataException
See Also:
Query.setParameter(String, Object, Type), PARAMETER_REGEXP

selected

public static Expression selected(Select select)
                           throws InvalidDataException
Create an expression for an already selected query element. If an alias has been specified it will be used, otherwise the entire expression is built again.

Parameters:
select - A selected query element
Returns:
A expression object representing the selected expression
Throws:
InvalidUseOfNullException - If the argument is null
InvalidDataException

log10

public static Expression log10(Expression e)
                        throws InvalidDataException
Take the 10-based logarithm of an expression: new expression = log10(e).

Parameters:
e - The expression to take the logarithm of
Returns:
The new expression
Throws:
InvalidDataException - If the argument is null

log2

public static Expression log2(Expression e)
                       throws InvalidDataException
Take the 2-based logarithm of an expression: new expression = log2(e).

Parameters:
e - The expression to take the logarithm of
Returns:
The new expression
Throws:
InvalidDataException - If the argument is null

ln

public static Expression ln(Expression e)
                     throws InvalidDataException
Take the natural logarithm of an expression: new expression = ln(e).

Parameters:
e - The expression to take the logarithm of
Returns:
The new expression
Throws:
InvalidDataException - If the argument is null

log

public static Expression log(double n,
                             Expression e)
                      throws InvalidDataException
Take the n-based logarithm of an expression: new expression = log(n, e).

Parameters:
n - The log base, must be > 0
e - The expression to take the logarithm of
Returns:
The new expression
Throws:
InvalidDataException - If the expression is null or if the base is 0 or below

sqrt

public static Expression sqrt(Expression e)
                       throws InvalidDataException
Take the square root of an expression: new expression = sqrt(e).

Parameters:
e - The expression to take the square root of
Returns:
The new expression
Throws:
InvalidDataException - If the argument is null

Last update: 2011-06-23