• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Notifiying EJB when database table changes

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic