Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9b9dc7e2
提交
9b9dc7e2
authored
8月 05, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add SysProperties.RETURN_OFFSET_DATE_TIME
上级
0c1e2a39
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
56 行增加
和
12 行删除
+56
-12
SysProperties.java
h2/src/main/org/h2/engine/SysProperties.java
+11
-0
JdbcResultSet.java
h2/src/main/org/h2/jdbc/JdbcResultSet.java
+3
-1
LocalDateTimeUtils.java
h2/src/main/org/h2/util/LocalDateTimeUtils.java
+1
-1
DataType.java
h2/src/main/org/h2/value/DataType.java
+14
-3
ValueTimestampTimeZone.java
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
+6
-2
TestTimeStampWithTimeZone.java
h2/src/test/org/h2/test/unit/TestTimeStampWithTimeZone.java
+21
-5
没有找到文件。
h2/src/main/org/h2/engine/SysProperties.java
浏览文件 @
9b9dc7e2
...
@@ -342,6 +342,17 @@ public class SysProperties {
...
@@ -342,6 +342,17 @@ public class SysProperties {
public
static
final
boolean
BIG_DECIMAL_IS_DECIMAL
=
public
static
final
boolean
BIG_DECIMAL_IS_DECIMAL
=
Utils
.
getProperty
(
"h2.bigDecimalIsDecimal"
,
true
);
Utils
.
getProperty
(
"h2.bigDecimalIsDecimal"
,
true
);
/**
* System property {@code h2.returnOffsetDateTime}, {@code false} by
* default. If {@code true}, {@link java.sql.ResultSet#getObject(int)} and
* {@link java.sql.ResultSet#getObject(String)} return
* {@code TIMESTAMP WITH TIME ZONE} values as
* {@code java.time.OffsetDateTime} instead of
* {@code org.h2.api.TimestampWithTimeZone}. This property has effect only
* on Java 8 / Android API 26 and later versions.
*/
public
static
final
boolean
RETURN_OFFSET_DATE_TIME
=
Utils
.
getProperty
(
"h2.returnOffsetDateTime"
,
false
);
/**
/**
* System property {@code h2.unlimitedTimeRange}, {@code false} by default.
* System property {@code h2.unlimitedTimeRange}, {@code false} by default.
...
...
h2/src/main/org/h2/jdbc/JdbcResultSet.java
浏览文件 @
9b9dc7e2
...
@@ -59,6 +59,7 @@ import org.h2.value.ValueShort;
...
@@ -59,6 +59,7 @@ import org.h2.value.ValueShort;
import
org.h2.value.ValueString
;
import
org.h2.value.ValueString
;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestampTimeZone
;
/**
/**
* <p>
* <p>
...
@@ -3929,7 +3930,8 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
...
@@ -3929,7 +3930,8 @@ public class JdbcResultSet extends TraceObject implements ResultSet, JdbcResultS
return
type
.
cast
(
value
==
ValueNull
.
INSTANCE
return
type
.
cast
(
value
==
ValueNull
.
INSTANCE
?
null
:
new
JdbcSQLXML
(
conn
,
value
,
JdbcLob
.
State
.
WITH_VALUE
,
id
));
?
null
:
new
JdbcSQLXML
(
conn
,
value
,
JdbcLob
.
State
.
WITH_VALUE
,
id
));
}
else
if
(
type
==
TimestampWithTimeZone
.
class
)
{
}
else
if
(
type
==
TimestampWithTimeZone
.
class
)
{
return
type
.
cast
(
value
.
convertTo
(
Value
.
TIMESTAMP_TZ
).
getObject
());
ValueTimestampTimeZone
v
=
(
ValueTimestampTimeZone
)
value
.
convertTo
(
Value
.
TIMESTAMP_TZ
);
return
type
.
cast
(
new
TimestampWithTimeZone
(
v
.
getDateValue
(),
v
.
getTimeNanos
(),
v
.
getTimeZoneOffsetMins
()));
}
else
if
(
DataType
.
isGeometryClass
(
type
))
{
}
else
if
(
DataType
.
isGeometryClass
(
type
))
{
return
type
.
cast
(
value
.
convertTo
(
Value
.
GEOMETRY
).
getObject
());
return
type
.
cast
(
value
.
convertTo
(
Value
.
GEOMETRY
).
getObject
());
}
else
if
(
type
==
LocalDateTimeUtils
.
LOCAL_DATE
)
{
}
else
if
(
type
==
LocalDateTimeUtils
.
LOCAL_DATE
)
{
...
...
h2/src/main/org/h2/util/LocalDateTimeUtils.java
浏览文件 @
9b9dc7e2
...
@@ -431,7 +431,7 @@ public class LocalDateTimeUtils {
...
@@ -431,7 +431,7 @@ public class LocalDateTimeUtils {
* @param offsetDateTime the OffsetDateTime to convert, not {@code null}
* @param offsetDateTime the OffsetDateTime to convert, not {@code null}
* @return the value
* @return the value
*/
*/
public
static
Value
offsetDateTimeToValue
(
Object
offsetDateTime
)
{
public
static
Value
TimestampTimeZone
offsetDateTimeToValue
(
Object
offsetDateTime
)
{
try
{
try
{
Object
localDateTime
=
OFFSET_DATE_TIME_TO_LOCAL_DATE_TIME
.
invoke
(
offsetDateTime
);
Object
localDateTime
=
OFFSET_DATE_TIME_TO_LOCAL_DATE_TIME
.
invoke
(
offsetDateTime
);
Object
localDate
=
LOCAL_DATE_TIME_TO_LOCAL_DATE
.
invoke
(
localDateTime
);
Object
localDate
=
LOCAL_DATE_TIME_TO_LOCAL_DATE
.
invoke
(
localDateTime
);
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
9b9dc7e2
...
@@ -583,9 +583,16 @@ public class DataType {
...
@@ -583,9 +583,16 @@ public class DataType {
break
;
break
;
}
}
case
Value
.
TIMESTAMP_TZ
:
{
case
Value
.
TIMESTAMP_TZ
:
{
TimestampWithTimeZone
value
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
columnIndex
);
Object
obj
=
rs
.
getObject
(
columnIndex
);
v
=
value
==
null
?
(
Value
)
ValueNull
.
INSTANCE
:
if
(
obj
==
null
)
{
ValueTimestampTimeZone
.
get
(
value
);
v
=
ValueNull
.
INSTANCE
;
}
else
if
(
LocalDateTimeUtils
.
isJava8DateApiPresent
()
&&
LocalDateTimeUtils
.
OFFSET_DATE_TIME
.
isInstance
(
obj
))
{
v
=
LocalDateTimeUtils
.
offsetDateTimeToValue
(
obj
);
}
else
{
TimestampWithTimeZone
value
=
(
TimestampWithTimeZone
)
obj
;
v
=
ValueTimestampTimeZone
.
get
(
value
);
}
break
;
break
;
}
}
case
Value
.
DECIMAL
:
{
case
Value
.
DECIMAL
:
{
...
@@ -772,6 +779,10 @@ public class DataType {
...
@@ -772,6 +779,10 @@ public class DataType {
// "java.sql.Timestamp";
// "java.sql.Timestamp";
return
Timestamp
.
class
.
getName
();
return
Timestamp
.
class
.
getName
();
case
Value
.
TIMESTAMP_TZ
:
case
Value
.
TIMESTAMP_TZ
:
if
(
SysProperties
.
RETURN_OFFSET_DATE_TIME
&&
LocalDateTimeUtils
.
isJava8DateApiPresent
())
{
// "java.time.OffsetDateTime";
return
LocalDateTimeUtils
.
OFFSET_DATE_TIME
.
getName
();
}
// "org.h2.api.TimestampWithTimeZone";
// "org.h2.api.TimestampWithTimeZone";
return
TimestampWithTimeZone
.
class
.
getName
();
return
TimestampWithTimeZone
.
class
.
getName
();
case
Value
.
BYTES
:
case
Value
.
BYTES
:
...
...
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
浏览文件 @
9b9dc7e2
...
@@ -10,8 +10,10 @@ import java.sql.SQLException;
...
@@ -10,8 +10,10 @@ import java.sql.SQLException;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.TimestampWithTimeZone
;
import
org.h2.api.TimestampWithTimeZone
;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.LocalDateTimeUtils
;
/**
/**
* Implementation of the TIMESTAMP WITH TIME ZONE data type.
* Implementation of the TIMESTAMP WITH TIME ZONE data type.
...
@@ -273,8 +275,10 @@ public class ValueTimestampTimeZone extends Value {
...
@@ -273,8 +275,10 @@ public class ValueTimestampTimeZone extends Value {
@Override
@Override
public
Object
getObject
()
{
public
Object
getObject
()
{
return
new
TimestampWithTimeZone
(
dateValue
,
timeNanos
,
if
(
SysProperties
.
RETURN_OFFSET_DATE_TIME
&&
LocalDateTimeUtils
.
isJava8DateApiPresent
())
{
timeZoneOffsetMins
);
return
LocalDateTimeUtils
.
valueToOffsetDateTime
(
this
);
}
return
new
TimestampWithTimeZone
(
dateValue
,
timeNanos
,
timeZoneOffsetMins
);
}
}
@Override
@Override
...
...
h2/src/test/org/h2/test/unit/TestTimeStampWithTimeZone.java
浏览文件 @
9b9dc7e2
...
@@ -14,6 +14,7 @@ import java.sql.Statement;
...
@@ -14,6 +14,7 @@ import java.sql.Statement;
import
java.util.TimeZone
;
import
java.util.TimeZone
;
import
org.h2.api.TimestampWithTimeZone
;
import
org.h2.api.TimestampWithTimeZone
;
import
org.h2.engine.SysProperties
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestDb
;
import
org.h2.test.TestDb
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.DateTimeUtils
;
...
@@ -64,7 +65,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
...
@@ -64,7 +65,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
ResultSet
rs
=
stat
.
executeQuery
(
"select t1 from test"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select t1 from test"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"1970-01-01 12:00:00+00:15"
,
rs
.
getString
(
1
));
assertEquals
(
"1970-01-01 12:00:00+00:15"
,
rs
.
getString
(
1
));
TimestampWithTimeZone
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
TimestampWithTimeZone
ts
=
test1_getTimestamp
(
rs
);
assertEquals
(
1970
,
ts
.
getYear
());
assertEquals
(
1970
,
ts
.
getYear
());
assertEquals
(
1
,
ts
.
getMonth
());
assertEquals
(
1
,
ts
.
getMonth
());
assertEquals
(
1
,
ts
.
getDay
());
assertEquals
(
1
,
ts
.
getDay
());
...
@@ -76,7 +77,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
...
@@ -76,7 +77,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
LocalDateTimeUtils
.
OFFSET_DATE_TIME
).
toString
());
LocalDateTimeUtils
.
OFFSET_DATE_TIME
).
toString
());
}
}
rs
.
next
();
rs
.
next
();
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
ts
=
test1_getTimestamp
(
rs
);
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
9
,
ts
.
getMonth
());
assertEquals
(
9
,
ts
.
getMonth
());
assertEquals
(
24
,
ts
.
getDay
());
assertEquals
(
24
,
ts
.
getDay
());
...
@@ -87,7 +88,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
...
@@ -87,7 +88,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
LocalDateTimeUtils
.
OFFSET_DATE_TIME
).
toString
());
LocalDateTimeUtils
.
OFFSET_DATE_TIME
).
toString
());
}
}
rs
.
next
();
rs
.
next
();
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
ts
=
test1_getTimestamp
(
rs
);
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
9
,
ts
.
getMonth
());
assertEquals
(
9
,
ts
.
getMonth
());
assertEquals
(
24
,
ts
.
getDay
());
assertEquals
(
24
,
ts
.
getDay
());
...
@@ -98,7 +99,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
...
@@ -98,7 +99,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
LocalDateTimeUtils
.
OFFSET_DATE_TIME
).
toString
());
LocalDateTimeUtils
.
OFFSET_DATE_TIME
).
toString
());
}
}
rs
.
next
();
rs
.
next
();
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
ts
=
test1_getTimestamp
(
rs
);
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
1
,
ts
.
getMonth
());
assertEquals
(
1
,
ts
.
getMonth
());
assertEquals
(
1
,
ts
.
getDay
());
assertEquals
(
1
,
ts
.
getDay
());
...
@@ -107,7 +108,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
...
@@ -107,7 +108,7 @@ public class TestTimeStampWithTimeZone extends TestDb {
LocalDateTimeUtils
.
OFFSET_DATE_TIME
).
toString
());
LocalDateTimeUtils
.
OFFSET_DATE_TIME
).
toString
());
}
}
rs
.
next
();
rs
.
next
();
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
ts
=
test1_getTimestamp
(
rs
);
assertEquals
(
2015
,
ts
.
getYear
());
assertEquals
(
2015
,
ts
.
getYear
());
assertEquals
(
12
,
ts
.
getMonth
());
assertEquals
(
12
,
ts
.
getMonth
());
assertEquals
(
31
,
ts
.
getDay
());
assertEquals
(
31
,
ts
.
getDay
());
...
@@ -124,6 +125,11 @@ public class TestTimeStampWithTimeZone extends TestDb {
...
@@ -124,6 +125,11 @@ public class TestTimeStampWithTimeZone extends TestDb {
// Types.TIMESTAMP_WITH_TIMEZONE
// Types.TIMESTAMP_WITH_TIMEZONE
// once Java 1.8 is required.
// once Java 1.8 is required.
assertEquals
(
2014
,
columnType
);
assertEquals
(
2014
,
columnType
);
if
(
SysProperties
.
RETURN_OFFSET_DATE_TIME
&&
LocalDateTimeUtils
.
isJava8DateApiPresent
())
{
assertEquals
(
"java.time.OffsetDateTime"
,
metaData
.
getColumnClassName
(
1
));
}
else
{
assertEquals
(
"org.h2.api.TimestampWithTimeZone"
,
metaData
.
getColumnClassName
(
1
));
}
rs
.
close
();
rs
.
close
();
...
@@ -135,6 +141,16 @@ public class TestTimeStampWithTimeZone extends TestDb {
...
@@ -135,6 +141,16 @@ public class TestTimeStampWithTimeZone extends TestDb {
conn
.
close
();
conn
.
close
();
}
}
private
static
TimestampWithTimeZone
test1_getTimestamp
(
ResultSet
rs
)
throws
SQLException
{
Object
o
=
rs
.
getObject
(
1
);
if
(
SysProperties
.
RETURN_OFFSET_DATE_TIME
&&
LocalDateTimeUtils
.
isJava8DateApiPresent
())
{
ValueTimestampTimeZone
value
=
LocalDateTimeUtils
.
offsetDateTimeToValue
(
o
);
return
new
TimestampWithTimeZone
(
value
.
getDateValue
(),
value
.
getTimeNanos
(),
value
.
getTimeZoneOffsetMins
());
}
return
(
TimestampWithTimeZone
)
o
;
}
private
void
test2
()
{
private
void
test2
()
{
ValueTimestampTimeZone
a
=
ValueTimestampTimeZone
.
parse
(
"1970-01-01 12:00:00.00+00:15"
);
ValueTimestampTimeZone
a
=
ValueTimestampTimeZone
.
parse
(
"1970-01-01 12:00:00.00+00:15"
);
ValueTimestampTimeZone
b
=
ValueTimestampTimeZone
.
parse
(
"1970-01-01 12:00:01.00+01:15"
);
ValueTimestampTimeZone
b
=
ValueTimestampTimeZone
.
parse
(
"1970-01-01 12:00:01.00+01:15"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论