Dear all,
Again, I am bothering you with some naive questions.
I am thinking about the process of booking and maybe returning(creating?) a room.
The following is the requirements.
---------------------------------------------
The User Interface
The user interface for this assignment must satisfy the following criteria:
It must be composed exclusively with components from the
Java Foundation Classes (Swing components).
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.
It must present search results in a JTable.
It must allow the user to book a selected record, updating the database file accordingly.
Server
Required Interface
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
package suncertify.db;
public interface DBMain {
// Reads a record from the file. Returns an array where each
// element is a record value.
public
String [] read(int recNo) throws RecordNotFoundException;
// Modifies the fields of a record. The new value for field n
// appears in data[n].
public void update(int recNo, String [] data)
throws RecordNotFoundException;
// Deletes a record, making the record number and associated disk
// storage available for reuse.
public void delete(int recNo) throws RecordNotFoundException;
// 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 int [] find(String [] criteria)
throws RecordNotFoundException;
// 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 int create(String [] data) throws DuplicateKeyException;
// Locks a record so that it can only be updated or deleted by this client.
// If the specified record is already locked, the current
thread gives up
// the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
// Releases the lock on a record.
public void unlock(int recNo) throws RecordNotFoundException;
// Determines if a record is currenly locked. Returns true if the
// record is locked, false otherwise.
public boolean isLocked(int recNo)
throws RecordNotFoundException;
}
(Sorry, it's too long)
--------------------------------------------------------------------
I think the booking process should be:
1. Lock the record (using method of public void lock(int recNo)).
2. Check the record is deleted or not. If not, go to 3. If deleted, tell user it is booked by another client, and then go to 5.
3. Update the record information, e.g. fill in the customer's ID. (using method of public void update(int recNo, String [] data)).
4. Delete the record, i.e. make the mark the record as deleted, and should not be showed in other clients' GUI in the future (using the method of public void delete(int recNo)).
5. unlock the record (using the method of public void unlock(int recNo)).
My first question is, am I right?
My second question is, since the requirment only say allow the user book a selected record, it doesn't say MUST allow user to return it, need I implement the Return function? And if I want to do the return function, I think the client can do a return only in the same session in which the Booking is made. Since if the user quit the client gui, and then start it again to return a room he just booked, he can find the record in the search result(the search I am going to do, will not show the deleted records), and it is difficult for the system to judge if he is the one who booked the room. So what I can do is to write this limitation in the docment. Am I right?
My third question is, in order to implement the return function, there should be a hashmap or some other data structure to store the information about the room and the its related client which booked the room. So together there should be 2 such globle data structure, one is for the lock/unlock, another one is for the book/return. Am I right?
Oops, hope you are not tired of reading my questions!
Thanks a million!!!
Joe