GUI programming. Synchronizing database and tables

I have been working on several desktop applications that used tables to group information from a database table. But updating this information made me hack various solutions, such as a worker thread that updates a table doing a query every X seconds, or just a button to update a view. I even saw an application that would update the table using mouse move events. So my question is what is your preferred method. Is there a "perfect" way to achieve this that I sleep in college? Thanks for the people's responses.

+1


source to share


6 answers


What are you trying to accomplish?
Is it some kind of real time monitoring app like stock trading, plant monitoring software, or do you have a grid in some CRUD app that you want to automatically update?

If this is a crud application , then first I have to check:

  • You really need to keep your user up to date,
  • Is the user constantly looking at the monitor?
  • Why? Maybe you can implement some sort of alert system that can be checked less often?

If you really need the approach you described, then you've done your best - you can use a timer or other event (button, mouse movement, ...) to update the data. Of course, persistent distortion will become a performance issue as the number of users increases.



If it is a real-time monitoring program with more data than you should not place the database at the center of the system. You should have a central service with which your clients connect to TCP (or a similar protocol). Central service should keep the system up to date (plus maybe some history). Clients can connect to the service, and the service must notify clients when new data arrives to avoid constant polling. The database should be used as a log that the application uses to analyze past events, but not for real-time display.

Edit:

Regarding Andrey's answer: I'm not sure if this will solve your problem. The observer pattern is usually implemented with a subscription / notification mechanism, so the data source can notify all observers when the data changes. The problem is that there is usually no mechanism in the DBMS that can notify you when data has changed. Even if they are, it is impractical, since there can be a large number of changes in a short period of time. Think of tens or hundreds of updates in the second - how often does an RDBMS need to notify customers of changes? What if there are hundreds of slow network clients? When you have more than one user, things get more complicated.

Work in progress on creating data binding - you cannot bind your grid directly to a table in the database. First, you need to get the data in your application into some kind of object that can be GUI bound (datasets, lists, ...)

+3


source


Some programming languages โ€‹โ€‹/ frameworks support data binding support. Data binding synchronizes the view (table component) and data (database tables).

Flex for example has built-in bindings, javafx also, for regular java you can use jgoodies bindings or oracle adf data controls and data binding.

If your language does not have a standard bindings solution, it might be helpful to see how an existing one, for example jgoodies bindings (its openource), is implemented.

Btw, most binding frameworks are based on some of the default design patterns, such as the observer pattern: the view component needs to subscribe to receive information about data updates.



Edit:

Good point in modifying the database. This is a little tricky. Technically, it should be possible to use triggers to inform the client. For example, in Oracle, a trigger can send a data change event message to a message queue using an extended queue that an interested client could listen to. In practice, I have not seen this. Usually, you don't want to enter gui client information into your database.

Better would be to have a data collection that is regularly updated using a survey. This data collection will be bound to the view component using bindings.

+2


source


Perfect suits your needs, but many websites simply update the table whenever you update a cell. This generates a lot of traffic. Perhaps you can queue the updates using, for example, a transaction, and then commit when the user closes the given table, presses save, or times out?

I think it all depends on your specific application.

0


source


The easiest way is to have a specific configurable timer thread that updates the request (assuming no timeouts occur every second). You can also show the timestamp of the last data collection and provide a Refresh button for users who need the current data.

0


source


Very helpful Andrey. Data combinations look like an easy way to go when you have the ability to use them.

Oh yes, observer sample:

in which the object maintains a list of its dependents and notifies them automatically of any state changes, usually by calling one of its methods. It is mainly used to carry out distributed processing of system events.

I find it very convenient that C # declares new events using delegates.

Thanks for your very good answers.

0


source


It's cool for a web application. But we are talking about a desktop application that, even in standby mode, has to update information from the database. This is more a design issue than a programming one.

-1


source







All Articles