5

I want to create java desktop application, which stores it's data offline in a database (not just some config files). 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?

Hristo Hristov
  • 4,021
  • 4
  • 25
  • 37
  • Is it one application + one online server? Or several applications + one online server? Or several applications + several online servers, where each application would have its own online server? – TacticalCoder Apr 18 '12 at 12:47
  • @TacticalCoder There will be many instances of the application and one online database. Like Dropbox, but for database, not files only. – Hristo Hristov Apr 18 '12 at 12:52

3 Answers3

2

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. It does what you want.

One of my fav discussions is Strategy for Offline/Online data synchronization

Community
  • 1
  • 1
Ryan Fernandes
  • 8,238
  • 7
  • 36
  • 53
0

Use one of the available pure java DB implementations as a local 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.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • Usually it's preferable not to access the remote db directly, though. Rather access it through a service instead (Web Service, Remote EJB,...). – Puce Apr 18 '12 at 12:52
  • The problem with this approach is the synchronization part. I am searching for solution that solves this automatically. I expect that when few records are inserted/deleted offline, the database keeps a note and applies the changes when online. – Hristo Hristov Apr 18 '12 at 12:55
0

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:

1) Each application instance can modify only its private part of the whole database. 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). 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. 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.

Alexei Kaigorodov
  • 13,189
  • 1
  • 21
  • 38
  • How would you implement that? Do you have a link to a tut or example or the technologies involved? – iOSAndroidWindowsMobileAppsDev Nov 28 '16 at 14:22
  • @Anon no I have no experience with working examples, and cannot recommend any particular implementation. Try to google for "java distributed database". If I were to implement this, then I first implement levels 1-2 and in parallel, ask user how he wants to avoid and/or resolve conflicts. Then, based on user use cases, I'd implement the 3d level. – Alexei Kaigorodov Nov 28 '16 at 19:22