Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S locking issues & findByCriteria

 
Bruce Xu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,ranchs,be glad to meet you guys here.
I have read the posts for some time so I put some questions of mine here.
My assignment is B&S and there's a function in the "DBAccess.java" interface:

//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);


Then,how to make sure that the record numbers the "findByCriteria" returns are up-to-date to client?
For example, if a client calls the "findByCriteria" and get returning {2,3,5,8}.But immediately after getting the record numbers, another client access the record "5" (just an example) and go to update it. Then how do you make sure the client GUI displays these records correctly?Because you only get record numbers,not the REAL records.
The point here is that the "findByCriteria" is a little bit misleading provided by SUN.If I were the "DBAccess.java" designer,I would like writing it as "public String[] findByCriteria(String[] criteria);" or returning a list of record objects.

We need to wrap this function with some locking mechanism if we wanna realize the "search" utility?! (I don't think client lay can directly call this function.)

Correct me if my assumption is not right.
thanks in advance
 
Yupp Cook
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My consideration was that there's is never certainty that find delivers "real time" data. Even if find returned the record refs there can be changes right after displaying. So we need to live with the uncertainty. But before updating a record it should be checked if there were changes in the meantime. If so booking should fail.

Hope this helps.
Yupp.
 
Bruce Xu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,Yupp Cook,thanks for the hints.
I have considered such way.But I'm probably going to wrap the function with some locking so that the client GUI will display the snapshot of the database at the time when the "findByCriteria" is called.Therefore the Client GUI will not display some unmatched results.
Just let the clients feel good.
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Well I believe the find() method in your assignment retrieving an array of long is ok. What i believe is that when the record numbers are retrieved from the search, you would now send such values to the read() method to get the actual record associated with the returned record numbers and then display the records within the GUI. So I feel SUN's approach to the find() method is just appropriate in this case.
Have a nice day.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic