private Map<String, RowMapper> rowMappers = new HashMap<String, RowMapper>();
@Override
public RowMapper getRowMapper(StatementMetaData modifier) {
RowHandler rowHandler = modifier.getAnnotation(RowHandler.class);
if (rowHandler != null) {
if (rowHandler.rowMapper() != RowHandler.ByDefault.class) {
try {
RowMapper rowMapper = rowHandler.rowMapper().newInstance();
if (logger.isInfoEnabled()) {
logger.info("using rowMapper " + rowMapper + " for " + modifier);
}
return rowMapper;
} catch (Exception ex) {
throw new BeanInstantiationException(rowHandler.rowMapper(), ex.getMessage(),
ex);
}
}
}
//
Class<?> returnClassType = modifier.getMethod().getReturnType();
Class<?> rowType = getRowType(modifier);
// BUGFIX: SingleColumnRowMapper 处理 Primitive Type 抛异常
if (rowType.isPrimitive()) {
rowType = ClassUtils.primitiveToWrapper(rowType);
}
// 根据类型创建 RowMapper
RowMapper rowMapper;
// 返回单列的查询的(或者返回只有2列的Map类型查询的)
if (TypeUtils.isColumnType(rowType)) {
if (returnClassType == Map.class) {
rowMapper = new MapEntryColumnRowMapper(modifier, rowType);
} else {
rowMapper = new SingleColumnRowMapper(rowType);
}
}
// 返回多列的,用Bean对象、集合、映射、数组来表示每一行的
else {
if (rowType == Map.class) {
rowMapper = new ColumnMapRowMapper();
} else if (rowType.isArray()) {
rowMapper = new ArrayRowMapper(rowType);
} else if ((rowType == List.class) || (rowType == Collection.class)) {
rowMapper = new ListRowMapper(modifier);
} else if (rowType == Set.class) {
rowMapper = new SetRowMapper(modifier);
} else {
boolean checkColumns = (rowHandler == null) ? true : rowHandler.checkColumns();
boolean checkProperties = (rowHandler == null) ? false : rowHandler
.checkProperties();
String key = rowType.getName() + "[checkColumns=" + checkColumns
+ "&checkProperties=" + checkProperties + "]";
rowMapper = rowMappers.get(key);
if (rowMapper == null) {