Hello all,
I think its a pretty dumb question, but I could'nt figure it out on how to do. Please suggest me, thanks.
In the DBAccess interface that is provided by Sun, many functions are taking recNo as an argument. Some of the code in the given interface looks like
public interface DBAccess
{
// Reads a record from the file. Returns an array where each
// element is a record value.
public
String [] readRecord(long recNo)
throws RecordNotFoundException;
// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.
public void deleteRecord(long recNo, long lockCookie)
throws RecordNotFoundException, SecurityException;
// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.
public long createRecord(String [] data)
throws DuplicateKeyException;
// Locks a record so that it can only be updated or deleted by this client.
// Returned value is a cookie that must be used when the record is unlocked,
// updated, or deleted. If the specified record is already locked by a different
// client, the current
thread gives up the CPU and consumes no CPU cycles until
// the record is unlocked.
public long lockRecord(long recNo)
throws RecordNotFoundException;
.............
.............
}
As far as I understood, there is no field in the db.db that correlates to the recNo in the above interface. I think this recNo acts like an index to the records in the db.db and we need to store them in an ArrayList(I'm not sure whether its ok? or use others). But I could not figure it out on how to relate the records in the db.db file with the recNo in the given interface.
Can anyone give some suggestion on how to relate the records in database with the recNo? And if we need to generate the recNo's and then relate them to records in db.db file, can I generate them like the cookie value(Please see my ideas on cookie generation)?
And I have another question. This one is regarding the cookie value. I'm thinking of a couple of ideas to generate the unique cookie value. One is using the Math.random() method. Other one is using the Date.getTime() method. Is this is a valid and reasonable approach. Or can I just use numbers 1,2,3... as lockCookie value.
Please suggest me on how to deal with the above problems. Really appreciate your help. Thanks.