Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best practise for returning data from EJB's

Status
Not open for further replies.
May 13, 2002
75
GB
I have an EJB that runs a query on a backend database and i want to return the data back to the GUI. Ideally i would like to pass a ResultSet back but i don't think they are serialisable so this isn't an option.

What's considered the best way to pass database results back from EJB's to a front end application ?

Thanks for any ideas you guys have
Alistair Alistair [monkey]
 
Well if you want language,platform, whatever independent data you use XML i guess. Or am i missing something?

-pete
 
I'm passing from a EJB to my Java app so language independance is not a problem. For large sets of data, is there an overhead converting data to and from XML as well as the size increase of the data to be communicated between EJB and app ?
If my app is the only thing using the beans and i know the data expected, would it be more efficient to pass data as String arrays ?

Thanks Alistair [monkey]
 
You could create a Value Object, which implements serializable, with the data from the ResultSet and pass it back.

ee1940
 
What form of interprocess communications is being used?

-pete

 
I'll take a look at the Value Object route. I tried using a CachedRowSet, which works and the code is quite neat, however it is pretty slow. It may be faster if i implement some other method such as Value Object or String arrays, i'll have a look and report back.

I'm carrying out the communication entirely within our corporate intranet (at the moment) and running the EJB's from within Oracle 9iAS, the client is a web start app, is that what you mean palbano ?

Alistair [monkey]
 
>> is that what you mean

Not exactly. How does the client application connect to the server? What API(s) are used?

-pete

 
oh ok, the client connects to the EJB using RMI to to connect to the EJB running on the applications server, i'm afraid i'm a bit hazy on the exact terminology so he's some code..

Code:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");

env.put(Context.SECURITY_PRINCIPAL, "username");
env.put(Context.SECURITY_CREDENTIALS, "password");
env.put(Context.PROVIDER_URL, "ormi://uksap13:23791/ESMA");

Context ctx = new InitialContext(env);
      
PropertiesEJBHome propertiesEJBHome = (PropertiesEJBHome)ctx.lookup("PropertiesEJB");
propertiesEJB = propertiesEJBHome.create(  );

Alistair [monkey]
 
RMI only supports serialization, so whatever you do you must use an Object that implements Serializable. For example java.lang.String does, so if you turn your result set into a String you can send it using RMI.

Does that help?
-pete


 
Yes, thanks, i tried the CachedRowSet and i've just looked at the API documents and it says it implements java.io.Serializable so that explains why it works. I will try converting my ResultSet to a String array instead and see if i get better performance

Thanks

Alistair [monkey]
 
Hi

Doing it this way you (returning a resultset and/or cached row set) TIE your application to only be able to handle info from a DB. If in the future your persistance isn't DB related (or changes from RDBMS to OO or an XML persistance layer) then you also have to re-write your front end.

The for implementing a session or facade layer to to decouple your tiers so they are independant, or unaffected, by changes to another underlying tier.

Use the VO (Value object) or XML routes. You have a cleaner seperation of tiers in your system and it's much more flexible for the future. If you want even more flexibility (I don't like this approach but you may) try the Data Transfer Hashmap way of transferring objects and their info.

Also, Never assume something will never change. I've made my career on 'things' that never were supposed to change, and did, but the original code couldn't handle it.

Hope this helps.

-=-=-=-=-=-=-=-=-
For ease of reading, any posted CODE should be wrapped by [ignore][COLOR][/COLOR] and
Code:
[/ignore] tags.

Ex:
Code:
SELECT 1 from sysobjects

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top