jsr338-experts@jpa-spec.java.net

[jsr338-experts] JPQL function invocation

From: Linda DeMichiel <linda.demichiel_at_oracle.com>
Date: Mon, 07 Mar 2011 13:20:40 -0800

In JPA 2.0 we extended the criteria API with the CriteriaBuilder
function method

<T> Expression<T> function (String name, Class<T> type, Expression<?>... args);

with the expectation that we would add similar support to JPQL in this
release.

The Criteria API currently doesn't specify whether we meant to support
aggregate/table functions via this mechanism as well as scalar
functions, although the syntax supports it. We need to discuss this,
and, assuming that we do support it, we need to clarify this point in
the spec.

I would propose that we support both scalar and aggregate functions in
JPQL as well as in the criteria API.

Here's a strawman syntax for JPQL to kick off the discussion

FUNC(function_name, arg1, ..., argn)

Function_name is a string that denotes the database function that is
to be invoked.

Example:

SELECT c
FROM Customer c
WHERE FUNC("hasGoodCredit", c.balance, c.creditLimit)

The arguments must be suitable for the database function that is to be
invoked.

The result of the function must be suitable for the invocation
context.

The function may be a database-defined function or a user-defined function.

Opinions?

thanks,

-Linda