Package org.apache.commons.dbutils
Class BasicRowProcessor
- java.lang.Object
-
- org.apache.commons.dbutils.BasicRowProcessor
-
- All Implemented Interfaces:
RowProcessor
public class BasicRowProcessor extends java.lang.Object implements RowProcessor
Basic implementation of theRowProcessor
interface.This class is thread-safe.
- See Also:
RowProcessor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BasicRowProcessor.CaseInsensitiveHashMap
A Map that converts all keys to lowercase Strings for case insensitive lookups.
-
Field Summary
Fields Modifier and Type Field Description private BeanProcessor
convert
Use this to process beans.private static BeanProcessor
defaultConvert
The default BeanProcessor instance to use if not supplied in the constructor.private static BasicRowProcessor
instance
The Singleton instance of this class.
-
Constructor Summary
Constructors Constructor Description BasicRowProcessor()
BasicRowProcessor constructor.BasicRowProcessor(BeanProcessor convert)
BasicRowProcessor constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected static java.util.Map<java.lang.String,java.lang.Object>
createCaseInsensitiveHashMap(int cols)
static BasicRowProcessor
instance()
Deprecated.Create instances with the constructors instead.java.lang.Object[]
toArray(java.sql.ResultSet rs)
Convert aResultSet
row into anObject[]
.<T> T
toBean(java.sql.ResultSet rs, java.lang.Class<? extends T> type)
Convert aResultSet
row into a JavaBean.<T> java.util.List<T>
toBeanList(java.sql.ResultSet rs, java.lang.Class<? extends T> type)
Convert aResultSet
into aList
of JavaBeans.java.util.Map<java.lang.String,java.lang.Object>
toMap(java.sql.ResultSet rs)
Convert aResultSet
row into aMap
.
-
-
-
Field Detail
-
defaultConvert
private static final BeanProcessor defaultConvert
The default BeanProcessor instance to use if not supplied in the constructor.
-
instance
private static final BasicRowProcessor instance
The Singleton instance of this class.
-
convert
private final BeanProcessor convert
Use this to process beans.
-
-
Constructor Detail
-
BasicRowProcessor
public BasicRowProcessor()
BasicRowProcessor constructor. Bean processing defaults to a BeanProcessor instance.
-
BasicRowProcessor
public BasicRowProcessor(BeanProcessor convert)
BasicRowProcessor constructor.- Parameters:
convert
- The BeanProcessor to use when converting columns to bean properties.- Since:
- DbUtils 1.1
-
-
Method Detail
-
createCaseInsensitiveHashMap
protected static java.util.Map<java.lang.String,java.lang.Object> createCaseInsensitiveHashMap(int cols)
-
instance
@Deprecated public static BasicRowProcessor instance()
Deprecated.Create instances with the constructors instead. This will be removed after DbUtils 1.1.Returns the Singleton instance of this class.- Returns:
- The single instance of this class.
-
toArray
public java.lang.Object[] toArray(java.sql.ResultSet rs) throws java.sql.SQLException
Convert aResultSet
row into anObject[]
. This implementation copies column values into the array in the same order they're returned from theResultSet
. Array elements will be set tonull
if the column was SQL NULL.- Specified by:
toArray
in interfaceRowProcessor
- Parameters:
rs
- ResultSet that supplies the array data- Returns:
- the newly created array
- Throws:
java.sql.SQLException
- if a database access error occurs- See Also:
RowProcessor.toArray(java.sql.ResultSet)
-
toBean
public <T> T toBean(java.sql.ResultSet rs, java.lang.Class<? extends T> type) throws java.sql.SQLException
Convert aResultSet
row into a JavaBean. This implementation delegates to a BeanProcessor instance.- Specified by:
toBean
in interfaceRowProcessor
- Type Parameters:
T
- The type of bean to create- Parameters:
rs
- ResultSet that supplies the bean datatype
- Class from which to create the bean instance- Returns:
- the newly created bean
- Throws:
java.sql.SQLException
- if a database access error occurs- See Also:
RowProcessor.toBean(java.sql.ResultSet, java.lang.Class)
,BeanProcessor.toBean(java.sql.ResultSet, java.lang.Class)
-
toBeanList
public <T> java.util.List<T> toBeanList(java.sql.ResultSet rs, java.lang.Class<? extends T> type) throws java.sql.SQLException
Convert aResultSet
into aList
of JavaBeans. This implementation delegates to a BeanProcessor instance.- Specified by:
toBeanList
in interfaceRowProcessor
- Type Parameters:
T
- The type of bean to create- Parameters:
rs
- ResultSet that supplies the bean datatype
- Class from which to create the bean instance- Returns:
- A
List
of beans with the given type in the order they were returned by theResultSet
. - Throws:
java.sql.SQLException
- if a database access error occurs- See Also:
RowProcessor.toBeanList(java.sql.ResultSet, java.lang.Class)
,BeanProcessor.toBeanList(java.sql.ResultSet, java.lang.Class)
-
toMap
public java.util.Map<java.lang.String,java.lang.Object> toMap(java.sql.ResultSet rs) throws java.sql.SQLException
Convert aResultSet
row into aMap
.This implementation returns a
Map
with case insensitive column names as keys. Calls tomap.get("COL")
andmap.get("col")
return the same value. Furthermore this implementation will return an ordered map, that preserves the ordering of the columns in the ResultSet, so that iterating over the entry set of the returned map will return the first column of the ResultSet, then the second and so forth.- Specified by:
toMap
in interfaceRowProcessor
- Parameters:
rs
- ResultSet that supplies the map data- Returns:
- the newly created Map
- Throws:
java.sql.SQLException
- if a database access error occurs- See Also:
RowProcessor.toMap(java.sql.ResultSet)
-
-