Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
29a989e2
提交
29a989e2
authored
11月 03, 2016
作者:
Noel Grandin
提交者:
GitHub
11月 03, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #389 from katzyn/LocalTime
Handle LocalTime with nanosecond resolution
上级
c8333c59
fe6f896b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
17 行删除
+23
-17
LocalDateTimeUtils.java
h2/src/main/org/h2/util/LocalDateTimeUtils.java
+16
-17
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+7
-0
没有找到文件。
h2/src/main/org/h2/util/LocalDateTimeUtils.java
浏览文件 @
29a989e2
...
@@ -63,13 +63,15 @@ public class LocalDateTimeUtils {
...
@@ -63,13 +63,15 @@ public class LocalDateTimeUtils {
// java.sql.Date#toLocalDate()
// java.sql.Date#toLocalDate()
private
static
Method
TO_LOCAL_DATE
;
private
static
Method
TO_LOCAL_DATE
;
// java.sql.Time#toLocalTime()
private
static
Method
TO_LOCAL_TIME
;
// java.time.LocalTime#ofNanoOfDay()
private
static
Method
LOCAL_TIME_OF_NANO
;
// java.sql.Date#valueOf(LocalDate)
// java.sql.Date#valueOf(LocalDate)
private
static
Method
DATE_VALUE_OF
;
private
static
Method
DATE_VALUE_OF
;
// java.sql.Time#valueOf(LocalTime)
private
static
Method
TIME_VALUE_OF
;
// java.time.LocalTime#toNanoOfDay()
private
static
Method
LOCAL_TIME_TO_NANO
;
// java.time.LocalDate#of(int, int, int)
// java.time.LocalDate#of(int, int, int)
private
static
Method
LOCAL_DATE_OF_YEAR_MONTH_DAY
;
private
static
Method
LOCAL_DATE_OF_YEAR_MONTH_DAY
;
...
@@ -145,10 +147,12 @@ public class LocalDateTimeUtils {
...
@@ -145,10 +147,12 @@ public class LocalDateTimeUtils {
Class
<?>
temporal
=
getClass
(
"java.time.temporal.Temporal"
);
Class
<?>
temporal
=
getClass
(
"java.time.temporal.Temporal"
);
TO_LOCAL_DATE
=
getMethod
(
java
.
sql
.
Date
.
class
,
"toLocalDate"
);
TO_LOCAL_DATE
=
getMethod
(
java
.
sql
.
Date
.
class
,
"toLocalDate"
);
TO_LOCAL_TIME
=
getMethod
(
java
.
sql
.
Time
.
class
,
"toLocalTime"
);
LOCAL_TIME_OF_NANO
=
getMethod
(
LOCAL_TIME
,
"ofNanoOfDay"
,
long
.
class
);
DATE_VALUE_OF
=
getMethod
(
java
.
sql
.
Date
.
class
,
"valueOf"
,
LOCAL_DATE
);
DATE_VALUE_OF
=
getMethod
(
java
.
sql
.
Date
.
class
,
"valueOf"
,
LOCAL_DATE
);
TIME_VALUE_OF
=
getMethod
(
java
.
sql
.
Time
.
class
,
"valueOf"
,
LOCAL_TIME
);
LOCAL_TIME_TO_NANO
=
getMethod
(
LOCAL_TIME
,
"toNanoOfDay"
);
LOCAL_DATE_OF_YEAR_MONTH_DAY
=
getMethod
(
LOCAL_DATE
,
"of"
,
LOCAL_DATE_OF_YEAR_MONTH_DAY
=
getMethod
(
LOCAL_DATE
,
"of"
,
int
.
class
,
int
.
class
,
int
.
class
);
int
.
class
,
int
.
class
,
int
.
class
);
...
@@ -390,26 +394,22 @@ public class LocalDateTimeUtils {
...
@@ -390,26 +394,22 @@ public class LocalDateTimeUtils {
* @return the LocalTime
* @return the LocalTime
*/
*/
public
static
Object
valueToLocalTime
(
Value
value
)
{
public
static
Object
valueToLocalTime
(
Value
value
)
{
return
timeToLocalTime
(
value
.
getTime
());
}
private
static
Object
dateToLocalDate
(
Date
date
)
{
try
{
try
{
return
TO_LOCAL_DATE
.
invoke
(
date
);
return
LOCAL_TIME_OF_NANO
.
invoke
(
null
,
((
ValueTime
)
value
.
convertTo
(
Value
.
TIME
)).
getNanos
()
);
}
catch
(
IllegalAccessException
e
)
{
}
catch
(
IllegalAccessException
e
)
{
throw
DbException
.
convert
(
e
);
throw
DbException
.
convert
(
e
);
}
catch
(
InvocationTargetException
e
)
{
}
catch
(
InvocationTargetException
e
)
{
throw
DbException
.
convertInvocation
(
e
,
"
dat
e conversion failed"
);
throw
DbException
.
convertInvocation
(
e
,
"
tim
e conversion failed"
);
}
}
}
}
private
static
Object
timeToLocalTime
(
Time
tim
e
)
{
private
static
Object
dateToLocalDate
(
Date
dat
e
)
{
try
{
try
{
return
TO_LOCAL_
TIME
.
invoke
(
tim
e
);
return
TO_LOCAL_
DATE
.
invoke
(
dat
e
);
}
catch
(
IllegalAccessException
e
)
{
}
catch
(
IllegalAccessException
e
)
{
throw
DbException
.
convert
(
e
);
throw
DbException
.
convert
(
e
);
}
catch
(
InvocationTargetException
e
)
{
}
catch
(
InvocationTargetException
e
)
{
throw
DbException
.
convertInvocation
(
e
,
"
tim
e conversion failed"
);
throw
DbException
.
convertInvocation
(
e
,
"
dat
e conversion failed"
);
}
}
}
}
...
@@ -495,8 +495,7 @@ public class LocalDateTimeUtils {
...
@@ -495,8 +495,7 @@ public class LocalDateTimeUtils {
*/
*/
public
static
Value
localTimeToTimeValue
(
Object
localTime
)
{
public
static
Value
localTimeToTimeValue
(
Object
localTime
)
{
try
{
try
{
Time
time
=
(
Time
)
TIME_VALUE_OF
.
invoke
(
null
,
localTime
);
return
ValueTime
.
fromNanos
((
Long
)
LOCAL_TIME_TO_NANO
.
invoke
(
localTime
));
return
ValueTime
.
get
(
time
);
}
catch
(
IllegalAccessException
e
)
{
}
catch
(
IllegalAccessException
e
)
{
throw
DbException
.
convert
(
e
);
throw
DbException
.
convert
(
e
);
}
catch
(
InvocationTargetException
e
)
{
}
catch
(
InvocationTargetException
e
)
{
...
...
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
29a989e2
...
@@ -620,6 +620,13 @@ public class TestPreparedStatement extends TestBase {
...
@@ -620,6 +620,13 @@ public class TestPreparedStatement extends TestBase {
Object
localTime2
=
rs
.
getObject
(
1
,
LocalDateTimeUtils
.
getLocalTimeClass
());
Object
localTime2
=
rs
.
getObject
(
1
,
LocalDateTimeUtils
.
getLocalTimeClass
());
assertEquals
(
localTime
,
localTime2
);
assertEquals
(
localTime
,
localTime2
);
rs
.
close
();
rs
.
close
();
localTime
=
LocalDateTimeUtils
.
parseLocalTime
(
"04:05:06.123456789"
);
prep
.
setObject
(
1
,
localTime
);
rs
=
prep
.
executeQuery
();
rs
.
next
();
localTime2
=
rs
.
getObject
(
1
,
LocalDateTimeUtils
.
getLocalTimeClass
());
assertEquals
(
localTime
,
localTime2
);
rs
.
close
();
}
}
private
void
testDateTime8
(
Connection
conn
)
throws
SQLException
{
private
void
testDateTime8
(
Connection
conn
)
throws
SQLException
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论