Synchronizing Data in Apollo using Flex Data Services

contacts3.gif

In my previous post, I provided an example of an Apollo application using the Flex Message Service. Since then, a number of people have asked for examples of Apollo applications accessing data using the Flex Data Management services. So here is a simple Contact Management application that demonstrates this integration.

Using the Data Services to work with data in Apollo offers several benefits. First, just like for traditional browser-based Flex apps, the Data Management Services automate 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: all that is managed automatically.

For this application, I actually used LiveCycle Data Services (the new name for Flex Data Services) 2.5 currently in beta 2, which offer additional benefits in the context of this application:

Installation instructions:

  1. Install LiveCycle Data Services 2.5 beta here
  2. Modify the flexdemosb 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>
    			    
    			    <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> 
    			</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.

Comments

19 Responses to “Synchronizing Data in Apollo using Flex Data Services”

  1. Adam Adamczyk on March 31st, 2007 1:01 pm

    Christoper,

    You have missed channel definition in your destination “sql-contact” settings. At least one channel must be defined. JRun trow following error

    03/31 21:56:58 user MessageBrokerServlet: **** MessageBrokerServlet failed to in
    itialize due to runtime exception: flex.messaging.config.ConfigurationException:
    Destination ’sql-contact’ must specify at least one channel.

  2. najier on April 11th, 2007 8:04 am

    Not bad. But this is too simple. I wonder if Christopher can increase the complexity a little bit to to work with a small object graph. How about grouping the contacts, so we have another object called contact group which has a list of contacts and also factor out the address so that a contact is associated with an address (a shared object). Contacts are lazy loaded.

    This would make a decent practical real-world example and will save thousands of suffering hours by developers.

    …najier

  3. Samuel Flores on April 19th, 2007 11:45 am

    Could you post the services-config.xml file you used for that application? I cannot compile the it and I’m not sure it’s the cause but I would like to look your configs. Thanks.

  4. Sebastien Denis on April 24th, 2007 7:11 am

    I just started my first SQLAssembler app.
    I managed one table. But how do you suggest to manage sub-table (for instance contacts friends).

    In the same DataService (destination)? Then same AS class “Contact.as”. But how to delete reference to one friend? And how doing the binding in the data-management.xml?
    Or in another DataService (destination)?
    Or SQLAssembler is not suitable for this…

    Thanks Christophe…

  5. Brian Cragin on April 25th, 2007 4:59 pm

    Greetings,

    I have visited your site several times and have enjoyed your comments. My company is looking to bolster our web capability (RIAs) and are looking at adding a position that is versed in flex and other relavent programming languages. What type of skillsets would be appropriate or common among flex developers and at what salary do they usually run. I’m sure the answer depends on many variables which I have not described, but we aren’t looking for third-base, only the ballpark. Any information you can provide would be valuable.

  6. Cameron Collins on April 30th, 2007 11:12 am

    I am about to start a multi-year project that will use Flex as the presentation layer technology. However I find it difficult to find any contacts at Adobe to help build the business case for using Flex. Please let me who I need to contact.

    Thanks

  7. Nabeel Kamboh on May 24th, 2007 11:14 am

    I was able to run the application with FDS successfully. I was also able to port the FDS code to run it on Tomcat.
    When I create a new apollo application in eclipse using the source code provided, I get an error in the service-config.xml. Turns out that channels now need to specify uri instead of url, also the default-channel needs to be included in each service not in the services block, also each service must have a messageTypes attribute.

    I made all of these changes and the app still works with the FDS. However, when I create a new Apollo application and run the apollo app using the eclipse builder, I get the following error:

    Error:[FaultEvent fault=[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error undefined url:'rtmp://ewApp.swf:2037'"] messageId=”18583AC9-C52C-9DA6-5F4C-BF42E2CC45CC” type=”fault” bubbles=false cancelable=true eventPhase=2]

    I have the FDS server running and working with the installed air file provided but I get an error when creating a project and running it in eclipse. I am connecting to the same fds provider as the app and doing the same fill operation

    Please advise.

  8. gxwzyrcldw on June 21st, 2007 10:29 pm

    Hello! Good Site! Thanks you! dnprtvfcklg

  9. Ahmed on August 14th, 2007 5:35 am

    Hello Christophe,

    First of all before I introduce myself I would like to compliment you on your amazing efforts in helping developers understand the true powers of Flex 2.0 and AIR. I am a big fan and found of your work on Adobe and your Blog. I have been working on my own in understanding the in-n-outs of Flex and how to create real powerful enterprise applications. I am strong follower of your work on Adobe and your own blog.

    I was trying your app the restaurant app. Finder posted on 15th March 2004. Currently on the Adobe web site. I have combined both the Java test drive with the restaurant app to create a working environment. Your work as helped me a great deal. I have been studying both of your apps, the restaurant search app (url) and the Java test drive. I am very grateful for your amazing efforts. In my learning process I found that your restaurant application is obviously written for the older version of Flex with Macromedia xmlns. I would like to repay your efforts in providing you with my update of the restaurant app to comply with Flex 2.0 in updating all the files including action scripts and functions even creating bind able custom events for the area search and review addition.

    I would be extremely honored to have my updated code reviewed by the top Flex evangelist world wide. Please find attached the following source files and the document that contains the change log on each exercise steps published on the web.

    Please let me know how I can email you my revised code? I was able to complete the restaurant app. But I did not have enough time to convert the restaurant admin app. I would like to complete it when the wife is not looking :p

  10. Synchronizing Data in AIR | Adobe AIR Tutorials on August 26th, 2007 4:59 am
  11. Robert on September 4th, 2007 10:31 am

    can you post the contacts.air for air runtime and not for apollo,please?

  12. sathish on September 19th, 2007 12:40 am

    superbuuuuuuuuuuuuuuuuuu

  13. davis on September 20th, 2007 9:03 pm

    when i use SQLAssembler on mySQL, it can’t display the chinese or janpanes with utf8 encoding on Flex DataGrid. would you please do me a favor?

  14. Nathalie Roman on October 2nd, 2007 7:17 am

    Hi Christophe,

    We’ve met a few weeks ago in Belgium concerning the usage of Flex Data Management Services for our data-driven application.

    This meeting was very useful to have an in-depth view on the most important features of FDMS.

    But I still have a few questions, otherwise it would be to perfect wright ;o))

    My questions:
    First what’s documented in flex2_devguide:
    ‘The Realtime Message Protocol (RTMP) channel maintains a connection between the client
    and the server, so the client does not have to poll the server. The Action Message Format
    (AMF) channel with polling enabled polls the server for new messages.’

    What’s confusing here is that FDMS works with a push-system to synchronize data instead of a poll-system - which is mentioned in the text above - to make sure that all client-app’s are working on the same up-to-date data.

    Could you elaborate if the usage of sprecific channel-types can interfere with the synchronization-mechanism of FDMS?

    Kind regards,
    Nathalie

  15. Christophe Coenraets » Offline Synchronization using AIR and LiveCycle Data Services on October 26th, 2007 1:05 pm

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

  16. chat on August 22nd, 2008 6:43 am

    super! :)

  17. sohbet on August 22nd, 2008 6:44 am

    Great ;)

  18. çet on August 22nd, 2008 6:45 am

    Güzel bilgiler.

  19. Adobe LCDS « SrikanthCreative Mind’s Weblog on October 27th, 2008 7:03 am

    [...] Christophe Coenraets :: Synchronizing Data in Apollo using Flex Data Services [...]

Leave a Reply