Data Push in Data Access

To give you an example of BlazeDS at work, we’re going to revisit the Café Townsend application and bring it even closer to reality. It’s great that the Café owner’s wife can populate (and update) employee data from a database, but in the real world of enterprise applications, more than one user often must work with the same data.

Say that users A and B have populated the employees’ data, and user B decides to update a record in the database. Will user A be notified about this change, or will she keep working with stale data?

You want multiple users to be able to update the table Employee simultaneously and to promote the data changes to other users instantaneously. Such data synchronization is available with LCDS Data Management Services, and with adjustments, you can achieve similar functionality using the open source implementation of AMF as well.

To start, examine the Assembler class that will be working closely with EmployeeDAO. As you can see in Example 6-23, the Java code takes all the changes submitted by any user and broadcasts them to all clients subscribed to the destination com.farata.datasource.Employee.getEmployees.

Example 6-23. Server-side push with the Assembler class

package com.farata.datasource; import java.util.*; import flex.messaging.MessageBroker; import flex.messaging.messages.AsyncMessage; import flex.messaging.util.UUIDUtils; public final class EmployeeAssembler{ public List /*EmployeeDTO[]*/ getEmployees() throws Exception { return ...

Get Agile Enterprise Application Development with Flex now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.