Skip to content

Commit

Permalink
fix: the issue of the ranking value of the edge object cannot be filled.
Browse files Browse the repository at this point in the history
  • Loading branch information
CorvusYe committed Apr 15, 2024
1 parent 42387fb commit 9ff7938
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This source code is licensed under Apache 2.0 License.

- fix: complete the error code of ResultSet into QueryException.
- fix: the issue of not being able to handle Set type.
- fix: the issue of the ranking value of the edge object cannot be filled.

## Dependencies upgrade

Expand Down
23 changes: 20 additions & 3 deletions src/main/java/org/nebula/contrib/ngbatis/utils/ResultSetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
import com.vesoft.nebula.client.graph.data.TimeWrapper;
import com.vesoft.nebula.client.graph.data.ValueWrapper;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -307,6 +305,7 @@ public static <T> T relationshipToResultType(Relationship r, Class<T> resultType
for (Map.Entry<String, ValueWrapper> entry : properties.entrySet()) {
ReflectUtil.setValue(t, entry.getKey(), ResultSetUtil.getValue(entry.getValue()));
}
setRanking(t, resultType, r);
} catch (UnsupportedEncodingException | InstantiationException
| NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
Expand Down Expand Up @@ -344,13 +343,31 @@ public static void relationshipToResultType(Object o, String fieldName,
* v 中,通过 id(n) 获取到的类型不匹配时报错
*/
public static void setId(Object obj, Class<?> resultType, Node v)
throws IllegalAccessException {
throws IllegalAccessException {
Field pkField = getPkField(resultType);
ValueWrapper idWrapper = v.getId();
Object id = ResultSetUtil.getValue(idWrapper);
ReflectUtil.setValue(obj, pkField, id);
}

/**
* <p> 从 resultType 中获取到用 @Id 注解的属性,
* 并将 relationship 对象的 ranking 属性的值填入 </p>
* @param obj 边的 java 对象
* @param resultType 边的 java 对象的类型
* @param e nebula 中的关系对象
* @throws IllegalAccessException
*/
public static void setRanking(Object obj, Class<?> resultType, Relationship e)
throws IllegalAccessException {
Field pkField = getPkField(resultType, false);
if (pkField == null) {
return;
}
long ranking = e.ranking();
ReflectUtil.setValue(obj, pkField, ranking);
}

/**
* Set java entity attributes from Node's properties.
* 兼容多标签,对 java 对象进行按标签设属性值。
Expand Down

0 comments on commit 9ff7938

Please sign in to comment.