Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one client app changes table and refresh the information in another

 
Alejandro Ortiz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crossposted:

http://stackoverflow.com/questions/37537051/one-client-app-makes-changes-in-a-table-in-mysql-and-refresh-the-information-in

I got an JavaFX aplication that usally makes CRUD operations in to a MySQL data base, there are many users at the same time its rare but they could be working in the same type of object.
here is and example.

the object class in this case is call "Paciente" here is the code



this is my data base table



here is how i get the observable list that i use for the table view


here is how i put the data in a tableview



here is the result




when the user makes changes to the data base table Pacientes the view refresh with the changes and there is no problem, but the problem i have is when other user makes changes in the same table i dont know how to tell to the app that is time for a new conection to the data base and fetch the new data.

i could create a schedule service that make the data fetch every X time, but this is less than optimal i hope for a better solution.

so here is my question: how to tell the app a change is make in the data base and needs to get the new data? or there is better approach for share changes between clients apps ?

there ara a couple of questions similar but the diferent with those questions is firts is the time there are 4 years old or more and i would like to now if there is a better wey now and the second diference is the plataform the way in that tableview in JavaFX refresh the contents gives a lot of more options to work with, also is possibly that my approach is wrong and i can make the desired behavior (all my clients apps share changes almost in real time) in another way
 
Paul Clapham
Sheriff
Posts: 21572
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You followed the Stack Overflow links which accused you of posting a duplicate question? (Yes, you aren't the first one to have this question.) Well, the answers there are pretty much the answers which you are going to get.

It isn't a JavaFX question, by the way. The database won't notify your application that a change has been made to one of its tables, and nothing you do on the client side (i.e. in JavaFX) is going to change that. You might think of using a trigger in the database to send your application some kind of a message when a record is changed (or added or deleted), but then you would have to build a big infrastructure where those messages would be sent to all active instances of your application (those "many users"). This would be a lot of work even if a MySQL trigger could be written to send some kind of message across the network, which I doubt is possible anyway. And if it were possible, having a trigger send network messages would slow down all of those database updates.

In other words I think your idea of refreshing the view every X seconds, like they do in the airport with the screens telling you when the flights are leaving and arriving, may actually be the optimal solution.
 
Paul Clapham
Sheriff
Posts: 21572
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, welcome to the Ranch!
 
Paul Clapham
Sheriff
Posts: 21572
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you said it was a rare occurrence for one user to need data recently changed by another user? In that case a better solution might be a simple "Refresh" button which goes out to the database and brings in the more current data.
 
Alejandro Ortiz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:But you said it was a rare occurrence for one user to need data recently changed by another user? In that case a better solution might be a simple "Refresh" button which goes out to the database and brings in the more current data.


hi thanks for your answer Paul, i check the other post in stack but i was been optimist and hoping for a simple solution to this situation, the problem i have in the app is there is a case in the app where i got a limited number of spaces and if other client app takes this espace how to tell the other users that spot is been taken, my solution to this was auto refresh, it feels like this is a common problem but i dont know how to resolve this, i been looking but i dont find an answer. (probably in looking wrong)
 
Paul Clapham
Sheriff
Posts: 21572
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yes, it is a common problem. When you buy plane tickets, you say where and when you want to go and the web site shows you flights which are available. Now it may happen that while you are thinking about it and telling your kids not to play ball in the house and so on, somebody else may buy some tickets and some of those flights aren't available any more. Not a common situation, but it can happen.

So the web site's solution is not to try to send you (and all of the other hundreds of customers in the same situation) a notification that Flight 8033 is now full. The web site does nothing. If you come back after a few minutes and try to book a seat on Flight 8033, it will say "Oh sorry, it looks like that flight is full after all. Sorry about that. Would you like... etc etc."

The same thing can happen in many other situations, and you'll almost never see the solution where the central database tries to notify everybody looking at it about recent changes. Despite you thinking there's a simple solution, there are only complicated and messy solutions which are usually impractical to implement. First of all something closely tied to the database has to monitor all changes. And that something has to keep track of clients who have recently made queries and might want to act on that query, and it must have a way of notifying those clients that if they ran the query now, they would get a different result.

And after all of that, the chances are that the client doesn't care that they would get a different result because the change wouldn't affect what they were looking for. If the client is even still connected, that is.

That isn't to say that nobody has solved the problem. For example Google Sheets allows you to put a spreadsheet in Google's cloud, and then several people can update it all at once with everybody seeing everybody else's changes almost instantly. But I don't think that Google's solution to the problem would have been very simple.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic