views:

36

answers:

1

Short background: I have a software that regularly downloads files. The Statistics of these downloads are stored in the database as a DownloadResult entity, which is in turn associated to the entity representing the download job.

Now I want to make sure, that only a fixed number of the n latest downloads are preserved in the database. AFAIK in a classical (non ORM/JPA) database application, this would be done with a stored procedure.

What would be the right way to do this in a JPA driven application?

+1  A: 

You can try Quartz http://www.quartz-scheduler.org/ if you want to stay withing Java boundaries, if it is not a requirement you can go with stored procedures.

Artem
Thanks for your answer. I'll look into it. I'm already using java.util.concurrent.ScheduledExecutorService. Any reasons why I should prefer Quartz over classes from standard API?
er4z0r
Couple of them: you don't need to run scheduler.schedule(), just setup your schedule, and Quartz has much more powerful way for setting up schedules, for instance you can set it up to sun every Saturday night. Also it is more convenient you can set up to sun your session bean's method directly from the scheduler
Artem
My understanding of Quartz is that it works how it would be specified in EJB spec
Artem
Sorry, I don't quite understand what you mean by "how it would be specified in EJB spec". Could you please elaborate on that?
er4z0r
ScheduledExecutorService is Java SE specific, not even sure it is allowed to be used in EE, in Java EE 5 spec they don't have advanced declaration-based scheduler.
Artem