Skip to content

Commit

Permalink
Merge pull request #268 from CorvusYe/master
Browse files Browse the repository at this point in the history
fix: remove unnecessary reflections in transformDateTime
  • Loading branch information
CorvusYe authored Nov 28, 2023
2 parents 2ceade1 + 13b8426 commit adbf0c4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This source code is licensed under Apache 2.0 License.

- [ ] Springboot 3.x support.

# 1.2.0
# 1.2.0-SNAPSHOT

## Dependencies upgrade

Expand Down Expand Up @@ -63,6 +63,7 @@ This source code is licensed under Apache 2.0 License.
> 如原来项目中分页相关接口,用了不起作用的 `@Param`, 但 xml 还是使用 p0, p1...
> 需要将 `@Param` 移除,或者将 xml 中的参数名改成 注解的参数名,以保证参数名统一
- fix:class 'ResultSetUtil.java' parse datetime type error. ([#241](https://github.com/nebula-contrib/ngbatis/pull/241), via [爱吃辣条的Jerry](https://github.com/bobobod))
- fix: remove unnecessary reflections in transformDateTime, and prevents errors in the millisecond bit in jdk17.

## Develop behavior change

Expand Down
2 changes: 1 addition & 1 deletion ngbatis-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>org.nebula-contrib</groupId>
<artifactId>ngbatis</artifactId>
<version>1.2.0</version>
<version>1.2.0-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<name>ngbatis</name>
<groupId>org.nebula-contrib</groupId>
<artifactId>ngbatis</artifactId>
<version>1.2.0</version>
<version>1.2.0-SNAPSHOT</version>

<developers>
<developer>
Expand Down
51 changes: 16 additions & 35 deletions src/main/java/org/nebula/contrib/ngbatis/utils/ResultSetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
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 @@ -69,18 +71,6 @@ public class ResultSetUtil {

public static String type_edge_value = "edge";

private static final Constructor<GregorianCalendar> CALENDAR_CONSTRUCTOR;

static {
try {
CALENDAR_CONSTRUCTOR = GregorianCalendar.class.getDeclaredConstructor(
int.class, int.class, int.class, int.class, int.class, int.class, int.class
);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

/**
* <p>根据nebula graph本身的类型说明,获取对应的 java对象值。</p>
* @param value nebula graph 类型数据,(结果集的元素)
Expand Down Expand Up @@ -128,29 +118,20 @@ public static <T> T getValue(ValueWrapper valueWrapper, Class<T> resultType) {

private static Object transformDateTime(DateTimeWrapper dateTime) {
DateTime localDateTime = dateTime.getLocalDateTime();
try {
CALENDAR_CONSTRUCTOR.setAccessible(true);
GregorianCalendar calendar = CALENDAR_CONSTRUCTOR.newInstance(
localDateTime.getYear(),
localDateTime.getMonth() - 1,
localDateTime.getDay(),
localDateTime.getHour(),
localDateTime.getMinute(),
localDateTime.getSec(),
Math.floorDiv(localDateTime.getMicrosec(), 1000)
);
CALENDAR_CONSTRUCTOR.setAccessible(false);
return calendar.getTime();
} catch (Exception e) {
return new GregorianCalendar(
localDateTime.getYear(),
localDateTime.getMonth() - 1,
localDateTime.getDay(),
localDateTime.getHour(),
localDateTime.getMinute(),
localDateTime.getSec()
).getTime();
}

int month = localDateTime.getMonth() - 1;
GregorianCalendar calendar = new GregorianCalendar(
localDateTime.getYear(),
month,
localDateTime.getDay(),
localDateTime.getHour(),
localDateTime.getMinute(),
localDateTime.getSec()
);

calendar.set(Calendar.MILLISECOND, Math.floorDiv(localDateTime.getMicrosec(), 1000));

return calendar.getTime();
}

private static Object transformDate(DateWrapper date) {
Expand Down

0 comments on commit adbf0c4

Please sign in to comment.