persistence@glassfish.java.net

Re: EJBQL changes in PFD version of persistence document

From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Date: Thu, 12 Jan 2006 15:00:45 +0100

Hi Tom,

attached you find my changes updating the EJBQL compiler to implement
the changes in the PFD version of the spec. This is what I changed:
- Restricted the path expression of a JOIN clause to be a single
navigation. So 'JOIN o.customer.spouse s' is not supported anymore.
- Support for setting a field to NULL in the SET clause of an UPDATE
statement.
- Removed support for Java escape notation from string literal.
- Updated handling of numeric literals.
Please have a look.

There are three PFD changes that do not effect the parser, but the
runtime. I propose I file a tasks in the glassfish issue tracker for
each of them. What do you think?

(1) Allow grouping by entities
The expression in a GROUP BY clause may now be an relationship, e.g.
   SELECT c.country FROM Customer c GROUP BY c.country

The runtime does not (yet) support this. The generated SQL misses the
expression in the GROUP BY clause
   SELECT t0.COUNTRY_ID, ... FROM CMP3_COUNTRY t0, CMP3_CUSTOMER t1
   WHERE (t0.COUNTRY_ID = t1.COUNTRY_ID) GROUP BY
The relationship access in the GROUP BY expression is represented as an
QueryKeyExpression instance. Method printSQL gets called to generated
the SQL which does not handle the relationship case.

(2) Allow setting relationship fields in UPDATE statement
Today the EJBQL query
  UPDATE Customer c SET c.country = :country
is mapped to a SQL set clause using the toString of the country instance
passed as actual parameter. This leads to a SQLException: ORA-01729:
database link name expected

(3) UPDATE statement does not change the version column.
Today the EJBQL query
   UPDATE Customer c SET c.name = 'CHANGED'
is mapped to the following SQL:
   UPDATE CMP3_CUSTOMER
   SET NAME = 'CHANGED', CUST_VERSION = (CUST_VERSION + 1)

Regards Michael

> Hi Tom,
>
> I went through the change bars in the EJBQL chapter of the PFD version
> to find areas where we need to update the EJQBL compiler.
>
> - More restrictive path expression in JOIN clause.
> - Lexer support for numeric literals.
> - Rename some parser rules to match the BNF.
> - GROUP BY now allows entities.
> - The SET clause now allows relationship settings.
>
> I need to do some testing in oder to see the impact of the GROUP BY- and
> SET-clause change. It might be only a minor change in the parser, but
> I'm not sure about the runtime.
>
> Regards Michael