Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes About my database file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "About my database file" Watch "About my database file" New topic
Author

About my database file

Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
From the BS's instruction.html, it describes the database field "customer holding this record owner field length=8 The customer id (an 8 digit number)"
But from my db-2x2.db file, the first record looks like this "Dogs with Tools, Smallville, Roofing, 7,$35, Hamner &Tong"
In my file, all owner is a null string.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

Helen Ma wrote:In my file, all owner is a null string.

Meaning all contractors are available for booking


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
So, that means a client is assigned a 8 digit ID, like its hashcode.
When client 12345678 book a contractor Dog with Tool for carpeting, another client 87654321 will wait until client 12345678 unbook this contractor. Is that the case?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

If a contractor is booked, it can't be booked by another customer (because unbooking functionality is not a requirement for this assignment). A client doesn't have to wait, he'll get immediately an exception "Contractor already booked. Please book another contractor".
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
So, it is not required the client 12345678 needs to unlock all the contractors when this client exits. Is it true?

So, I don't need to consider this scenario:
1. client 12345678 locks a contractor, Dogs with Tools.
2. client 87654321 gets an error message because Dogs with Tools is locked.
3. client 12345678 exits the application.
4. client 87654321 still gets the error message when he/she tries to lock Dogs with Tools.

In this scenario, in step 3, should client 12345678 unlock Dogs with Tools when he/she exit?

The instruction does not say anything about this.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

Maybe you should first try to understand the difference between lock/unlock (logical record locking, a mechanism to prevent 2 clients from booking the same record) and booking (unbooking) of a contractor (which is the purpose of the application). Booking a contractor is not the same as locking a record, Unbooking a contractor (which is not a requirement) is not the same as unlocking a record (which is required to do, otherwise your program will never finish)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

Helen Ma wrote:So, I don't need to consider this scenario:
1. client 12345678 locks a contractor, Dogs with Tools.
2. client 87654321 gets an error message because Dogs with Tools is locked.
3. client 12345678 exits the application.
4. client 87654321 still gets the error message when he/she tries to lock Dogs with Tools.


Corrected version of this scenario:
1. client 12345678 books a contractor, Dogs with Tools. (in order to book a contractor, your code will have to lock, update and unlock the corresponding record)
2. client 87654321 gets an error message because Dogs with Tools is already booked by another client.
3. client 12345678 exits the application.
4. client 87654321 still gets the error message when he/she tries to book Dogs with Tools. (the thread which executes the request of this client will be able to lock the corresponding record, it will not be able to book this contractor because it was already booked by another client, hence the ContractorAlreadyBookedException)
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
Hi, I just got a message from Roberto and he sent me his publication.
I revisited his publication.

I now get the idea:
1. Client 12345678 books the contractor, locks this contractor , updates the db file (write the client id 12345678 to the file), unlocks the contractor.
Client 12345678 does this sequence of actions in a thread safe code. Also, unlocking the contractor can make sure the contractor won't be locked forever and cause deadlock.

2. Client 87654321 tries to book the same contractor, waits until this contractor is unlocked, then locks the contractor, but the db file shows client id 12345678, it unlocks the contractor and get the error message. Again, this sequence of actions should be done in a thread safe code.


By the way, since client id is not given in the file, I think I should use its hashcode to represent it. If I use random number generator (eg Math.random(...)) , I may possibly get the same id, which is not good.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

Helen Ma wrote:I now get the idea



Helen Ma wrote:By the way, since client id is not given in the file, I think I should use its hashcode to represent it. If I use random number generator (eg Math.random(...)) , I may possibly get the same id, which is not good.

That's not according to the given instructions.
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
I read the instruction.html, but so far, I did not see any requirement on how to generate the 8 digit customer ID. Maybe, I need to manually fill out the 8 digit ID as an input in the JTable on the GUI.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

I believe instructions says that a CSR knows the customer id, so when booking a contractor the CSR will simply enter the 8-digit id of the customer booking the contractor.
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
Yes, that is how I interpret the instruction.html.
When the project is launched by two JVM's , two client windows show up. One CSR enter "12345678" in the editable cell of the JTable. The second CSR may not see "12345678" in that table. The second CSR tries to book the contractor. But it gets an error message. Then, the cell shows 12345678 and it should be make editable=false, so that no one can edit the ID.

It may seem like the Denny's DVD project. When client 1 rent one DVD with 6 copies originally, client 2 does not see the most updated number of DVD copies = 5 until client 2 rents the same DVD. Then, the correct number of copies = 4 is shown.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5222
    
  12

Excellent!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: About my database file