Hi Folks,
I implemented a custom PropertySelector. Unfortunaly it does not care about boolean values. The convering fields are still in WHERE cause of the genrated SELECt. :-(
Any ideas? Attached you can find the code. As far as I can see the boolean values are handled correctly:
Code:
private class ContactPropertyFilter implements Example.PropertySelector {
/**
* Filters out every boolean value
*
* @see net.sf.hibernate.expression.Example.PropertySelector#include(java.lang.Object,
* java.lang.String, net.sf.hibernate.type.Type)
*/
public boolean include(Object propertyValue, String propertyName,
Type type) {
boolean keep = false;
if (propertyValue != null) {
if ( type.getReturnedClass().isAssignableFrom(String.class)) {
keep = !(propertyValue.equals(""));
} else {
keep = filterPrimitives(propertyValue, type);
}
}
return keep;
}
/**
* @param propertyValue
* @param type hibernate type
* @return
*/
private boolean filterPrimitives(Object propertyValue, Type type) {
if (propertyValue instanceof Float )
return !(((Float) propertyValue).floatValue() == 0.0);
if (propertyValue instanceof Double )
return !(((Double) propertyValue).doubleValue() == 0.0);
if (propertyValue instanceof Integer )
return !(((Integer) propertyValue).intValue() == 0);
if (propertyValue instanceof Long )
return !(((Long) propertyValue).longValue() == 0);
if (propertyValue instanceof Short)
return !(((Short) propertyValue).shortValue() == 0);
if (propertyValue instanceof Character)
return !(((Character) propertyValue).charValue() == '\u0000');
if (propertyValue instanceof Boolean ) {
return (((Boolean) propertyValue).booleanValue());
}
if (propertyValue instanceof Enum ) {
return !(((Enum) propertyValue).getName().equals(""));
}
// let's pass components, collections and one-to-one relations
return true;
}
}
A lot of thx.
Toby