Adobe® LiveCycle® Data Services ES 2.6 Developer Guide

The query approach

You can implement a relationship between two objects by using queries where one of the parameters of a fill() method in the assembler is the identity property (defined in a destination definition in the data-management-config.xml file) of the related object. The query approach is more efficient for large collections of objects than the managed association approach. For example, it would make sense to use it if you have a Company object that has a large number of Employee instances.

The following code from the CRM sample application shows the crm-company destination definition, which declares the companyId property as the identity property:

<destination id="crm-company">
    <adapter ref="java-dao" />
    <properties>
        <source>flex.samples.crm.company.CompanyAssembler</source>
        <scope>application</scope>
        <metadata>
            <identity property="companyId"/>
        </metadata>
        ...
    </properties>
</destination>

The following example shows the fill() method of the EmployeeAssembler class in the CRM application. The boldface text highlights the part of the method that finds employees by company, based on the numeric company.companyId property value provided in a client's fill request.

...
public Collection fill(List fillParameters){
    if (fillParameters.size() == 0){
        return dao.getEmployees();
    }
    String queryName = (String) fillParameters.get(0);
    if (queryName.equals("by-name"))
        return dao.findEmployeesByName((String) fillParameters.get(1));
    if (queryName.equals("by-company"))
        return dao.findEmployeesByCompany((Integer) fillParameters.get(1));
    return super.fill(fillParameters); // throws a nice error
    }

The boldface code in the following example is the corresponding client-side fill request that gets employees by company:

private function companyChange():void {
    if (dg.selectedIndex > -1)
    {
        if (company != companies.getItemAt(dg.selectedIndex))
        {
            company = Company(companies.getItemAt(dg.selectedIndex));
            dsEmployee.fill(employees, "byCompany",
            company.companyId);
        }
    }
}

The query approach to implementing a relationship has some characteristics that make it not appropriate for all situations. When you change an employee companyId, the Data Management Service must update the results of the fill methods affected by that change for clients that display the list of employees to be updated automatically. By default, it uses the auto-refresh feature to re-execute every outstanding fill method that returns employees. You can adjust this behavior to avoid re-executing these queries so aggressively, but that requires some additional coding in your assembler.

The query approach also does not detect conflicts when you update that association. You would not want to detect a conflict if two clients added an employee to the same company at roughly the same time, but you could want to detect a conflict if two clients simultaneously update addresses for the same customer. With managed association properties, you can use the Data Management Service conflict detection mechanism to detect data conflicts on the complete contents of the collections; however, with a fill method, conflicts are only detected on the properties of the item, not the filled collection the item was returned in.

The CRM application implements a relationship between companies and employees in the fill() method of the EmployeeAssembler class. The source code for the Java assembler and DAO classes are in the WEB_INF/src/flex/samples/crm directory of the lcds-samples web application.


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/lcds/dms_managedobjects_4.html