简体   繁体   English

如何使用离线和在线数据库创建Java桌面应用程序,并定期进行同步?

[英]How to create java desktop application with offline and online database, syncing periodically?

I want to create java desktop application, which stores it's data offline in a database (not just some config files). 我想创建一个Java桌面应用程序,将它的数据离线存储在数据库中(而不仅仅是一些配置文件)。 The application should work fine when the user is offline. 当用户脱机时,该应用程序应该可以正常运行。 When the user becomes online, the offline database should be able to sync with the online master. 当用户联机时,脱机数据库应该能够与联机主数据库同步。

Any ideas which technologies can be used to achieve this? 有什么想法可以用来实现这一目标的技术吗?

This has been discussed on stackoverflow a lot and it usually boils down to: don't roll out your own solution - This is a very specialized field - Look up SymmetricDS. 关于堆栈溢出的讨论很多,通常可以归结为:不要推出自己的解决方案-这是一个非常专业的领域-查找SymmetricDS。 It does what you want. 它可以满足您的需求。

One of my fav discussions is Strategy for Offline/Online data synchronization 我最喜欢的讨论之一是离线/在线数据同步策略

Use one of the available pure java DB implementations as a local DB. 使用可用的纯Java DB实现之一作为本地DB。 Use any other DB as a remote one. 使用任何其他数据库作为远程数据库。 Implement logic that tries to connect to remote DB and fall backs to local one on failure. 实现尝试连接到远程数据库并在失败时回退到本地数据库的逻辑。 If it connects successfully to remote DB implement the data synchronization. 如果成功连接到远程数据库,则执行数据同步。

When the local application operates, it should not only change database, but also log the changes. 当本地应用程序运行时,它不仅应更改数据库,还应记录更改。 That changes are sent to the server when the connection is available. 当连接可用时,这些更改将发送到服务器。 Also, the application receives logged changes stored on the server (from other application instances). 同样,应用程序从其他应用程序实例接收存储在服务器上的记录的更改。

The main problem is how to merge changes made by different instances. 主要问题是如何合并不同实例所做的更改。 There can be 3 variants: 可以有3种变体:

1) Each application instance can modify only its private part of the whole database. 1)每个应用程序实例只能修改其整个数据库的私有部分。 Your are lucky, no merging needed, and server can store only logs and not run the whole database. 您很幸运,不需要合并,服务器只能存储日志,不能运行整个数据库。

2) modifications always can be merged automatically (for example, application can add a value to a common variable, but cannot set it directly). 2)修改总是可以自动合并(例如,应用程序可以将值添加到公共变量,但不能直接设置它)。 The server runs the whole database, accepts partial logs from clients, generates its own log and sends it to clients. 服务器运行整个数据库,从客户端接受部分日志,生成自己的日志并将其发送给客户端。

3) Clients are allowed to do arbitrary modifications. 3)允许客户进行任意修改。 This leads to potential conflicts. 这导致潜在的冲突。 In case of conflicts, one of conflicting changes should be rejected. 如果发生冲突,则应拒绝其中一项相冲突的更改。 That means, that if a client made local modifications, that modifications can be rejected later by the server. 这意味着,如果客户端进行了本地修改,则该修改稍后可以被服务器拒绝。 The user interface must reflect this issue. 用户界面必须反映此问题。 In the rest, this is similar to the variant 2. 在其余部分中,这类似于变体2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM