Class AbstractKeyedHandler<K,V>
- java.lang.Object
-
- org.apache.commons.dbutils.handlers.AbstractKeyedHandler<K,V>
-
- Type Parameters:
K
- the type of keys maintained by the returned mapV
- the type of mapped values
- All Implemented Interfaces:
ResultSetHandler<java.util.Map<K,V>>
- Direct Known Subclasses:
BeanMapHandler
,KeyedHandler
public abstract class AbstractKeyedHandler<K,V> extends java.lang.Object implements ResultSetHandler<java.util.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
Constructors Constructor Description AbstractKeyedHandler()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract K
createKey(java.sql.ResultSet rs)
This factory method is called byhandle()
to retrieve the key value from the currentResultSet
row.protected java.util.Map<K,V>
createMap()
This factory method is called byhandle()
to create the Map to store records in.protected abstract V
createRow(java.sql.ResultSet rs)
This factory method is called byhandle()
to store the currentResultSet
row in some object.java.util.Map<K,V>
handle(java.sql.ResultSet rs)
Convert each row's columns into a Map and store then in aMap
underResultSet.getObject(key)
key.
-
-
-
Method Detail
-
handle
public java.util.Map<K,V> handle(java.sql.ResultSet rs) throws java.sql.SQLException
Convert each row's columns into a Map and store then in aMap
underResultSet.getObject(key)
key.- Specified by:
handle
in interfaceResultSetHandler<K>
- Parameters:
rs
-ResultSet
to process.- Returns:
- A
Map
, nevernull
. - Throws:
java.sql.SQLException
- if a database access error occurs- See Also:
ResultSetHandler.handle(java.sql.ResultSet)
-
createMap
protected java.util.Map<K,V> createMap()
This factory method is called byhandle()
to create the Map to store records in. This implementation returns aHashMap
instance.- Returns:
- Map to store records in
-
createKey
protected abstract K createKey(java.sql.ResultSet rs) throws java.sql.SQLException
This factory method is called byhandle()
to retrieve the key value from the currentResultSet
row.- Parameters:
rs
- ResultSet to create a key from- Returns:
- K from the configured key column name/index
- Throws:
java.sql.SQLException
- if a database access error occurs
-
createRow
protected abstract V createRow(java.sql.ResultSet rs) throws java.sql.SQLException
This factory method is called byhandle()
to store the currentResultSet
row in some object.- Parameters:
rs
- ResultSet to create a row from- Returns:
- V object created from the current row
- Throws:
java.sql.SQLException
- if a database access error occurs
-
-