Hi Hugi;

You can use EJBQL queries with timestamps, but there is presently no supported _literal_ representation for a timestamp inside the query string so you have to use parameters instead. Here is an example;

  EJBQLQuery q = new EJBQLQuery(String.format(
    "DELETE FROM %s r WHERE r.createTimestamp < :expiryTimestamp",
    Response.class.getSimpleName()));

  q.setParameter("expiryTimestamp",
    new Timestamp(System.currentTimeMillis() -
    TimeUnit.SECONDS.toMillis(expirySeconds)));

  getServerRuntime().getContext().performQuery(q);

To help with getting Expression objects to over to EJBQL with timestamp literals;

  Expression#toEJBQL(List<Object> parameterAccumulator, String rootId)

So you call that and as it creates the EJBQL fragment, it will insert any necessary parameters into the parameterAccumulator for you all set to go into the EJBQLQuery.

Hopefully that helps?

cheers.

[1] https://github.com/aplgithub/haikudepotserver/blob/master/haikudepotserver-webapp/src/main/java/org/haikuos/haikudepotserver/captcha/DatabaseCaptchaRepository.java


  For example;

  SELECT f FROM Foo f WHERE f.createTimestamp > ?

Then you just need to use the


On 12/08/15 20:35, Hugi Thordarson wrote:
Hi Andrew,
thanks for that. I see what the problem is.
But if I can’t use EJBQL when generating queries that use dates, can I go down 
any different paths or do I have to revert to writing plain old SQL?

--
Andrew Lindesay

Reply via email to