Search code examples
javajooq

Using Jooq's DAOImpl, is there a way to fetch in time range?


I am working on using Jooq's out-of-the-box DAOs and am looking for a way to perform the following:

dslContext.select(RECORD.ID)
        .from(RECORD)
        .where(RECORD.CREATED.ge(new Timestamp(startTime.getTimeInMillis())))
        .and(RECORD.CREATED.lt(new Timestamp(endTime.getTimeInMillis())))
        .fetch();

I do see in the DAOImpl abstract class, that there is a notion of "fetch by Created", but not in a time range fashion.

Is this something that can be accomplished without extending the BasicDao? And if not, is there a more elegant way to do this beside getting the dsl context in the child class and writing the above query?

Thanks.


Solution

  • This is an interesting idea, which I've put on the roadmap of jOOQ 3.12: https://github.com/jOOQ/jOOQ/issues/8925

    Currently, the simplest way to run this query is to run

    dslContext.fetch(RECORD, RECORD.between(startTime, endTime))
    

    Notice that the BETWEEN predicate forms an inclusive (on both ends) interval