Recordset: Create Iterating Domain Objects via Inheritance
Now bundled with its distant cousin, the composite Iterator, Recordset provides methods and properties for list traversal via inheritance. Recordset is not a query, but rather a query that is converted to an array of structs. Extending Recordset is useful as an alternative to maintaining an array of objects, or if you want to display a list with calculated fields (an employee has a startdate, but display format is "years of service").
I chose Recordset as the name, because it provides similar methods to an ADO Recordset.
Recordset has the following public methods:
next():boolean - the next record is set.
previous():boolean - the previous record is set.
reset():void - reset the index.
end():void - set the index to the last record
pageCount():numeric - if pagination is desired, returns the number of pages in the Recordset.
recordCount():numeric - total number of records.
loadQuery():void - accepts a ColdFusion query
setPage():void - set desired page for next iteration (used only with pagination).
How to use Recordset:
If your transient objects do not extend another class, you can simply extend Recordset.
<cfset variables.instance = StructNew() />
...
</cfcomponent>
To display a list of users by role, first instantiate the user list and set the user role and load the list in your controller.
<cfset usersByRoleQuery = variables.UserService.getUsersByRole() />
<cfset userList.loadQuery(usersByRoleQuery) />
Loop through the list in your display view while next() returns true.
{display code}
</cfloop>
Many thanks go out to Aaron Roberson for recommending inheritable iteration among other excellent suggestions that are implemented with this release.


