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.
Thanks,<br /> Zafer<br /> SCJP, SCWCD
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
// 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);
Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
The "and/or" in your instructions can be translated in : search on name, or search on location , or search on name and location.
It must allow the user to search the data for all records, or for records where the name and/or location fields exaclty match values specified by the user.
Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
Anyway I cant understand what the problem is.
It must allow the user to search the data for all records, or for records where the name and/or location fields exaclty match values specified by the user
// A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
Originally posted by Denis Spirin:
Marcel,
I guess the only way to do this is to implement find() as it is proposed in instructions, and give user lists of possible choices for names and locations (say, via ComboBoxes). Thus, method find is implemented as proposed, and user gets only exact matches (although we used startWith).
Regards
Your project must conform to this specification. Features that deviate from specification will not receive full credit. You will not receive extra credit points for work beyond the requirements of the specification.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
The IT director does not anticipate much reuse of the first Java technology system, but intends to use that system as a learning exercise before going on to a web based system.
Your user interface should be designed with the expectation of future functionality enhancements, and it should establish a framework that will support this with minimal disruption to the users when this occurs
The question now is whether an *exact* search should be implemented or a partial-matching algorithm as the comment for the findByCriteria()method demands? In other words, should a search for a hotel with the criteria "Ocean" return only hotels named "Ocean" or also hotels such as "Ocean View" or "Ocean Resort"?
The match should be exact. A search for "Ocean" should not return "Ocean View" or "Ocean Resort".
Bing:
Given that, I figured I should define the searchable columns and that better to be done on server side and the Service would provide a interface for clients to get it through the service control. And that's done in the DataInfo, in which other server wide configuration are specified too, like the columns to present to clients when they want to create a new contractor. This make the applicaton a little more maintainable in terms of making change to column name, or add/delete a column. And columns can be
added or taken out from the defined columns vector without ever change the client code.
Marcel:
It's now confirmed: the search MUST be exact. I've sent an email to Sun asking for clarification:
Question from Marcel to SUN:
The question now is whether an *exact* search should be implemented or a partial-matching algorithm as the comment for the findByCriteria()method demands? In other words, should a search for a hotel with the criteria "Ocean" return only hotels named "Ocean" or also hotels such as "Ocean View" or "Ocean Resort"?
Answer from SUN:
The match should be exact. A search for "Ocean" should not return "Ocean View" or "Ocean Resort".
Marcel's conclusion:
So, the specs are clear now - there are still different ways to achive the desired behavior.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Personally I prefer Phil's second solution, which I think is more in keeping with his three layer concept.
The method in the Data class can do an inexact match, and a higher level method can then do any further restrictions necessary.
This means that the database is doing the minimum amount of work. The harder work is being done on a seperate machine.
Another reason (in my mind) for doing this is that the find() method only returns an array of record numbers - you still have to go and read each individual record seperately. This means that between the time that find() reported that a record matched your criteria, and the time you read the record, it could concievably have changed so that it no longer matches your criteria. So having an additional check at a higher level which confirms that the record still matches (and does the exact match) makes sense.
Originally posted by Philippe Maquet:
Aah... arguing with you Andrew, I haven't had that pleasure for a while now! Thank you!
Originally posted by Philippe Maquet:
It really depends on your implementation. Typically, the Data layer will have its own efficient means to access data that the business layer cannot use. Indexes for instance (back to this further).
Originally posted by Philippe Maquet:
Now as I needed a findByRangedCriteria() anyway, to handle criteria *ranges*
Originally posted by Andrew Monkhouse:
Another reason (in my mind) for doing this is that the find() method only returns an array of record numbers - you still have to go and read each individual record seperately. This means that between the time that find() reported that a record matched your criteria, and the time you read the record, it could concievably have changed so that it no longer matches your criteria. So having an additional check at a higher level which confirms that the record still matches (and does the exact match) makes sense.
Originally posted by Philippe Maquet:
Good point... although.
As the business layer (wherever it is) cannot do anything with the recNos returned by find() except reading records, the time between find() returns and reads are performed will be very short. Much shorter anyway that the time spend to process the records read (especially if the user enters in the play ).
Originally posted by Philippe Maquet:
The business layer must *read* the records to perform its additional checks (which BTW gives some additional work to the database), while the Data layer performing the same checks by itself may not need any read. So each time Data is able to return exactly the recNos the business layer needs (with no useless records to be rejected at the business layer level), while performing less reads on average than the business layer would do, the database is globally doing *less* work.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
(Actually I suspect your ranged find might fit into the "simple generic search method" concept which will simplify use of the Data class - but then I question this assignment's need for a ranged find. :tongue: )
Of course if you are worried about network speeds and transferring huge amounts of data which may be culled at the client side, then you may want to have more efficient searches in the Data class - however this is not a consideration for this assignment .
A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is a little more efficient.
Why do you need this? (findByRangedCriteria()):
Yes, but even in your case, since you are returning record numbers, there is the potential that by the time the real records are read, the "exact match" will no longer match. :tongue:
It's interesting to see you two fight.
For this assignment,there is no way to avoid a scan over the file when doing find, like doing table scan in a relational database where there is no index created.
What is the point to return the record number instead the record itself?
You got the record when during comparison already and a record number returned and the called has to go into the data to read the record again. That's a waste of everything.
I have, before this discussion, implemented Sun's DB find but it is not used(like some of ranchers do here). I noted this in the choices.txt. Now I am sure that this would work after all this discusion and my being lost and found. My own find is a overload of sun's. it takes a boolean indicator to do either exact or not-exact search. And it returns a string array with and later packed in a contractor object and presented to the client.
I implemented field indexes as TreeMaps mapping keys (field values) to TreeSets of recnos, which fits very well with ranged criteria (think of TreeMap.subMap()). With such a design it's as easy (a few lines of code) as efficient to return a Set of the recnos corresponding to a range of keys.
I planned to use the same strategy for my indexes. However, I'm a little stuck I would say. One needs to loop through the criterias...and then?
How do you match one criteria (e.g. criteria[n]) to an index?
Different question, how do you know that there's an index for the particular criteria?
After all, the indexed fields need to be searched first.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |