Hi Ganapathy,
This email is just to give alternate viewpoints (there is no one right way to do this assignment).
You suggested:
What Ifeel about locking is there need not be any locking mechanism in single user mode(standalone mode). The way I see it, the deliverable is broken into three major sections:
Client GUI <--> Interface <--> Database
The interface could be either direct connection (local mode) or networked.
Looking at the instructions for the old FBNS assignment, we have:
The remote client code that you write must provide all the public methods of the suncertify.db.Data class.
I have taken that to mean that at least the client side of the network must have access to remote lock and unlock methods (whether it uses them, and what they do is up for discussion
).
It would be possible to still have the GUI unaware of the locking mechanism, however I believe that for future extensibility the GUI should lock records itself.
To give you an example of why, consider a two part flight: one flight leaving Holland at 7am arriving in London at 7.30am, to catch the 8.30am flight from London to Sydney. If I cannot get the Holland - London flight, then I dont want the London - Sydney flight. Likewise if I cannot get the London-Sydney flight then I dont want the Holland-London flight. Due to the limited flights from London to Sydney, it is a case of getting both these flights or nothing.
Now, if I can lock records on the client side, then I can lock the Holland - London flight, check that there is a seat available, lock the London - Sydney flight, check that there is a seat available, book both flights, and unlock them both.
Without this locking mechanism, I would have to have a method of reversing the entries. Quite often you will find that doing this will generate a lot more network traffic than my "locking" solution, depending on audit requirements may require more data to be saved on the far server, and depending on authorization requirements may require manager intervention. All of which adds up to I would rather be able to lock records and never update than to update and then back out changes.
I know - the specs dont require anything like this. However the specs do say:
Your user interface should be designed with the expectation of future functionality enhancements
So I want to have locking client side - that is
my design decision
no one else has to follow it
Going further with your comments, you have the lock - update - unlock in a synchronized block. I cannot see any need for that. The locking mechanism is almost certainly going to be synchronized, and once we have a lock the record is ours - we no longer need to be synchronized.
You also said:
some people used Map where key and value paris are stored. I feel this is not needed People have done this because of the old assignment requirement:
If an attempt is made to unlock a record that has not been locked by this connection, then no action is be taken.
Some people have tried to keep track of which client locked the record to meet this requirement, hence the Map. I am not commenting on whether I agree or not
I do not think your suggestion of a volatile variable for tracking how many seats have been booked is viable. Are you keeping a variable for evey flight that may be booked? That could be a lot of variables. Plus it is then making the database specific to the current implementation of flights availability. This is wrong on two counts: if the requirments change (e.g. having different numbers of business class versus normal class to be booked) then you would have to rethink the entire booking concept. More importantly, the database is no longer a generic database, but specifically tied to the data it is storing.
Regards, Andrew
[ May 04, 2003: Message edited by: Andrew Monkhouse ]