-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
解决同一点的Tag实体类相互独立时,映射的Object类型可能发生错误的问题 #311
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,24 +79,26 @@ public class ResultSetUtil { | |
* @param <T> 目标结果类型 | ||
* @return | ||
*/ | ||
public static <T> T getValue(ValueWrapper value) { | ||
public static <T> T getValue(ValueWrapper value,Class<T> resultType) { | ||
try { | ||
Object o = value.isLong() ? value.asLong() | ||
: value.isBoolean() ? value.asBoolean() | ||
: value.isDouble() ? value.asDouble() | ||
: value.isString() ? value.asString() | ||
: value.isBoolean() ? value.asBoolean() | ||
: value.isDouble() ? value.asDouble() | ||
: value.isString() ? value.asString() | ||
: value.isTime() ? transformTime(value.asTime()) | ||
: value.isDate() ? transformDate(value.asDate()) | ||
: value.isDateTime() ? transformDateTime(value.asDateTime()) | ||
: value.isVertex() ? transformNode(value.asNode()) | ||
: value.isEdge() ? transformRelationship(value) | ||
: value.isPath() ? value.asPath() | ||
: value.isList() ? transformList(value.asList()) | ||
: value.isSet() ? transformSet(value.asSet()) | ||
: value.isMap() ? transformMap(value.asMap()) | ||
: value.isDuration() ? transformDuration(value.asDuration()) | ||
: null; | ||
|
||
: value.isDate() ? transformDate(value.asDate()) | ||
: value.isDateTime() ? transformDateTime(value.asDateTime()) | ||
: value.isVertex() ? transformNode(value.asNode(),resultType) | ||
: value.isEdge() ? transformRelationship(value) | ||
: value.isPath() ? value.asPath() | ||
: value.isList() ? transformList(value.asList()) | ||
: value.isSet() ? transformSet(value.asSet()) | ||
: value.isMap() ? transformMap(value.asMap()) | ||
: value.isDuration() ? transformDuration(value.asDuration()) | ||
: null; | ||
Comment on lines
+89
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我也觉得这个格式看起来会更符合一些,但是代码风格校验会通不过 |
||
if (o instanceof Number) { | ||
o = castNumber((Number) o, resultType); | ||
} | ||
return (T) o; | ||
} catch (UnsupportedEncodingException e) { | ||
throw new RuntimeException(e); | ||
|
@@ -106,15 +108,11 @@ public static <T> T getValue(ValueWrapper value) { | |
/** | ||
* 根据 resultType 从 nebula 的数据类型中获取 java 类型数据 | ||
* @param valueWrapper nebula 的数据类型 | ||
* @param resultType 接口返回值类型(类型为集合时,为集合泛型) | ||
* @param <T> 调用方用来接收结果的类型,即 resultType | ||
* @return java类型结果 | ||
*/ | ||
public static <T> T getValue(ValueWrapper valueWrapper, Class<T> resultType) { | ||
T value = getValue(valueWrapper); | ||
if (value instanceof Number) { | ||
value = (T) castNumber((Number) value, resultType); | ||
} | ||
public static <T> T getValue(ValueWrapper valueWrapper) { | ||
T value = getValue(valueWrapper,null); | ||
return value; | ||
} | ||
|
||
|
@@ -149,16 +147,16 @@ private static Object transformDuration(DurationWrapper du) { | |
return java.time.Duration.ofNanos(du.getSeconds() * 1000000000); | ||
} | ||
|
||
private static Object transformNode(Node node) { | ||
private static Object transformNode(Node node,Class<?> resultType) { | ||
MapperContext mapperContext = MapperProxy.ENV.getMapperContext(); | ||
Map<String, Class<?>> tagTypeMapping = mapperContext.getTagTypeMapping(); | ||
Class<?> nodeType = null; | ||
Class<?> nodeType = resultType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这边可能会导致 nodeType 始终都不为空,可能会影响到现有的 如果无映射类型会将节点转换成 map 的功能。虽然正常不推荐该用法 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果只是找到 tagType 的时候 增加一个判断 resultType和tagType 是否具备继承关系,具备继承关系才赋予 nodeType 为tagType,这样应该可以不影响 转Map |
||
List<String> tagNames = node.tagNames(); | ||
|
||
for (String tagName : tagNames) { | ||
Class<?> tagType = tagTypeMapping.get(tagName); | ||
boolean tagTypeIsSuperClass = isCurrentTypeOrParentType(nodeType, tagType); | ||
if (!tagTypeIsSuperClass) { | ||
if (!tagTypeIsSuperClass && nodeType.isAssignableFrom(tagType)) { | ||
nodeType = tagType; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
公开方法如果要拓展,可能做一层重载会合适一些