The solution

Coding the solution involves these steps:

Create a class variable to hold the DAO

This step is identical to that in You want to read some data from a database table above.

Use the DAO to retrieve all the instances of the entity

In your façade method, code a variable to hold a set of instances of the entity interface, and set its value by calling.readAll() on the DAO:

Figure 1. Calling a DAO method to read multiple entity instances
// retrieve all the instances of the entity
    final Set<SomeEntity> someEntities = someEntityDAO.readAll();
Note that (in this particular example):
  • the DAO readAll method returns a Set, typed with the entity interface (SomeEntity); and
  • this scenario assumes that the API designer created a readAll method on the DAO (it does not have one by default).

Iterate the set of entity instances and access these instances to map field values to the client struct

Now code a loop which iterates the set retrieved, and maps each instance to the client struct. Note that since a Set is used, the Java 5 syntax for "for" loops can be used:

Figure 2. Iterating through multiple entity instances
// map the details returned
    for (final SomeEntity someEntity : someEntities) {
      final SomeEntitySummaryDetails someEntitySummaryDetails =
        new SomeEntitySummaryDetails();
      someEntitySummaryDetails.someEntityID = someEntity.getID();
      someEntitySummaryDetails.name = someEntity.getName();

      list.details.addRef(someEntitySummaryDetails);
    }