org.apache.commons.dbutils.handlers
Class AbstractKeyedHandler<K,V>

java.lang.Object
  extended by org.apache.commons.dbutils.handlers.AbstractKeyedHandler<K,V>
Type Parameters:
K - the type of keys maintained by the returned map
V - the type of mapped values
All Implemented Interfaces:
ResultSetHandler<Map<K,V>>
Direct Known Subclasses:
KeyedHandler

public abstract class AbstractKeyedHandler<K,V>
extends Object
implements ResultSetHandler<Map<K,V>>

ResultSetHandler implementation that returns a Map. ResultSet rows are converted into objects (Vs) which are then stored in a Map under the given keys (Ks).

Since:
DbUtils 1.3
See Also:
ResultSetHandler

Constructor Summary
AbstractKeyedHandler()
           
 
Method Summary
protected abstract  K createKey(ResultSet rs)
          This factory method is called by handle() to retrieve the key value from the current ResultSet row.
protected  Map<K,V> createMap()
          This factory method is called by handle() to create the Map to store records in.
protected abstract  V createRow(ResultSet rs)
          This factory method is called by handle() to store the current ResultSet row in some object.
 Map<K,V> handle(ResultSet rs)
          Convert each row's columns into a Map and store then in a Map under ResultSet.getObject(key) key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractKeyedHandler

public AbstractKeyedHandler()
Method Detail

handle

public Map<K,V> handle(ResultSet rs)
                throws SQLException
Convert each row's columns into a Map and store then in a Map under ResultSet.getObject(key) key.

Specified by:
handle in interface ResultSetHandler<Map<K,V>>
Parameters:
rs - ResultSet to process.
Returns:
A Map, never null.
Throws:
SQLException - if a database access error occurs
See Also:
ResultSetHandler.handle(java.sql.ResultSet)

createMap

protected Map<K,V> createMap()
This factory method is called by handle() to create the Map to store records in. This implementation returns a HashMap instance.

Returns:
Map to store records in

createKey

protected abstract K createKey(ResultSet rs)
                        throws SQLException
This factory method is called by handle() to retrieve the key value from the current ResultSet row.

Parameters:
rs - ResultSet to create a key from
Returns:
K from the configured key column name/index
Throws:
SQLException - if a database access error occurs

createRow

protected abstract V createRow(ResultSet rs)
                        throws SQLException
This factory method is called by handle() to store the current ResultSet row in some object.

Parameters:
rs - ResultSet to create a row from
Returns:
V object created from the current row
Throws:
SQLException - if a database access error occurs


Copyright © 2002-2011 The Apache Software Foundation. All Rights Reserved.