aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Notifiying EJB when database table changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Notifiying EJB when database table changes" Watch "Notifiying EJB when database table changes" New topic
Author

Notifiying EJB when database table changes

Jayakumar Gopalan
Greenhorn

Joined: Jan 27, 2001
Posts: 20
How to notify the EJB when some datas are being inserted or updated into the database table? I wrote a trigger to fire when there is some changes in the table, but I don't know how to notify EJB? Is it possible by some means that the trigger will create or put in to the particular queue/topic so that I can use the Message Driven Beans to receive it? If yes, how? Can any one please help me on this issue. Any pointers related to this or any sample codes will be of great help to me?
Thanks in advance!
Regards,
Jayakumar
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

EJB's always perform ejbLoad before the execution of a transactional business method, and always call ejbStore after the method completes.

So if your database has changed in the meantime, it doesn't matter that the bean is not immediately refreshed, since it is guaranteed to be fresh when it's really needed.

Also - and I haven't confirmed it... but I understand that the container will know when you have deleted rows from the database, and it will unload the corresponding EJB's. I would assume it would do this when an attempt is made to findByPrimaryKey, but I'm not sure.
Jayakumar Gopalan
Greenhorn

Joined: Jan 27, 2001
Posts: 20
Mike Curwen,
Thanks for your interest response. I will explain my problem in detail so that you can get the background of it. I am having a client (JSP) which will display some data from the database and it has to be updated as soon as the data is changed in the database. The changing of data in the database table, may happen at any time. So it is not possible to keep on pooling the database for changes. If some changes happened in the database, a trigger will be fired and I want to know how to catch that changes by some way (may be put that to a queue/topic) and give that changed data it to EJB (Message Driven Bean can take that).
If anybody have any idea of how to do this, please reply.
Thanks in advance.
Regards,
Jayakumar
Originally posted by Mike Curwen:
EJB's always perform ejbLoad before the execution of a transactional business method, and always call ejbStore after the method completes.

So if your database has changed in the meantime, it doesn't matter that the bean is not immediately refreshed, since it is guaranteed to be fresh when it's really needed.

Also - and I haven't confirmed it... but I understand that the container will know when you have deleted rows from the database, and it will unload the corresponding EJB's. I would assume it would do this when an attempt is made to findByPrimaryKey, but I'm not sure.

Prabhu Vastrad
Greenhorn

Joined: May 17, 2001
Posts: 3
If you are using Oracle the trigger can call java classes. In that case your java class will be a Message Producer to produce changes to queue/topic. Use message driven bean or message consumer to get changes from queue/topic and refresh the JSP page with new data. Hope this helps.
Originally posted by Jayakumar Gopalan:
Mike Curwen,
Thanks for your interest response. I will explain my problem in detail so that you can get the background of it. I am having a client (JSP) which will display some data from the database and it has to be updated as soon as the data is changed in the database. The changing of data in the database table, may happen at any time. So it is not possible to keep on pooling the database for changes. If some changes happened in the database, a trigger will be fired and I want to know how to catch that changes by some way (may be put that to a queue/topic) and give that changed data it to EJB (Message Driven Bean can take that).
If anybody have any idea of how to do this, please reply.
Thanks in advance.
Regards,
Jayakumar

Jayakumar Gopalan
Greenhorn

Joined: Jan 27, 2001
Posts: 20
Hi Prabhu Vastrad,
Thanks for your interest to shed some light on my problem. I am using Oracle as my backend. If you know any sample code of how to put the messages in the queue from Oracle trigger, can you please point me to those urls.
Thanks in advance.
Regards,
Jayakumar.
Kailas Kore
Greenhorn

Joined: Nov 11, 2003
Posts: 2
Hi
I am having a client (JSP) which will display some data from the database. Database is MS SQL Server 2000. I created triggers to fire if some body changes data in the database thorugh JSP Client. I want to know how to catch that changes by some way and give that changed data it to EJB (Message Driven Bean can take that). As above Prabhu was talking this can be possible with Oracle. Is their are any solution for MS SQL Server as well.
If possible send me sample code else give URL's where I will get information
Thanks in advance.
Regard
Kailas
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Sorry, this all falls down in that there is no way to asynchronously update the user's screen from a Servlet/JSP.
Just put a <META> tag in the HTML of the JSP that displays the page to refresh the page every 10-20 seconds, and that will probably be close enough for your application. If it's not, then you need to build a desktop Java application and use JMS directly to the client instead.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
 
subject: Notifiying EJB when database table changes