This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes [UrlyBird 1.2.1] A design issue with the Remote exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "[UrlyBird 1.2.1] A design issue with the Remote exception" Watch "[UrlyBird 1.2.1] A design issue with the Remote exception" New topic
Author

[UrlyBird 1.2.1] A design issue with the Remote exception

Pablo Aravena
Greenhorn

Joined: May 04, 2006
Posts: 13
Hi friends
I think I need some advice regarding to this issue:

Right now I'm implementing the remote tier of the application (UrlyBird 1.2.1) and I found that I can't use the same interface DBAccess as the local and remote view for my GuiController class for example:

I have my Data class that implements the DBAccess interface:

puclic class Data implements DBAccess

And also have my remote class which implements a remote interface:

public interface DatabaseRemote extends Remote, DBAccess

Then in the my remote class which implements this interface, I can't declare the methods as throwing RemoteException because this exception wasn't declared in the DBAccess interface.

So I was thinking about creating a new interface that only include the methods required by te application (reserve a room, search etc.), and these methods only throw IOException (because is the parent exception of the remote exception), then maybe I can use this interface in the same way as in the Denny's Dvd application. what do you think?

Any Help will be appreciated
Thanks very much
Thirumurugan Mylrajan
Ranch Hand

Joined: Jan 26, 2006
Posts: 64
Hi,

Did more or less like you said. Since DBAccess has already been provided and also it "Must" be implemented in java, cannot use DBAccess as such.

So I now have two interfaces, one for local and one for remote. Since I thought it was important to notify the client in case of communication failure, I have used RemoteException.

Waiting to see the response of other people.

Thanks.


SCJP , SCJD. (IBM 142 in progress).
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi, Guys

I choose to throw RTE also, even if I am not so happy with this solution.
An other solution is to throw subclasses(of RecordNotFound or DuplicateException).

Regards M.


SCJP, SCJD, SCWCD, OCPJBCD
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
And that's even worse as the exception isn't in any way related to the hierarchy you're descending it from.


42
Pablo Aravena
Greenhorn

Joined: May 04, 2006
Posts: 13
Hi friends

What I've done until now is create an Adapter class for my Data class like this:

public interface DataAdapter {
public List<String[]> search(String[] criteria) throws IOException;
}

and an implementation:

public class DataAdapterImpl implements DataAdapter {
private Data database;

public DataAdapterImpl(String dbLocation) {
database = new Data(dbLocation);
}

public List<String[]> search(String[] criteria) throws RecordNotFoundException {
....
....
}
}

and RecordNotFoundException extends IOException

Then I can use the same Adapter interface when I create my remote interface:

public interface DatabaseRemote extends DataAdapter, Remote {
}

After that I resolve the problem. I think I will use this approach for implementing the server.

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Ahoy guys

Pablo,

The idea with the adaptor is good but I am not shore to make RecordNotFoundException a subclass of IOException. You may get a RecordNotFoundException from other reasons than a IOException, lets say that you try to delete a deleted record or you try to update a deleted record - in both cases the cause is not a IO cause.


Jeroen,

And that's even worse as the exception isn't in any way related to the hierarchy you're descending it from.

If you fail to find(update or delete) a record because a IOException then you have a RecordNotFoundIOException(extends IOException), you 'll work with a sql database and you can not find(update or delete) a record because of a
SQLException then you have a RecordNotFoundSQLException(extends SQLException) and so on.
On this layer you manipulate records and if this fails then you should signal that is something wrong with the record.

Why you think that the Exception hierarchy is a bad idea ? Can you bring some arguments ?


Regards M
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
RecordNotFoundException to me means there's no such record in the database.
IOException means something else entirely, that there was a problem with the network or file system trying to get at the data.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi, Jeroen

Touche , you are right, I have this sentence in my specs :

Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.

There is no doubt about, RecordNotFoundException can not be related with the any other exception(except Exception).
But, I still have one question, Why ? What's the reason can have sun for such an action.
To test ours capacity of decision(&dealing with imperfect specs) ? or
They try to say that during read, update, delete, etc no other exception can occur ?

What you think about ?

Regads M.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
it is to get you to THINK instead of mindless code your way through an assignment that's all laid out for you in bite sized chunks.

This isn't some school assignment where kids complain that their teacher is bad because they can't solve it without looking at the API docs to find a method their teacher hasn't explained to them yet.
 
Don't get me started about those stupid light bulbs.
 
subject: [UrlyBird 1.2.1] A design issue with the Remote exception