wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Optional parameters in EJB QL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Optional parameters in EJB QL?" Watch "Optional parameters in EJB QL?" New topic

Optional parameters in EJB QL?

L Duperval
Ranch Hand

Joined: May 14, 2003
Posts: 63
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?

Live Free, Live Happy
Howard Kushner
Ranch Hand

Joined: Sep 19, 2003
Posts: 361
Hi Laurent,
Those look like four different custom finders to me.

Howard Kushner<br />IBM Certified Enterprise Developer - WebSphere Studio Application Developer V5.0<br />IBM Certified Advanced System Administrator - WebSphere Application Server V5.0<br />IBM Certified Solution Developer - Web Services with WebSphere Studio V5.1<br /><a href="http://www.amazon.com/exec/obidos/tg/detail/-/1931182108/" target="_blank" rel="nofollow">Developing J2EE Applications with WebSphere Studio</a> my Certification Study Guide for IBM Test 287
jQuery in Action, 2nd edition
subject: Optional parameters in EJB QL?
Similar Threads
clicking on text retrieve data from database
Oracle cast()+PreparedStatement
Handling Dates in JSP + Beans
CMP 2.0 problem in Jboss 4.0.2
why we can set String to date ?