File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lock/read/write/unlock sequence

 
Eduard Jodas
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nigel Browne
Ranch Hand
Pie
Posts: 682
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eduard Jodas
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you work? I want interns too! I always seem to have to do things myself.
Mark
 
Daniela Ch
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic