Offline Synchronization using AIR and LiveCycle Data Services

contacts3.gif

As part of my MAX talks in Chicago and Barcelona, I used a simple Contact Manager application to demonstrate offline synchonization using AIR and LiveCycle Data Services (LCDS). Many people have asked me to share the code, so here it is… This is actually an update of an application I posted a few months ago (but that didn’t include the offline synchronization part at the time).

Using the Data Services to work with data in AIR offers several benefits:

First, just like for traditional browser-based Flex apps, the Data Management Service automates the synchronization of data between the client and the middle-tier. In other words, you don’t have to flag/keep track of the changes made at the client-side, and then make corresponding RPC calls to send changes to the server: this is all managed automatically.

Second, you can access and enter data while offline: the Data Management Service takes care of storing your data locally and synchronizing the changes with the server when you go back online. To enable offline synchronization, the Data Management Service API provides methods (such as saveCache() / clearCache()) to save data locally and manipulate the local data store. When you go back online, the commitRequired attribute of your dataService indicates if changes have been made offline. Invoking commit() on the dataService automatically synchronizes the offline changes with the server. See main.mxml for an example.

In the current AIR betas, the Flex Data Management Service uses Local Shared Objects as the local data store. For the AIR 1.0 release, we will use the SQLite database embedded in the AIR runtime instead.

In this application, I use the SQL assembler to provide the server-side persistence logic. Using the SQL assembler, you don’t have to write server-side components if you don’t want/need to: you just provide a series of SQL statements indicating how data should be retrieved, and how changes should be persisted in the database. The SQL assembler makes it extremely fast and easy to create applications that don’t require sophisticated persistence logic.

