This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes using LockManager method in DataManager Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "using LockManager method in DataManager" Watch "using LockManager method in DataManager" New topic
Author

using LockManager method in DataManager

Mary John
Ranch Hand

Joined: Sep 17, 2007
Posts: 109
Hi
I have a question regarding using a method of LockManger in DataManager
my design is pretty much same as that described in Andrews book and follow the facade pattern for the Data class that implements the DBAccess interface.
So Data class calls methods of DataManager class(all read/write/find methods) and LockManager (lock, unlock) methods


My question is can I call LockManager method within methods of DataManager eg update, delete etc? is it against the principle of separation of classes?

pseudocode:

class DataManager{
public void updateRecord(data, recno, cookie)throws securityexception, rnf
{
if(LockManager.isLockedBy(recno,cookie))
throw new securityexception();
//continue update record

}

class LockMananger
{
map of locked records;
lock method returns cookie;
unlock method;
isLockedBy method return boolean;

}
[ April 17, 2008: Message edited by: Mary John ]

SCJP 5.0<br />SCJD working on it
Eric Ushie
Ranch Hand

Joined: Dec 01, 2005
Posts: 31
Hi Mary,

With reference to Andrew's book, i think you can call methods of LockManager from your DataManager given your scenario without breaking any rule.
Jimmy Ho
Ranch Hand

Joined: Jul 31, 2007
Posts: 61
Quick question: Which book is "Andrew's book"? Can someone give the title and author? Thanks.
Justin Rundle
Ranch Hand

Joined: Mar 26, 2008
Posts: 123

Hi Jimmy,

Well actually the author is Andrew... Andrew Monkhouse and Terry Camerlengo and the name of the book is "SCJD Exam with J2SE 5 (2nd Edition)".

Good luck!
Cristian Aionesa
Greenhorn

Joined: Jan 05, 2007
Posts: 20
Mary John wrote:Hi
I have a question regarding using a method of LockManger in DataManager
my design is pretty much same as that described in Andrews book and follow the facade pattern for the Data class that implements the DBAccess interface.
So Data class calls methods of DataManager class(all read/write/find methods) and LockManager (lock, unlock) methods


My question is can I call LockManager method within methods of DataManager eg update, delete etc? is it against the principle of separation of classes?

pseudocode:

class DataManager{
public void updateRecord(data, recno, cookie)throws securityexception, rnf
{
if(LockManager.isLockedBy(recno,cookie))
throw new securityexception();
//continue update record

}

class LockMananger
{
map of locked records;
lock method returns cookie;
unlock method;
isLockedBy method return boolean;

}
[ April 17, 2008: Message edited by: Mary John ]




Hi Mary John,

I have the same problem as you did. How did you handle it? The solution that you gave is the only one that I can think of, but this make my classes depend of one another...or not?! If I reconsider my thoughts the fact that one class uses the services from another is not a bad thing. I'll probably follow your design.

What do you guys say about that? Any advice? Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using LockManager method in DataManager
 
Similar Threads
locking help
Create/Update Method Synchronization
lockRecord method help
my question about LockManager.java
lock-cookie generation?