jsr338-experts@jpa-spec.java.net

[jsr338-experts] Re: query improvements: downcasting

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Tue, 08 Mar 2011 16:20:39 -0400

Hello Emmanuel,
    Comments below:
--Gordon

Emmanuel Bernard wrote:
> On 7 mars 2011, at 21:45, Linda DeMichiel wrote:
>
>
>> SELECT e FROM Employee JOIN e.projects p
>> WHERE TREAT(p AS LargeProject).budget > 1000 OR
>> TREAT(p AS SmallProject).name LIKE "Persist%" OR
>> p.description LIKE "COST OVERRUN"
>>
>
> This is really the use case that makes the most sense to me as the other use cases Linda has shown seem to overlap with TYPE.
>
> but that leads to some questions:
> 1. if both LargeProject and SmallProject have a budget property, do we return all Projects.budget > 1000? Or is the query more like
> SELECT e FROM Employee JOIN e.projects p
> WHERE ( TYPE(p) = LargeProject AND p.budget > 1000) OR
> (TYPE(p) = SmallProject AND p.name LIKE "Persist%" ) OR
> p.description LIKE "COST OVERRUN"
>
The query would actually return more than just the Projects with budget
> 1000, the "OR" is complicating the example. The java code below is a
better representation. The result would include LargeProjects (and
sub-classes) with budgets > 1000 and SmallProjects (and sub-classes)
with a name like "Persist%" and any Projects with a description like
"COST OVERRUN".
> For reference the idiom in Java is
> (p instanceof LargeProject && ( (LargeProject) p).projects > 1000) ||
> (p instanceof SmallProject && isLike( ((SmallProject) p).name, "Persist%" ) ) ||
> isLike(p.description, "COST OVERRUN") //evaluates to true all the time?
>
> And assuming javac was smarter we could do
>
Yes, this is the equivalent Java.
> (p instanceof LargeProject) && p.projects > 1000) ||
> (p instanceof SmallProject) && isLike( p.name, "Persist%" ) ||
> isLike(p.description, "COST OVERRUN")
>
> 2. if LargeProject does not have a budget property, what happens?
>
>
>