Installation instructions:

  1. Install LiveCycle Data Services 2.5 here
  2. In the samples web application, modify the flexdemodb database file to add the contact table: replace WEB-INF\db\flexdemodb\flexdemodb.script with this version.
  3. Open WEB-INF\flex\data-management-config.xml and add the following destination.
    <destination id="sql-contact">
    
    	<adapter ref="java-dao" />
    
    	<properties>
    
    		<use-transactions>true</use-transactions>
    		<source>flex.data.assemblers.SQLAssembler</source>
    		<scope>application</scope>
    		<metadata>
    			<identity property="CONTACT_ID"/>
    		</metadata>
    
    		<network>
    			<session-timeout>20</session-timeout>
    			<paging enabled="false" pageSize="10" />
    			<throttle-inbound policy="ERROR" max-frequency="500"/>
    			<throttle-outbound policy="REPLACE" max-frequency="500"/>
    		</network>
    
    		<server>
    
    			<database>
    			    <driver-class>org.hsqldb.jdbcDriver</driver-class>
    			    <!-- Modify the URL below with the actual location of the flexdemodb database on your system -->
    			    <url>jdbc:hsqldb:file:C:/lcds/jrun4/servers/default/samples/WEB-INF/db/flexdemodb/flexdemodb</url>
    			    <username>sa</username>
    			    <password></password>
    				<login-timeout>15</login-timeout>
    			</database>
    
    			<actionscript-class>Contact</actionscript-class>
    
     			<fill>
       				<name>all</name>
       				<sql>SELECT * FROM CONTACT</sql>
     			</fill>
    
    			<get-item>
    				<sql>SELECT * FROM CONTACT WHERE CONTACT_ID = #CONTACT_ID#</sql>
    			</get-item>
    
     			<create-item>
    			  <sql>INSERT INTO CONTACT
    			  		(FIRST_NAME,LAST_NAME,EMAIL,PHONE,ADDRESS,CITY,STATE,ZIP,COUNTRY,NOTES)
    			  		VALUES (#FIRST_NAME#, #LAST_NAME#, #EMAIL#, #PHONE#, #ADDRESS#, #CITY#, #STATE#, #ZIP#, #COUNTRY#, #NOTES#)</sql>
    			  <id-query>CALL IDENTITY()</id-query> <!-- HSQLDB syntax to retrieve value of autoincremented column -->
    			</create-item>
    
     			<update-item>
    			  <sql>UPDATE CONTACT SET FIRST_NAME=#FIRST_NAME#,LAST_NAME=#LAST_NAME#,EMAIL=#EMAIL#,PHONE=#PHONE#,ADDRESS=#ADDRESS#,CITY=#CITY#,STATE=#STATE#,ZIP=#ZIP#,COUNTRY=#COUNTRY#,NOTES=#NOTES#
    			  		WHERE CONTACT_ID=#_PREV.CONTACT_ID#</sql>
    			</update-item>
    
     			<delete-item>
    			  <sql>DELETE FROM CONTACT WHERE CONTACT_ID=#CONTACT_ID#</sql>
    			</delete-item>
    
    			<count>
    				<name>all</name>
    				<sql>SELECT count(*) FROM CONTACT</sql>
    			</count>
    
    		</server>
    
    	</properties>
    
    </destination>
    
  4. Start the server
  5. Install contacts.air and run the application

NOTE: The application has been compiled assuming that an RTMP endpoint named my-rtmp is configured at rtmp://localhost:2037. If your server isn’t configured that way, you will have to recompile the application. You can also provide the endpoints at runtime. See my previous post for more information on defining a ChannelSet.

You can download the source code here.

Application Walkthrough

  1. Start the application. Notice the green light in the upper right corner indicating that the dataService is connected to the server.
  2. Double-click a contact in the list to open the details form. Modify some data and click “Save”.
  3. Shut down your server. Notice that the connectivity status light is now red. Close the application to make it clear that your are not working with data cached in memory.
  4. Restart the application. It will take a second before you see the data: the dataService first tries to connect to the server before loading the data from the local cache. Open a contact, make some changes to the data and click “Save”. Your change is saved to the local cache.
  5. Close the application.
  6. Restart your server.
  7. Restart the application. Notice that the application automatically detects that changes have been made offline, and synchronizes the offline changes.

, ,

79 Responses to Offline Synchronization using AIR and LiveCycle Data Services

  1. Mike Brunt October 27, 2007 at 4:22 am #

    Christopher, thanks for this. Will your app work with the version of LiveCycle Data Services included in the ColdFusion 8 install?

  2. Gary Gilbert October 29, 2007 at 3:47 am #

    @Mike,

    Yes it will work you just need to configure the gateway and then of course build the services in CF

  3. Chris Sharon October 30, 2007 at 2:07 pm #

    Just a couple of questions.

    1. What if you have relational data?
    Lets say I wanted to use your SalesBuilder Example and have it cache data locally and sync with lcds. Is it true that the cache doesn’t work with nested Destinations? (in it’s current form) lcds 2.5.1

    2. In SalesBuilder would you have 3 Destinations and 3 dataservices each with their own cacheId. (Accounts, Contacts, Opportunities), if so would the destinations include relationships with each other)

    By the way thanks for the examples, they have been extremely helpful.

  4. Nikki November 15, 2007 at 6:57 am #

    this is really great stuff! i am infinately impressed!
    i am in the process of trying to speak to cf using the livecycle data services and am hoping to use your app as a platform for my education.
    on this note, i have imported the source files to flex builder (v3 b2), but cannot compile due to some errors with types not being found and undefined properties.
    i am fairly new to this all and am not too sure how to solve this.
    any advice?

  5. Sid Maestre November 21, 2007 at 5:16 pm #

    Hey Chris,

    I’m at a bit of loss.

    Can’t find WEB-INF\db\flexdemodb\flexdemodb.script

    I’ve installed CF8 and then downloaded and installed the LCDS from adobe. Searched my HD for flexdemodb.

    I must be missing something real obvious.

    Thanks for you help

  6. Elijah November 21, 2007 at 7:36 pm #

    It is located at:

    C:\Program Files\LCDS\jrun4\servers\default\samples\WEB-INF\db\flexdemodb

  7. robert November 25, 2007 at 2:42 pm #

    hello, the application is nice to get started. i have a question: is it possible to get a installed air application get connected to a destination on a extern server, not on the local computer???

  8. todd geist November 25, 2007 at 7:32 pm #

    I downloaded the source and tried to re-compile, but i am getting an error.

    in main.mxml

    private function conflictHandler(event:DataConflictEvent):void

    is giving this error

    1046: type was not found, or was not a compile time constant: DataConflictEvent

    any clues?

    Thanks

  9. robson November 26, 2007 at 2:27 am #

    @todd: did you have an import of the DataConflictEvent?

  10. Nikki December 5, 2007 at 12:24 am #

    is it possible to create an air app that doesn’t rely on local livecycle services in order to do this sort of thing… i.e. will all of our clients have to install LCDS when installing our app?

  11. Daniel F. Boada December 6, 2007 at 9:22 pm #

    No idea were to ask this… hope anyone knows it…

    Can i use the ‘Public’ java APIs in the LiveData Cycles for my application without paying the license of LiveData Cycles?
    I what to use MessageBroker class.
    THanks,
    Dani.

  12. Valerio Vitullo January 17, 2008 at 11:43 am #

    Hi,

    We are a young italian company working in IT. Since we choose to invest in adobe technology for all provided services (graphics, media, development web and desktop application) we are trying to offer our customers a set of new interesting feature in view of a market widening.

    Actually we focus our attention on the possibility, that the LCDS allow, to store server database data locally and synchronize it when possible.

    Your post ” Offline Synchronization using AIR and LiveCycle Data Services” was a very nice example, but the cached data of DataService object seems available only during the run time period of the air application, right?. The limit of 100 kilobytes is also another dramatic disadvantage.

    Bear in mind that cached data should be always available on the client as first choose of our application and eventually should be possible synchronize it if server is available, embedded SQLite can help us?
    How SQLite can synchronize it with server database?
    I can use SQLite with DataService object?
    Do you have any documentation or example about it?

    I will be very glad if you can answer us and also If you have any alternative solution about this problem.

    Kind regards

  13. trotters213 April 16, 2008 at 3:44 am #

    Hi guy and thanks you so much for your example.

    I’m searching on LCDS possibilities and I found your very tutorial.

    I’ve got 2 problems :
    - if I try to launch contact.air I’ve got this problem : “This application requires a version of Adobe AIR which is no longer supported. Please contact the application author for an updated version.”

    - If I try to recompile but I got 2 errors :
    “1046: type was not found, or was not a compile time constant: DataConflictEvent” in spite of the import “import mx.data.CacheDataDescriptor;” (like todd geist). And the other error is “1120 Acces to CacheDataDescriptor property not defined” at this line : “var token:AsyncToken = ds.getCacheData(dgCacheDescripors.selectedItem as CacheDataDescriptor);”

    Somebody has an idea about solutions ?

    Thank you for all.

  14. mkpgbydf fgmsk June 19, 2008 at 9:21 pm #

    uaojcd enporfv vkhup iuxvojm tsgeq lbrvjq cwpvrfnd

  15. onur gunduz June 20, 2008 at 11:27 pm #

    type was not found or not a compile time constant?? come onn

  16. uvetynak July 31, 2008 at 4:37 pm #

    amateur porn dump

  17. radyo dinle August 22, 2008 at 5:46 am #

    thanks ;)

  18. forum August 22, 2008 at 5:47 am #

    thanks a lot ;)

  19. sohbet August 22, 2008 at 5:47 am #

    teşekkürler ;)

  20. chat August 22, 2008 at 5:47 am #

    thanks a lot ..

  21. kktc August 24, 2008 at 1:48 am #

    thanks

  22. sohbet August 25, 2008 at 3:57 am #

    Thank you very much for this information. I like this site

  23. Kamalanathan August 25, 2008 at 5:37 am #

    The information is much useful. I like this article. Thanks for providing me the same.

  24. muhabbet August 26, 2008 at 5:49 am #

    thanks you very much.

  25. Ebby October 26, 2008 at 2:09 pm #

    Hello everyone. Please i have a problem. I did a sample application that pushes content realtime, with flex and livecycle on coldfusion. However, when i try making it an Air application. it doesn’t work. I get “consumer error”.

    Pls how do i solve this problem? is there a special way to use air with livecycle and coldfusion..

    thanks

  26. lapto battery November 20, 2008 at 9:23 pm #

    Hello everyone. Please i have a problem. I did a sample application that pushes content realtime, with flex and livecycle on coldfusion. However, when i try making it an Air application. it doesn’t work. I get “consumer error”.

    Pls how do i solve this problem? is there a special way to use air with livecycle and coldfusion..

  27. uvilviru November 20, 2008 at 9:38 pm #

    salma hayek naked

  28. daslaber January 7, 2009 at 1:27 pm #

    Hey Chris,

    I’m at a bit of loss.

    Can’t find WEB-INF\db\flexdemodb\flexdemodb.script

    I’ve installed CF8 and then downloaded and installed the LCDS from adobe. Searched my HD for flexdemodb.

  29. netlog February 28, 2009 at 1:28 pm #

    thank you

  30. sohbet March 4, 2009 at 7:33 pm #

    thank you

  31. ghd hair straighteners March 17, 2009 at 8:52 am #

    i am in the process of trying to speak to cf using the livecycle data services and am hoping to use your app as a platform for my education.
    on this note,

  32. araç sorgulama March 17, 2009 at 5:03 pm #

    I must be missing something real obvious.

  33. nude March 20, 2009 at 1:25 am #

    emily osment nude

  34. mirc March 30, 2009 at 4:58 pm #

    Thank you very much

  35. sohbet April 2, 2009 at 9:23 am #

    type was not found or not a compile time constant?? come onn

  36. arkadaş,izlesene,sohbet,video,chat April 17, 2009 at 3:37 pm #

    tanky

  37. dizi izle April 22, 2009 at 5:15 pm #

    thaks you

  38. Türkçe Forum May 15, 2009 at 3:18 pm #

    Thanks My Friend..

  39. Chat May 16, 2009 at 2:12 pm #

    thank you

  40. sohbet May 17, 2009 at 8:52 am #

    hallo i wish you verry succes operator

  41. Edencity May 19, 2009 at 8:28 am #

    Thank You

  42. sohbet May 20, 2009 at 4:09 am #

    Thank you.

  43. hole May 21, 2009 at 3:04 pm #

    thankss yourss verfy good life

  44. chat June 6, 2009 at 3:28 am #

    chat thanks

  45. sohbet June 6, 2009 at 3:36 am #

    sohbet thankss

  46. medyum July 6, 2009 at 3:42 am #

    this is really great stuff! i am infinately impressed!
    i am in the process of trying to speak to cf using the livecycle data services and am hoping to use your app as a platform for my education.
    on this note, i have imported the source files to flex builder (v3 b2), but cannot compile due to some errors with types not being found and undefined properties.
    i am fairly new to this all and am not too sure how to solve this.

  47. medyum July 13, 2009 at 7:11 am #

    Your post ” Offline Synchronization using AIR and LiveCycle Data Services” was a very nice example, but the cached data of DataService object seems available only during the run time period of the air application, right?. The limit of 100 kilobytes is also another dramatic disadvantage.

  48. ssk July 23, 2009 at 9:37 am #

    I downloaded the source and tried to re-compile, but i am getting an error.

    in main.mxml

    private function conflictHandler(event:DataConflictEvent):void

    is giving this error

    1046: type was not found, or was not a compile time constant: DataConflictEvent

    any clues?

    Thanks

  49. zerrin egeliler July 23, 2009 at 11:52 am #

    The information is much useful. I like this article. Thanks for providing me the same

  50. medyum August 11, 2009 at 12:08 pm #

    i am in the process of trying to speak to cf using the livecycle data services and am hoping to use your app as a platform for my education.
    on this note,

  51. laptop tamiri August 23, 2009 at 6:37 am #

    But not very cool

  52. Sohbet September 1, 2009 at 9:12 pm #

    thanx admins

  53. Note Computer September 28, 2009 at 5:32 am #

    Thank you for post.

  54. çet October 1, 2009 at 2:15 pm #

    thankss yourss verfy good life

  55. izmir sohbet October 1, 2009 at 2:16 pm #

    But not very cool

  56. reklam October 3, 2009 at 10:04 pm #

    thank you mennnnnnnnnnÇ:S

  57. qpygduhku October 10, 2009 at 9:21 pm #

    vanessa hudgens pics

  58. matbaa August 8, 2010 at 9:25 am #

    But not very cool

  59. kablo tv October 9, 2010 at 12:11 pm #

    thanks good services

  60. adem October 28, 2010 at 11:38 pm #

    Matbaa

  61. Notebook servisi November 30, 2010 at 6:38 pm #

    So if both are good, together they

  62. çilingir January 11, 2011 at 1:34 pm #

    thank you so much nice post

  63. chat February 8, 2011 at 7:12 am #

    admin thanks you for sharing sende olmasan napacaz biz . :)

  64. çelik kapı February 14, 2011 at 3:14 am #

    nice sharing. man thank you :)
    çelik kapı

  65. constipation diet April 29, 2011 at 10:30 pm #

    Good info, numerous thanks to the author. It’s puzzling to me now, generally, the usefulness as well as significance is overpowering. Greatly thanks once more and best of luck!

  66. Rickie Kobbe September 5, 2011 at 7:05 pm #

    Great post. I was checking constantly this blog and I’m impressed! Extremely useful info specifically the last part :) I care for such information a lot. I was seeking this certain information for a long time. Thank you and good luck.

  67. maviajansmatbaa September 16, 2011 at 11:38 am #

    really liked your presentation on QCON a few weeks ago. I could really tell you are very good at what you do. My compliment for that.

    I have a question though: I some environments like banks etc Flash plugin is disabled in the browser (security wise). How can we still use this technology wit

  68. Daysi Mizell October 4, 2011 at 1:34 pm #

    I think one of your adverts caused my window to resize, you may well want to put that on your blacklist.

  69. Prometeus April 10, 2012 at 11:41 am #

    Hi Christophe! Can you help? I can’t download the source code, when I go after the link it says: Not Found | The requested URL /downloads/contacts/contacts-src.zip was not found on this server.
    Thanks.

