Skip to content

feat: Add addOrOfNotNull and addAndOfNotNull methods#78

Merged
chinhtrung merged 5 commits intomainfrom
trungnguyen.implementaddOrOfNotNullandaddAndOfNotNull
Dec 16, 2025
Merged

feat: Add addOrOfNotNull and addAndOfNotNull methods#78
chinhtrung merged 5 commits intomainfrom
trungnguyen.implementaddOrOfNotNullandaddAndOfNotNull

Conversation

@chinhtrung
Copy link
Contributor

Add addOrOfNotNull and addAndOfNotNull convenience methods

Summary

Adds two new convenience methods to TypeSafeCriteriaWithWhere for handling nullable criteria in dynamic query building.

Changes

  • addOrOfNotNull(vararg predicates: YawnQueryCriterion?) - Automatically filters null criteria before applying OR logic
  • addAndOfNotNull(vararg predicates: YawnQueryCriterion?) - Automatically filters null criteria before applying AND logic

Problem Solved

When building dynamic queries with conditionally nullable criteria, developers previously had to manually filter nulls:

// Before
addOr(listOfNotNull(criteria1, criteria2, criteria3))
addAnd(listOfNotNull(criteria1, criteria2, criteria3))

// After
addOrOfNotNull(criteria1, criteria2, criteria3)
addAndOfNotNull(criteria1, criteria2, criteria3)

Test Coverage

Added comprehensive tests in YawnCriterionTest demonstrating both methods correctly filter out null criteria while preserving the expected query logic.

@chinhtrung chinhtrung changed the title add addOrOfNotNull and addAndOfNotNull methods feat: add addOrOfNotNull and addAndOfNotNull methods Dec 13, 2025
@chinhtrung chinhtrung changed the title feat: add addOrOfNotNull and addAndOfNotNull methods feat: Add addOrOfNotNull and addAndOfNotNull methods Dec 13, 2025
@luanpotter luanpotter requested a review from QuinnB73 December 16, 2025 16:23
Copy link
Collaborator

@QuinnB73 QuinnB73 left a comment

Choose a reason for hiding this comment

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

LGTM

* Instead of manually filtering nulls with `addOr(listOfNotNull(...))`, you can pass
* nullable criteria directly and let this method handle the filtering.
*
* Note: If all predicates are null (resulting in an empty list), no condition is added to the query.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: That's only true because of the hidden implementation detail that we're deferring to Hibernate, so it could be worth mentioning Hibernate in some way so that once we decouple Yawn from Hibernate we know to either maintain this behaviour or stop documenting it

Copy link
Contributor Author

@chinhtrung chinhtrung Dec 16, 2025

Choose a reason for hiding this comment

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

I just added a quick empty check to ensure that we control the behaviours without the hidden implementation detail from Hibernate. Does it look good to you?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep that LGTM!

@chinhtrung chinhtrung requested a review from QuinnB73 December 16, 2025 16:43
@chinhtrung chinhtrung enabled auto-merge (squash) December 16, 2025 17:04
@chinhtrung chinhtrung merged commit 3d3af64 into main Dec 16, 2025
7 checks passed
@chinhtrung chinhtrung deleted the trungnguyen.implementaddOrOfNotNullandaddAndOfNotNull branch December 16, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants