Wait a second, here. It just occurred to me that downcasting could be
used as part of the filter expression and/or as part of the projection
expression.
Quick terminological review:
Projection == the shape of the results (the "select" part)
Filter == the conditions the data must satisfy (the "where" part)
Fetch plan == the breadth & depth of the objects that are returned in
the project (not defined in JPA yet)
Now, take Linda's first example:
SELECT b.name, b.ISBN
FROM Order o JOIN TREAT(o.product AS Book) b
This query would obviously fail all of the time, unless all orders had
a product that was of type Book. It's clear to me in this example
that the downcast is being used to filter results. In this case,
there should be no ClassCastException thrown -- the expression should
be considered as returning a false in the condition. It's like a
WHERE without the WHERE.
Now, let's modify it a bit and use it only in the projection of the query:
SELECT TREAT(o.product AS Book).ISBN
FROM Order o JOIN o.product
WHERE ...
The ellipsis ("...") in the filter would be some set of conditions
that should only cause the return of orders with products of type
Book. In this case, if some orders with products not of type Book
were returned, the user's expectation was certainly not met and a
ClassCastException should be thrown.
I think that there are two uses/contexts for the use of downcasting
here that we were not separating thus far in the discussion.
Thoughts?
-matthew
On Thu, Mar 10, 2011 at 9:37 AM, Emmanuel Bernard
<emmanuel.bernard_at_jboss.com> wrote:
> no that was a copy/paste error.
>
> On 8 mars 2011, at 21:34, Werner Keil wrote:
>
>> @Emanuel, was there a reason why you changed your Java example to: "p.projects > 1000" not "p.budget > 1000" ?
>
>
--
mailto:matthew_at_matthewadams.me
skype:matthewadams12
yahoo:matthewadams
aol:matthewadams12
google-talk:matthewadams12_at_gmail.com
msn:matthew_at_matthewadams.me
http://matthewadams.me
http://www.linkedin.com/in/matthewadams