Hi Anil,
Yes, sort of. You could basically register a virtual attribute called ’shippingDelay’ as follows:
parser.registerAttribute(new SimpleAttribute<Order, Long>("shippingDelay") {
@Override
public Long getValue(Order order, QueryOptions queryOptions) {
return (order.shipDate.getTime() - order.orderDate.getTime()) / 86400000;
}
});
And then use it in SQL or CQN queries as follows:
ResultSet<Car> results = parser.retrieve(cars, "SELECT * FROM orders WHERE (shippingDelay > 4)");
For queries relative to the current time in such as 'shipDate < today's date', you could register the DateMathParser as the value parser for type Date, with the SQL parser:
parser.registerValueParser(Date.class, new DateMathParser());
And then use it in SQL queries as follows:
ResultSet<Car> results = parser.retrieve(cars, "SELECT * FROM orders WHERE (shipDate < +0DAY)");
Basically, you can register a custom value parser for any type of value. In the case of ‘shipDate’ here, the SQL or CQN parsers, will look for an attribute called ’shipDate’ which has been registered with the parser, it will determine that the type of the shipDate attribute is Date, and will then look for a value parser which can parse the string ‘+0DAY’ into a Date object. So it finds DateMathParser, and invokes that to parse the string.
DateMathParser is just one parser. You could register your own SuperFlexibleDateParser if you wanted to support say several allowed date formats, and possibly date math statements as well, in the same query.
HTH!
Niall