wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes lock/read/write/unlock sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "lock/read/write/unlock sequence" Watch "lock/read/write/unlock sequence" New topic
Author

lock/read/write/unlock sequence

Eduard Jodas
Ranch Hand

Joined: May 14, 2002
Posts: 80
Hi,
a question about lock/read/write/unlock sequence:
In order to first lock and then read a record we must first know the position of this record in the database. I see two choices here:
- keep the record number in the client an use it directly in the lock/read/write/unlock sequence
- perform a search first by primary key so the sequence would be: find/lock/read/write/unlock
Personally I don't like the first option because the record number is a low-level db issue the client should not be aware of. I have a Flight class which contains all the data of a flight. I'd need to add a field with the record number to the Flight class, but this field is not related to a Flight ... not a technical problem a psichological one ...
On the contrary the second option is far less efficient and, at the last point, also needs to deal with the record number.
Which option did you choose?
Jim Bedenbaugh
Ranch Hand

Joined: Nov 09, 2001
Posts: 171
Originally posted by Eduard Jodas:
Hi,
a question about lock/read/write/unlock sequence:
In order to first lock and then read a record we must first know the position of this record in the database. I see two choices here:
- keep the record number in the client an use it directly in the lock/read/write/unlock sequence
- perform a search first by primary key so the sequence would be: find/lock/read/write/unlock
Personally I don't like the first option because the record number is a low-level db issue the client should not be aware of. I have a Flight class which contains all the data of a flight. I'd need to add a field with the record number to the Flight class, but this field is not related to a Flight ... not a technical problem a psichological one ...
On the contrary the second option is far less efficient and, at the last point, also needs to deal with the record number.
Which option did you choose?

I don't know why you wouldn't keep the record key in an object on the client. It's no more "low-level" than origin or destination - it's just data like the rest.
I'm assuming your GUI sequence goes something like -
1. Search for a flight meeting your criteria.
2. Choose to update a record from the GUI.
3. Check to see if the record is locked. If not, lock it.
4. Read for Update and write.
5. Unlock.
This is my approach. If I don't keep the key, I have to add a step to re-find the record in the database for the matching flight. Did I miss something?
[ May 29, 2002: Message edited by: Jim Bedenbaugh ]

Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
If you are using the MVC pattern for your gui the view never communicates to the model directly. The model in this case is the data schema.
The record number in the schema is unique and is therefore the primary key of the schema.
When a flight is selected by the user, the view is totally unaware of which flight has been selected, it is only via controller/model communication that this is resolved and flights can be booked. Once a booking has been made it is up to the controller to refresh the view.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Or if you look closely to the Data class, you will find the "find" method accepts a string, which is the flight number which the JTable knows, because it is the first column.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Eduard Jodas
Ranch Hand

Joined: May 14, 2002
Posts: 80
I suppose you're right. I'll do the same.
My GUI sequence is a bit different from yours, though:
- In step 3 I don't check if a record is locked. I just lock and, if already locked, get blocked.
- between steps 3 and 4 I re-read the record in case data has been changed
Thanks!
Jim Bedenbaugh
Ranch Hand

Joined: Nov 09, 2001
Posts: 171
Originally posted by Mark Spritzler:
Or if you look closely to the Data class, you will find the "find" method accepts a string, which is the flight number which the JTable knows, because it is the first column.
Mark

This is okay if a flight only runs one day a week. If it runs every day, then what?
Keeping the record key seems more reasonable.
Daniela Ch
Ranch Hand

Joined: Dec 13, 2002
Posts: 96
Originally posted by Mark Spritzler:
Or if you look closely to the Data class, you will find the "find" method accepts a string, which is the flight number which the JTable knows, because it is the first column.
Mark


This is the comment written by the "intern" in my Data class for the find():
For this assignment, key field is the record number.
@param toMatch The key field value to match upon for a successful find.
The "find" method accepts a string, which is the record number, not the flight number...
/Daniela
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Actually it corresponds to the first field in the db.db file which is Flight Number. The documentation that Sun provides in the Data class for that method is incorrect in stating Record Number as in 1-15 for 15 records.
Mark
Daniela Ch
Ranch Hand

Joined: Dec 13, 2002
Posts: 96
aahh..those interns...
I didnt use this method (not yet) and i am done with my implementation..maybe i wont need it, I only have the gui left...

guis are usually done by interns I hate guis
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Where do you work? I want interns too! I always seem to have to do things myself.
Mark
Daniela Ch
Ranch Hand

Joined: Dec 13, 2002
Posts: 96
hahahaa!!
I lost my job in july, I have been cut twice in 2 years
btw, I am finally going to use find()...I used to hardcode the field names but I just read a post where you say that you didn't...and I thought, if he can do it, I can
/Daniela
 
 
subject: lock/read/write/unlock sequence