Just to give you something to think about: if you read an entire record as one big byte array, then you could check whether the record was deleted and convert the byte array into individual Strings outside of the synchronized block.
read() is not guaranteed to read the requested number of bytes. Take a look at readFully().
Ulrich:
1. Concerning the expression: "allRecLen % getRecordLength()) != 0", I suppose you Gurus will critize it because it isn't very elegant, or?
Andrew:
I think that this is perfect. It is simple to read, and does exactly what you want.
quote:
Ulrich:
2. "throw new IOException("the db-file might be corrupted")"
When the length of that part of the file which is reserved for storing the Records can't be divided through the number of Records, I have to suppose that the db-file is corrupted and in that case the IOException is the appropriate Exception.
Andrew:
Yep, the db-file would have to be corrupt in that case
The Data.find() method will do "starts with" matches, whereas the GUI must only display "exact" matches.
So you already have to have a method (in the GUI (IMHO)) that will verify whether the data returned by read() is an exact match or not. This routine can automatically discard any records that have been modified.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
John, I think that you are doing what I mention above. But I wanted to clarify just to make sure that we all are on the same page.
Personally I think you could go one of two ways here: either have the validation inside the synchronized block which will limit the race condition, or read the entire record as one long buffer within the synchronized block and then run your validation and conversion routines on that read buffer.
The Data.find() method will do "starts with" matches, whereas the GUI must only display "exact" matches.
So you already have to have a method (in the GUI (IMHO)) that will verify whether the data returned by read() is an exact match or not. This routine can automatically discard any records that have been modified.
Nope - not acceptable.
But this brings up another issue: when you go to book the record, if the details have changed, what do you do? What can you do if you are running fat client? What can you do if you are running thin client? Do you go back to my comment above about just documenting this as an issue?
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Ulrich ReadFully() throws an EOFException. How should I handle it? .... So following the logic [that EOFException should not occur] it would make sense to catch it and to throw it as IOException. What do you think about it?
Bharat I compare the criteria strings using starts with in the Data.find() method, but don't do anything at the client end with the returned records. I am not sure what do you mean when you say that the GUI must only display the exact matches?
"This routine can automatically discard any records that have been modified." - I am afraid I don't understand again.
John I need a little help regarding my unlock method (see below). ... I am not overly familiar with Maps but will do some reading up on them soon.
John a similar type of race condition now exists in the lock() and unlock() functions.
John The find() method returns an array of int with each int representing a record number that matches the search criteria.
John Andrew, are you suggesting that we process the resulting records again to double check that they match the criteria or have you (or anyone) another way of suggesting we do this?
John I don?t really know what you mean by ?fat client? and ?thin client?
Bharat I am struggling with an efficient way of writing to the RAF. .... I have to: Add all individual field Strings into a big record String plus add a deleted flag byte before this big string.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Check your instructions. Do you have a comment (possibly in the "User Interface" section) stating "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"?
That "exactly match" criteria gives you a basic discrepancy between the requirements of the server and the requirements of the client interface. On the client side you can only show "exact matches" but the server can provide "starts with matches".
Therefore you have to have code on the client side that will reduce the results from the server to just exact matches. And if one of the criteria fields has been modified between the time of the search and the time of the retrieval of the record, then it will automatically be discarded as it will not be an exact match.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Note that this implementation is not synchronized. If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.)
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|