Trackbacks/Pingbacks

  1. Sönke Rohde » AIR examples/links, Desktop 2.0 and Adobe Developer Connection - October 29, 2007

    [...] Christophe Coenraets released the code Code from his MAX session in Barcelona about Offline Synchronization using AIR and Live Cycle Data Services. [...]

  2. Franto.com Flash blog » Presentations sources from Adobe Max 2007 - November 6, 2007

    [...] – Offline Synchronization using AIR and LiveCycle Data Services [...]

  3. poker odds kalkyl - February 18, 2008

    poker odds kalkyl…

    incredulity sheepskin striving!library:corrosive acetone …

  4. 17 Pens » links for 2008-04-10 - April 10, 2008

    [...] Offline Synchronization using AIR and LiveCycle Data Services : Christophe Coenraets (tags: lcds air flex) [...]

  5. illinois auto insurance - May 31, 2008

    illinois auto insurance…

    boasting Korean!yelling …

  6. About LCDS « It’s all about RIA - October 14, 2008

    [...] Christophe Coenraets :: Offline Synchronization using AIR and LiveCycle Data Services [...]

  7. Adobe LCDS « Flex Generation Weblog - October 14, 2008

    [...] Christophe Coenraets :: Offline Synchronization using AIR and LiveCycle Data Services [...]

  8. Adobe LCDS « SrikanthCreative Mind’s Weblog - October 27, 2008

    [...] Christophe Coenraets :: Offline Synchronization using AIR and LiveCycle Data Services [...]

  9. on the internet cheapest calorie meter clock - October 30, 2008

    on the internet cheapest calorie meter clock…

    reservoir heiress cisterns …

  10. life cycle data service and mx.data.* classes | msn messenger smiley - May 30, 2012

    [...] http://coenraets.org/blog/2007/10/offline-synchronization-using-air-an d-livecycle-data-services/ [...]

Leave a Reply

css.php