File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes [NX] Question about the findByCriteria. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "[NX] Question about the findByCriteria." Watch "[NX] Question about the findByCriteria." New topic
Author

[NX] Question about the findByCriteria.

Kai Liu
Greenhorn

Joined: May 29, 2002
Posts: 9
Hi everyone,
I get one question about the findByCriteria(URLyBird).
According to the instructions, the client can search by either one or both of "name", "location" fields.
But my question is what about server side ?!
cos the interface DBAceess looks like this:
//return an array of record numbers that match the specified criteria.
//Field n in the database file is described by criteria[n].
//A null value in criteria[n] matches any field value. A non-null value
//in criteria[n] matches any field value that begins with criteria[n].
public long[] findByCriteria(String[] criteria)
Should I implement search on the server-side as I did in client-side or in a different way searching throught all fields which might be cubersome?!
Thanks in advance.
Best,
FRank
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Kai,
Should I implement search on the server-side as I did in client-side or in a different way searching throught all fields which might be cubersome?!

Server-side and client-side requirements are different and both are *must* requirements.
(1) Server-side : search on all fields possibly, wilcard matches.
(2) Client-side : search on location and/or name fields only, exact matches.
And ideally, implementation of (2) should make use of (1).
Regards,
Phil.
Kai Liu
Greenhorn

Joined: May 29, 2002
Posts: 9
Thanks, pill.
I get it.
But now I am thinking the efficient way to implement search on server-side.
Coz I want to write GUI on SERVER-SIDE too.
So how can I do that in a easy way?!
I mean what kind of the swing components I need to use in order to search throught all fields?!
(i.e: how does the user specify which field(s) to compare)
What I can imagine is to use "textbox" allowing user to enter the criteria, and ComboBox to indicate which fields to compare but it's not ideal for multiple fields. Or I just search all fields no matter what kind the criteria is.
Please advise.
Thanks in advance.
Best
FRank
[ December 23, 2003: Message edited by: Kai Liu ]
Seid Myadiyev
Ranch Hand

Joined: Jul 02, 2002
Posts: 196
Hello Kai and Philippe,
Can you please explain the difference between "search on client" and "search on server"?
I thought I understood the search requirement very well until I read this thread!
Thank you very much!
Seid
Kai Liu
Greenhorn

Joined: May 29, 2002
Posts: 9
The client can search by name, location fields (either one or both).
But what about the the Non-network mode which is on the server-side?!
Can the user on the server side search by all of the fields or just two fields as client did?!
Otherwise, we won't have the findByCriteria singnature like this :
public long[] findByCriteria(String[] criteria)
( We can just pass two string for name, location fields)
What do you think?!
FRank
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Kai and Seid,
Kai:
Coz I want to write GUI on SERVER-SIDE too.

What do you mean there ?!
Can you please explain the difference between "search on client" and "search on server"?

