Details
-
Improvement
-
Status: Closed
-
Normal
-
Resolution: Fixed
-
3.2.0
-
None
Description
Found during training:
In HST query execution code, if you do like the following:
Filter filter = hstQuery.createFilter(); filter.addGreaterThan("myhippoproject:availability", 0); // in order to query only available products hstQuery.setFilter(filter); HstQueryResult result = hstQuery.execut();
Then, it throws an exception because it cannot make a query statement from the number argument, "0".
If I change it to (long) 0, it works.
I see the following in FilterImpl.java:
public String getStringValue(Object value) throws FilterException{ if(value instanceof String || value instanceof Boolean) { return "'" + value.toString() + "'"; } else if(value instanceof Long || value instanceof Double) { return value.toString(); } else if(value instanceof Calendar){ return DateTools.createXPathConstraint(session, (Calendar)value); } else if(value instanceof Date){ Calendar cal = new GregorianCalendar(); cal.setTime((Date)value); return DateTools.createXPathConstraint(session, cal); } throw new FilterException("Unsupported Object type '"+value.getClass().getName()+"' to query on."); }
I guess it's better to use value instanceof Number instead. Then you can allow any number in making xpath query for developer's convenience.