Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLyBird 1.1.3, current issue with the "find()" method

 
Eric Chou
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As the interface defines, the method find() return an array of integer rather than an array of ValueObject instances. If a user wants to show the finding results, at first, he has to call the find() method to get all the matching records' numbers, and then he has to loop those numbers and get the real content of each record to show them up.

However, there is a current issue between finding and looping. If another user updates or deletes one of the matched record when the previous user are looping those records' numbers, the result showing up on the previous user's screen will be wrong.

Anybody thought about this issue? Any good solutions?


Thanks in advance

Eric Chou

(Fighting against SCJD ...)
 
Alexandre Baldo
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use 'ReadWriteLock' to avoid this situation.

For more information, take a look at this link:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html

See ya!

Baldo.
 
Zonglin Li
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric and Alexandre
Actually I have got the same question. In my opinion, �ReadWriteLock� only works for extract data from the database and write the data to the database.

For example, a user did a search, found the record number 1,2,3 and its GUI shows the values of these three records. At this moment these records are not locked (for write) anymore. If another user comes, he could get the lock and change the record (for example the record 2). So the record (record 2) showing for the second user and any future users is different comparing with the first user.

I am not sure is this the case or not.

Thanks in advance!
 
Jevgeni Zhukov
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eric Chou:
Hi,

However, there is a current issue between finding and looping. If another user updates or deletes one of the matched record when the previous user are looping those records' numbers, the result showing up on the previous user's screen will be wrong.

Anybody thought about this issue? Any good solutions?


Thanks in advance

Eric Chou

(Fighting against SCJD ...)


I don't see a problem if another user updates something. It's the same issue as with any other booking information system. For example you want to book a ticket to fly somewhere, once you go to the web to do so, you can find out there is only one ticket left, while filling information and pressing submit you get the error message something like "Sorry no more tickets!". It is typical that interface doesn't show the instant database state.
If another user deletes some record then wile looping you'll get RecordNotFoundException from readRecord() method.
 
Eric Chou
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I Jevgeni is right: do not lock while looping the record. When a user tries to book a room, just show the error message if the room record was deleted or already booked by somebody else.
Thanks again for all the buddies.
Cheers!
 
Ernesto Elias-Nieland
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

Actually, in real database systems you can specify if you want another user to be able to modify the records you queried. I think you can go for either option if you can justify your decision in the choises.txt.

Check this out:
http://en.wikipedia.org/wiki/Isolation_(computer_science)#REPEATABLE_READ

Cheers,
Ernie
 
Joe Richard
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I recommend not locking the record when reading the database. Locking the record when the database is read will only allow 1 client to update records.
One of the requirements is to allow multiple clients to connect and use the database.

I used a design pattern to take care of database changes. All users of the database are notified when a change occurs. object to get the records. I loop though the array of integers returned by the find() method with the read() method. I only use 1 class to do all of my database actions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic