1. The record's location in the db file. (I chose this to implement the DBAccess. Am I wrong?)
I don't think you are wrong because I chose the same approach. Essentially, every time I come across a
record in the database file, I assign it a record number in my cache, and I store the record information.
2. The order of the record in the db file.
I'm not quite sure what you mean by this. If you are talking a sequential order, isn't this the same as option 1?
I'm not aware of any others, but if some developers found different ways to handling records, I'd like to see
their approach, but I think almost everyone will use approach 1.
I just used 0, 1, 2,... as record numbers (because in the Java world almost everything is 0-based, I decided to start the record numbers also from 0).
So if you want to lock the 5th record (in the database file), you just call lock(4);
I wouldn't use the record's location in the database file (the offset in bytes: record 1 = 250, record 2 = 350, record 3 = 450, ...), because that is not really intuitive: if you call lock(250), it seems you are locking record 250 (or 251), but you are locking record x at an offset of 250 bytes
Maybe you can keep a close look on this thread as well, because it also handles about record numbers (and what to use).
I've decided to change the recNo to the sequence order number, the first record stats from 0, second is 1 and so on...
I've also caching the db file into a HashMap, and this procedure will only be run once when the Server starts successfully. Every time the user alters the record througth JTable will only modify the contents in the HashMap.
My question is: When can I save the contents stored in the HashMap into back to the db file? I know it will happen when the server is closed, but i don't know how to do it. Is it done by implementing a server close listener? I used RMI method.