InSync: Automatic Offline Data Synchronization in AIR using LCDS 2.6


LCDS 2.6 allows you to build AIR applications with automatic offline data synchronization. This feature leverages the SQLite relational database system embedded in the AIR runtime, but the advantage is that the data synchronization process is entirely automatic: you don’t have to write SQL statements or synchronization logic to keep your local database in sync with your central database.
I have been getting a number of questions related to this feature, so I decided to build a sample application that demonstrates how it works.
In this application the synchronization process is implicit. When you are online, the cache (a SQLite database) is automatically updated along with the server database to make sure the user can go offline with the latest data without explicitly triggering a synchronization process. When you are offline, the changes are saved in the local cache. If the network becomes available while working in the application, the application will detect the network status change and automatically synchronize data (send your offline changes to the server, and get changes made by other users while you were offline).
Installation Instructions
- If you haven’t already done so, install LCDS 2.6.
- Unzip insync.zip
- Copy the content of the sampledb folder in the sampledb folder of your existing LCDS directory
- Copy the content of the tomcat folder in the tomcat folder of your existing LCDS directory
- Add the following destination to data-management-config.xml
<destination id="insync"> <adapter ref="java-dao" /> <properties> <source>lcds.samples.contact.ContactAssembler</source> <scope>application</scope> <metadata> <identity property="contactId" undefined-value="0"/> </metadata> </properties> </destination> - Restart the sample database: run sampledb.bat (Windows) or sampledb.sh (Unix) in the sampledb directory
- Restart your application server
Quick Tour
- Install and run the AIR application. Notice the green light in the status bar indicating that the application is in online mode.
Please upgrade your Flash Player This is the content that would be shown if the user does not have Flash Player 9.0.115 or higher installed.
- Double click a contact to view the contact details.
- Modify the data in a few fields and click Save. Your server console indicates that the contact has been updated.
- Click the + button in the application title bar. Enter a first name, last name, etc and click Save. Your server console indicates that the contact has been updated.
- Shut down the server
- Notice that the green light turns grey to indicate that the application is now working in offline mode.
- Repeat steps 2 to 4 above: changes are saved locally. Notice that the offline status (not modified, created, or updated is displayed in the contact form (bottom left corner)
- Restart the server.
- The green light appears in that status bar as soon as the server is up and running. Notice that LCDS automatically detects the offline changes and sends them to the server.
Comments
22 Responses to “InSync: Automatic Offline Data Synchronization in AIR using LCDS 2.6”
Leave a Reply









In case data of the same item changes in both offline cache & online database.
which data is taken?
it seems great,may i use BlazeDS instead of using LiveCycle ?
Forrest, Offline sync is a feature of Data Management Services which is part of LCDS. Note that there is a free version of LCDS currently called LCDS Express.
Christophe
@Rosenthal Ido: if you go back online and try to apply a change to an item that someone else has already changed in the central database, you will have a conflict. There is a conflict resolution API that you use to resolve this situation.
I was just talking with a friend the other and we were brainstorming on how to accomplish this very task. Auto Sync of a local database with a server database is a very nice feature to have.
Thanks!
[...] InSync: Automatic Offline Data Synchronization in AIR using LCDS 2.6 : Christophe Coenraets (tags: lcds read air) Posted in del.icio.us [...]
[...] Online/Offline Synchronizaton with AIR and LCDS at 360|Flex San Jose, but Christophe Coenraets just published a wicked example of how it works called InSync. Well worth checking out. This entry was posted on Tuesday, May 20th, 2008 at 5:26 pm and is [...]
[...] then points us to a resource that can help. Using LCDS, Christophe Coenraets has just published a sample application called InSync (zip file) that shows developers how to build [...]
[...] then points us to a resource that can help. Using LCDS, Christophe Coenraets has just published a sample application called InSync (zip file) that shows developers how to build [...]
That’s great - I have been waiting for something like that!
Thank you!
WE need to vote again :) https://bugs.adobe.com/jira/browse/FP-247
I realy hope we can have USB communication in AIR and Flash Player :)
I can imagine many different type of applications which can communicate with different devices connected over USB, atleast my phone (over bluetooth or cable)…
It would be great if AIR and Flash player can have USB API for those things, so that we (developers) are not forced to write socket-servers and take care of installation etc..
Any chance you’ll be releasing the source behind your AIR app?
Very cool btw.
Tristan, the source code for the AIR app is actually available in insync.zip.
Christophe
[...] Coenraets has an AIR demo for offline data syncing with LiveCycle [...]
Can I use this progoram with my MySQL database? If so, how can I set it? Thank you so much anyone. This is a super cool program.
Hi Christophe,
Very useful and clean tutorial as usual. I had to change a couple of things ( most of them related to my eclipse developing environment ) to have this working but, finally, everything works fine now.
Congratulations again for your work.
Alberto
Hi Christophe,
I know it’s not really the right place to ask this, but… :-)
Is it possible (or if not is it planned) to have the Air runtime and application installers localized…?
Thx.
Really exited about this because currently we’re having to maintain a SQLlite db “manually” on a big project.
Started testing this and got a run-time error… all I’m doing is creating a new DataService and setting the cacheID=”users”;
userDataService = new DataService(”UserService”);
userDataService.cacheID = “users”;
ReferenceError: Error #1065: Variable mx.data::LocalStoreFactory is not defined.
at mx.data::DataStore/get localStore()[C:\depot\flex\branches\enterprise_corfu_b2\frameworks\projects\data\src\mx\data\DataStore.as:2670]
at mx.data::DataStore/set cacheID()[C:\depot\flex\branches\enterprise_corfu_b2\frameworks\projects\data\src\mx\data\DataStore.as:317]
at mx.data::ConcreteDataService/set cacheID()[C:\depot\flex\branches\enterprise_corfu_b2\frameworks\projects\data\src\mx\data\ConcreteDataService.as:231]
at mx.data::DataService/set cacheID()[C:\depot\flex\branches\enterprise_corfu_b2\frameworks\projects\data\src\mx\data\DataService.as:428]
at LCDSX/init()[C:\Documents and Settings\Karlsson\My Documents\Flex 3\LCDSX\src\LCDSX.mxml:14]
Any pointers?
Thanks
Nevermind - adding the airfds.swc to the project helps :)
Anyone have problems with going back online after a network disconnection [using authentication]? I’m the client is always successful in sending data [like dataService.deleteItem] but ~60% of the time it’s not receiving updates from the server [although it fill()'s just fine].
Any pointers would be greatly appreciated. / Thanks
Found that if I disconnect using “ipconfig /release” I get the 60% failure - but if I disconnect the ehternet cable and then reconnect it something is cleared up automatically and it works fine.
I’m trying to simulate a rather unique network environment :) - is there a way to “manually reset” or “clear” the RTMPChannel/ChannelSet/DataService such that it gets into the same state as it was before starting to use it [other than restarting the app]?
If I add delete and update lots of data while offline and then come to online while running the application its gets synchronized fine.
But if i close the application after making changes and again start it in offline status if goes failed and show s the alert “Cannot Fill”……
It is going fine if i add only the first name or change the phone number…..
but if i add a full details of a person and do the said process it fails….
please help…. and how to improve it?