• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to define criteria for search

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing the Bodgitt and Scarper. I am a little bit confusing about how to define the criteria in my �find� method.

My find is defined like this:
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".)

Could anyone explain this please!

Thank you very much!!
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a record and criteria that look like:

you have a match, and should return the record (or it's id) as found.

If you have:

then you don't have a match.

Is this an answer that you expected? If not, please rephrase your question.
 
Zonglin Li
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alecsandru:
Thank you very much for your reply. It is very clear.

If I want to get all the records, I could just set the criteria to: null null null null null. So I don�t need to create a method to get all the records. Do you think so?

Cheers
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i append question, thanks.

The requirement of search function may only contains some of the fields. For example name and location is required to search, so the criteria[] array may only need to contain the two element? is it not neccessary to contains all fields in the db data file?

Thanks a lot.
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Zonglin Li:
If I want to get all the records, I could just set the criteria to: null null null null null. So I don�t need to create a method to get all the records. Do you think so?


To be on the safe side, I'd say you are not allowed to change the interface you received in the assignment. If you have a method in the interface which is something like getAllRecords(), then you must implement it. If not, then, in order to retrieve all the records, you should call the find() method with an all-null criteria. (This is also valid the other way round - if you call the method find() with all-null criteria, you should return all records).

I'd also recommend that you test your implementation with something like JUnit in order to be sure that everything works as expected.
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jin Young:
Hello, i append question, thanks.

The requirement of search function may only contains some of the fields. For example name and location is required to search, so the criteria[] array may only need to contain the two element? is it not neccessary to contains all fields in the db data file?

Thanks a lot.


The database access layer provides a lower-level access to data (for example uses arrays, and provides basic functions - like lock, unlock, update, delete, etc - functions that you must call in a certain sequence in order to "do" something - e.g. lock/update/unlock for "updating"). But, at the same time, it's broader - meaning you can do almost anything with it, including searching for something that your client side will not need (like matches on something else than "location" and "name").

So, yes, I'd say you should implement a criteria with all fields, not only 2 of them. But the decision is yours, and of you decide otherwise, you should document it in your choices file.
I wouldn't (and I didn't) implement searching only for two fields...
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm a little confused about this:

In the User Interface section says:

The user interface for this assignment must satisfy the following criteria:

* 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.



But in the DB Interface I got:

// 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".)



Which one should I implement? It would very silly to implement the db in a way that finds partially matched criterias and then filter those results to provide exact matches only.


Any recommendations? Regards
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you read carefully my previous post, you'll see that what DB provides is different from what the client really uses. So you must apply some more restrictions in another layer (business layer, for a three tier architecture, or client if you're using a 2-tier).

Anyway, try to search around for answers to questions like these. They've been asked and answered quite often until now.
[ November 15, 2008: Message edited by: Alecsandru Cocarla ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Martin,

You asked about the search (exact match) for the GUI vs. the
starts with search defined in DBMain.

Which one should I implement? It would very silly to implement the db in a way that finds partially matched criterias and then filter those results to provide exact matches only.



Your Data class must contain a find
method that exactly matches the functionality and signature defined
in your instructions. SUN tests your GUI and they also directly
connect to you Data class to check that DBMain is implemented.

DBMain is an ugly interface. Design-wise you need to decide how
you want to handle these limitations. The simplest solution is
to "work with the limitations". For searching that would mean
that whatever calls Data has to filter the results.

If you want to have your database provide "exact match" searching
you need to design your system so that it implements
"more than just DBMain".

One option is to have a second interface that
provides extra and/or overloaded methods. The second
interface can extend DBMain so that Data implements all
of the methods SUN expects plus the ones you added.

There are many useful design discussion on this forum.
If you are not in a rush, I recommend taking time to think about
your design and draw it on paper before you start coding.

Good luck with your project,
Karen
 
Martin Castellanos
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for the clarification.

Regards
reply
    Bookmark Topic Watch Topic
  • New Topic