• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FBN : Exception in High level Data Interface

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having hard time in designing my High level Data interface. I want to use this interface in local and remote mode ( As per Max book example). I have added all public methods of Data class in this interface, and all of them throw IOException.
My DataInterface :

But what to do with the methods that throw Database exception in Data class for ex.
one method in given Data class :

I think have two choices,
1. either i add DatabaseException in my DataInterface;
2. or modify this method in Data class to throw only IOException.

Which is rigt choice ? Or is there any other way to handle this ?

Thanks in Advance.
Regards,
Akash
 
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Akash,
There are many ways to do. I personally decided that IOException is not nice. I use DatabaseException. The problem is that your remote interface should let all method throw RemoteException. I have made an Adapter on the client, that chained all these RemoteException to the DatabaseException.
The adevantage of Max sample is that you don't need it, because RemoteException is chilf of IOException. Still, I decided at the cost of one additional class I want to have DatabaseException.
Just a sample: JDBC methods throw SQLException, not IOException
Best,
Vlad
 
Akash Singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vlad,
First, Thanks for your answer.
I agree with you that DataInterface should throw DatabaseException.


The problem is that your remote interface should let all method throw RemoteException. I have made an Adapter on the client, that chained all these RemoteException to the DatabaseException.


I could not understand how to implement this. Could you give some basic sample code examples for local and remote data implmentation ?
Regards,
Akash
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Akash,
Personally I like the idea of your interfaces throwing both IOException and DatabaseException. IOException is for your communication level exceptions, and DatabaseException (or any other exception) is your application level exception.
This is similar to how an EJB's interfaces are declared: A remote interface will always throw RemoteException + application exceptions (and application exceptions cannot be subclasses of RemoteException).
Just to give you a third option (although I am not really recommending it, just mentioning it), you could change DatabaseException to subclass IOException. This would not break any existing code, and would mean that your signatures above would then be correct. But it means that you would be changing a "complete" class .
Regards, Andrew
 
Akash Singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew, Vlad
I am always thankful for your help. I would like your opinion on my design for local and remote data class from the point of view of exception , flexibility of changing protocol in the network server , and change in Data class implementation .
DB
1. I have high level DataInterface

You notice all of them throw IOException , because this therface can be implemented by classes in network server also. Some of them throw Database exception for exclusive database access related exception.

2. I have extended this DataInterface to create a LocalDataInterface, in this i have not included IOException, because this will be implemented by Data class, and DataAdapter which are working in local mode.

Data class implements this subinterface (LocalDatainterface). I did not change in Data class as for as exception types are concerned.
3. I have DataAdapter to access the Data (database). This DataAdapter implements LocalDataInterface throws only DatabaseException.
No IOException is thrown in any of the methods in this class.
RMI Server :
4. RemoteData class extends DataInterface and Remote:

5. RemoteDataImpl access database using DataAdapter but all methods throws IOException/ or (IOException,DatabaseException) as per DataInterface signature.
6. I have ConnectionFactory, which is bound to registry at the server startup. Client using the reference of connectionFactory object, get the unique instance of RemoteDataImpl. This class has static reference to DataInterface, means each RemoteData object shares instance of DataInterface through DataAdapter.
GUI :
I have DataClient (a Facade) class in my ui package, this implements DataInterface. This class has two method get localDataClient(return DataAdapter) and getRemoteDataClient (return RemoteDataImpl .In this class all method catch Exception and throw DataAccessException which is subclass of IOException.
Here onwards, i have not done yet, but this is my plan.
This DataClient will be called by FBNConnector (similar to DVDConnector from Max book).
GUIController will hold reference of DataClient. In case of any exception,
this will throw GUIControllerException ( subclass of DataAccessException)
that will be displayed by view in JOptionPane.
In this way , DataInterface is a type, which is used in all packages db,server,ui packages where Data is accessed. It will also work , if Data implemention changes, as long as it it fullfills interface contracts. Server is flexible for protocol change ( as per Max book).
Am i doing right ?
Regards,
Akash
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Akash,

I could not understand how to implement this. Could you give some basic sample code examples for local and remote data implmentation ?


Yeap :

Andrew,

Personally I like the idea of your interfaces throwing both IOException and DatabaseException. IOException is for your communication level exceptions,...


It is Ok, but there is no any communication level in local mode, so communication level exceptions. As you see above (in my samples) only remote mode can have communication problems and therefore RemoteException is defined.
In any case, I agree with statements of Andrew and the choise between my idea and his one is a matter of taste
Best,
Vlad
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vlad,

It is Ok, but there is no any communication level in local mode, so communication level exceptions. As you see above (in my samples) only remote mode can have communication problems and therefore RemoteException is defined.


Yes - that is good.
And if we were later to port the server to a J2EE server, then your scenario would port easier, since an EJB would need separate interfaces for local and remote access, and the local interface cannot throw communications exceptions. Hmmm, can you tell what I have been studying
The advantage of having the one interface throwing IOException is that on the client side, you can map both the local and remote clients to the one interface. Which means you can have one single set of code for calling the database.
You are right - this comes down to a matter of taste. Make a design decision. And document it!
Regards, Andrew
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andrew,

The advantage of having the one interface throwing IOException is that on the client side, you can map both the local and remote clients to the one interface. Which means you can have one single set of code for calling the database.
And if we were later to port the server to a J2EE server, then your scenario would port easier, since an EJB would need separate interfaces for local and remote access, and the local interface cannot throw communications exceptions.


Exactly!

Make a design decision. And document it


Exactly!
For any decision taken these two remarks should be satificiant to justify the decision.
Hm, there some discussions in the forum where all agree. Is it good or bad?
Best,
Vlad
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vlad,

Hm, there some discussions in the forum where all agree. Is it good or bad?


Scary!

Regards, Andrew
reply
    Bookmark Topic Watch Topic
  • New Topic