My server implementation is as below.
Sun has provided the DB interface. My Data.java provides the implementation for this.
I use Data directly to make the application work in local mode.
But for Remote mode I have an issue. I have to throw the RemoteExceptions to heed to the RMI conventions. So I wrote a new interface RemoteDB having the same methods as DB. The only difference being they all throw RemoteExceptions as well.
The RemoteDbImpl extends UnicastRemoteObject and implements RemoteDB. For implementing the methods in RemoteDBImpl, I use the methods implemenation is Data class.
e.g. in RemoteDBImpl , the read method is something like
public
String[] read(int recNo) throws RecordNotFoundException, RemoteException {
return db.read(recNo);
}
where db is an instance of Data class.
In the Client side I have a DBAdapter class that implements DB. This helps me to produce a DB type object independent of the mode(local or remote).
So In DBAdapter my code is something like
public String[] read(int recNo) throws RecordNotFoundException {
String[] result = null;
try{
result = remotedb.read(recNo);
} catch(RemoteException Rex) {
}
return result;
}
Please let me know if you see any flaws here or can think of a better approach. Any help is highly appreciated!