• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

GUI display & booking questions

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm going the implement the GUI , but i have a few questions about the information which display in the JTable and the booking mechanism.

I'v gone through this https://coderanch.com/t/424629/Developer-Certification-SCJD/certification/B-S-Questions-about-lock,
and I've decided to use the following booking mechanism from one of the replys from Roberto Perillo

Yes, the system you are creating does not interact with these numbers (like, they are not taken from a table that keeps the customers data). You just have to accept them, assuming that any 8 digit number provided is valid, you know? For instance, this is how the GUI of my project works: there's a JTable that shows all records in the database. There's an area that shows some data of the record that is selected in the JTable. When you click on any record, its data is shown in this area, which also has a JTextField where you insert any 8 digit number (it can be 98767433 or 16510200 or even 41610001! ). Then, when you click on the "Book Room" button, a JOptionPane.showConfirmDialog is shown, with some data of the room being booked, the number of the customer booking the room, and a phrase "Please make sure this information is correct. This action cannot be undone" (before you have this other doubt, I'll tell you now ). An "unbook" function is not required in this project (that is, updating the customer ID field so it is blank again), that's why I did not implement one (and another advice: stick to simplicity). When you confirm the booking of the room, the record is updated with that customer ID. Do not forget to make sure that the client updating that record has locked it first. You also have to check this in your delete method (note the comments of the lock method in your interface).



Assuming 2 users are trying to book one record, user A get the lock and performing update, in the mean time, user B is blocked because he need to wait the lock.

My question: Do i need to put a progress (Swing worker) bar in user B's GUI showing something like 'The record is locking by other user' during user B is waiting for the lock or just let the program freezing? If I just choose let the program freezing (Because it is simple ), will I fail? Assuming user A takes a long time to finish the update.

Now user A has finished booking by updating the customer ID, the user B obtains the lock and he wants to update the same record with a different customer ID.

My question: Do i need to show a warning dialog showing information like 'The record has been booked, Continue?' or just let User B overwrites update the record without any extract actions? If i choose let user B override the update without any extract actions (Because it is simple ), will I fail?

As for the GUI, I'm going to implement the GUI with the MVC design pattern. Do I need to set the Model(Database) as Observable and make the View (My GUI) and Controller become Oberver? It means every user's GUI will refresh & display the least information (only if the updated record is displaying in JTable ) when the Database has been updated.

Or in order to do it simply, I'll continue to use MVC design pattern to build my GUI, but it will only refresh the Jtable's information when user runs the find function. That means I don't apply the Observer design pattern in the MVC. Will I fail if I choose the routine?

I've read the assignment requestment:


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.



The assignment doesn't neither request to display the least information in JTable when the Database has been updated or pervent user overwriting a booked record. I just want to pass the assignment in a simple design, will it possible that the examiner reduces my score because I haven't applied the business logic which are not required in the assignment ? Because less funciton, less error!

Thank you in advance.

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pkinuk,

Do i need to put a progress (Swing worker) bar in user B's GUI showing something like 'The record is locking by other user' during user B is waiting for the lock or just let the program freezing? If I just choose let the program freezing (Because it is simple ), will I fail? Assuming user A takes a long time to finish the update.

I didn't use a swing worker / progress bar. I think it is important to keep the time a record is locked (the time between the calls to lock and unlock) as short as possible! I used a thin client approach, so everything is handled at the server (so not really necessary to have a progress bar).
But if you use thick client approach:
1/ user hits book-button, record is locked, dialog opens, user enters customer-id, user confirms dialog/booking and record is updated and unlocked
2/ user hits book-button, dialog opens, user enters customer-id, user confirms dialog/booking and record is locked, updated and unlocked

I believe the 2nd option is the better one, because the record is locked if the booking is confirmed and the time the record is locked will be the shortest (with 1st option user can go for a coffee break after hitting book-button and the record will be locked until he returns and completes the booking process)

Do i need to show a warning dialog showing information like 'The record has been booked, Continue?' or just let User B overwrites update the record without any extract actions? If i choose let user B override the update without any extract actions (Because it is simple ), will I fail?

If a record is booked by customerA it can NOT be booked by customerB. Otherwise different customers will be able to book the same room and i don't think customers will be happy if they appear at the hotel and it seems the room they booked is already taken.
I don't think you'll fail, but I'm almost certain you'll might lose some points.

I'll continue to use MVC design pattern to build my GUI, but it will only refresh the Jtable's information when user runs the find function. That means I don't apply the Observer design pattern in the MVC. Will I fail if I choose the routine?

I didn't implement Observable pattern to refresh the information in my JTable. The table is refreshed with each find- and book-operation.

The assignment doesn't neither request to display the least information in JTable when the Database has been updated or pervent user overwriting a booked record.

The purpose of lock/unlock methods is preventing a record being overwritten by different threads. So why use these methods if you plan allowing overwriting booked records?
And you say that your assignment doesn't prevent overwriting a booked record, but in my assignment I can read

The id value (an 8 digit number) of the customer who has booked this. Note that for this application, you should assume that customers and CSRs know their customer ids. The system you are writing does not interact with these numbers, rather it simply records them. If this field is all blanks, the record is available for sale.

So that means that a record containing a customer-id is not for sale and thus can't be booked.

Kind regards,
Roel
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But if you use thick client approach:
1/ user hits book-button, record is locked, dialog opens, user enters customer-id, user confirms dialog/booking and record is updated and unlocked
2/ user hits book-button, dialog opens, user enters customer-id, user confirms dialog/booking and record is locked, updated and unlocked



Hello, Roel!
I was going to ask exactly the same question about these two locking strategies :-)
I want to implement the first approach and these are my argumentations:
- When the CSR select the record and click "Book..." button, the record will be re-readed from database (to ensure that it is not stale), after that the records gets locked and booking dialog window opens, where only Owner ID field is editable. During this operation CSR will be confident that another CSR (who probably type faster) will not "intercept" his record in it's process of booking.
- because of slow typing or coffe break the lock may be held pretty long time, so I implemented the timed version of my lock record (beyound the base interface, of course) which tries to get lock no longer than n seconds (2sec. <= n <= 5sec.) and if this method return false, the message like "This record is temporarily locked by another CSR. Try again later" will appear.

