| Basic usage is: "select ${identifier} from ${classname} AS ${identifier} where ${identifier}.${propertyname} [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter]"
multiproperty queries are of the form
"select ${identifier} from ${classname} AS ${identifier} where ${identifier}.${propertyname} [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter] [and,or] ${identifier}.${propertyname}
[=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter]"
compound queries are supported as ${query} [and,or] ${query}
ordering for compound queries is achieved through use of bracket groups
"... where ( ${identifier}.${propertyname} [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter] [and,or] ${identifier}.${propertyname} [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter] )
[and,or] ${identifier}.${propertyname} [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter] "
multiclass queries are of the form
select ${identifierA}, ${identifierB} From ${classname} AS ${identifierA}, ${classname} AS ${identifierB} where ${identifierA}.${propertyname} [=,<,>,!=,>=,<=] 'value' [and.or] ${identifierB}.${propertyname} [=,<,>,!=,>=,<=] 'value'"
All values are created using a reflective String constructor .So if you want to Compare an Integer(22) you just specify
value=22 - the value type is chosen based on the declared type of the field.
For primitives, primitive wrappers or some natively comparable classes in the JVM the propertyname is always the literal string 'VALUE' (case insensitive)
- java.lang.String.class,
- java.lang.Integer.class,
- java.lang.Double.class,
- java.lang.Float.class,
- java.lang.Long.class,
- java.lang.Short.class,
- java.math.BigInteger.class,
- java.math.BigDecimal.class,
- java.util.Date.class,
- java.net.URI.class
- java.lang.Byte.class
- java.lang.Character.class
- java.sql.Timestamp.class
For example to query an integer you would write
select i from java.lang.Integer i where i.VALUE = 20
or
select i from java.lang.Integer as i where i.VALUE =20
Dates are constructed using the default encoding of the JVM. So a UK encoding would be:
select d from java.util.Date d where d.value <='4/10/1901 00:00:00'
For user defined classes in order to query the property type must have a String constructor and must
implement equals and hashCode correctly.
For those classes that do not support String constructors or if you wish to use already existing values then you can use either
the Named parameter or Positional parameter format.
For instance to query for an integer as above we can use:
new EJBQuery("select i from java.lang.Integer as i where i.value =:intVal").setParameter("intVal", new Integer(20));
or
new EJBQuery("select i from java.lang.Integer as i where i.value =?1").setParameter(1, new Integer(20));
author: Steve Woodcock version: 1.0 |