Skip to content

Refactor JPQL predicate composition by flattening AND/OR#4195

Closed
l2yujw wants to merge 2 commits into
spring-projects:mainfrom
l2yujw:refactor/jpql-flatten-predicates
Closed

Refactor JPQL predicate composition by flattening AND/OR#4195
l2yujw wants to merge 2 commits into
spring-projects:mainfrom
l2yujw:refactor/jpql-flatten-predicates

Conversation

@l2yujw

@l2yujw l2yujw commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Motivation

Chained predicate composition currently builds nested AND/OR predicate trees internally.
Even if the rendered output is the same, deep nesting makes the structure harder to reason about and maintain.

Changes

  • Flatten AND/OR predicate composition by merging parts during Predicate#and / Predicate#or composition.
  • Change AndPredicate / OrPredicate records to hold List<Predicate> parts and normalize nested predicates via compact constructors.
  • Keep nest() behavior unchanged.

Tests

  • Added regression tests for chained AND/OR rendering to keep the rendered output stable.

Notes

There is an existing comment in Predicate#and suggesting the current structuring is not ideal.
This change addresses that concern while preserving the rendered output (covered by tests).

Checklist

  • You have read the Spring Data contribution guidelines.
  • You used the provided code formatters and did not submit formatting-only changes.
  • You submitted test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched.

Signed-off-by: l2yuPa <jeungwon28@gmail.com>
Signed-off-by: l2yuPa <jeungwon28@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 19, 2026
@mp911de mp911de added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 20, 2026
@mp911de mp911de added this to the 4.0.4 (2025.1.4) milestone Feb 20, 2026
@mp911de mp911de closed this in ef98596 Feb 20, 2026
mp911de added a commit that referenced this pull request Feb 20, 2026
Introduce factory methods to flatten predicates. Also, avoid list copies.

See #4195
mp911de pushed a commit that referenced this pull request Feb 20, 2026
Signed-off-by: l2yuPa <jeungwon28@gmail.com>
Closes #4195
mp911de added a commit that referenced this pull request Feb 20, 2026
Introduce factory methods to flatten predicates. Also, avoid list copies.

See #4195
@mp911de

mp911de commented Feb 20, 2026

Copy link
Copy Markdown
Member

Thank you for your contribution. That's merged, polished, and backported now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: task A general task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants