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