• Post Reply Bookmark Topic Watch Topic
  • New Topic

DB Facade design

 
Niclas Åstrand
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have decided to use a facade to implement the DBAccess interface and have one class to implement locking and another the actual file access.

In the update method in my DBAccess interface there is a lock cookie passed and the only way I can think of is to have logic in my Facade that handles the interaction between locking and reading.

Here is what I'm thinking - just pseudo code.
//Data.java

public void update(recNo, data, lockCookie) {

if (LockManager.isLocked(lockCookie)) {
throw new AppropriateException("The record is locked");
} else {
FileAccessManager.update(recNo, data);
}
}

Am I missing something or is this the way to go about it?

TIA
Niclas
 
Cristian Aionesa
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think it's a good design. If all the locking checks are done at the facade level you don't have to use LockManager in FileAccessManager or viceVersa. And through this you get a clear separation of concerns. If anyone thinks otherwise please reply.Thanks.
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Niclas,

Your pseudo-code looks ok, but I guess the isLocked-method should take 2 arguments: recNo and lockCookie. And if the record is correctly locked the update should be executed (not throw an exception). Just my 2 cents.

btw I decided not to use the facade design pattern, just 1 Data class. So maybe I'm not the best person to give advice on this one

Good luck!
Kind regards,
Roel
 
Niclas Åstrand
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for your input! I thought I was missing something.

You are correct about the pseudo code Roel!

Niclas
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!