• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to do this?

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I am working on the RMI, I realize that the methods provided by the remote interface are identical to those provided by the data class. This is actually stated in the assignment specification. Currently, my data client coding has a lot of places calling up various data class methods for direct database access. Is there any way I can efficiently call up the remote methods or direct access methods without placing if-else statements in many different places like the following:
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I want to elaborate my coding a little bit more:
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rudy,

I believe that Sun has given this scenario(local and network connections) on purpose. You are right saying that putting so many if/else statements is a bit awkward.
I really think that sceneario is a great opportunity to demonstrate polymorphism and that is the way I did it.
Vladan
Where a calculator on the ENIAC is equpped with 18,000 vaccuum
tubes and weighs 30 tons, computers in the future may have only
1,000 vaccuum tubes and perhaps weigh 1 1\2 tons.
-- Popular Mechanics, March 1949

[This message has been edited by Vladan Radovanovic (edited March 09, 2001).]
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you elaborate a bit more or maybe provide a snippet of your explanation?
 
Vladan Radovanovic
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rudy Yeung:
While I am working on the RMI, I realize that the methods provided by the remote interface are identical to those provided by the data class.


Because the Data class and your "RemoteRequest" class in this case have identical methods they can implement the same interface. Let's call that interface "DatabaseInterface". That means that Your client can be of type DatabaseInterface.
You can say

Now You can simply call any method throughout with Client.methodName
This way you can disconnect and connect back very easily. I am sure that there is a lot of solutions out there that are applications that stay in only one mode once You start them but this way You can switch between local connection and network one whenever You want and as many times as You want.
Hope this helps.
Vladan
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vladan,
Thank you for your help. I learn one more thing in OO design.
Rudy
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still have a problem in implementing the DatabaseInterface you mention. Though the data and remote objects have the same methods, the remote methods require throwing RemoteException whereas the data class need not. How do you tackle the throwing exception situation?
Rudy
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rudy see the discussion here http://www.javaranch.com/ubb/Forum25/HTML/000418.html
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I just get stuck at the same place as you guys did. Thanks for the link anyway.
Rudy
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul and Vlad,
At the end, my coding needs to throw DatabaseException and Exception, say for the modify() method. Does this also happen to you?
Rudy
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rudy ,
I defined methods in remote interface like throwing DatabaseException and RemoteException.
for example ,
public DataInfo[] criteriaFind(String criteria) throws DatabaseException,RemoteException;
So in Client side, i am able to catch DatabaseException in local mode and RemoteEception in network.

any suggestions!
joey
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joey,
What about your client side? I mean do you have another database interface for the client side, but then as a whole you do not need to throw a general Exception? For me, I have a database interface throwing Exception (just a general exception), which is extended by both the remote and local database interface. The remote database interface will throw the remote and database exeptions, whereas the local database interface will throw only the database exception.
Rudy
 
joey phillip
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rudy,
I have only one interface which is remote interface. I am using the same interface for both local and network mode. read this forum http://www.javaranch.com/ubb/Forum25/HTML/000445.html
where i explained my design.
why do you need to create theree different interaces. I may be wrong here.Could you please explain.
Thanks
joey
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rudy Yeung:
Joey,
What about your client side? I mean do you have another database interface for the client side, but then as a whole you do not need to throw a general Exception? For me, I have a database interface throwing Exception (just a general exception), which is extended by both the remote and local database interface. The remote database interface will throw the remote and database exeptions, whereas the local database interface will throw only the database exception.
Rudy


I [re]used the RMI server IMPLEMENTATION class to connect to the database in local mode. When something is wrong in
the database the implementation class methods throw the RemoteException anyway. It saves a lot of coding time.
- Alex
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joey,
The main reason why I use three interfaces is because I do not want to throw the remote exception in the local connection, but just the exception. There is nothing wrong with your design, and I do not think there is anything wrong with mine either. Can someone provide feedbacks on this?
Rudy
 
joey phillip
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rudy,
Since i have declared the Remote interface methods as throwing both DatabaseException and RemotException , when there is some problem in local mode it will be caught by DatabaseException only and not by RemoteException.
Alex,
I think you are declaring the remote interface methods as throwing Remote Exception only.

joey




 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joey and Alex,
I understand your point and design. From your point of view, do you think my design of having three interfaces is acceptable?
Rudy
 
joey phillip
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rudy,
I was just looking at your design explanation
http://www.javaranch.com/ubb/Forum25/HTML/000474.html.
I didn't find anything wrong.
Initally i did same like you. Then I had a feeling like i am complicating the design and i modified my design. I switched to this design (keeping one interface) almost two weeks before , and i didn't proceed after that because i want to make sure my design is accepatable or not. So i started reading everyone's design.
Thanks
joey

[This message has been edited by joey phillip (edited March 12, 2001).]
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joey,
I finally decide to make programming changes and shrink it down to using one single inteface for both the local and remote data access. I think throwing a general exception is worse than throwing a remote exception in the local connection. Comparing to using three interface, a single interface is simple and comparatively easy to maintain in the long-run.
Rudy
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rudy I have a question I create my instance in main and pass it to my clients constructor but when I use the instance to call the data classes methods problem is it works once the first time when searching the database, but if I create a new instance every time in my search method it works find how do you implement the Data instance in your client..
Thanks Lisa
 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lisa,
For my design in the client part, I instantiate the data object in the main method. In the long run, this data object may be used in some other places other than the FBN itself. In view of this, I declare a static reference to hold the data object instead of passing the data object to another object. I have an object that serves as an interface between the GUI and the Database. This object will grab the data object and perform various database activity.
Rudy
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rudy I believe I will myself create one interface I have been following your discussion and I can relate to this very well.
As for my instance problem I will redesign using an interface to connect between my client and database...
Thanks Lisa
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic