This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Is this design OK?

 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all. Please review my design for the db part and give me your opinion on my questions, Thanks.

I have three data classes on the server side:
DataAdapter, Data, and DBHelper.
I will have a new DataAdaper instance for each client connection. Each DataAdaper will have a new Data instance, and each Data call static method in DBHelper.
The methods in DBHelper are static synchronized atomic file operations on only one record except the create() method.
Both my find() method in Data class and search() method in DataAdaper class will call read(int recNo) method in Data class and thus will have to eat up the exception been thrown, is that ok?
Is it true that in this project, we only need three methods in DataAdapter class: search(), book() and getMetaInfo()?
The only place I use the lock/unlock is in the book() method:
book(int recNo) {
lock(recNo);
a = read (recNo);
confirm (a);
update (recNo,b);
unlock(recNo);
}
I didn't use lock for the update() method in the Data class, since I think the program shouldn't call this update() method directly because only the methods in DataAdpter can be called. Is this assumption reasonable or do I have to also lock my update() method of Data class?
Please give me your opinion.
Thanks.
[ October 24, 2003: Message edited by: Peter Ye ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
Originally posted by Peter Ye:
Both my find() method in Data class and search() method in DataAdaper class will call read(int recNo) method in Data class and thus will have to eat up the exception been thrown, is that ok?

That could be OK.
Why do you have the find() method call the Data.read() method? I would have expected, from your description, that Data.read() was pretty much a wrapper to DBHelper.read(). In which case I would have thought that Data.find() could call DBHelper.read() directly.
I am not saying you are wrong, just trying to understand what you are doing.
Originally posted by Peter Ye:
Is it true that in this project, we only need three methods in DataAdapter class: search(), book() and getMetaInfo()?

Take a look at the thread "Should lock methods be callable by the client". There you will find lots of opinions on whether you can have the server just supplying business methods like you are asking, or whether the server must provide equivalent methods to all those specified in the interface you are implementing.
Originally posted by Peter Ye:
I didn't use lock for the update() method in the Data class, since I think the program shouldn't call this update() method directly because only the methods in DataAdpter can be called. Is this assumption reasonable or do I have to also lock my update() method of Data class?

I think it is nice for the update() method to check if the record has been locked before doing the update. This does depend on whether the update() method can throw an exception if the record is not locked though.
But you are correct - the client should not be calling Data.update() directly, it should be calling your wrapper class. And your wrapper class can enforce the locking.
Regards, Andrew
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both my find() method in Data class and search() method in DataAdaper class will call read(int recNo) method in Data class and thus will have to eat up the exception been thrown, is that ok?
Could you elaborate some more. This does not sound ok.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,
As I mentioned earlier, I would expect the Data.read() method to be just a wrapper around DBHelper.read().
Is that the case?
If not, what else does Data.read() do?
Regards, Andrew
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
I think Bill was quoting from Peter's post above ... About one hour ago, I was ready to send a reply to Bill when I finally unsderstood that he was asking Peter
Best,
Phil.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops.
Sorry Bill.
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,Andrew.

Thanks for your comments. I will change my find() method so that it will call the Helper class directly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic