As a follow up to my previous post, here is the sample Sales Force Automation application I built to demonstrate the Flex/Google Gears integration, and that Kevin Lynch demonstrated during the Google Developer Day keynote last week in San Jose.
SalesBuilder uses the Google Gears Database API to save data to an embedded SQLite database, and the LocalServer API to enable offline access to the application.
In this hosted version, I removed the server component (to avoid having to watch all the bad things that can happen to a shared demo database). An XML document plays the role of server data. You work offline and the changes you make are saved to your local SQLite database. A simple data synchronization mechanism allows you to initially populate your local database, and to inform you of the changes that would be pushed to the server.
NOTE: Make sure you install Google Gears before running the application. Also, depending on the browser you use, make sure you check the security bar at the top of the content area: you may be required to explicitely allow Google Gears plugin (ActiveX in IE) to execute.
Part 1: Using the local database and simple data sync
- Click here to start the application.
- Click the Search button in the left drawer. Notice that there is no data (you haven’t populated your local database yet).
- Optionally start the SQLAdmin tool in another browser window/tab.
- Enter “salesbuilder” as the database name
- Click “New Query” in the menu bar
- Type “select * from account” or “select * from contact”: no data
- In the SalesBuilder app, click the Sync button in the menu bar.
- Click the Search Button again: You now have data.
- If you started the SQLAdmin app, click the Execute button again and notice that your local database has been populated.
- In the SalesBuilder app, double-Click “Adobe” in the search results.
- Note that this is an MDI type of user interface. The list of open windows (panels) is available under “Open Items” in the drawer. You can click an item to restore it.
- Make some changes to the Adobe data (for example, change the phone number), and click “Save”.
- Click the Sync button again.
- On the Contacts tab, you can grab an org chart item with the mouse and move it around.
- To open the details view for a contact, either double-click an org chart item, or click “Show Grid” and double-click a contact in the datagrid.
- On the Market History tab, you can grab the chart with the mouse and move it left and right, adjust the time selection using the dividers in the bottom chart, etc.
- Continue to add and modify accounts and contacts, and click the Sync button to simulate data sync with the server.
Part 2: Accessing the application while offline
- Click here to access the application’s offline management page. Note that the options provided on this page could be integrated in the application itself.
- Click the Capture button. Wait a few seconds until the status message indicates that the application is available offline. The application has now been saved locally (in a Google Gears Managed Store).
- Disconnect from the network and disable your wireless connection.
- Clear your browser cache to make sure the application won’t be served from the cache
- Access the application again using its normal URL: http://coenraets.org/salesbuilder/salesbuilder.html
- You have access to the application and to your local database.
Source Code and Disclaimer
Click here to download the source code of the application.
It was definitely interesting to build this application and use some well known data access patterns at the client side of a web app. Look for example at the data access objects: AccountDAO and ContactDAO. In this application, I’m embedding SQL statements directly in the data access objects, but it is inevitable that layers of abstraction, ORM and data synchronization solutions will soon be available on top of the low level Gears API. In fact, the Flex Data Services provide a data synchronization API that could be integrated with Gears.
This application is a proof of concept and not a full featured application. Some modules of the application (like opportunities and activities) are not implemented in this version.
Kevin also demonstrated an Apollo version of the same application. The Apollo version runs outside the browser just like a traditional desktop application. As such it also has additional features, like drag-and-drop between the app and the desktop, access to the file system, etc. I will make that version available as soon as the new Apollo beta goes public (very soon).