I'm not sure I follow your answer Divya, what I think you are saying is to
pass null parameters.  This will work as long as the item passed is still
the correct type.  But if you mean to simply not pass the parameters that
will cause java to look for a method that takes the new combination of
parameters.

Eric,
I think what you are looking for is overloaded methods.

For instance:
public Collection findByAll(Float price)
public Collection findByAll(Float price, int age)
public Collection findByAll(Float price, int age, int weight)
public Collection findByAll(Float price, int age, int weight, String name)

These four methods could do a totally different search based on the
different criteria passed by overloading the method, you don't need to use a
different method name for each type of search.

Alternately you could make one method that requires all the parameters then
check to see which parameters are filled to determine your search.  This
would not be the preferred way because the calling application would have to
create a blank variable for all the search criteria even for the things not
required for their search.  It would be much better to have overloaded
methods for every combination of items that could be passed in.

What I feel would be the BEST way to do what you need would be to create a
class that holds your 20 attributes with setter and getter methods for each.
Then you create one object and fill in the attributes you want to search for
and only pass the object to your method:

public Collection findByAll(ObjTestContainer search)

This way the calling application simply creates an ObjTestContainer object
and fills in the attributes they need, then passes the object to the
findByAll method.  Further, you could add code to the constructor method in
the class to fill in the default values.

See the end of this email for a sample class that could be used the way I
suggest.



Dale Nicholson


> -----Original Message-----
> From: Divya [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 28, 2002 3:08 AM
> To: [EMAIL PROTECTED]
> Subject: Re: How many Finders to I need for a search enginer?
>
>
> A method
>
> findByAll(Float Price, int Age, int Weight,............){}.
>
> If the any parameter is NULL ( or not specifies by User ) ,
> then assign the
> default value for that parameter like * in DB2 and % in Oracle.
>
> Eg:  select * from ABC where Price like '*' and ............
>
> Best Regards,
> Divya.
>
>
>
>
> > Hi,
> >  I have an app that is going to have very intricate search
> capabilities.
> It is using CMP2.0. How would I implement finders in the
> system if I had for
> instance 20 attributes for an entity, and the search could be any
> combination of the 20 attributes?(ie an item has price, age,
> weight and i
> want price >$20, age <50 years, weight == 10 pounds). Would I
> need to create
> a specific finder for this ie
> >
> > public Collection findByPriceANDAgeANDWeight(Float Price,
> int Age, int
> Weight) throws RemoteException, FinderException;
> >
> > and so on for every permutation (n^2 finders!?!?!?!) This
> seems a bit
> ridiculous. Somebody please help, it almost makes me scared
> of using EJBs
> for this purpose, becuase I could more easily create a custom
> finder in a
> normal JDBC client that appends SQL contraints like WHERE
> Price > 20. Is
> there a way to do this better in EJB (maybe a dynamic FindStatement?)
> similar to my JDBC client way?
> >
> > Warmest Regards,
> > Eric Dunn
> > [EMAIL PROTECTED]
> >
> >
> ==============================================================
> =============
> > To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the
> body
> > of the message "signoff EJB-INTEREST".  For general help,
> send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> >
>
> ==============================================================
> =============
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff EJB-INTEREST".  For general help,
> send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>

package your.package.path.and.name;
import java.io.Serializable;
public class ObjTestContainer implements Serializable{
    public ObjTestContainer() {
    }
    private String field1 = "";  // these would be your 20 attributes
    private String field2 = "";  // this example only has 4
    private String field3 = "";
    private String field4 = "";

    public String getField1(){
        return field1;
    }
    public void setField1(String field1){
        this.field1 = field1;
    }
    public String getField2(){
        return field2;
    }
    public void setField2(String field2){
        this.field2 = field2;
    }
    public String getField3(){
        return field3;
    }
    public void setField3(String field3){
        this.field3 = field3;
    }
    public String getField4(){
        return field4;
    }
    public void setField4(String field4){
        this.field4 = field4;
    }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to