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

Confusion over where to call lock methods

 
Nina Binde
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a FileManager and a LockManager class which does what
their name implies. The Data class implements the given
interface DBAccess and is a facade of the above two classes.
I have a question regarding the methods "delete" and "update"
in DBAccess class which take a lockCookie as a parameter.
Consider the "delete" method's pseudocode.
<CODE>
public void delete(long recNo, long lockCookie)
throws RecordNotFoundException, SecurityException {
Gets a map of lockedRecords from LockManager

if there is no entry for (recNo,lockCookie) in lockedRecords,
then throws SecurityException

Else, calls FileManager's delete method.
}
</CODE>

I would be practically doing the same thing in my business layer's
"delete" method like:
<CODE>
public void delete(int recNo)
throws DataAccessException, SecurityException{
long lockCookie = data.lockRecord(recNo);
data.delete(recNo, lockCookie);
data.unlock(recNo, lockCookie);
}
</CODE>

The lockRecord method of data inturn calls LockManager's lock
method which again checks for the (recNo,lockCookie) in lockedRecords
map.

I somehow think I am going down the wrong lane. Maybe, I should have a
sequence of lock, delete and unlock in my Data class's "delete" method,
is it? Then, just call the Data class's delete method in my business
layer and not bother about the sequence again here of lock, delete, unlock?
In that case, the lock and unlock methods of Data class might as well
be made private!! But Sun insists to be made them as public!

Please someone advise. Thanks..
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nina Binde:

I would be practically doing the same thing in my business layer's
"delete" method...


Why does your business layer have a delete method at all? In my assignment, there is only a demand for a business layer's book method, and a find method. There is no requirement to call a delete method in my assignment, but of course I don't know about yours.


But this of course does not answer your question. What I did in my assignment with cookies is:

1 from data.delete call lockmanager.verifyCookie, in order to check if the cookie value passed is indeed of this record.
2 if this returns true, call filemanager.delete (from data.delete)


The calling method should typically call everything in the following sequence: call Data.lock -> call Data.delete -> call Data.unlock.

(though about the latter there has quite some discussion been going on, but this was my choice).

hope this helps, Rinke
[ August 11, 2007: Message edited by: rinke hoekstra ]
 
Nina Binde
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rinke for the response. As for your first question, I have all the business methods irrespective of what is needed at the client side. But the client side just uses "book" and "search".
For the second answer you gave me, I am doing the exact same thing as you mentioned in a different way. You are right that I should call the lockManager.verify instead of doing the roundabout way.
My confusion was not justified since I thought verify and lock from the lockManager would be doing the same thing by checking if the hashtable contains the recNo and cookie combination. I realise now that the lock method does much more than that.
Thanks for the clarification rinke!
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, you're wellcome.

Always nice to know you could help someone out with not much effort :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic