So each record has a 1 byte flag at that start of it. I was doing something like this:
<CODE> private final static int INVALID_FLAG = 0xFF
extract from read(..)
int flag = temp[0]; if(flag == INVALID_FLAG){ throw new RecordNotFoundException("Record number " + recNo + " was not found");
}
extract from delete(..)
randomAccessFile.write(this.INVALID_FLAG);
</CODE>
However upon debugging I found that an invalid (deleted) record was returning -1. So the check in read was returning false even if the record was deleted If I change the invalid flag declarartion to
private final static int INVALID_FLAG = -1
then it all works ok.
Firstly am I missing here ? And secondly is it ok to do it this way ?
Thanks.
Alan Morgan
Ranch Hand
Joined: Apr 18, 2005
Posts: 113
posted
0
Doh.
Of course the easy answer is rather than check if flag == INVALID_FLAG all I have to do is check if flag != VALID_FLAG.
And given that VALID_FLAG is set to 00 there is no problem with that.
I've been looking at this for too long
Tinky
Greenhorn
Joined: Oct 02, 2005
Posts: 4
posted
0
Hi Alan,
Since the length of the flag field in your database is one byte, you should use the following to declare your flag:
The value of INVALID_FLAG is now -1 and you can now use your original if-statement to test whether a record is valid or not.