com.ibatis.sqlmap.client.extensions
public interface TypeHandlerCallback
Here's a simple example of a boolean handler that uses "Yes" and "No".
public class YesNoBoolTypeHandlerCallback implements TypeHandlerCallback {
private static final String YES = "Yes";
private static final String NO = "No";
public Object getResult(ResultGetter getter) throws SQLException {
String s = getter.getString();
if (YES.equalsIgnoreCase(s)) {
return new Boolean (true);
} else if (NO.equalsIgnoreCase(s)) {
return new Boolean (false);
} else {
throw new SQLException ("Unexpected value " + s + " found where "+YES+" or "+NO+" was expected.");
}
}
public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {
boolean b = ((Boolean)parameter).booleanValue();
if (b) {
setter.setString(YES);
} else {
setter.setString(NO);
}
}
public Object valueOf(String s) {
if (YES.equalsIgnoreCase(s)) {
return new Boolean (true);
} else if (NO.equalsIgnoreCase(s)) {
return new Boolean (false);
} else {
throw new SQLException ("Unexpected value " + s + " found where "+YES+" or "+NO+" was expected.");
}
}
}
| Method Summary | |
|---|---|
| Object | getResult(ResultGetter getter)
Performs processing on a value before after it has been retrieved
from a ResultSet.
|
| void | setParameter(ParameterSetter setter, Object parameter)
Performs processing on a value before it is used to set
the parameter of a PreparedStatement.
|
| Object | valueOf(String s)
Casts the string representation of a value into a type recognized by
this type handler. |
Parameters: getter The interface for getting the value from the ResultSet.
Returns: The processed value.
Throws: SQLException If any error occurs.
Parameters: setter The interface for setting the value on the PreparedStatement. parameter The value to be set.
Throws: SQLException If any error occurs.
Parameters: s A string representation of a valid value for this type.
Returns: One of the following: