com.ibatis.sqlmap.client.event
Interface RowHandler

All Known Implementing Classes:
DefaultRowHandler, RowHandlerAdapter, SqlMapSessionImpl.DeprecatedRowHandlerAdapter

public interface RowHandler

Event handler for row by row processing.

The RowHandler interface is used by the SqlMapSession.queryWithRowHandler() method. Generally a RowHandler implementation will perform some row-by-row processing logic in cases where there are too many rows to efficiently load into memory.

Example:

 sqlMap.queryWithRowHandler ("findAllEmployees", null, new MyRowHandler()));
 


Method Summary
 void handleRow(java.lang.Object valueObject)
          Handles a single row of a result set.
 void handleRow(java.lang.Object valueObject, java.util.List list)
          Deprecated. THIS WILL BE REMOVED BY FINAL RELEASE

Use RowHandler.handleRow(Object) instead.

queryForList(String,Object,RowHandler) has been renamed BACK to queryWithRowHandler(String,Object,RowHandler). The new signature is:

void queryWithRowHandler(String id, Object parameterObject, RowHandler rowHandler) throws SQLException;

The RowHandler interface will also be changed back to the original strategy used in 1.x. That is, there will no longer be a List parameter in the method signature of the handleRow() method. The new signature is:

public void handleRow(Object valueObject);

This was necessary to make the API more flexible. Many people complained about the change because they did not want to return a list. They may have been using a RowHandler to build a Map, or even aggregate into a single result object. In these cases the List parameter and return type on the RowHandler API was unecessary, confusing and extra overhead.

WHAT SHOULD YOU DO?

Well, basically your RowHandlers will need to be changed to handle the List themselves. For example:

                                                 

----------------------------
// OLD WAY

public class MyRowHandler imlements RowHandler {
public void handleRow(Object valueObject, List list) {
list.add(valueObject);
}
}

// NEW WAY

public class MyNewRowHandler imlements RowHandler {
private List list = new ArrayList();
public void handleRow(Object valueObject) {
list.add(valueObject);
}
public List getList () {
return list;
}
}
----------------------------

Obviously the calling code will need to be changed too. For example:

----------------------------
// OLD WAY
RowHandler rowHandler = new MyRowHandler();
List list = sqlMap.queryForList("name", param, rowHandler);

// NEW WAY

RowHandler rowHandler = new MyNewRowHandler();
sqlMap.queryWithRowHandler("name", param, rowHandler);
List list = rowHandler.getList();
----------------------------

The cost is a few extra lines of code, but the benefit is a great deal of
flexibility and eliminated redundancy.
 

Method Detail

handleRow

public void handleRow(java.lang.Object valueObject)
Handles a single row of a result set.

This method will be called for each row in a result set. For each row the result map will be applied to build the value object, which is then passed in as the valueObject parameter.

Parameters:
valueObject - The object representing a single row from the query.
See Also:
SqlMapSession

handleRow

public void handleRow(java.lang.Object valueObject,
                      java.util.List list)
Deprecated. THIS WILL BE REMOVED BY FINAL RELEASE

Use RowHandler.handleRow(Object) instead.

queryForList(String,Object,RowHandler) has been renamed BACK to queryWithRowHandler(String,Object,RowHandler). The new signature is:

void queryWithRowHandler(String id, Object parameterObject, RowHandler rowHandler) throws SQLException;

The RowHandler interface will also be changed back to the original strategy used in 1.x. That is, there will no longer be a List parameter in the method signature of the handleRow() method. The new signature is:

public void handleRow(Object valueObject);

This was necessary to make the API more flexible. Many people complained about the change because they did not want to return a list. They may have been using a RowHandler to build a Map, or even aggregate into a single result object. In these cases the List parameter and return type on the RowHandler API was unecessary, confusing and extra overhead.

WHAT SHOULD YOU DO?

Well, basically your RowHandlers will need to be changed to handle the List themselves. For example:

                                                 

----------------------------
// OLD WAY

public class MyRowHandler imlements RowHandler {
public void handleRow(Object valueObject, List list) {
list.add(valueObject);
}
}

// NEW WAY

public class MyNewRowHandler imlements RowHandler {
private List list = new ArrayList();
public void handleRow(Object valueObject) {
list.add(valueObject);
}
public List getList () {
return list;
}
}
----------------------------

Obviously the calling code will need to be changed too. For example:

----------------------------
// OLD WAY
RowHandler rowHandler = new MyRowHandler();
List list = sqlMap.queryForList("name", param, rowHandler);

// NEW WAY

RowHandler rowHandler = new MyNewRowHandler();
sqlMap.queryWithRowHandler("name", param, rowHandler);
List list = rowHandler.getList();
----------------------------

The cost is a few extra lines of code, but the benefit is a great deal of
flexibility and eliminated redundancy.

TODO : Deprecated and will be removed.

See Also:
handleRow(Object)