I am going through some legacy code of ours.
We have a WHERE clause being assembled programmatically through the JPA criteria API.
The clause begins life like this:
Predicate filter = cb.conjunction();
Then, based on various things the user has supplied, this WHERE clause might get added to. Here's one example:
filter = cb.and(filter, cb.like(cb.upper(path), paramDescription));
Then there's a block of code that attempts to see if the where clause should be bolted on to the rest of the query. This part I wrote, and it is never firing, and I think I've gravely misunderstood something.
Here's what I wrote:
if (!filter.getExpressions().isEmpty()) { // XXX filter.getExpressions() is always empty!
}
This block never "fires" because filter.getExpressions() is always of size 0. Debugging into the EclipseLink 2.3.2 source (the one that comes with GlassFish 3.1.2.2), I find that at this stage filter is a CompoundExpressionImpl, and that class does this in the body of its getExpressions() method:
public List<_expression_<Boolean>> getExpressions(){
return new ArrayList();
}
However, his (inherited) expressions instance field is of size 2. Eep. Is this an oversight, or--I suspect--by design and I am just being clueless about how to work with the criteria builder API? Is there a different way of determining whether I need to invoke the where() method?
Thanks,
Laird
--
http://about.me/lairdnelson