Hooli Hooli - 1 year ago 135
Java Question

cqengine compare by datetime

I'm trying to find a list of objects that are after a certain

. In order to do so, I've created the following query:

return foos.retrieve(QueryFactory.equal(EXPIRY_INDEX, new DateTime()));

I then created the following index:

public static final Attribute<Foo, DateTime> EXPIRY_INDEX = new SimpleAttribute<Foo, DateTime>() {
public DateTime getValue(Foo foo, QueryOptions queryOptions) {
return foo.getEXPIRY();

So far all good, except, the
method will invoke
as far as I know which will ultimately return
all the time. What I need is a way to call

How can I find all elements in a collection that have a
after right now?

Answer Source

If I understand correctly, you should use a greaterThan() query instead of an equals() query.

These will rely on Comparable.compareTo(), instead of Object.equals(). So it should work if your DateTime object implements the Comparable interface properly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download