Dashboard > RIFE > ... > Database > Row processors
RIFE Log In | Sign Up   View a printable version of the current page.
Row processors


Added by Steven Grimm, last edited by Steven Grimm on Jul 18, 2006
Labels: 
(None)

In the database chapter of the user's guide, we used a simple row processor, that takes rows from the database and appends the information as blocks in a template.

Row processors can be used in a more powerful way than that. A nice pattern that can be useful if you need to reuse a processor in various places in different ways, is to do as following: Create an abstract row processor class that implements the processRow method and gets the data from the result set as usual. Then it calls an abstract method, that you can be overridden in a subclass, to perform the actual work.

An abstract row processor
public boolean processRow(ResultSet resultSet)
throws SQLException
{
  String name = resultSet.getString("name");

  if (name != null)
  {
    gotName(name);
  }
}

protected abstract gotName(String name);

This allows you to reuse the row processor and change its behavior instead of writing a new one every time. Since the actual logic of accessing the resultset and column names is isolated in one worker method, any class that extends this abstract row processor doesn't have to know the slightest single bit about the actual structure of the database itself.

You could even make the abstract row processor implement an interface that only declares the abstract methods and make your application completely independent of the fact that the data is provided through a database.



Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators