• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Optional parameters in EJB QL?

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'm trying to create a finder in a container-managed EJB, with optional parameters. What do I mean? Well, I'm looking for certain data in my tables which occur within a certain date interval. I would like to use a single method for this:
findDataInInterval(Integer type, Date occursAfterThisDate, Date occursBeforeThisDate)
Which can conceivably generate at least 4 SQL queries (using a EJB-QL'ish syntax):
select * from my table where type = ?type
select * from my table where type = ?type and mydate > ?occursAfterThisDate
select * from my table where type = ?type and mydate < ?occursBeforeThisDate
select * from my table where type = ?type and mydate > ?occursAfterThisDate and mydate < ?occursBeforeThisDate
Is there a way to generalise the four queries into one entry, so that the mydate clauses are ignored if either (or both) dates are null?
Thanks,
L
 
author
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Laurent,
Those look like four different custom finders to me.
Regards,
 
Not so fast naughty spawn! I want you to know about
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic