Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#658] Support JPQL Treated paths for WHERE clause #2530

Merged
merged 1 commit into from
Dec 31, 2020
Merged

[#658] Support JPQL Treated paths for WHERE clause #2530

merged 1 commit into from
Dec 31, 2020

Conversation

jwgmeligmeyling
Copy link
Member

@jwgmeligmeyling jwgmeligmeyling commented Feb 15, 2020

JPA 2.1 introduced the TREAT operator for explicit casting. Initial support for TREAT in the FROM clause was added in PR #705. However, the specification also describes the notion of treated_subpath expressions (chapter 4.4.4.1) that are allowed in the WHERE clause of a query.

The syntax is as follows:

treated_subpath ::= TREAT(general_subpath AS subtype)

single_valued_path_expression ::= qualified_identification_variable | 
    TREAT(qualified_identification_variable AS subtype) | 
    state_field_path_expression | 
    single_valued_object_path_expression

And can be used as such:

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

(Example from chapter 4.4.9).

This pull request adds the support for treated subpaths in QueryDSL. It does so by introducing a new PathType and convenience method JPAExpressions.treat.

Fixes #658

A full list of treat support throughout JPA providers can be found at https://github.com/beikov/jpa-treat-variations

@jwgmeligmeyling
Copy link
Member Author

@idosal could you review this one? 😄

@idosal
Copy link
Member

idosal commented Mar 21, 2020

Sure, I'll get on it soon. Sorry for the delay, it kind of fell between the cracks.

@johnktims johnktims added this to the 4.4.0 milestone May 27, 2020
@johnktims johnktims added the jpa label May 28, 2020
@jwgmeligmeyling jwgmeligmeyling self-assigned this Jun 1, 2020
* @param <T> the expression type
* @return subtype instance with the same identity
*/
public static <U extends BeanPath<? extends T>, T> U treat(BeanPath<? extends T> path, Class<U> subtype) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnktims Apprently this is now considered a breaking change:

Class com.querydsl.jpa.JPAExpressions
 Added Method treat, sig <U:Lcom/querydsl/core/types/dsl/BeanPath<+TT;>;T:Ljava/lang/Object;>(Lcom/querydsl/core/types/dsl/BeanPath<+TT;>;Ljava/lang/Class<TU;>;)TU;, desc (Lcom/querydsl/core/types/dsl/BeanPath;Ljava/lang/Class;)Lcom/querydsl/core/types/dsl/BeanPath;, access public static
[WARNING] Rule 0: org.semver.enforcer.RequireBackwardCompatibility failed with message:
Current codebase is not backward compatible (BACKWARD_COMPATIBLE_USER) with version <4.3.2-20200601.233131-46>. Compatibility type has been detected as <NON_BACKWARD_COMPATIBLE>

How should we resolve this? Bump the snapshot version? Move the method to a new class? Add some sort of surpression?

@jwgmeligmeyling jwgmeligmeyling modified the milestones: 4.4.0, 5.0 Oct 14, 2020
@jwgmeligmeyling jwgmeligmeyling added this to In progress in 5.x via automation Oct 14, 2020
JPA 2.1 introduced the TREAT operator for explicit casting. Initial support for TREAT in the FROM clause was added in PR #705. However, the specification also describes the notion of `treated_subpath` expressions (chapter 4.4.4.1) that are allowed in the WHERE clause of a query.

The syntax is as follows:

> ```
> treated_subpath ::= TREAT(general_subpath AS subtype)
>
> single_valued_path_expression ::= qualified_identification_variable | TREAT(qualified_identification_variable AS subtype) | state_field_path_expression | single_valued_object_path_expression
> ```

And can be used as such:

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

(Example from chapter 4.4.9).

This pull request adds the support for treated subpaths in QueryDSL. It does so by introducing a new `PathType` and convenience method `JPAExpressions.treat`.
@jwgmeligmeyling jwgmeligmeyling merged commit c75ef4c into querydsl:master Dec 31, 2020
5.x automation moved this from In progress to Done Dec 31, 2020
@jwgmeligmeyling jwgmeligmeyling deleted the jpa-treated-path branch December 31, 2020 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
5.x
  
Done
Development

Successfully merging this pull request may close these issues.

JPA 2.1 capabilities
3 participants