JPQL : In-Memory queries

The typical use of a JPQL query is to translate it into the native query language of the datastore and return objects matched by the query. For many datastores it is simply impossible to support the full JPQL syntax in the datastore native query language and so it is necessary to evaluate the query in-memory. This means that we evaluate as much as we can in the datastore and then instantiate those objects and evaluate further in-memory. Here we document the current capabilities of in-memory evaluation in DataNucleus.

  • Subqueries using ALL, ANY, SOME, EXISTS are not currently supported
  • MEMBER OF syntax is not currently supported.

To enable evaluation in memory you specify the query hint datanucleus.query.evaluateInMemory to true as follows

query.setHint("datanucleus.query.evaluateInMemory","true");


Methods

JPQL defines support for some methods within its syntax. The following are supported for in-memory evaluation currently.

Java Type Method Description
CURRENT_DATE Returns the current date
CURRENT_TIME Returns the current time
CURRENT_TIMESTAMP Returns the current timestamp
ABS(numericExpr) Returns the absolute value of the passed arg
SQRT(numericExpr) Returns the square root of the passed arg
MOD(numericExpr, numericExpr) Returns the modulus of the passed arg
SIZE(collectionExpr) Returns the modulus of the passed arg
UPPER(stringExpr) Returns the passed string in UPPERCASE
LOWER(stringExpr) Returns the passed string in lowercase
LENGTH(stringExpr) Returns the length of the passed string
CONCAT(stringExpr, stringExpr [,stringExpr]) Returns a concatenation of the supplied strings
LOCATE(stringExpr, stringExpr [,numericExpr]) Returns the position of the second arg within the first arg
SUBSTRING(stringExpr, numericExpr [,numericExpr]) Returns the substring of the first arg
TRIM([trimChar] [FROM] stringExpr) Returns a trimmed form of the string argument

Support for in-memory evaluation of query methods is provided via a plugin-point so can be extended easily.