• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exposing DBAcess Interface to client

 
Mark Thomson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just deciding how to implement my Data Access layer and have the following question.

My assignment states

Your data access class must be called Data.java, must be in a package suncertify.db and must implement the DBAccess interface


now in the spec for the interface DBAccess the javadoc comments for the lock method states


//Locks a record so that it can only be updated or deleted by this client.
// Returned value is a cookie that must be used when the record is unlocked,
// updated, or deleted. If the specified record is already locked by a different
// client, the current thread gives up the CPU and consumes no CPU cycles until
// the record is unlocked.


Now it mentions a client and kind of points towards the fact that a client will access this interface directly.

Now I was hoping to implment this data access layer using the Adapter pattern where my clients access the Database via the adapter interface I define.

Now after re-reading the spec I am not so sure

Do I have to expose the DBAccess interface to my clients or can I wrap it up within my own interface ( as with the adapter pattern )??

Your thoughts will be most appreciated
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only have to do the requirements that have MUST. Exposing Data to the client is not a requirement(even if you do an adaptor pattern the client can still access Data indirectly).
Definitley using a Adapter/Fasade type pattern is almost a must

1.If you use RMI you have to use an adaptor because the remote interface methods must throw remote exceptions
2 If you choose to deal with orphan locks this is the way to go(Dealing with disconnected clients that have a lock, not a requirement).
3. In my requirements(not sure about yours) the find for Data provides a non exact match while the GUI requires an exact match this is one place you could deal with it(you can also deal with it at the client end).

Hope that answers your question.
[ October 25, 2004: Message edited by: Inuka Vincit ]
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Mark. When I was doing the project (note: I do not yet know if I passed) I chose the thin-client version, with the caveat that the record-filtering capabilities could be given to the client by changing a few flags. I hid the Data class behind a business facade object that had business methods such as bookRoom. The actual client never directly ran the Data class code. This gave me less network traffic and allowed me not to worry about crushed clients.

I would recommend this approach to people just starting on their server-side code: to keep the Data class hidden from the client. It will save you some programming complexity.

However, it is only one solution - there have been others which may appeal to you better.
[ October 26, 2004: Message edited by: Anton Golovin ]
 
Mark Thomson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to use an adapter pattern but am usure how to fit it in bearing in mind that I am forced to already implement an interface in Data.java class

I was hoping to have the following

1. DBClient Interface - interface to expose only business methods to client object

2. DBAdapter Class - Implements the DBClient Interface and wraps the lock / unlock calls before calling the underlying Data class. This class contains an instance of Data.java .

3. Data.java ( as required by Sun specs ) implementing DBAccess interface ( also as required by sun specs )

I know my Data.java class needs to implement the DBAccess interface but I can't see how that DBAccess interface helps me with my suggested implementation. I suppose my DBAdapter class can have a reference of type DBAccess instead of Data but I can't see the benefit of this. Any thoughts??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic