Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Real time update from database

 
Matt Thomassan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

I am facing difficulty in achieving the following scenario.

Consider we have a employee table that has firstname and lastname as its column.
Employee (firstname, lastname)

I am writing the data in employee table to a file using java io. So suppose if one more record is added in the employee table, then the file must be updated with the new information.

We can achieve this by restarting the server manually. But in a real time environment, it is not possible to restart the server every time a record is inserted in the employee table.

Some how we need a component that is always checking the data in the employee table and keeps the file updated with the most current data.

Can you guys suggest a way to solve this problem?

I am using Java 5, Tomcat and Oracle.

Any suggestions, links and tutorials are welcome.

Thanks
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a Listener. Every time some class modifies the file it notifies the listener.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian Janisch wrote:You could use a Listener. Every time some class modifies the file it notifies the listener.

In the servlet environment, there are no such listeners. In fact, there is no guarantee that the browser even has the page loaded!

Why on earth are you writing the data to a file before displaying it?
 
Shankar sanjay
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet Listener will not pool any database table, to get info like any new record inserted or deleted... I would suggest you that in Database (table trigger) we can write code to add new record details into a file.

Regards,

Sankar. S
 
Matt Thomassan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Bear
The example I gave is not the exact implementation in the application.
The application has a component in the home page that reads the file that I am writing to. This component then (after some business logic) reads the file and displays the data in it.
Hope I have made myself clear.

@Sankar
Thanks for giving your idea. Writing a trigger will definitely be in the direction to solve the problem. But it is a huge overhead on the application.

Is there any other alternative to solve this problem?

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34179
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Thomassan wrote:Is there any other alternative to solve this problem?

What problem? You still haven't described the purpose of this file. I would say the "solution" would be to get rid of the file and read from the database if you don't have a reason for the file existing.
 
Matt Thomassan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Jeanne,

The following is the purpose of the file:
Home page has a flash component that reads data from xml file. This xml file is required to be updated when some database modifications happen.

What do you think about the problem now?

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may be too late in the day to suggest this but any reason you didn't just query the database form your Flash application? This would be a far easier way of doing this.

The only guarenteed way to push data out to the file is a database trigger. If your database supports it you could use Java to write such a trigger for update, insert and delete events. If it doesn't support Java some databases have their own mechanisms for doing this sort of thing. Not very nice adding the overhead of this extra IO work for every mutation on the table though. And if you ever deploy your application in a clustered environment you are stuffed.

Another alternative is to poll the database from your Java code using something like a timer task and update the file accordingly. This has the advantage of not burdening your database with the file creation, but has the disadvantage that your data is always out of date (though you have engineered that problem into your application anyway by using a file as an intermediary).

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34179
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Polling is what I'd suggest too if you can't change the Flash code. Or if you control the writer to have it update the file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic