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

  1. If you haven’t already done so, install LCDS 2.6.
  2. Unzip insync.zip
  3. Copy the content of the sampledb folder in the sampledb folder of your existing LCDS directory
  4. Copy the content of the tomcat folder in the tomcat folder of your existing LCDS directory
  5. 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>
    

  6. Restart the sample database: run sampledb.bat (Windows) or sampledb.sh (Unix) in the sampledb directory
  7. Restart your application server

Quick Tour

  1. Install and run the AIR application. Notice the green light in the status bar indicating that the application is in online mode.

    [airbadge]sqliteadmin, http://coenraets.org/apps/insync/insync.air, v1.0, http://coenraets.org/apps/insync/insync1.png[/airbadge]

  2. Double click a contact to view the contact details.
  3. Modify the data in a few fields and click Save. Your server console indicates that the contact has been updated.
  4. 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.
  5. Shut down the server
  6. Notice that the green light turns grey to indicate that the application is now working in offline mode.
  7. 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)
  8. Restart the server.
  9. 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.

, , ,

77 Responses to InSync: Automatic Offline Data Synchronization in AIR using LCDS 2.6

  1. Rosenthal Ido May 20, 2008 at 1:08 am #

    In case data of the same item changes in both offline cache & online database.
    which data is taken?

  2. Forrest May 20, 2008 at 2:16 am #

    it seems great,may i use BlazeDS instead of using LiveCycle ?

  3. christophe May 20, 2008 at 8:21 am #

    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

  4. christophe May 20, 2008 at 8:26 am #

    @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.

  5. Dan Vega May 20, 2008 at 8:48 am #

    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!

  6. cp8r May 22, 2008 at 2:14 am #

    That’s great – I have been waiting for something like that!

    Thank you!

  7. Cato Paus May 22, 2008 at 10:44 am #

    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..

  8. Tristan May 22, 2008 at 2:10 pm #

    Any chance you’ll be releasing the source behind your AIR app?

    Very cool btw.

  9. christophe May 22, 2008 at 2:20 pm #

    Tristan, the source code for the AIR app is actually available in insync.zip.
    Christophe

  10. Flex Rules May 25, 2008 at 7:51 am #

    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.

  11. Alberto May 26, 2008 at 9:19 am #

    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

  12. Charly June 12, 2008 at 3:07 am #

    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.

  13. Martin Karlsson June 27, 2008 at 1:23 pm #

    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

  14. Martin Karlsson June 27, 2008 at 1:48 pm #

    Nevermind – adding the airfds.swc to the project helps :)

  15. Martin Karlsson June 30, 2008 at 4:31 pm #

    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

  16. Martin Karlsson July 3, 2008 at 1:03 pm #

    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]?

  17. Subhadip Chakraborty July 8, 2008 at 2:15 am #

    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?

  18. florence kolberg July 24, 2008 at 3:14 am #

    hi,

    I have installed LCDS 2.6 and started the server, after I started the sample database.
    When I run the inSync app. I get an green online button, but I also get a “cannot fill” message popping.
    Could anyone help me solving that issue? it looks like the contactdb.script is not run or something.

    Thanks,
    Florence

  19. florence kolberg July 25, 2008 at 9:25 am #

    Hi,

    I have been debugging the insync application – it still does not work on my computer for some reasons – and I get the following error message:

    Error: Unable to initialize destinations on server: [“insync”]
    at ()[C:\depot\flex\branche\enterprise_corfu_rc\frameworks\projects\data\src\mx\data\DataStore.as:2347]
    at ()[C:\depot\flex\branches\enterprise_corfu_rc\frameworks\projects\data\src\mx\data\DataStore.as:2363]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.data::SQLDBCache/dispatchStatusEvent()[C:\depot\flex\branches\enterprise_corfu_rc\frameworks\projects\airfds\src\mx\data\SQLDBCache.as:540]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.rpc::AsyncDispatcher/timerEventHandler()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AsyncDispatcher.as:50]
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

    If anyone has a pointer to how I can solve that problem, I gladly take it.

    thanks
    Florence

  20. Araba, Yarış Oyunları August 6, 2008 at 5:46 pm #

    Güzel bilgiler..Teşekkürler…

  21. Joe August 6, 2008 at 9:14 pm #

    I’m having the same issue as Florence…. can’t seem to quite figure this one out. Could really use the help on this one if someone knows what’s going on.

    thanks,

    Joe

  22. onur August 16, 2008 at 7:42 am #

    Greatest AIR app interface designer ever

  23. sohbet August 22, 2008 at 5:24 am #

    Güzel bilgiler..Teşekkürler…

  24. Damian Vuckovich August 29, 2008 at 7:44 am #

    Yah i’m getting the same problem as Florence and can’t figure it out myself. Any pointers would be useful. The debug statements kept on saying the server producer was disconnecting right before i’d see the error message.

  25. nimesh nanda September 12, 2008 at 6:54 am #

    Hi,

    please help me how to synchronize online and offline data in Flex (AIR) and Ruby on Rails ..

    Regrads,
    Nimesh nanda

  26. Sky September 18, 2008 at 7:23 pm #

    I’m currently having the same problem as “Martin Karlsson” (from June 27th, 2008 1:23 pm). I added the airfds.swc to the compilation line… and it doesn’t work. :( It did work for a while, but then I had to change my DSN source in CF8 to point to a different DB. I don’t think that should change anything…

    Any ideas?

  27. kauser November 13, 2008 at 4:42 am #

    Hi,
    I am working on a simple application using flex and air as the presentation layer, java as the back end and the data base which i am using is ms access. Can you tell me how to use LCDS with an application whose back end is written in java. Thanks in advance.

  28. Jin Lei November 13, 2008 at 4:12 pm #

    To make the installation instruction more clear,

    5. Add the following destination to data-management-config.xml

    actually, add the following destination to

    tomcat folder, \webapps\lcds-samples\WEB-INF\flex\management-config.xml

  29. kauser November 25, 2008 at 7:06 am #

    Hi,
    I went through the sample lcds application for data synchronization and created a similar application. I am getting the following errors:
    1. Unable to initialize destinations on server.
    2. No destination with id ‘[my id]’ is registered with any service.
    Can you tell me what could be the possible cause of this error. Thanks.

  30. ED December 30, 2008 at 4:49 am #

    Is this possible using Coldfusion 8 alone (From what I understand LiveCycle Data Services is integrated in Coldfusion 8) ? Thanks in advance.

  31. Souvik Mukherjee February 3, 2009 at 5:01 am #

    I am developing an application and I am in a position where I can push messages to one or many AIR applications and the selection of AIR application will be decided by LCDS server. Here I am making use of JMS along with JMS adapter. I need a way to receive an acknowledgement to LCDS server when the message is delivered.
    I have found few application where JMS subscriber is sending acknowledgement to JMS producer, but I need a way where JMS producer is getting acknowledgement from each Flex client.

  32. some hardware guy March 15, 2009 at 9:25 am #

    So I spent three days on this, and I think I solved or at least identified a work around for the problem that several guys including florence were having above. I tried to write down all the steps I took to get this demo running in three parts. Part three is here and has the fix of compiling in your services to fix the dreaded Error: Unable to initialize destinations on server: [“insync”]

    Hope it helps

    http://somehardwareguy.blogspot.com/2009/03/part-3-lcds-insync-example-it-works-and.html

  33. Sam May 19, 2009 at 8:58 am #

    Hi Christophe,

    Is there any limitation on the amount of datasets you can cache offline? I am working on a rather large AIR/LCDS/Flex/ColdFusion application and the offline caching seems to work fine when using one dataset but if I enable the others I get one of two errors…

    Error 1:

    Database must be connected to perform this operation

    Error 2:

    Nested transactions are not supported

    The application runs fine and super-fast when I disable saveToCache on my DataService objects but fails when I enable it.

    ANY help would be greatly appreciated.

  34. مسلسلات حليمه September 5, 2009 at 11:17 pm #

    Is this possible using Coldfusion 8 alone (From what I understand LiveCycle Data Services is integrated in Coldfusion 8) ? Thanks in advance

  35. Mike October 2, 2009 at 12:40 am #

    This is realy. The application runs fine and super-fast when I disable saveToCache on my DataService objects but fails when I enable it.

  36. Edward Lane October 10, 2009 at 9:36 pm #

    There’s good info here. I did a search on the topic and found most people will agree with your blog. Keep up the good work mate!

  37. sohbet odası November 24, 2009 at 6:13 am #

    how are you baby melisa

  38. Jalousien November 26, 2009 at 4:48 am #

    that is a awesome tool

  39. chat December 3, 2009 at 12:08 pm #

    that is a awesome tool

  40. ibrahim saraçoğlu January 6, 2010 at 12:03 pm #

    that is a awesome tool, thank you.

  41. Sohbet January 10, 2010 at 10:18 pm #

    good post admin, thank you very much

  42. Andi January 12, 2010 at 5:41 am #

    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.

    I would also like to know.

  43. Eşref Atak January 30, 2010 at 2:05 pm #

    Is there any way to do similar application without write any server side Java code? Thank you for your entry.

  44. Abhishek D.V. February 1, 2010 at 3:57 am #

    Mr. Coenraets,

    I am thinking of implementing your application, but I don’t have LiveCycle DS 2.6. Instead, I am using LCDS 2.5. Will this pose any problem? That is, will I have to make any modifications to the code and/or settings or will the application work fine with LCDS 2.5?

  45. chat sitesi March 19, 2010 at 4:47 am #

    I am thinking of implementing your application, but I don’t have LiveCycle DS 2.6. Instead, I am using LCDS 2.5. Will this pose any problem? That is, will I have to make any modifications to the code and/or settings or will the application work fine with LCDS 2.5?

  46. AdWords Agentur May 28, 2010 at 9:11 am #

    that is a awesome tool.

  47. AdWords Agentur May 28, 2010 at 9:13 am #

    Top Sehr Gut…………..

  48. chat June 19, 2010 at 4:03 pm #

    Well done and good luck with your very great work thanks

  49. rottweiler July 16, 2010 at 9:02 pm #

    thanks for information

  50. Webdesign Agentur July 17, 2010 at 4:14 am #

    very good contributing very helpful thank you.

  51. sohbet August 9, 2010 at 2:49 pm #

    thanx so much

  52. توبيكات August 12, 2010 at 12:05 am #

    thanx so much

  53. mohsin August 19, 2010 at 9:26 pm #

    is it possible using lcds can we store the data to mysql

  54. isvicresesli December 17, 2010 at 2:13 pm #

    Thank you, I´ve tried Piwik and it worked very good!

  55. isvicresesli December 17, 2010 at 2:14 pm #

    Thank you, I´
    ve tried Piwik and it worked very good! super dancke

  56. facebook-video December 26, 2010 at 12:08 pm #

    güzel bilgiler.

  57. slims January 14, 2011 at 4:00 pm #

    Auto Trader compares over 400 car insurance prices
    to find you the right policy.

  58. Maikl January 15, 2011 at 5:08 am #

    A farm is a place of growing, nurturing, life, hope and peace. and A farm can be a destination location, a place of sharing and learning for those wishing to experience a touch yesteryear in the rural whether it be for an hour or two, or an entire day

  59. Krisi January 15, 2011 at 3:43 pm #

    The Debian Free Software Guidelines

  60. Jalousien January 18, 2011 at 10:39 am #

    Thank You for the Automatic Offline Data Synchronization Quick Tour.

  61. sumasearch February 7, 2011 at 10:48 am #

    Paylasdigin icin tesekkürler ederim !

  62. Intermediaries April 10, 2011 at 4:56 am #

    As an independent financial adviser, broker or agent, you want to ensure that your clients are getting the best international private medical insurance to suit their needs.

  63. chat May 22, 2011 at 8:18 am #

    very good, thanx

  64. Twila Moake June 3, 2012 at 9:04 am #

    Whoa that is strange. I merely wrote an really extensive comment but when i pressed send my thoughts did not show up. Nevermind I am certainly not writing that all over again. Anyhow, I only wanted to speak about your wonderful site!

  65. Samba Siva Reddy December 10, 2013 at 10:44 am #

    Can any one help me providing full set of LCDS Data Sync Example!..

Trackbacks/Pingbacks

  1. 17 Pens » links for 2008-05-20 - May 20, 2008

    […] InSync: Automatic Offline Data Synchronization in AIR using LCDS 2.6 : Christophe Coenraets (tags: lcds read air) Posted in del.icio.us […]

  2. Ryan Stewart - Rich Internet Application Mountaineer » Online/Offline Synchronization with Adobe AIR - May 20, 2008

    […] 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 […]

  3. LCDS Makes AIR Offline Sync Easy (…and Why You’ll Care) | 网络赚钱网摘 - May 21, 2008

    […] 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 […]

  4. LCDS Makes AIR Offline Sync Easy (…and Why You’ll Care) - May 21, 2008

    […] 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 […]

  5. FlexLive.net » Flex Developer Update - May 23, 2008 - May 23, 2008

    […] Coenraets has an AIR demo for offline data syncing with LiveCycle […]

  6. pocker game holdem texas hold em - September 2, 2008

    pocker game holdem texas hold em…

    tenement,Gus Campbellsport grocer Crusoe,swampy …

  7. Ryan Stewart - Rich Internet Application Mountaineer » Blog Archive » Online/Offline Synchronization with Adobe AIR, ColdFusion and LCDS - September 3, 2008

    […] got the slides for anyone who wants to jump in and try it out. I highly suggest checking out Christophe’s demo from which I drew a bunch of my inspiration. He’s implemented the functionality in Java while […]

  8. Life As An Evangelist » Online/Offline Synchronization with Adobe AIR, ColdFusion and LCDS - September 22, 2008

    […] got the slides for anyone who wants to jump in and try it out. I highly suggest checking out Christophe’s demo from which I drew a bunch of my inspiration. He’s implemented the functionality in Java while […]

  9. Cornel Creanga » Blog Archive » LiveCycle Data Services 2.6 – new features (4) - October 14, 2008

    […] are several resources describing in details this feature in detail and providing some samples – Cristophe Coenraets blog, an article on Inside RIA and the developer […]

  10. Solution Hacker » Adobe Air with SQLite database - July 2, 2009

    […] http://coenraets.org/blog/2008/05/insync-automatic-offline-data-synchronization-in-air-using-lcds-26… […]

  11. Integration with two database – Transfer of data between two database » free icons download - June 20, 2012

    […] db and your server side database (though the data being sent to server is AMF format). Check out http://coenraets.org/blog/2008/05/insync-automatic-offline-data-synchr onization-in-air-using-lcds-2… for more info on that. ||| Hi Anirudh, Thanks for the […]

  12. Article: AIR Data Synchronization via LiveCycle Data Services ES 2.6 | John C. Bland II - April 16, 2013

    […] after I submitted my final draft, Christophe came out with an app to show the offline sync abilities in 2.6. His app looks really nice and he has a custom Java assembler included in his source. My app […]

Leave a Reply

css.php