Skip to content

CXF-9174: Allow customization of JPA FIQL predicate building#2798

Merged
gnodet merged 1 commit intoapache:mainfrom
raoua-eng:CXF-9174-predicate-extension
Mar 11, 2026
Merged

CXF-9174: Allow customization of JPA FIQL predicate building#2798
gnodet merged 1 commit intoapache:mainfrom
raoua-eng:CXF-9174-predicate-extension

Conversation

@raoua-eng
Copy link
Contributor

@raoua-eng raoua-eng commented Dec 23, 2025

This PR addresses CXF-9174.

It makes doBuildPredicate(...) and doBuildCollectionPredicate(...) protected to allow customization of predicate construction in JPACriteriaQueryVisitor.

A new test demonstrates how a custom visitor can override predicate behavior without duplicating the entire visitor implementation.

This enables use cases such as database-specific functions (e.g. accent-insensitive comparisons).

@raoua-eng
Copy link
Contributor Author

Hi @reta,
as discussed in CXF-9174, this PR opens up predicate customization by making the relevant methods protected and adds a test to demonstrate the extension mechanism.

Let me know if you'd like any adjustments.

@raoua-eng
Copy link
Contributor Author

@reta
The failure is unrelated to the PR changes.
The build fails during Maven extension resolution (maven-bundle-plugin / org.eclipse.sisu.inject) which points to a corrupted Maven repository or CI environment issue on Windows.

@reta
Copy link
Member

reta commented Dec 23, 2025

@reta The failure is unrelated to the PR changes. The build fails during Maven extension resolution (maven-bundle-plugin / org.eclipse.sisu.inject) which points to a corrupted Maven repository or CI environment issue on Windows.

Yeah, something is unstable, I will rerun checks shortly

@reta
Copy link
Member

reta commented Dec 23, 2025

@raoua-eng could you please fix checkstyle violations:

Error:  Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.2.2:checkstyle (validate) on project cxf-rt-rs-extension-search: An error has occurred in Checkstyle report generation. Failed during checkstyle execution: There are 85 errors reported by Checkstyle 12.3.0 with cxf-checkstyle.xml ruleset. -> [Help 1]

@raoua-eng
Copy link
Contributor Author

raoua-eng commented Dec 24, 2025

Fixed whitespace and tab character issues.
Line length trimmed to comply with style rules.

@reta
Copy link
Member

reta commented Dec 24, 2025

Error: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.2.2:checkstyle (validate) on project cxf-rt-rs-extension-search: An error has occurred in Checkstyle report generation. Failed during checkstyle execution: There are 83 errors reported by Checkstyle 12.3.0 with cxf-checkstyle.xml ruleset. -> [Help 1]

@raoua-eng could you please run mvn install -DskipTests=true -DskipITs=true locally? it will help you to catch issues, thank you

@raoua-eng
Copy link
Contributor Author

@reta I ran mvn install -DskipTests=true -DskipITs=true locally.
The remaining Checkstyle violations are in existing code and unrelated to the changes introduced by this PR.
Please let me know if you would still prefer me to address them in a separate commit.

@reta
Copy link
Member

reta commented Dec 24, 2025

The remaining Checkstyle violations are in existing code and unrelated to the changes introduced by this PR.

Thanks @raoua-eng , well, we cannot merge unless checks pass. If you are up to it, would be great to fix those, thank you

gnodet added a commit to gnodet/cxf that referenced this pull request Mar 10, 2026
Make doBuildPredicate and doBuildCollectionPredicate methods protected
in AbstractJPATypedQueryVisitor to allow subclasses to customize
predicate construction for specific properties or collection checks.

Add getEntityManager() accessor to AbstractJPATypedQueryVisitorTest
and new test classes demonstrating the extension capability.

Based on PR apache#2798 by mkarg, with fixes for checkstyle compliance
(tabs to spaces, import ordering) and corrected test assertions.
@gnodet
Copy link
Contributor

gnodet commented Mar 11, 2026

CI Failure Analysis

