aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes FBN : Exception in High level Data Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "FBN : Exception in High level Data Interface" Watch "FBN : Exception in High level Data Interface" New topic
Author

FBN : Exception in High level Data Interface

Akash Singh
Ranch Hand

Joined: Aug 21, 2003
Posts: 80
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
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
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

Joined: Aug 21, 2003
Posts: 80
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
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Akash Singh
Ranch Hand

Joined: Aug 21, 2003
Posts: 80
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

Joined: Jul 07, 2003
Posts: 555
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
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

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

Joined: Jul 07, 2003
Posts: 555
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
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

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

Scary!

Regards, Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FBN : Exception in High level Data Interface