<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Christophe Coenraets &#187; Data Services</title>
	<atom:link href="http://coenraets.org/blog/tag/data-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://coenraets.org/blog</link>
	<description>Rich Internet Applications, Flex, AIR, Java, Android</description>
	<lastBuildDate>Fri, 23 Jul 2010 14:45:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Offline Synchronization using AIR and LiveCycle Data Services</title>
		<link>http://coenraets.org/blog/2007/10/offline-synchronization-using-air-and-livecycle-data-services/</link>
		<comments>http://coenraets.org/blog/2007/10/offline-synchronization-using-air-and-livecycle-data-services/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 20:05:12 +0000</pubDate>
		<dc:creator>Christophe Coenraets</dc:creator>
				<category><![CDATA[Air]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[Data Services]]></category>
		<category><![CDATA[Offline]]></category>

		<guid isPermaLink="false">http://coenraets.org/blog/2007/10/offline-synchronization-using-air-and-livecycle-data-services/</guid>
		<description><![CDATA[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&#8230; This is actually an update of an application I posted a few months ago [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image30" alt=contacts3.gif src="http://coenraets.org/blog/wp-content/uploads/2007/03/contacts3.gif" /></p>
<p>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&#8230; This is actually an update of <a href="http://coenraets.org/blog/2007/03/synchronizing-data-in-apollo-using-flex-data-services/">an application I posted a few months ago</a> (but that didn&#8217;t include the offline synchronization part at the time).</p>
<p><span id="more-54"></span></p>
<p>Using the Data Services to work with data in AIR offers several benefits:</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p><strong>Installation instructions:</strong></p>
<ol>
<li>Install LiveCycle Data Services 2.5 <a href="https://www.adobe.com/cfusion/tdrc/index.cfm?product=livecycle%5Fdataservices">here</a></li>
<li>In the samples web application, modify the flexdemodb database file to add the contact table: replace WEB-INF\db\flexdemodb\flexdemodb.script with <a href="/downloads/contacts/flexdemodb.zip">this version</a>.</li>
<li>Open WEB-INF\flex\data-management-config.xml and add the following destination.
<pre class="brush: xml;">
&lt;destination id=&quot;sql-contact&quot;&gt;

	&lt;adapter ref=&quot;java-dao&quot; /&gt;

	&lt;properties&gt;

		&lt;use-transactions&gt;true&lt;/use-transactions&gt;
		&lt;source&gt;flex.data.assemblers.SQLAssembler&lt;/source&gt;
		&lt;scope&gt;application&lt;/scope&gt;
		&lt;metadata&gt;
			&lt;identity property=&quot;CONTACT_ID&quot;/&gt;
		&lt;/metadata&gt;

		&lt;network&gt;
			&lt;session-timeout&gt;20&lt;/session-timeout&gt;
			&lt;paging enabled=&quot;false&quot; pageSize=&quot;10&quot; /&gt;
			&lt;throttle-inbound policy=&quot;ERROR&quot; max-frequency=&quot;500&quot;/&gt;
			&lt;throttle-outbound policy=&quot;REPLACE&quot; max-frequency=&quot;500&quot;/&gt;
		&lt;/network&gt;

		&lt;server&gt;

			&lt;database&gt;
			    &lt;driver-class&gt;org.hsqldb.jdbcDriver&lt;/driver-class&gt;
			    &lt;!-- Modify the URL below with the actual location of the flexdemodb database on your system --&gt;
			    &lt;url&gt;jdbc:hsqldb:file:C:/lcds/jrun4/servers/default/samples/WEB-INF/db/flexdemodb/flexdemodb&lt;/url&gt;
			    &lt;username&gt;sa&lt;/username&gt;
			    &lt;password&gt;&lt;/password&gt;
				&lt;login-timeout&gt;15&lt;/login-timeout&gt;
			&lt;/database&gt;

			&lt;actionscript-class&gt;Contact&lt;/actionscript-class&gt;

 			&lt;fill&gt;
   				&lt;name&gt;all&lt;/name&gt;
   				&lt;sql&gt;SELECT * FROM CONTACT&lt;/sql&gt;
 			&lt;/fill&gt;

			&lt;get-item&gt;
				&lt;sql&gt;SELECT * FROM CONTACT WHERE CONTACT_ID = #CONTACT_ID#&lt;/sql&gt;
			&lt;/get-item&gt;

 			&lt;create-item&gt;
			  &lt;sql&gt;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#)&lt;/sql&gt;
			  &lt;id-query&gt;CALL IDENTITY()&lt;/id-query&gt; &lt;!-- HSQLDB syntax to retrieve value of autoincremented column --&gt;
			&lt;/create-item&gt;

 			&lt;update-item&gt;
			  &lt;sql&gt;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#&lt;/sql&gt;
			&lt;/update-item&gt;

 			&lt;delete-item&gt;
			  &lt;sql&gt;DELETE FROM CONTACT WHERE CONTACT_ID=#CONTACT_ID#&lt;/sql&gt;
			&lt;/delete-item&gt;

			&lt;count&gt;
				&lt;name&gt;all&lt;/name&gt;
				&lt;sql&gt;SELECT count(*) FROM CONTACT&lt;/sql&gt;
			&lt;/count&gt;

		&lt;/server&gt;

	&lt;/properties&gt;

&lt;/destination&gt;
</pre>
</li>
<li>Start the server</li>
<li>Install <a href="/downloads/contacts/contacts.air">contacts.air</a> and run the application</li>
</ol>
<p>NOTE: The application has been compiled assuming that an RTMP endpoint named my-rtmp is configured at rtmp://localhost:2037. If your server isn&#8217;t configured that way, you will have to recompile the application. You can also provide the endpoints at runtime. See my <a href="http://coenraets.org/blog/2007/03/real-time-market-data-using-apollo-and-flex-data-services/">previous post</a> for more information on defining a ChannelSet.</p>
<p>You can download the source code <a href="/downloads/contacts/contacts-src.zip">here</a>.</p>
<p><strong>Application Walkthrough</strong></p>
<ol>
<li>Start the application. Notice the green light in the upper right corner indicating that the dataService is connected to the server.</li>
<li>Double-click a contact in the list to open the details form. Modify some data and click &#8220;Save&#8221;.</li>
<li>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.</li>
<li>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 &#8220;Save&#8221;. Your change is saved to the local cache.</li>
<li>Close the application.</li>
<li>Restart your server.</li>
<li>Restart the application. Notice that the application automatically detects that changes have been made offline, and synchronizes the offline changes.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://coenraets.org/blog/2007/10/offline-synchronization-using-air-and-livecycle-data-services/feed/</wfw:commentRss>
		<slash:comments>66</slash:comments>
		</item>
	</channel>
</rss>
