Issue Details (XML | Word | Printable)

Key: NUCJPA-235
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Andy Jefferson
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus API JPA

Support JPA 2.1 JPQL "TREAT" in WHERE clause

Created: 28/May/13 08:43 AM   Updated: 10/Dec/13 10:24 AM   Resolved: 04/Dec/13 02:47 PM
Component/s: API
Affects Version/s: None
Fix Version/s: 3.3.5


 Description  « Hide
4.4.9 Downcasting
The use of the TREAT operator is supported for downcasting within path expressions in the FROM and WHERE clauses. Use of the TREAT operator allows access to subclass-specific state.

WHERE Clause
If during query execution the first argument to the TREAT operator is not a subtype (proper or improper) of the target type, the path is considered to have no value, and does not participate in the determination of the result. That is, in the case of a join, the referenced object does not participate in the result, and in the case of a restriction, the associated predicate is false. Use of the TREAT operator therefore also has the effect of filtering on the specified type (and its subtypes) as well as performing the downcast. If the target type is not a subtype (proper or improper) of the static type of the first argument, the query is invalid.

Examples:
SELECT e FROM Employee e 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"

SELECT e FROM Employee e
WHERE TREAT(e AS Exempt).vacationDays > 10
OR TREAT(e AS Contractor).hours > 100

Andy Jefferson made changes - 29/May/13 07:58 PM
Field Original Value New Value
Fix Version/s 3.3.0.release [ 11948 ]
Andy Jefferson made changes - 17/Jun/13 12:57 PM
Summary Support JPA 2.1 JPQL "TREAT" (as cast operator) Support JPA 2.1 JPQL "TREAT"
Priority Major [ 3 ] Minor [ 4 ]
Andy Jefferson made changes - 17/Jun/13 12:58 PM
Fix Version/s 3.3.0.release [ 11948 ]
Andy Jefferson made changes - 04/Dec/13 02:45 PM
Summary Support JPA 2.1 JPQL "TREAT" Support JPA 2.1 JPQL "TREAT" in WHERE clause
Description 4.4.9 Downcasting
The use of the TREAT operator is supported for downcasting within path expressions in the FROM and WHERE clauses. Use of the TREAT operator allows access to subclass-specific state.

WHERE Clause
If during query execution the first argument to the TREAT operator is not a subtype (proper or improper) of the target type, the path is considered to have no value, and does not participate in the determination of the result. That is, in the case of a join, the referenced object does not participate in the result, and in the case of a restriction, the associated predicate is false. Use of the TREAT operator therefore also has the effect of filtering on the specified type (and its subtypes) as well as performing the downcast. If the target type is not a subtype (proper or improper) of the static type of the first argument, the query is invalid.

Examples:
SELECT b.name, b.ISBN
FROM Order o JOIN TREAT(o.product AS Book) b

SELECT e FROM Employee e JOIN TREAT(e.projects AS LargeProject) lp
WHERE lp.budget > 1000

SELECT e FROM Employee e 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"

SELECT e FROM Employee e
WHERE TREAT(e AS Exempt).vacationDays > 10
OR TREAT(e AS Contractor).hours > 100
4.4.9 Downcasting
The use of the TREAT operator is supported for downcasting within path expressions in the FROM and WHERE clauses. Use of the TREAT operator allows access to subclass-specific state.

WHERE Clause
If during query execution the first argument to the TREAT operator is not a subtype (proper or improper) of the target type, the path is considered to have no value, and does not participate in the determination of the result. That is, in the case of a join, the referenced object does not participate in the result, and in the case of a restriction, the associated predicate is false. Use of the TREAT operator therefore also has the effect of filtering on the specified type (and its subtypes) as well as performing the downcast. If the target type is not a subtype (proper or improper) of the static type of the first argument, the query is invalid.

Examples:
SELECT e FROM Employee e 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"

SELECT e FROM Employee e
WHERE TREAT(e AS Exempt).vacationDays > 10
OR TREAT(e AS Contractor).hours > 100
Andy Jefferson made changes - 04/Dec/13 02:45 PM
Comment [ Upon analysis of the options for implementing this, it appears to refer to some vendor-specific TREAT SQL function (only available in Oracle RDBMS). Consequently it is considered low priority. Anyone requiring it can offer their time/resources to implement it ]
Andy Jefferson added a comment - 04/Dec/13 02:47 PM
SVN trunk supports JPQL "TREAT" in WHERE clause. Not tried in FROM clause but most logical usage is in WHERE IMHO. If anyone wants FROM clause support then write tests and implement any additions that are needed

Andy Jefferson made changes - 04/Dec/13 02:47 PM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 3.3.5 [ 12047 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 10/Dec/13 10:24 AM
Status Resolved [ 5 ] Closed [ 6 ]