hii i am working on spring and hibernate, i have a situation when i want to call a method when changes is done in data base means like notification whenever a new notification is come then my page automatically show the no of notification, i have done this work using timer but its not good it because it call repeatedly and load on server is increased unusually so please tell me is there any way to listen the data base and call the method only when a new entry ios done or any change is made on data base
You have two options:
Trigger from database to java program using sys_exec():
see https://github.com/mysqludf/lib_mysqludf_sys
Use an hibernate entity listener. This only work if hibernate has excusive access to database.
see http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/listeners.html
If I've understood your question correctly, you have a web interface which should show a notification, if there's a new DB entry?
Then you've first got to choose one of Jose Luis Martin's suggestions, in order to have the notification on the server side. And then you have to forward this notification to the client. For this there are a few possibilities:
(What you already did): Use polling (sending a request from client to server every x seconds, asking for new entries): http://en.wikipedia.org/wiki/Polling_(computer_science)
Let the server push the data to the client. This is the more "modern" solution: http://en.wikipedia.org/wiki/Push_technology
I'd suggest using the second approach in combination with some framework like Atmosphere: https://github.com/Atmosphere/atmosphere
This framework supports several different ways of communication, with fallbacks etc.
EDIT:
If you really just want the information inside a server method, and the information hasn't to be 100% precise, you could also use a timer on the server to count the new items every 30 seconds and kinda cache the result for the client requests.
Related
I could not find something specific about what I'm trying to understand.
I want to know what is the best pratice to keep the data always updated. For example, using React, you will fetch the data of something using an API, then you will work with the state to keep the data updated for the user on the screen. But let's think that it is a software in which are other people working in the same "database". How may I keep this data updated from external changes?
I know it is possible to use things like a React Lifecycle Method to updated or even setTimeOut to request a new json. But there is other way to do something similar to Firebase Realtime database?
Regards.
I've used sockets.io to broadcast updates to connected React clients. Server side I have a 'job' tied into a setTimeout function. Every time the job runs, it broadcasts the results to the client. It should be straightforward to detect a data change and then fire that to the clients.
I am developing a Delphi XE7 application with data stored in an online Mysql database. For the database access I use FireDAC. Because the application can be used on more than one computer simultaneously I need to be notified when a table is changed, so I can update the displayed information on each computer. FireDAC has a component called TFDEventAlerted which sounded like exactly what I need for this. But this component gives an error when activating (calling Register): [FireDAC][Phys][MySQL]-303. Capability is not supported.
I am not sure what this means, but after reading more about the component it seems Mysql does not support this type of events? If so: can anyone tell me whether there is another solution to accomplish the same?
Any help would be appreciated as I cannot seem to find a good solution.
Native MySQL doesn't have the push-notification feature you're hoping to use. To make this work you'll need to poll (to regularly run a query) to look for changes.
There are some ways to overcome this limitation if the scale of your system makes polling infeasible. You could add a user-defined function to your MySQL server, like this one to send messages: https://github.com/mysqludf/lib_mysqludf_stomp#readme
This won't work if you don't own the MySQL server; most hosting services won't allow you to install UDFs.
Or, you could build a message publish/subscribe app. This is pretty easy to do with the Amazon simple queuing service or with rabbitmq. But it's a different kind of system design from what you are probably used to.
In my article series about Firebird Database Events I proposed a solution based on message-oriented middleware. The middle tier of your application then would notify all interested parties about certain database events. Middle tier code would be database independent, all you need is a message broker who is specialized in reliable message delivery. An imaginary example for a 'after post' event handler is shown below:
procedure TAppDataModule.PurchaseOrderAfterPost(DataSet: TDataSet);
var
Notification: INotification;
begin
Notification := NotificationService.CreateNotification(PURCHASE_ORDER_TABLE_UPDATED);
Notification.SetIntProperty(PURCHASE_ORDER_ID, PurchaseOrderID.AsInteger);
NotificationService.Send(Notification);
end;
Popular free/libre open source message brokers are for example Apache ActiveMQ and RabbitMQ.
TFDEventAlerted control is not for MySQL database. That database doesn't support event model. If you want update data in "real time" then you must add manual request for changed data
Here are steps:
Add new field to your database table like "last_updated";
Fill that field by now() value on update or insert actions (by trigger or sql);
Add timer to delphi app and add request by SELECT MAX(last_updated) AS last_updated FROM my_table for last updated time;
If that time is new then request updated data by SELECT * FROM my_table WHERE last_updated >= :need_last_updated.
I'm having a strange problem with ASP.NET MVC4 and Entity Framework 5: The web application I'm building retrieves data from a database and sends it as Json into a viewmodel on the page, from which it then gets presented in a table on the page. The data represents the state of some datapoints that change every now and then.
Now I observed the following behaviour:
when I run the web application from my development server, everything works fine and the shown data is up to date.
when I deploy the web app to a production server (which talks to the very same DB), the page does not represent the current state of the data
I can't breakpoint the controller method that retrieves the data, as it only occurs on the production server, but when I look into the Json data I can see that it actually is old data. So it seems like EF is caching the retrieved data. This is a serious problem as we use this web application for industrial monitoring purposes and therefore need to rely on up-to-date data.
Has anyone encountered the same issue? Any help on this is greatly appreciated!
I don't know entity framework that well but I think this has something to do with change tracking. I'd try disabling it to force EF to re-query the DB, I think (and others please can correct me if I'm wrong) but unless SaveChanges has been called on an ObjectContext if you re-query the same data the database won't be queried again.
I've used MergeOption = MergeOption.NoTracking (on the ObjectSet) to turn it off in my project.
I'm building a simple commenting system using node and i need to configure this in a PHP project running in Apache server. So, i need to trigger node.js when some changes made in MySQL database table present in the Apache server. So, i need to know whether it is possible to do this in a Apache server? If so, then how to do that? Any idea or suggestions on this are greatly welcome. Please help...
I guess there are few options you could take, but I don't think you can get some sort of triggered action from within MySQL or Apache. IMHO, you these are the approaches you can take:
you can expose a HTTP API from node and every time you need to notify the node app, you could simply insert the data into MySQL using PHP and then issue a simple GET request to trigger node.
You could use some sort of queuing system (rabbitmq, redis, etc.) to manage the messages to and from the two application, hence orchestrating the flow of the data between the two apps (and later the db).
you could poll the database from node and check for new rows to be available. This is fairly inefficient and quite tricky, but it sounds more close to what you want.
I am running into a problem using couchbase, but it may be because I don't quite understand how couchbase works. I have created a simple console .NET app to do some simple stores and gets on data. The problem I am having is when I close the app, then restart it and try to get data I previously stored, it will not retrieve any data. But, if I store and then get before closing the app, it returns data. Can anyone offer me clarification? Thanks!
Found my problem... I was not disposing of the client properly. I had the client as a member of another class, which is what I had in my using statement, so I guess that does not properly dispose.