Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d78d54cd
提交
d78d54cd
authored
10月 23, 2016
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove the "TIMESTAMP UTC" datatype, an experiment that was never finished.
上级
9f69e3cb
显示空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
11 行增加
和
434 行删除
+11
-434
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
ValueDataType.java
h2/src/main/org/h2/mvstore/db/ValueDataType.java
+0
-11
Data.java
h2/src/main/org/h2/store/Data.java
+0
-14
Column.java
h2/src/main/org/h2/table/Column.java
+0
-3
DataType.java
h2/src/main/org/h2/value/DataType.java
+3
-24
Transfer.java
h2/src/main/org/h2/value/Transfer.java
+0
-8
Value.java
h2/src/main/org/h2/value/Value.java
+2
-54
ValueTimestampUtc.java
h2/src/main/org/h2/value/ValueTimestampUtc.java
+0
-267
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+0
-2
TestTimeStampUtc.java
h2/src/test/org/h2/test/unit/TestTimeStampUtc.java
+0
-46
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+4
-2
TestValueMemory.java
h2/src/test/org/h2/test/unit/TestValueMemory.java
+0
-3
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
d78d54cd
...
...
@@ -25,6 +25,8 @@ Change Log
</li>
<li>
PR #364: fix compare TIMESTAMP WITH TIMEZONE
</li>
<li>
Remove the "TIMESTAMP UTC" datatype, an experiment that was never finished.
</li>
<li>
PR #363: Added support to define last IDENTIFIER on a Trigger.
</li>
<li>
PR #366: Tests for timestamps
...
...
h2/src/main/org/h2/mvstore/db/ValueDataType.java
浏览文件 @
d78d54cd
...
...
@@ -46,7 +46,6 @@ import org.h2.value.ValueStringIgnoreCase;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestampTimeZone
;
import
org.h2.value.ValueTimestampUtc
;
import
org.h2.value.ValueUuid
;
/**
...
...
@@ -278,12 +277,6 @@ public class ValueDataType implements DataType {
putVarLong
(
nanos
);
break
;
}
case
Value
.
TIMESTAMP_UTC
:
{
ValueTimestampUtc
ts
=
(
ValueTimestampUtc
)
v
;
long
dateTimeValue
=
ts
.
getUtcDateTimeNanos
();
buff
.
put
((
byte
)
type
).
putVarLong
(
dateTimeValue
);
break
;
}
case
Value
.
TIMESTAMP_TZ
:
{
ValueTimestampTimeZone
ts
=
(
ValueTimestampTimeZone
)
v
;
long
dateValue
=
ts
.
getDateValue
();
...
...
@@ -502,10 +495,6 @@ public class ValueDataType implements DataType {
long
nanos
=
readVarLong
(
buff
)
*
1000000
+
readVarLong
(
buff
);
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValue
,
nanos
);
}
case
Value
.
TIMESTAMP_UTC
:
{
long
dateTimeValue
=
readVarLong
(
buff
);
return
ValueTimestampUtc
.
fromNanos
(
dateTimeValue
);
}
case
Value
.
TIMESTAMP_TZ
:
{
long
dateValue
=
readVarLong
(
buff
);
long
nanos
=
readVarLong
(
buff
)
*
1000000
+
readVarLong
(
buff
);
...
...
h2/src/main/org/h2/store/Data.java
浏览文件 @
d78d54cd
...
...
@@ -50,7 +50,6 @@ import org.h2.value.ValueStringIgnoreCase;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestampTimeZone
;
import
org.h2.value.ValueTimestampUtc
;
import
org.h2.value.ValueUuid
;
/**
...
...
@@ -539,12 +538,6 @@ public class Data {
}
break
;
}
case
Value
.
TIMESTAMP_UTC
:
{
ValueTimestampUtc
ts
=
(
ValueTimestampUtc
)
v
;
writeByte
((
byte
)
type
);
writeVarLong
(
ts
.
getUtcDateTimeNanos
());
break
;
}
case
Value
.
TIMESTAMP_TZ
:
{
ValueTimestampTimeZone
ts
=
(
ValueTimestampTimeZone
)
v
;
writeByte
((
byte
)
type
);
...
...
@@ -787,9 +780,6 @@ public class Data {
DateTimeUtils
.
getTimeUTCWithoutDst
(
readVarLong
()),
readVarInt
());
}
case
Value
.
TIMESTAMP_UTC
:
{
return
ValueTimestampUtc
.
fromNanos
(
readVarLong
());
}
case
Value
.
TIMESTAMP_TZ
:
{
long
dateValue
=
readVarLong
();
long
nanos
=
readVarLong
();
...
...
@@ -1044,10 +1034,6 @@ public class Data {
return
1
+
getVarLongLen
(
DateTimeUtils
.
getTimeLocalWithoutDst
(
ts
))
+
getVarIntLen
(
ts
.
getNanos
()
%
1000000
);
}
case
Value
.
TIMESTAMP_UTC
:
{
ValueTimestampUtc
ts
=
(
ValueTimestampUtc
)
v
;
return
1
+
getVarLongLen
(
ts
.
getUtcDateTimeNanos
());
}
case
Value
.
TIMESTAMP_TZ
:
{
ValueTimestampTimeZone
ts
=
(
ValueTimestampTimeZone
)
v
;
long
dateValue
=
ts
.
getDateValue
();
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
d78d54cd
...
...
@@ -33,7 +33,6 @@ import org.h2.value.ValueString;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestampTimeZone
;
import
org.h2.value.ValueTimestampUtc
;
import
org.h2.value.ValueUuid
;
/**
...
...
@@ -296,8 +295,6 @@ public class Column {
value
=
ValueInt
.
get
(
0
).
convertTo
(
type
);
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP
)
{
value
=
ValueTimestamp
.
fromMillis
(
session
.
getTransactionStart
());
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP_UTC
)
{
value
=
ValueTimestampUtc
.
fromMillis
(
session
.
getTransactionStart
());
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP_TZ
)
{
long
ms
=
session
.
getTransactionStart
();
value
=
ValueTimestampTimeZone
.
fromDateValueAndNanos
(
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
d78d54cd
...
...
@@ -65,7 +65,7 @@ public class DataType {
*/
private
static
final
ArrayList
<
DataType
>
TYPES
=
New
.
arrayList
();
private
static
final
HashMap
<
String
,
DataType
>
TYPES_BY_NAME
=
New
.
hashMap
();
private
static
final
ArrayList
<
DataType
>
TYPES_BY_VALUE_TYPE
=
New
.
arrayList
();
private
static
final
HashMap
<
Integer
,
DataType
>
TYPES_BY_VALUE_TYPE
=
New
.
hashMap
();
/**
* The value type of this data type.
...
...
@@ -185,9 +185,6 @@ public class DataType {
}
static
{
for
(
int
i
=
0
;
i
<
Value
.
TYPE_COUNT
;
i
++)
{
TYPES_BY_VALUE_TYPE
.
add
(
null
);
}
add
(
Value
.
NULL
,
Types
.
NULL
,
"Null"
,
new
DataType
(),
new
String
[]{
"NULL"
},
...
...
@@ -316,13 +313,6 @@ public class DataType {
// 24 for ValueTimestamp, 32 for java.sql.Timestamp
56
);
add
(
Value
.
TIMESTAMP_UTC
,
Types
.
TIMESTAMP
,
"TimestampUtc"
,
createDate
(
ValueTimestamp
.
PRECISION
,
"TIMESTAMP_UTC"
,
ValueTimestamp
.
DEFAULT_SCALE
,
ValueTimestamp
.
DISPLAY_SIZE
),
new
String
[]{
"TIMESTAMP_UTC"
},
// 24 for ValueTimestampUtc, 32 for java.sql.Timestamp
56
);
add
(
Value
.
TIMESTAMP_TZ
,
Types
.
OTHER
,
"TimestampTimeZone"
,
createDate
(
ValueTimestampTimeZone
.
PRECISION
,
"TIMESTAMP_TZ"
,
ValueTimestampTimeZone
.
DEFAULT_SCALE
,
ValueTimestampTimeZone
.
DISPLAY_SIZE
),
...
...
@@ -388,11 +378,7 @@ public class DataType {
new
String
[]{
"RESULT_SET"
},
400
);
for
(
int
i
=
0
,
size
=
TYPES_BY_VALUE_TYPE
.
size
();
i
<
size
;
i
++)
{
DataType
dt
=
TYPES_BY_VALUE_TYPE
.
get
(
i
);
if
(
dt
==
null
)
{
DbException
.
throwInternalError
(
"unmapped type "
+
i
);
}
for
(
Integer
i
:
TYPES_BY_VALUE_TYPE
.
keySet
())
{
Value
.
getOrder
(
i
);
}
}
...
...
@@ -428,7 +414,7 @@ public class DataType {
}
TYPES_BY_NAME
.
put
(
dt
.
name
,
dt
);
if
(
TYPES_BY_VALUE_TYPE
.
get
(
type
)
==
null
)
{
TYPES_BY_VALUE_TYPE
.
se
t
(
type
,
dt
);
TYPES_BY_VALUE_TYPE
.
pu
t
(
type
,
dt
);
}
TYPES
.
add
(
dt
);
}
...
...
@@ -554,12 +540,6 @@ public class DataType {
ValueTimestamp
.
get
(
value
);
break
;
}
case
Value
.
TIMESTAMP_UTC
:
{
Timestamp
value
=
rs
.
getTimestamp
(
columnIndex
);
v
=
value
==
null
?
(
Value
)
ValueNull
.
INSTANCE
:
ValueTimestampUtc
.
fromMillisNanos
(
value
.
getTime
(),
value
.
getNanos
());
break
;
}
case
Value
.
TIMESTAMP_TZ
:
{
TimestampWithTimeZone
value
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
columnIndex
);
v
=
value
==
null
?
(
Value
)
ValueNull
.
INSTANCE
:
...
...
@@ -738,7 +718,6 @@ public class DataType {
// "java.sql.Date";
return
Date
.
class
.
getName
();
case
Value
.
TIMESTAMP
:
case
Value
.
TIMESTAMP_UTC
:
// "java.sql.Timestamp";
return
Timestamp
.
class
.
getName
();
case
Value
.
TIMESTAMP_TZ
:
...
...
h2/src/main/org/h2/value/Transfer.java
浏览文件 @
d78d54cd
...
...
@@ -387,11 +387,6 @@ public class Transfer {
}
break
;
}
case
Value
.
TIMESTAMP_UTC
:
{
ValueTimestampUtc
ts
=
(
ValueTimestampUtc
)
v
;
writeLong
(
ts
.
getUtcDateTimeNanos
());
break
;
}
case
Value
.
TIMESTAMP_TZ
:
{
ValueTimestampTimeZone
ts
=
(
ValueTimestampTimeZone
)
v
;
writeLong
(
ts
.
getDateValue
());
...
...
@@ -585,9 +580,6 @@ public class Transfer {
return
ValueTimestamp
.
fromMillisNanos
(
readLong
(),
readInt
()
%
1000000
);
}
case
Value
.
TIMESTAMP_UTC
:
{
return
ValueTimestampUtc
.
fromNanos
(
readLong
());
}
case
Value
.
TIMESTAMP_TZ
:
{
return
ValueTimestampTimeZone
.
fromDateValueAndNanos
(
readLong
(),
readLong
(),
(
short
)
readInt
());
...
...
h2/src/main/org/h2/value/Value.java
浏览文件 @
d78d54cd
...
...
@@ -159,9 +159,8 @@ public abstract class Value {
*/
public
static
final
int
GEOMETRY
=
22
;
/**
*
The value type for TIMESTAMP UTC values
.
*
23 was a short-lived experiment "TIMESTAMP UTC" which has been removed
.
*/
public
static
final
int
TIMESTAMP_UTC
=
23
;
/**
* The value type for TIMESTAMP WITH TIMEZONE values.
*/
...
...
@@ -170,7 +169,7 @@ public abstract class Value {
/**
* The number of value types.
*/
public
static
final
int
TYPE_COUNT
=
TIMESTAMP_TZ
+
1
;
public
static
final
int
TYPE_COUNT
=
TIMESTAMP_TZ
;
private
static
SoftReference
<
Value
[]>
softCache
=
new
SoftReference
<
Value
[]>(
null
);
...
...
@@ -306,8 +305,6 @@ public abstract class Value {
return
31
;
case
TIMESTAMP:
return
32
;
case
TIMESTAMP_UTC:
return
33
;
case
TIMESTAMP_TZ:
return
34
;
case
BYTES:
...
...
@@ -553,7 +550,6 @@ public abstract class Value {
case
TIME:
case
DATE:
case
TIMESTAMP:
case
TIMESTAMP_UTC:
case
TIMESTAMP_TZ:
case
BYTES:
case
JAVA_OBJECT:
...
...
@@ -572,7 +568,6 @@ public abstract class Value {
case
INT:
return
ValueByte
.
get
(
convertToByte
(
getInt
()));
case
LONG:
case
TIMESTAMP_UTC:
return
ValueByte
.
get
(
convertToByte
(
getLong
()));
case
DECIMAL:
return
ValueByte
.
get
(
convertToByte
(
convertToLong
(
getBigDecimal
())));
...
...
@@ -597,7 +592,6 @@ public abstract class Value {
case
INT:
return
ValueShort
.
get
(
convertToShort
(
getInt
()));
case
LONG:
case
TIMESTAMP_UTC:
return
ValueShort
.
get
(
convertToShort
(
getLong
()));
case
DECIMAL:
return
ValueShort
.
get
(
convertToShort
(
convertToLong
(
getBigDecimal
())));
...
...
@@ -622,7 +616,6 @@ public abstract class Value {
case
SHORT:
return
ValueInt
.
get
(
getShort
());
case
LONG:
case
TIMESTAMP_UTC:
return
ValueInt
.
get
(
convertToInt
(
getLong
()));
case
DECIMAL:
return
ValueInt
.
get
(
convertToInt
(
convertToLong
(
getBigDecimal
())));
...
...
@@ -662,8 +655,6 @@ public abstract class Value {
}
return
ValueLong
.
get
(
Long
.
parseLong
(
getString
(),
16
));
}
case
TIMESTAMP_UTC:
return
ValueLong
.
get
(
getLong
());
case
TIMESTAMP_TZ:
throw
DbException
.
get
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
getString
());
...
...
@@ -682,7 +673,6 @@ public abstract class Value {
case
INT:
return
ValueDecimal
.
get
(
BigDecimal
.
valueOf
(
getInt
()));
case
LONG:
case
TIMESTAMP_UTC:
return
ValueDecimal
.
get
(
BigDecimal
.
valueOf
(
getLong
()));
case
DOUBLE:
{
double
d
=
getDouble
();
...
...
@@ -718,7 +708,6 @@ public abstract class Value {
case
INT:
return
ValueDouble
.
get
(
getInt
());
case
LONG:
case
TIMESTAMP_UTC:
return
ValueDouble
.
get
(
getLong
());
case
DECIMAL:
return
ValueDouble
.
get
(
getBigDecimal
().
doubleValue
());
...
...
@@ -741,7 +730,6 @@ public abstract class Value {
case
INT:
return
ValueFloat
.
get
(
getInt
());
case
LONG:
case
TIMESTAMP_UTC:
return
ValueFloat
.
get
(
getLong
());
case
DECIMAL:
return
ValueFloat
.
get
(
getBigDecimal
().
floatValue
());
...
...
@@ -763,9 +751,6 @@ public abstract class Value {
case
TIMESTAMP:
return
ValueDate
.
fromDateValue
(
((
ValueTimestamp
)
this
).
getDateValue
());
case
TIMESTAMP_UTC:
return
ValueDate
.
fromMillis
(
((
ValueTimestampUtc
)
this
).
getUtcDateTimeMillis
());
case
TIMESTAMP_TZ:
return
ValueDate
.
fromDateValue
(
((
ValueTimestampTimeZone
)
this
).
getDateValue
());
...
...
@@ -781,9 +766,6 @@ public abstract class Value {
case
TIMESTAMP:
return
ValueTime
.
fromNanos
(
((
ValueTimestamp
)
this
).
getTimeNanos
());
case
TIMESTAMP_UTC:
return
ValueTime
.
fromMillis
(
((
ValueTimestampUtc
)
this
).
getUtcDateTimeMillis
());
case
TIMESTAMP_TZ:
return
ValueTime
.
fromNanos
(
((
ValueTimestampTimeZone
)
this
).
getTimeNanos
());
...
...
@@ -798,10 +780,6 @@ public abstract class Value {
case
DATE:
return
ValueTimestamp
.
fromDateValueAndNanos
(
((
ValueDate
)
this
).
getDateValue
(),
0
);
case
TIMESTAMP_UTC:
return
ValueTimestamp
.
fromMillisNanos
(
((
ValueTimestampUtc
)
this
).
getUtcDateTimeMillis
(),
((
ValueTimestampUtc
)
this
).
getNanosSinceLastMillis
());
case
TIMESTAMP_TZ:
return
ValueTimestamp
.
fromDateValueAndNanos
(
((
ValueTimestampTimeZone
)
this
).
getDateValue
(),
...
...
@@ -809,34 +787,6 @@ public abstract class Value {
}
break
;
}
case
TIMESTAMP_UTC:
{
switch
(
getType
())
{
case
BOOLEAN:
return
ValueTimestampUtc
.
fromNanos
(
getBoolean
().
booleanValue
()
?
1
:
0
);
case
BYTE:
return
ValueTimestampUtc
.
fromNanos
(
getByte
());
case
SHORT:
return
ValueTimestampUtc
.
fromNanos
(
getShort
());
case
INT:
return
ValueTimestampUtc
.
fromNanos
(
getInt
());
case
LONG:
return
ValueTimestampUtc
.
fromNanos
(
getLong
());
case
DECIMAL:
return
ValueTimestampUtc
.
fromNanos
(
getBigDecimal
().
longValue
());
case
FLOAT:
return
ValueTimestampUtc
.
fromNanos
((
long
)
getFloat
());
case
DOUBLE:
return
ValueTimestampUtc
.
fromNanos
((
long
)
getDouble
());
case
TIMESTAMP:
return
ValueTimestampUtc
.
fromMillisNanos
(
((
ValueTimestamp
)
this
).
getTimestamp
().
getTime
(),
((
ValueTimestamp
)
this
).
getTimestamp
().
getNanos
());
case
TIMESTAMP_TZ:
// TODO
throw
DbException
.
getUnsupportedException
(
"unimplemented"
);
}
break
;
}
case
BYTES:
{
switch
(
getType
())
{
case
JAVA_OBJECT:
...
...
@@ -976,8 +926,6 @@ public abstract class Value {
return
ValueDate
.
parse
(
s
.
trim
());
case
TIMESTAMP:
return
ValueTimestamp
.
parse
(
s
.
trim
());
case
TIMESTAMP_UTC:
return
ValueTimestampUtc
.
parse
(
s
.
trim
());
case
TIMESTAMP_TZ:
return
ValueTimestampTimeZone
.
parse
(
s
.
trim
());
case
BYTES:
...
...
h2/src/main/org/h2/value/ValueTimestampUtc.java
deleted
100644 → 0
浏览文件 @
9f69e3cb
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, and the
* EPL 1.0 (http://h2database.com/html/license.html). Initial Developer: H2
* Group
*/
package
org
.
h2
.
value
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.TimeZone
;
import
org.h2.message.DbException
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StringUtils
;
/**
* Implementation of the TIMESTAMP UTC data type.
*/
public
final
class
ValueTimestampUtc
extends
Value
{
/**
* The precision in digits.
*/
public
static
final
int
PRECISION
=
23
;
/**
* The display size of the textual representation of a timestamp. Example:
* 2001-01-01 23:59:59.000 UTC
*/
static
final
int
DISPLAY_SIZE
=
27
;
/**
* The default scale for timestamps.
*/
static
final
int
DEFAULT_SCALE
=
10
;
/**
* Time in nanoseconds since 1 Jan 1970 i.e. similar format to
* System.currentTimeMillis()
*/
private
final
long
utcDateTimeNanos
;
private
ValueTimestampUtc
(
long
utcDateTimeNanos
)
{
this
.
utcDateTimeNanos
=
utcDateTimeNanos
;
}
/**
* Get or create a timestamp value for the given date/time in millis.
*
* @param utcDateTimeMillis the date and time in UTC milliseconds
* @param nanos the nanoseconds since the last millisecond
* @return the value
*/
public
static
ValueTimestampUtc
fromMillisNanos
(
long
utcDateTimeMillis
,
int
nanos
)
{
if
(
nanos
<
0
||
nanos
>=
1000
*
1000
)
{
throw
new
IllegalArgumentException
(
"nanos out of range "
+
nanos
);
}
return
(
ValueTimestampUtc
)
Value
.
cache
(
new
ValueTimestampUtc
(
utcDateTimeMillis
*
1000
*
1000
+
nanos
));
}
/**
* Get or create a timestamp value for the given date/time in millis.
*
* @param ms the milliseconds
* @return the value
*/
public
static
ValueTimestampUtc
fromMillis
(
long
ms
)
{
return
fromMillisNanos
(
ms
,
(
short
)
0
);
}
/**
* Get or create a timestamp value for the given date/time in nanos.
*
* @param nanos the nanos
* @return the value
*/
public
static
ValueTimestampUtc
fromNanos
(
long
nanos
)
{
return
(
ValueTimestampUtc
)
Value
.
cache
(
new
ValueTimestampUtc
(
nanos
));
}
/**
* Parse a string to a ValueTimestamp. This method supports the format
* +/-year-month-day hour:minute:seconds.fractional and an optional timezone
* part.
*
* @param s the string to parse
* @return the date
*/
public
static
ValueTimestampUtc
parse
(
String
s
)
{
ValueTimestamp
t1
=
ValueTimestamp
.
parse
(
s
);
java
.
sql
.
Timestamp
t2
=
t1
.
getTimestamp
();
return
fromMillisNanos
(
t2
.
getTime
(),
t2
.
getNanos
());
}
/**
* Time in nanoseconds since 1 Jan 1970 i.e. similar format to
* System.currentTimeMillis().
*
* @return the number of milliseconds
*/
public
long
getUtcDateTimeNanos
()
{
return
utcDateTimeNanos
;
}
/**
* Time in milliseconds since 1 Jan 1970 i.e. same format as
* System.currentTimeMillis()
*
* @return the number of milliseconds
*/
public
long
getUtcDateTimeMillis
()
{
return
utcDateTimeNanos
/
1000
/
1000
;
}
/**
* Get the number of nanoseconds since the last full millisecond.
*
* @return the number of nanoseconds
*/
int
getNanosSinceLastMillis
()
{
return
(
int
)
(
utcDateTimeNanos
%
(
1000
*
1000
));
}
@Override
public
java
.
sql
.
Timestamp
getTimestamp
()
{
java
.
sql
.
Timestamp
ts
=
new
java
.
sql
.
Timestamp
(
getUtcDateTimeMillis
());
ts
.
setNanos
(
getNanosSinceLastMillis
());
return
ts
;
}
@Override
public
int
getType
()
{
return
Value
.
TIMESTAMP_UTC
;
}
@Override
public
String
getString
()
{
Calendar
cal
=
new
GregorianCalendar
(
TimeZone
.
getTimeZone
(
"UTC"
));
cal
.
setTimeInMillis
(
getUtcDateTimeMillis
());
StringBuilder
buff
=
new
StringBuilder
(
DISPLAY_SIZE
);
// date part
int
y
=
cal
.
get
(
Calendar
.
YEAR
);
int
m
=
cal
.
get
(
Calendar
.
MONTH
);
int
d
=
cal
.
get
(
Calendar
.
DAY_OF_MONTH
);
if
(
y
>
0
&&
y
<
10000
)
{
StringUtils
.
appendZeroPadded
(
buff
,
4
,
y
);
}
else
{
buff
.
append
(
y
);
}
buff
.
append
(
'-'
);
StringUtils
.
appendZeroPadded
(
buff
,
2
,
m
);
buff
.
append
(
'-'
);
StringUtils
.
appendZeroPadded
(
buff
,
2
,
d
);
buff
.
append
(
' '
);
// time part
long
timeNanos
=
cal
.
get
(
Calendar
.
HOUR_OF_DAY
);
timeNanos
*=
24
;
timeNanos
+=
cal
.
get
(
Calendar
.
MINUTE
);
timeNanos
*=
60
;
timeNanos
+=
cal
.
get
(
Calendar
.
SECOND
);
timeNanos
*=
60
;
timeNanos
+=
cal
.
get
(
Calendar
.
MILLISECOND
);
timeNanos
*=
1000
*
1000
;
timeNanos
+=
getNanosSinceLastMillis
();
ValueTime
.
appendTime
(
buff
,
timeNanos
,
true
);
buff
.
append
(
" UTC"
);
return
buff
.
toString
();
}
@Override
public
String
getSQL
()
{
return
"TIMESTAMP UTC '"
+
getString
()
+
"'"
;
}
@Override
public
long
getPrecision
()
{
return
PRECISION
;
}
@Override
public
int
getScale
()
{
return
DEFAULT_SCALE
;
}
@Override
public
int
getDisplaySize
()
{
return
DISPLAY_SIZE
;
}
@Override
public
Value
convertScale
(
boolean
onlyToSmallerScale
,
int
targetScale
)
{
if
(
targetScale
>=
DEFAULT_SCALE
)
{
return
this
;
}
if
(
targetScale
<
0
)
{
throw
DbException
.
getInvalidValueException
(
"scale"
,
targetScale
);
}
// TODO
// long n = timeNanos;
// BigDecimal bd = BigDecimal.valueOf(n);
// bd = bd.movePointLeft(9);
// bd = ValueDecimal.setScale(bd, targetScale);
// bd = bd.movePointRight(9);
// long n2 = bd.longValue();
// if (n2 == n) {
// return this;
// }
return
this
;
}
@Override
protected
int
compareSecure
(
Value
o
,
CompareMode
mode
)
{
ValueTimestampUtc
t
=
(
ValueTimestampUtc
)
o
;
return
MathUtils
.
compareLong
(
utcDateTimeNanos
,
t
.
utcDateTimeNanos
);
}
@Override
public
boolean
equals
(
Object
other
)
{
if
(
this
==
other
)
{
return
true
;
}
else
if
(!(
other
instanceof
ValueTimestampUtc
))
{
return
false
;
}
ValueTimestampUtc
x
=
(
ValueTimestampUtc
)
other
;
return
utcDateTimeNanos
==
x
.
utcDateTimeNanos
;
}
@Override
public
int
hashCode
()
{
return
(
int
)
(
utcDateTimeNanos
^
(
utcDateTimeNanos
>>>
32
));
}
@Override
public
Object
getObject
()
{
return
getTimestamp
();
}
@Override
public
long
getLong
()
{
return
utcDateTimeNanos
;
}
@Override
public
void
set
(
PreparedStatement
prep
,
int
parameterIndex
)
throws
SQLException
{
prep
.
setTimestamp
(
parameterIndex
,
getTimestamp
());
}
@Override
public
Value
add
(
Value
v
)
{
ValueTimestampUtc
t
=
(
ValueTimestampUtc
)
v
.
convertTo
(
Value
.
TIMESTAMP_UTC
);
long
d1
=
utcDateTimeNanos
+
t
.
utcDateTimeNanos
;
return
new
ValueTimestampUtc
(
d1
);
}
@Override
public
Value
subtract
(
Value
v
)
{
ValueTimestampUtc
t
=
(
ValueTimestampUtc
)
v
.
convertTo
(
Value
.
TIMESTAMP_UTC
);
long
d1
=
utcDateTimeNanos
-
t
.
utcDateTimeNanos
;
return
new
ValueTimestampUtc
(
d1
);
}
}
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
d78d54cd
...
...
@@ -207,7 +207,6 @@ import org.h2.test.unit.TestSort;
import
org.h2.test.unit.TestStreams
;
import
org.h2.test.unit.TestStringCache
;
import
org.h2.test.unit.TestStringUtils
;
import
org.h2.test.unit.TestTimeStampUtc
;
import
org.h2.test.unit.TestTimeStampWithTimeZone
;
import
org.h2.test.unit.TestTools
;
import
org.h2.test.unit.TestTraceSystem
;
...
...
@@ -865,7 +864,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest
(
new
TestSort
());
addTest
(
new
TestStreams
());
addTest
(
new
TestStringUtils
());
addTest
(
new
TestTimeStampUtc
());
addTest
(
new
TestTimeStampWithTimeZone
());
addTest
(
new
TestTraceSystem
());
addTest
(
new
TestUpgrade
());
...
...
h2/src/test/org/h2/test/unit/TestTimeStampUtc.java
deleted
100644 → 0
浏览文件 @
9f69e3cb
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, and the
* EPL 1.0 (http://h2database.com/html/license.html). Initial Developer: H2
* Group
*/
package
org
.
h2
.
test
.
unit
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
/**
*/
public
class
TestTimeStampUtc
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
@Override
public
void
test
()
throws
SQLException
{
deleteDb
(
"timestamp_utc"
);
test1
();
deleteDb
(
"timestamp_utc"
);
}
private
void
test1
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"timestamp_utc"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity, t1 timestamp_utc)"
);
stat
.
execute
(
"insert into test(t1) values(0)"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select t1 from test"
);
rs
.
next
();
assertEquals
(
0
,
rs
.
getLong
(
1
));
assertEquals
(
new
java
.
sql
.
Timestamp
(
0
),
rs
.
getTimestamp
(
1
));
conn
.
close
();
}
}
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
d78d54cd
...
...
@@ -68,9 +68,11 @@ public class TestValue extends TestBase {
rs
.
addRow
(
new
Object
[]{
null
});
rs
.
next
();
for
(
int
type
=
Value
.
NULL
;
type
<
Value
.
TYPE_COUNT
;
type
++)
{
if
(
type
!=
23
)
{
// a defunct experimental type
Value
v
=
DataType
.
readValue
(
null
,
rs
,
1
,
type
);
assertTrue
(
v
==
ValueNull
.
INSTANCE
);
}
}
testResultSetOperation
(
new
byte
[
0
]);
testResultSetOperation
(
1
);
testResultSetOperation
(
Boolean
.
TRUE
);
...
...
h2/src/test/org/h2/test/unit/TestValueMemory.java
浏览文件 @
d78d54cd
...
...
@@ -47,7 +47,6 @@ import org.h2.value.ValueStringIgnoreCase;
import
org.h2.value.ValueTime
;
import
org.h2.value.ValueTimestamp
;
import
org.h2.value.ValueTimestampTimeZone
;
import
org.h2.value.ValueTimestampUtc
;
import
org.h2.value.ValueUuid
;
/**
...
...
@@ -164,8 +163,6 @@ public class TestValueMemory extends TestBase implements DataHandler {
return
ValueDate
.
get
(
new
java
.
sql
.
Date
(
random
.
nextLong
()));
case
Value
.
TIMESTAMP
:
return
ValueTimestamp
.
fromMillis
(
random
.
nextLong
());
case
Value
.
TIMESTAMP_UTC
:
return
ValueTimestampUtc
.
fromMillis
(
random
.
nextLong
());
case
Value
.
TIMESTAMP_TZ
:
// clamp to max legal value
long
nanos
=
Math
.
max
(
Math
.
min
(
random
.
nextLong
(),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论