dcracauer wrote:
<embarrassed>Works like a charm.</embarrassed>
Thanks,
Dave
I don't think you should be too embarassed. I had the same question and the answer isn't very obvious to someone new to Hibernate. It seems like there should be a easy switch like excludeBlankStrings that would do this for all of your String properties. And unless you have a bit of understanding of how the Example class works, you may not realize that there can be only one property selector (from what I can tell). So if you write
Code:
Example.create(myExample)
.ignoreCase()
.excludeZeroes()
.setPropertySelector(mySelector);
You're probably not going to get what you expected unless you added the logic from excludeZeroes into your selector.
Please correct me if I'm wrong.
Anyway, here's what I came up with for my situation:
Code:
static final class
NotNullOrBlankStringPropertySelector
implements Example.PropertySelector
{
public boolean include(Object object, String propertyName, Type type)
{
return object!=null && (
!(object instanceof String)
|| StringUtils.isNotBlank((String)object)
);
}
}
It would be nice if there was some way to chain these together so I could say
Code:
Example.create(myExample)
.ignoreCase()
.ignoreZeroes()
.ignoreBlankStrings();
But that's just me :-)