|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
java.lang.Objectorg.apache.commons.dbutils.handlers.KeyedHandler
public class KeyedHandler
ResultSetHandler implementation that returns a Map of Maps.
ResultSet rows are converted into Maps which are then stored
in a Map under the given key. Although this implementation uses Maps to
store row contents, subclasses are encouraged to override the
createRow() method to convert the rows into any kind of object.
If you had a Person table with a primary key column called ID, you could retrieve rows from the table like this:
ResultSetHandler h = new KeyedHandler("id");
Map found = (Map) queryRunner.query("select id, name, age from person", h);
Map jane = (Map) found.get(new Long(1)); // jane's id is 1
String janesName = (String) jane.get("name");
Integer janesAge = (Integer) jane.get("age");
Note that the "id" passed to KeyedHandler and "name" and "age" passed to the
returned Map's get() method can be in any case. The data types returned for
name and age are dependent upon how your JDBC driver converts SQL column
types from the Person table into Java types.
To avoid these type issues you could subclass KeyedHandler and override
createRow() to store rows in Java bean instances (ie. a
Person class).
This class is thread safe.
ResultSetHandler| コンストラクタの概要 | |
|---|---|
KeyedHandler()
Creates a new instance of KeyedHandler. |
|
KeyedHandler(int columnIndex)
Creates a new instance of KeyedHandler. |
|
KeyedHandler(RowProcessor convert)
Creates a new instance of KeyedHandler. |
|
KeyedHandler(java.lang.String columnName)
Creates a new instance of KeyedHandler. |
|
| メソッドの概要 | |
|---|---|
java.lang.Object |
handle(java.sql.ResultSet rs)
Convert each row's columns into a Map and store then in a Map under ResultSet.getObject(key) key. |
| クラス java.lang.Object から継承されたメソッド |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| コンストラクタの詳細 |
|---|
public KeyedHandler()
public KeyedHandler(RowProcessor convert)
convert - The RowProcessor implementation
to use when converting rows into Mapspublic KeyedHandler(int columnIndex)
columnIndex - The values to use as keys in the Map are
retrieved from the column at this index.public KeyedHandler(java.lang.String columnName)
columnName - The values to use as keys in the Map are
retrieved from the column with this name.| メソッドの詳細 |
|---|
public java.lang.Object handle(java.sql.ResultSet rs)
throws java.sql.SQLException
Map under ResultSet.getObject(key) key.
ResultSetHandler 内の handlers - The ResultSet to handle. It has not been touched
before being passed to this method.
Map of Maps, never null.
java.sql.SQLException - if a database access error occursResultSetHandler.handle(java.sql.ResultSet)
|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||