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

Handle RemoteException

 
Bj�rn Tikkanen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have run into (what I see as) a huge problem. In URLyBird 1.2.2 I have decided to go for the RMI solution.

What I have done is:
Guicontroller class has connection to database facade via interface DatabaseInterface (both for RMI and local mode).

I have data access class (Data.java) implementing DBAccess in the bottom. On top of that in local mode I have DatabaseImpl (facade class) implementing DatabaseInterface. So far, all good and works ok.

Same basic setup for RMI part, but with RemoteDatabaseImpl implementing RemoteDatabaseInterface (extends Remote and DatabaseInterface). From the controller a factory class is used to return instance on which we can run the getConnection() method -> gives us (DatabaseInterface)RemoteDatabaseImpl
. But since this is RMI RemoteDatabaseImpl has to throw RemoteException for all methods (and hey, now it has to be in the interface as well). The interface used in controller class has to declare all methods that we want to use there (search, makeReservation etc) and now we have a problem Houston! Yikes, controller class has to handle RemoteExceptions also for local mode.

Besides being ugly, is this also criminal and worse, close to failure?

I have turned and tweaked and tested different solutions but I really don't ge a nice solution sofar. Maybe a good advice or I think its time to start over from scratch with a new design again.
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My suggestion: (just to have something to think about, perhaps it will give you some idea)

Create new interface, that will just have DatabaseExceptions. In this kind of exception you can chain all other exceptions, that can arise along the way.

Implement this interface by 2 adapter classes,
- 1. for working with remote database - handling remote exception and taking care of RMI
- 2. for working with locale database

And have your controller class access to one of these adapters and handle DatabaseException-s only.
 
Bj�rn Tikkanen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Stone:
My suggestion: (just to have something to think about, perhaps it will give you some idea)

Create new interface, that will just have DatabaseExceptions. In this kind of exception you can chain all other exceptions, that can arise along the way.

Implement this interface by 2 adapter classes,
- 1. for working with remote database - handling remote exception and taking care of RMI
- 2. for working with locale database

And have your controller class access to one of these adapters and handle DatabaseException-s only.


I just realized this reading another trail in the forum. I was so focused on the "must throw RemoteException" so I didn't even think about wrapping it... So, actually, this works out perfect for me with minimal changes.

Thank you for the help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic