提交 0b2d5ad0 编写于 作者: 菜鸟阿达's avatar 菜鸟阿达

修复返回值为option时 缓存的key问题

上级 589ed422
...@@ -27,7 +27,16 @@ import org.springframework.jdbc.core.ColumnMapRowMapper; ...@@ -27,7 +27,16 @@ import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SingleColumnRowMapper; import org.springframework.jdbc.core.SingleColumnRowMapper;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/** /**
* 支持DAO方法返回类型: * 支持DAO方法返回类型:
...@@ -113,13 +122,16 @@ public class DefaultRowMapperFactory implements RowMapperFactory { ...@@ -113,13 +122,16 @@ public class DefaultRowMapperFactory implements RowMapperFactory {
} else { } else {
boolean checkColumns = (rowHandler == null) || rowHandler.checkColumns(); boolean checkColumns = (rowHandler == null) || rowHandler.checkColumns();
boolean checkProperties = (rowHandler != null) && rowHandler.checkProperties(); boolean checkProperties = (rowHandler != null) && rowHandler.checkProperties();
String key = rowType.getName() + "[checkColumns=" + checkColumns
+ "&checkProperties=" + checkProperties + "]";
rowMapper = rowMappers.get(key);
if (rowMapper == null) {
boolean toOptional = rowType == Optional.class; boolean toOptional = rowType == Optional.class;
if (toOptional) {
Class<?>[] genericReturnTypes = modifier.getGenericReturnTypes(); Class<?>[] genericReturnTypes = modifier.getGenericReturnTypes();
StringBuilder key = new StringBuilder(rowType.getName());
key.append("[checkColumns=").append(checkColumns).append("&checkProperties=").append(checkProperties);
if (genericReturnTypes != null && genericReturnTypes.length == 1) {
key.append("&genericReturnTypes=").append(genericReturnTypes[0].getTypeName());
}
rowMapper = rowMappers.get(key.append("]").toString());
if (rowMapper == null) {
if (toOptional) {
if (genericReturnTypes == null || genericReturnTypes.length != 1) { if (genericReturnTypes == null || genericReturnTypes.length != 1) {
throw new JadeExcetion("option generic paradigm [T] is null or length not equal to 1"); throw new JadeExcetion("option generic paradigm [T] is null or length not equal to 1");
} }
...@@ -128,7 +140,7 @@ public class DefaultRowMapperFactory implements RowMapperFactory { ...@@ -128,7 +140,7 @@ public class DefaultRowMapperFactory implements RowMapperFactory {
// jade's BeanPropertyRowMapper here // jade's BeanPropertyRowMapper here
rowMapper = rowMapper =
new BeanPropertyRowMapper(rowType, checkColumns, checkProperties, toOptional); new BeanPropertyRowMapper(rowType, checkColumns, checkProperties, toOptional);
rowMappers.put(key, rowMapper); rowMappers.put(key.toString(), rowMapper);
} }
} }
// 如果DAO方法最终返回的是Map,rowMapper要返回Map.Entry对象 // 如果DAO方法最终返回的是Map,rowMapper要返回Map.Entry对象
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册