approach 2 is easier in implementation, but IMO it has serious drawback: CSR certainly will not be happy if he picked up a free record, opened the booking dialog, type the client number, and after pressing "Confirm booking" button suddenly get an error, because another faster CSR has already booked the same record couple of seconds ago :-(

Please, answer me:
1) is my described approach sensible?
2) will I not be punished for using my timed version of lock() method, instead of timeless version provided by assignment interface? Of course, I created both versions to implement interface.
3) My GUI client will not allow to lock more than one record at a time, but what about business service layer? What if the same client already has a lock and is trying to obtain another record's lock? What do I need to do:
a) simply allow to obtain multiple lock but write some warning message to log about possible deadlock?
b) silently release the previous lock before obtaining the new one?
c) throw some kind of RuntimeException and do not allow to aquire second lock?

Thank you in advance for your valuable answers!

 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andriy,

If I understand you correctly you have 2 lock-methods: the one from Sun's interface and one you created your own using a time-out mechanism for locking? And in the application you use your version of the lock-method. I think your approach is fine (as long as the original lock-method is working as expected). You have done more than required and you certainly won't receive extra credit for it. Make sure to justify your decision in choices.txt
I still think you should keep the locking time as short as possible.

What if the same client already has a lock and is trying to obtain another record's lock?

My Data class throws an IllegalStateException.

Kind regards,
Roel

 
Andriy Pererva
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roel, thank you for the quick answer!
I think, I very overcomplicated my solution
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic