views:

1294

answers:

6

My requirement is I have server J2EE web application and client J2EE web application. Sometimes client can go offline. When client comes online he should be able to synchronize changes to and fro. Also I should be able to control which rows/tables need to be synchronized based on some filters/rules. Is there any existing Java frameworks for doing it? If I need to implement on my own, what are the different strategies that you can suggest?

One solution in my mind is maintaining sql logs and executing same statements at other side during synchronization. Do you see any problems with this strategy?

A: 

One approach is Google Gears. It forces the user to install a plugin in the browser so maybe it is not possible in your case.

Guido
Yes. I am looking for more of a back end framework. The client or server application should be independent of synchronization framework.
Adi
Google Gears makes no attempt at automating any synchronization, though it will help you with the serving of content when offline (via the resource cache), and data storage (via the embedded database).
jamesh
A: 

The biggist issue with synchronization is when the user edits something offline, and it is edited online at the same time. You need to merge the two changed pieces of data, or deal with the UI to allow the user to say which version is correct. If you eliminate the possibility of both being edited at the same time, then you don't have to solve this sticky problem.

The method is usually to add a field 'modified' to all tables, and compare the client's modified field for a given record in a given row, against the server's modified date. If they don't match, then you replace the server's data.

Be careful with autogenerated keys - you need to make sure your data integrity is maintained when you copy from the client to the server. Strictly running the SQL statements again on the server could put you in a situation where the autogenerated key has changed, and suddenly your foreign keys are pointing to different records than you intended.

Often when importing data from another source, you keep track of the primary key from the foreign source as well as your own personal primary key. This makes determining the changes and differences between the data sets easier for difficult synchronization situations.

Kieveli
I voted this down (sorry) because I think it vastly oversimplifies the issues involved. It doesn't address security at all or selective synchronization. The thesis from Stettler is a good intro to the issues (http://www.ifi.uzh.ch/archive/mastertheses/DA_Arbeiten_2003/Stettler_Christian.pdf)
Hamlet D'Arcy
+6  A: 

There are a number of Java libraries for data synchronizing/replication. Two that I'm aware of are daffodil and SymmetricDS. In a previous life I foolishly implemented (in Java) my own data replication process. It seems like the sort of thing that should be fairly straightforward, but if the data can be updated in multiple places simultaneously, it's hellishly complicated. I strongly recommend you use one of the aforementioned projects to try and bypass dealing with this complexity yourself.

Don
+2  A: 

Your synchronizer needs to identify when data can just be updated and when a human being needs to mediate a potential conflict. I have written a paper that explains how to do this using logging and algebraic laws.

Norman Ramsey
There is also Christian Stettler's Master's Thesis on the issue: http://www.ifi.uzh.ch/archive/mastertheses/DA_Arbeiten_2003/Stettler_Christian.pdfThere are big security concerns that need to be addressed, and this paper covers them nicely.
Hamlet D'Arcy
A: 

You can use an alternate method and customize it according to you need. Online Offline Database Synchronization

Ankit Verma
A: 

Web Services may be used for data synchronization like SOALIB is doing http://soalib.com.

mikessa