The build failure on JDK 21 (and the cancellation on JDK 17) is caused by 2 checkstyle ImportOrder violations in the new test files. The other test failures (JMS timeout, tracing, Brave span counts) are pre-existing flaky tests unrelated to this PR.

Checkstyle errors

Both errors are [ImportOrder] — "Extra separation in import group":

  1. CustomJPACriteriaVisitor.java:27 — blank line between jakarta.* and org.apache.cxf.* imports
  2. JPACriteriaQueryVisitorExtensionTest.java:26 — blank line between jakarta.* and org.apache.cxf.* imports

CXF's checkstyle rules require jakarta.* and org.apache.* imports to be in the same group (no blank line separator). See AbstractJPATypedQueryVisitorTest.java lines 29-40 for the expected pattern.

Fix

In CustomJPACriteriaVisitor.java, remove the blank line between lines 25-27:

// Before (wrong):
import jakarta.persistence.metamodel.Bindable;

import org.apache.cxf.jaxrs.ext.search.ConditionType;

// After (correct):
import jakarta.persistence.metamodel.Bindable;
import org.apache.cxf.jaxrs.ext.search.ConditionType;

In JPACriteriaQueryVisitorExtensionTest.java, remove the blank line between lines 24-26:

// Before (wrong):
import jakarta.persistence.criteria.CriteriaQuery;

import org.apache.cxf.jaxrs.ext.search.SearchCondition;

// After (correct):
import jakarta.persistence.criteria.CriteriaQuery;
import org.apache.cxf.jaxrs.ext.search.SearchCondition;

…ted for extensibility

Allow subclasses of AbstractJPATypedQueryVisitor to customize JPA predicate
building by changing doBuildPredicate() and doBuildCollectionPredicate() from
private to protected visibility. This enables the Template Method pattern for
custom FIQL-to-JPA predicate generation without modifying the core visitor.

Includes tests demonstrating a custom visitor with case-insensitive LIKE
matching and collection predicate override.
@gnodet gnodet force-pushed the CXF-9174-predicate-extension branch from 4f7ac27 to ebbcb4d Compare March 11, 2026 10:11
@reta
Copy link
Member

reta commented Mar 11, 2026

Thanks for cleanup @gnodet , non-code concern: the user has asked for this feature and then lost interest in it, I would prefer to hold on merging this change, it is ready but apparently not needed anymore. wdyt?

@gnodet
Copy link
Contributor

gnodet commented Mar 11, 2026

I think it's worth merging — the production change is just privateprotected on two methods, which is low-risk and follows standard Java extensibility patterns.

The use case is legitimate: if you need custom JPA predicates (e.g., database-specific functions like accent-insensitive comparisons), you currently have to duplicate the entire visitor. With this change, you just override the predicate-building method.

Whether or not the original requester still needs it, it's a reasonable extension point that others could benefit from. I'd rather merge it than let it go stale.

@gnodet gnodet merged commit 95a5856 into apache:main Mar 11, 2026
4 of 6 checks passed
reta pushed a commit that referenced this pull request Mar 11, 2026
…ted for extensibility (#2798)

Allow subclasses of AbstractJPATypedQueryVisitor to customize JPA predicate
building by changing doBuildPredicate() and doBuildCollectionPredicate() from
private to protected visibility. This enables the Template Method pattern for
custom FIQL-to-JPA predicate generation without modifying the core visitor.

Includes tests demonstrating a custom visitor with case-insensitive LIKE
matching and collection predicate override.

Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
(cherry picked from commit 95a5856)
reta pushed a commit that referenced this pull request Mar 11, 2026
…ted for extensibility (#2798)

Allow subclasses of AbstractJPATypedQueryVisitor to customize JPA predicate
building by changing doBuildPredicate() and doBuildCollectionPredicate() from
private to protected visibility. This enables the Template Method pattern for
custom FIQL-to-JPA predicate generation without modifying the core visitor.

Includes tests demonstrating a custom visitor with case-insensitive LIKE
matching and collection predicate override.

Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
(cherry picked from commit 95a5856)
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