DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page JavaEE EJB. How to send large data to JavaSE client
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Join Date: Jan 2009
Default JavaEE EJB. How to send large data to JavaSE client - 07-30-2009, 07:13 AM

I plan to write some kind of reporting application using EJB3 technology. But specific of this application is to generate and send huge amount of data to client. If I understand EJB right it serialize java object in some way and then sends it to client. For example if I make fetch from database I do not want to fetch all data and then send it to client. I want fetch first 10 records and then send it, then fetch another 10 and so on. Also client must have option to cancel fetch.

I can do it using servlet without any problems. I just can, for example, use Stream and send to client everything I want. But how I can do it using EJB?

As I see possible solution is to create statefull session bean, on session create open cursor on database side and upon consequent requests from client fetch by 10 row at once till the EOF

So my question is about application design. Is it right way to use EJB statefull bean?
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Join Date: Jul 2009
Default Yes, this is fine. - 07-30-2009, 08:31 AM

Yes, this is fine using EJB @Remote and @Stateful. Indeed, things would probably scale much better because of RMI vs. HTTP, pooling, passivation, etc as compared with Servlets.

You can even try JPA query paging via setFirstResult/setMaxResults besides trying to use a cursor yourself. Also, it might be worth trying to push all the data at once. RMI can be surprisingly robust/performant handling large amounts of data over the network. Unlike Servlets, there are no HTTP timeouts to deal with in RMI.

Hope it helps,
Reza
Reply With Quote
The Following User Says Thank You to rrahman For This Useful Post:
narcom_baku@yahoo.com (07-31-2009)
  (#3 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Oct 2009
Default 10-08-2009, 08:24 AM

Hi:
My experience is not to use EJBs for reporting since reporting per se spans across multiple data domain and hence is effeciently handled using a servlet and backend database.
Possible implementation:
Use a map and store it in Session object and show records only on demand. Hope it helps, my 2 cents
regards
--Sabarish
Reply With Quote
  (#4 (permalink)) Old
Member
 
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
Join Date: Jan 2008
Location: Germany, Munich
Send a message via MSN to mende
Default 10-09-2009, 12:07 PM

EJBs can also be used for reporting. There is no advantage of having a servlet which handles the diffrent databases. This can also be done with ejbs and the diffrent domain-objects (and, you can also have native sql-queries if you need them).

The problem is the large amount of data. In this case I would use an ejb to invoke the reporting process and deliver the results using jms. Then the successfully computed parts can be deliverd when they'll be ready.

The SFSB example with the cursor looks good but the problem is the lifecycle in many applicationservers the connection will be given back to the pool when the SFSB is passivated. So you can't handle the cursor-way with these applicationservers.

From my point of view I would prefer the way to invoke the reporting-process and deliver the results using jms.

yours
marc


Ceterum censeo Carthaginem esse delendam.
Reply With Quote
  (#5 (permalink)) Old
Member
 
Posts: 19
Thanks: 0
Thanked 1 Time in 1 Post
Join Date: Jan 2008
Location: Germany, Munich
Send a message via MSN to mende
Default 10-09-2009, 12:07 PM

EJBs can also be used for reporting. There is no advantage of having a servlet which handles the diffrent databases. This can also be done with ejbs and the diffrent domain-objects (and, you can also have native sql-queries if you need them).

The problem is the large amount of data. In this case I would use an ejb to invoke the reporting process and deliver the results using jms. Then the successfully computed parts can be deliverd when they'll be ready.
(and you can implement a cancel-operation, which you can't having a servlet or a simple ejb-call)

The SFSB example with the cursor looks good but the problem is the lifecycle in many applicationservers the connection will be given back to the pool when the SFSB is passivated. So you can't handle the cursor-way with these applicationservers.

From my point of view I would prefer the way to invoke the reporting-process and deliver the results using jms.

yours
marc


Ceterum censeo Carthaginem esse delendam.
Reply With Quote
  (#6 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Join Date: Jul 2009
Default Seems to be an EJB 2 specific comment - 10-14-2009, 04:43 PM

Sabarish,

Your experience appears to be EJB 2.x entity beans specific. As mende mentions, cross domain mappings are not really that big of a deal with EJB3/JPA.

Cheers,
Reza
Reply With Quote
  (#7 (permalink)) Old
Moderator
 
jwenting's Avatar
 
Posts: 99
Thanks: 0
Thanked 8 Times in 8 Posts
Join Date: Feb 2008
Send a message via MSN to jwenting
Default 10-15-2009, 07:58 AM

As you should never send ResultSet and other jdbc entities using EJBs, there's no problem. The resulting data should be translated into something that can be sent, usually some form of POJO.
EJB Entity beans (or preferably the newish EJB3 entities) take care of that for you.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to print report on client default printer ? jaae251 Java 1 06-18-2009 08:21 AM
Large Map / HashMap sshark Java 2 11-06-2008 07:55 AM
Building Intranet with JavaEE or Opensource cyberziko Java 1 02-27-2008 08:12 AM
AIR client for DZone: Should we have a contest? rick Flash, Flex & AIR 8 02-01-2008 01:21 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com