Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
af80d630
提交
af80d630
authored
5月 09, 2014
作者:
noelgrandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reduce unnecessary object creation in Timestamp routines
上级
a9905aa0
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
37 行增加
和
22 行删除
+37
-22
Function.java
h2/src/main/org/h2/expression/Function.java
+3
-4
Data.java
h2/src/main/org/h2/store/Data.java
+3
-4
Column.java
h2/src/main/org/h2/table/Column.java
+1
-2
DataType.java
h2/src/main/org/h2/value/DataType.java
+1
-2
Transfer.java
h2/src/main/org/h2/value/Transfer.java
+4
-6
ValueTimestamp.java
h2/src/main/org/h2/value/ValueTimestamp.java
+22
-1
TestDataPage.java
h2/src/test/org/h2/test/unit/TestDataPage.java
+2
-2
TestValueMemory.java
h2/src/test/org/h2/test/unit/TestValueMemory.java
+1
-1
没有找到文件。
h2/src/main/org/h2/expression/Function.java
浏览文件 @
af80d630
...
@@ -885,7 +885,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -885,7 +885,7 @@ public class Function extends Expression implements FunctionCall {
case
NOW:
case
NOW:
case
CURRENT_TIMESTAMP:
{
case
CURRENT_TIMESTAMP:
{
long
now
=
session
.
getTransactionStart
();
long
now
=
session
.
getTransactionStart
();
ValueTimestamp
vt
=
ValueTimestamp
.
get
(
new
Timestamp
(
now
)
);
ValueTimestamp
vt
=
ValueTimestamp
.
fromMillis
(
now
);
if
(
v0
!=
null
)
{
if
(
v0
!=
null
)
{
Mode
mode
=
database
.
getMode
();
Mode
mode
=
database
.
getMode
();
vt
=
(
ValueTimestamp
)
vt
.
convertScale
(
vt
=
(
ValueTimestamp
)
vt
.
convertScale
(
...
@@ -1226,8 +1226,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1226,8 +1226,7 @@ public class Function extends Expression implements FunctionCall {
c
.
set
(
Calendar
.
MINUTE
,
0
);
c
.
set
(
Calendar
.
MINUTE
,
0
);
c
.
set
(
Calendar
.
SECOND
,
0
);
c
.
set
(
Calendar
.
SECOND
,
0
);
c
.
set
(
Calendar
.
MILLISECOND
,
0
);
c
.
set
(
Calendar
.
MILLISECOND
,
0
);
result
=
ValueTimestamp
.
get
(
result
=
ValueTimestamp
.
fromMillis
(
c
.
getTimeInMillis
());
new
java
.
sql
.
Timestamp
(
c
.
getTimeInMillis
()));
}
else
{
}
else
{
double
d
=
v0
.
getDouble
();
double
d
=
v0
.
getDouble
();
int
p
=
v1
==
null
?
0
:
v1
.
getInt
();
int
p
=
v1
==
null
?
0
:
v1
.
getInt
();
...
@@ -1453,7 +1452,7 @@ public class Function extends Expression implements FunctionCall {
...
@@ -1453,7 +1452,7 @@ public class Function extends Expression implements FunctionCall {
null
:
v3
==
ValueNull
.
INSTANCE
?
null
:
v3
.
getString
();
null
:
v3
==
ValueNull
.
INSTANCE
?
null
:
v3
.
getString
();
java
.
util
.
Date
d
=
DateTimeUtils
.
parseDateTime
(
java
.
util
.
Date
d
=
DateTimeUtils
.
parseDateTime
(
v0
.
getString
(),
v1
.
getString
(),
locale
,
tz
);
v0
.
getString
(),
v1
.
getString
(),
locale
,
tz
);
result
=
ValueTimestamp
.
get
(
new
Timestamp
(
d
.
getTime
()
));
result
=
ValueTimestamp
.
fromMillis
(
d
.
getTime
(
));
}
}
break
;
break
;
}
}
...
...
h2/src/main/org/h2/store/Data.java
浏览文件 @
af80d630
...
@@ -763,10 +763,9 @@ public class Data {
...
@@ -763,10 +763,9 @@ public class Data {
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValue
,
nanos
);
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValue
,
nanos
);
}
}
case
Value
.
TIMESTAMP
:
{
case
Value
.
TIMESTAMP
:
{
Timestamp
ts
=
new
Timestamp
(
return
ValueTimestamp
.
fromMillisNanos
(
DateTimeUtils
.
getTimeUTCWithoutDst
(
readVarLong
()));
DateTimeUtils
.
getTimeUTCWithoutDst
(
readVarLong
()),
ts
.
setNanos
(
readVarInt
());
readVarInt
());
return
ValueTimestamp
.
get
(
ts
);
}
}
case
Value
.
BYTES
:
{
case
Value
.
BYTES
:
{
int
len
=
readVarInt
();
int
len
=
readVarInt
();
...
...
h2/src/main/org/h2/table/Column.java
浏览文件 @
af80d630
...
@@ -294,8 +294,7 @@ public class Column {
...
@@ -294,8 +294,7 @@ public class Column {
if
(
dt
.
decimal
)
{
if
(
dt
.
decimal
)
{
value
=
ValueInt
.
get
(
0
).
convertTo
(
type
);
value
=
ValueInt
.
get
(
0
).
convertTo
(
type
);
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP
)
{
}
else
if
(
dt
.
type
==
Value
.
TIMESTAMP
)
{
value
=
ValueTimestamp
.
get
(
new
Timestamp
(
value
=
ValueTimestamp
.
fromMillis
(
session
.
getTransactionStart
());
session
.
getTransactionStart
()));
}
else
if
(
dt
.
type
==
Value
.
TIME
)
{
}
else
if
(
dt
.
type
==
Value
.
TIME
)
{
value
=
ValueTime
.
fromNanos
(
0
);
value
=
ValueTime
.
fromNanos
(
0
);
}
else
if
(
dt
.
type
==
Value
.
DATE
)
{
}
else
if
(
dt
.
type
==
Value
.
DATE
)
{
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
af80d630
...
@@ -990,8 +990,7 @@ public class DataType {
...
@@ -990,8 +990,7 @@ public class DataType {
}
else
if
(
x
instanceof
Timestamp
)
{
}
else
if
(
x
instanceof
Timestamp
)
{
return
ValueTimestamp
.
get
((
Timestamp
)
x
);
return
ValueTimestamp
.
get
((
Timestamp
)
x
);
}
else
if
(
x
instanceof
java
.
util
.
Date
)
{
}
else
if
(
x
instanceof
java
.
util
.
Date
)
{
return
ValueTimestamp
.
get
(
return
ValueTimestamp
.
fromMillis
(((
java
.
util
.
Date
)
x
).
getTime
());
new
Timestamp
(((
java
.
util
.
Date
)
x
).
getTime
()));
}
else
if
(
x
instanceof
java
.
io
.
Reader
)
{
}
else
if
(
x
instanceof
java
.
io
.
Reader
)
{
Reader
r
=
new
BufferedReader
((
java
.
io
.
Reader
)
x
);
Reader
r
=
new
BufferedReader
((
java
.
io
.
Reader
)
x
);
return
session
.
getDataHandler
().
getLobStorage
().
return
session
.
getDataHandler
().
getLobStorage
().
...
...
h2/src/main/org/h2/value/Transfer.java
浏览文件 @
af80d630
...
@@ -565,13 +565,11 @@ public class Transfer {
...
@@ -565,13 +565,11 @@ public class Transfer {
if
(
version
>=
Constants
.
TCP_PROTOCOL_VERSION_9
)
{
if
(
version
>=
Constants
.
TCP_PROTOCOL_VERSION_9
)
{
return
ValueTimestamp
.
fromDateValueAndNanos
(
readLong
(),
readLong
());
return
ValueTimestamp
.
fromDateValueAndNanos
(
readLong
(),
readLong
());
}
else
if
(
version
>=
Constants
.
TCP_PROTOCOL_VERSION_7
)
{
}
else
if
(
version
>=
Constants
.
TCP_PROTOCOL_VERSION_7
)
{
Timestamp
ts
=
new
Timestamp
(
DateTimeUtils
.
getTimeUTCWithoutDst
(
readLong
()));
return
ValueTimestamp
.
fromMillisNanos
(
ts
.
setNanos
(
readInt
());
DateTimeUtils
.
getTimeUTCWithoutDst
(
readLong
()),
return
ValueTimestamp
.
get
(
ts
);
readInt
()
);
}
}
Timestamp
ts
=
new
Timestamp
(
readLong
());
return
ValueTimestamp
.
fromMillisNanos
(
readLong
(),
readInt
());
ts
.
setNanos
(
readInt
());
return
ValueTimestamp
.
get
(
ts
);
}
}
case
Value
.
DECIMAL
:
case
Value
.
DECIMAL
:
return
ValueDecimal
.
get
(
new
BigDecimal
(
readString
()));
return
ValueDecimal
.
get
(
new
BigDecimal
(
readString
()));
...
...
h2/src/main/org/h2/value/ValueTimestamp.java
浏览文件 @
af80d630
...
@@ -13,7 +13,6 @@ import java.sql.SQLException;
...
@@ -13,7 +13,6 @@ import java.sql.SQLException;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.TimeZone
;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.message.DbException
;
import
org.h2.message.DbException
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.DateTimeUtils
;
...
@@ -79,6 +78,28 @@ public class ValueTimestamp extends Value {
...
@@ -79,6 +78,28 @@ public class ValueTimestamp extends Value {
return
fromDateValueAndNanos
(
dateValue
,
nanos
);
return
fromDateValueAndNanos
(
dateValue
,
nanos
);
}
}
/**
* Get or create a timestamp value for the given date/time in millis.
*
* @return the value
*/
public
static
ValueTimestamp
fromMillisNanos
(
long
ms
,
int
nanos
)
{
long
dateValue
=
DateTimeUtils
.
dateValueFromDate
(
ms
);
long
timeNanos
=
nanos
+
DateTimeUtils
.
nanosFromDate
(
ms
);
return
fromDateValueAndNanos
(
dateValue
,
timeNanos
);
}
/**
* Get or create a timestamp value for the given date/time in millis.
*
* @return the value
*/
public
static
ValueTimestamp
fromMillis
(
long
ms
)
{
long
dateValue
=
DateTimeUtils
.
dateValueFromDate
(
ms
);
long
nanos
=
DateTimeUtils
.
nanosFromDate
(
ms
);
return
fromDateValueAndNanos
(
dateValue
,
nanos
);
}
/**
/**
* Parse a string to a ValueTimestamp. This method supports the format
* Parse a string to a ValueTimestamp. This method supports the format
* +/-year-month-day hour:minute:seconds.fractional and an optional timezone
* +/-year-month-day hour:minute:seconds.fractional and an optional timezone
...
...
h2/src/test/org/h2/test/unit/TestDataPage.java
浏览文件 @
af80d630
...
@@ -166,8 +166,8 @@ public class TestDataPage extends TestBase implements DataHandler {
...
@@ -166,8 +166,8 @@ public class TestDataPage extends TestBase implements DataHandler {
testValue
(
ValueDate
.
get
(
new
Date
(
0
)));
testValue
(
ValueDate
.
get
(
new
Date
(
0
)));
testValue
(
ValueTime
.
get
(
new
Time
(
System
.
currentTimeMillis
())));
testValue
(
ValueTime
.
get
(
new
Time
(
System
.
currentTimeMillis
())));
testValue
(
ValueTime
.
get
(
new
Time
(
0
)));
testValue
(
ValueTime
.
get
(
new
Time
(
0
)));
testValue
(
ValueTimestamp
.
get
(
new
Timestamp
(
System
.
currentTimeMillis
()
)));
testValue
(
ValueTimestamp
.
fromMillis
(
System
.
currentTimeMillis
(
)));
testValue
(
ValueTimestamp
.
get
(
new
Timestamp
(
0
)
));
testValue
(
ValueTimestamp
.
fromMillis
(
0
));
testValue
(
ValueJavaObject
.
getNoCopy
(
null
,
new
byte
[
0
],
this
));
testValue
(
ValueJavaObject
.
getNoCopy
(
null
,
new
byte
[
0
],
this
));
testValue
(
ValueJavaObject
.
getNoCopy
(
null
,
new
byte
[
100
],
this
));
testValue
(
ValueJavaObject
.
getNoCopy
(
null
,
new
byte
[
100
],
this
));
for
(
int
i
=
0
;
i
<
300
;
i
++)
{
for
(
int
i
=
0
;
i
<
300
;
i
++)
{
...
...
h2/src/test/org/h2/test/unit/TestValueMemory.java
浏览文件 @
af80d630
...
@@ -162,7 +162,7 @@ public class TestValueMemory extends TestBase implements DataHandler {
...
@@ -162,7 +162,7 @@ public class TestValueMemory extends TestBase implements DataHandler {
case
Value
.
DATE
:
case
Value
.
DATE
:
return
ValueDate
.
get
(
new
java
.
sql
.
Date
(
random
.
nextLong
()));
return
ValueDate
.
get
(
new
java
.
sql
.
Date
(
random
.
nextLong
()));
case
Value
.
TIMESTAMP
:
case
Value
.
TIMESTAMP
:
return
ValueTimestamp
.
get
(
new
java
.
sql
.
Timestamp
(
random
.
nextLong
()
));
return
ValueTimestamp
.
fromMillis
(
random
.
nextLong
(
));
case
Value
.
BYTES
:
case
Value
.
BYTES
:
return
ValueBytes
.
get
(
randomBytes
(
random
.
nextInt
(
1000
)));
return
ValueBytes
.
get
(
randomBytes
(
random
.
nextInt
(
1000
)));
case
Value
.
STRING
:
case
Value
.
STRING
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论