Yes, this thread is a bit confusing. What I tried to explain to Kai above, is that the global search process uses two *pieces* of software, one server-side and one client-side. Both are defined in our instructions (Data.findByCriteria() and search requirements for the client) and *seem* to be incompatible at first sight (Data.findByCriteria() must use wildcards while client search must work on exact matches). The challenge is to find a way to :
  • make those two pieces of code work *together*
  • though respecting the specific requirements we have for each of them


  • Best,
    Phil.
    [ December 23, 2003: Message edited by: Philippe Maquet ]
    Seid Myadiyev
    Ranch Hand

    Joined: Jul 02, 2002
    Posts: 196
    Hello Philippe,
    In my specs I have 2 statements:
    1.
    // Returns an array of record numbers that match the specified
    // criteria ...
    // criteria[n] matches any field value that begins with criteria[n]...
    public long[] findByCriteria(String[] criteria);

    2.
    - It must allow the user to search the data for all records,
    or for records where the name and/or location fields exactly match values specified by the user.
    My question is: how is one not compatible with the other? Could you please clarify these points?
    Thank you again!
    Seid
    George Marinkovich
    Ranch Hand

    Joined: Apr 15, 2003
    Posts: 619
    Originally posted by Seid Myadiyev:
    In my specs I have 2 statements:
    1.
    // Returns an array of record numbers that match the specified
    // criteria ...
    // criteria[n] matches any field value that begins with criteria[n]...
    public long[] findByCriteria(String[] criteria);

    2.
    - It must allow the user to search the data for all records,
    or for records where the name and/or location fields exactly match values specified by the user.
    My question is: how is one not compatible with the other? Could you please clarify these points?

    Is "begins with" the same as "exactly match?" My DBMain interface describes the find method as follows:

    // Returns an array of record numbers that match the specified
    // criteria. Field n in the database file is described by
    // criteria[n]. A null value in criteria[n] matches any field
    // value. A non-null value in criteria[n] matches any field
    // value that begins with criteria[n]. (For example, "Fred"
    // matches "Fred" or "Freddy".)

    That sounds like it's doing a wildcard match (specifically a starts-with match). In an exact match would "Fred" match "Freddy?"
    How to handle this discrepancy? One way is to filter the results on the client-side. Your client calls find("Fred") and gets back two records: "Fred" and "Freddy." The first record is an exact match so it is displayed to the user, while the second record is not displayed to the user because it is not an exact match. (Note: of course the find method actually takes a String[] and returns a long[], but I'm simplifying things here to make a point.) In this way both the requirements of the find specification and the requirements for an exact match are satisfied.
    Philippe has earlier explained a clever alternative that involves right- padding the search criteria. You can pursue that here: http://www.coderanch.com/t/184550/java-developer-SCJD/certification/NX-Search-Criteria-GUI
    The assignment instructions appear to have a lot of contradictions in them and I think this may have been on purpose. Your job is to resolve these contradictions in your mind (and thereby hopefully in the mind of the grader as well). How can I let the user perform exact match searches when the DBMain spec I've been given doesn't really do an exact match? How can I use RMI when the DBMain spec contains methods that don't throw the required RemoteException?
    Hope this helps,
    George
    [ December 23, 2003: Message edited by: George Marinkovich ]

    Regards, George
    SCJP, SCJD, SCWCD, SCBCD
    Seid Myadiyev
    Ranch Hand

    Joined: Jul 02, 2002
    Posts: 196
    Thank you so much, George!
    Your explanation is very clear! I can continue with my design now.
    Seid
    amchi gelo
    Ranch Hand

    Joined: Jul 01, 2002
    Posts: 75
    My requirement states:

    // Returns an array of record numbers that match the specified
    // criteria. Field n in the database file is described by
    // criteria[n]. A null value in criteria[n] matches any field
    // value. A non-null value in criteria[n] matches any field
    // value that begins with criteria[n]. (For example, "Fred"
    // matches "Fred" or "Freddy".)
    public long[] findByCriteria(String[] criteria);

    I have made my search to be case sensitive, and the matches any field that begins with the criteria value as asked... am I missing anything?
    Sanjay


    Sun Certified Web Component Developer 1.4<br />Sun Certified Java Developer 1.4<br />IBM Certified Associate Developer - WebSphere Studio, V5.0 (285)<br />IBM Certified Specialist - IBM WebSphere Application Server, Adv Single Server Edition for Multiplatforms, V4.0 (158)<br />IBM Certified Solutions Expert - IBM Websphere Studio V4.0 (487)<br />IBM Certified Specialist - IBM Visual Age for Java V4.0 (283)<br />Sun Certified Java Programmer 1.2
    George Marinkovich
    Ranch Hand

    Joined: Apr 15, 2003
    Posts: 619
    Hi Sanjay,
    Originally posted by Sanjay Joshi:
    I have made my search to be case sensitive, and the matches any field that begins with the criteria value as asked... am I missing anything?

    I think you've correctly implemented the findByCriteria method on the server. The question is whether this implementation also satisfies the part of the assignment instructions that states:
    It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.

    So if your client merely calls the findByCriteria method will he really be getting an "exact match"? Many people seem to feel that the findByCriteria method doesn't really implement an exact match (but rather a starts-with match). Is it OK if the user enters "Fred" as the name search criterion and gets back a record with a name of "Freddy"? Many people seem to feel that this would not be meeting the "exact match" criteria. One solution is to filter the results returned by findByCriteria to get rid of matches that are not exact. So if you search for "Fred", and you get back from findByCriteria "Fred" and "Freddy", you filter out "Freddy" because it doesn't exactly match "Fred", and so you would return to the client only "Fred".
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: [NX] Question about the findByCriteria.