• 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

Confuse the findByCriteria()

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,all
After looking up relational posts,I found some difficulties to understand the findByCriteria() method.

According to the part of code,I guess that is the following presentation:

What do you think of the implementation about this for details?
Regards,
Richard
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what does the long[] represent
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am assuming an array of UNIQUE record numbers
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Bill


what does the long[] represent ?


Because the "findByCriteria()" method will return a array with long values.

What's your useful opinion to implement the method?
Does all I written have some shortages?
Welcome other people to join us and criticize the topic.
Regards,
Richard
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Richard,
You need to consider three more points in your search algorithm:
1. ANY - value which means that any value for the field which is part of the criteria, and this is completely different from �a null value in criteria[n] matches any field value �null for any� if criteria includes more than 2 (two) fields.
2. AND/OR - logical condition between the two field values as a pat of your criteria.
3. Upper/Lower case � String.startsWith(�) is case-sensitive; (is this acceptable by your specifications?)
Please share you ideas on these points!
+Seid
[ November 16, 2003: Message edited by: Seid Myadiyev ]
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,Seid
Thank you analyze for details.

3. Upper/Lower case � String.startsWith(�) is case-sensitive; (is this acceptable by your specifications?)


I will study the 'startsWith()' and other methods in Java2 API,and then use them
What ways to implement it in your project?Would you like to give notes?
In my Assignment,there are not limitation statements about CASE-SENSITIVE.
Please join us. - other experts
Regards,
Richard
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Richard Jackson:
In my Assignment,there are not limitation statements about CASE-SENSITIVE.


Hi Richard,
Are you sure case-sensitivity may not be implied by your specifications? I have the Contractors 2.1.1 assignment and they state that the user interface "must allow the user to search the data... for records where the name and/or location fields exactly match values specified by the user." (Please note that the emphasis on the word "exactly" was placed by me.)
Of course, how you interpet an "exact" search can be a discussion left for your design document, but it is my opinion after reading a bunch of threads on this search criteria issue that it is probably a safe bet that "exact" means a "case-sensitive" search.
Offering search criteria choices in JComboBoxes provides a nice clean way to implement this functionality.

Regards,
Paul
[ November 16, 2003: Message edited by: Paul Tongyoo ]
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Paul
Sorry.

Are you sure case-sensitivity may not be implied by your specifications?


I am ashamed of about this point.I dont exactly understand the "implied" meaning.
In my instructions.html,

All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field.


I think that all text values also contain the "criteria" string,and all fields strings present every field values of record.
I really do this not easily.
Please each one clarify the findByCriteria() with your experiences.
Regards,
Richard
 
Paul Tongyoo
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Richard,
I apologize -- I was referring to the implied meaning of the specifications listed under the "User Interface" section of the specifications document. You are correct to not see any implied meaning in the statements you cite above; they are definitely straight to the point.
Could you restate your questions about the findByCriteria method? I'm afraid I do not understand what exactly you are finding difficult to understand.

Regards,
Paul
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Paul
Here,I repost the part of my instructions.html file,


// 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 ensure that:
A. The criteria[n] is the search key value that we might enter it into a text field.We use it to search those required records/fields.
B. When we enter null value in the criteria text field,this mean that we select all records.
When we enter a value starts with criteria[n] (like "Rich" matches "Richard" or "Richman" ),the method will return relational record numbers (into array).
My misunderstanding problems are:
1) How to judge whether the criteria[n] is valid? (only by startsWith() method ?)
2) Must I read records firstly ?Do I need know the length of "record number array"?
3) Am I still use String.match() method?
Regards,
Richard
 
Paul Tongyoo
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Richard Jackson:
My misunderstanding problems are:
1) How to judge whether the criteria[n] is valid? (only by startsWith() method ?)
2) Must I read records firstly ?Do I need know the length of "record number array"?
3) Am I still use String.match() method?


Hi Richard--
For your first question, I do not believe there exists any notion of a valid search criteria; if you are asking how to check if criteria[n] matches a field value in your record, then, yes, String.startsWith() is the operation that most closely matches the specified functionality. If you can justify your decision in your design document, however, you can use what ever means you'd like to determine a criteria match.
For your second question, you'll know the length of the returned record number array after traversing your entire list and comparing your criteria array against each record to determine if the two "match". The length of your return array will equal the number of matches you encounter. Reading the entire database in memory is a design decision; I personally read all the data contents of the file into a linked-list "cache" and used a list iterator to traverse the list and find all my matches. I am definitely sure there are more efficient ways to do this, however efficiency is not a requirement of my specifications so I believe my implementation is sufficient.
For your last question, if you are referring to the String.matches(String regex) operation, this is also a design decision. To satisfy the criteria match requirements on server-side, IMO String.startsWith(String) is sufficient. On client-side you'll find the criteria specifications differ, and it will be your call on what route to follow (which API function(s) to use).

HTH
Regards,
Paul
[ November 17, 2003: Message edited by: Paul Tongyoo ]
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,


For your last question, if you are referring to the String.matches(String regex) operation, this is also a design decision. To satisfy the criteria match requirements on server-side, IMO String.startsWith(String) is sufficient. On client-side you'll find the criteria specifications differ, and it will be your call on what route to follow (which API function(s) to use).


So, should I create a new function, say search(), in order to fulfill the client requirements, i.e. using String.indexOf(String) instead of String.startsWith(String)?
Or, I can simply use String.startsWith(String) as the search operation for the client?
Thanks
 
Paul Tongyoo
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
So, should I create a new function, say search(), in order to fulfill the client requirements, i.e. using String.indexOf(String) instead of String.startsWith(String)?
Or, I can simply use String.startsWith(String) as the search operation for the client?


Hi Nicholas--
You are on "a" right track; performing a filtering process on client-side is a possible solution to the criteria specification descrepency issue. Have you considered what Swing widgets you will be using to capture the user's search criteria? A nice solution that ranchers in this forum have come up with is choosing a widget that allows the user to submit exact values to the db.find(String[] criteria) function so that the server (which still only uses the String.startsWith(String) operation) will return only the records clients wanted and nothing more.
Regards,
Paul
 
reply
    Bookmark Topic Watch Topic
  • New Topic