• 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: 10662
144
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic