Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
dbca79d7
提交
dbca79d7
authored
1月 24, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use own constants in Data
上级
36aa52bc
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
103 行增加
和
80 行删除
+103
-80
Data.java
h2/src/main/org/h2/store/Data.java
+103
-80
没有找到文件。
h2/src/main/org/h2/store/Data.java
浏览文件 @
dbca79d7
...
...
@@ -76,22 +76,44 @@ public class Data {
*/
public
static
final
int
LENGTH_LONG
=
8
;
/**
* Storage type for ValueRow.
*/
private
static
final
int
ROW
=
27
;
private
static
final
int
INT_0_15
=
32
;
private
static
final
int
LONG_0_7
=
48
;
private
static
final
int
DECIMAL_0_1
=
56
;
private
static
final
int
DECIMAL_SMALL_0
=
58
;
private
static
final
int
DECIMAL_SMALL
=
59
;
private
static
final
int
DOUBLE_0_1
=
60
;
private
static
final
int
FLOAT_0_1
=
62
;
private
static
final
int
BOOLEAN_FALSE
=
64
;
private
static
final
int
BOOLEAN_TRUE
=
65
;
private
static
final
int
INT_NEG
=
66
;
private
static
final
int
LONG_NEG
=
67
;
private
static
final
int
STRING_0_31
=
68
;
private
static
final
byte
NULL
=
0
;
private
static
final
byte
BYTE
=
2
;
private
static
final
byte
SHORT
=
3
;
private
static
final
byte
INT
=
4
;
private
static
final
byte
LONG
=
5
;
private
static
final
byte
DECIMAL
=
6
;
private
static
final
byte
DOUBLE
=
7
;
private
static
final
byte
FLOAT
=
8
;
private
static
final
byte
TIME
=
9
;
private
static
final
byte
DATE
=
10
;
private
static
final
byte
TIMESTAMP
=
11
;
private
static
final
byte
BYTES
=
12
;
private
static
final
byte
STRING
=
13
;
private
static
final
byte
STRING_IGNORECASE
=
14
;
private
static
final
byte
BLOB
=
15
;
private
static
final
byte
CLOB
=
16
;
private
static
final
byte
ARRAY
=
17
;
private
static
final
byte
RESULT_SET
=
18
;
private
static
final
byte
JAVA_OBJECT
=
19
;
private
static
final
byte
UUID
=
20
;
private
static
final
byte
STRING_FIXED
=
21
;
private
static
final
byte
GEOMETRY
=
22
;
private
static
final
byte
TIMESTAMP_TZ
=
24
;
private
static
final
byte
ENUM
=
25
;
private
static
final
byte
INTERVAL
=
26
;
private
static
final
byte
ROW
=
27
;
private
static
final
byte
INT_0_15
=
32
;
private
static
final
byte
LONG_0_7
=
48
;
private
static
final
byte
DECIMAL_0_1
=
56
;
private
static
final
byte
DECIMAL_SMALL_0
=
58
;
private
static
final
byte
DECIMAL_SMALL
=
59
;
private
static
final
byte
DOUBLE_0_1
=
60
;
private
static
final
byte
FLOAT_0_1
=
62
;
private
static
final
byte
BOOLEAN_FALSE
=
64
;
private
static
final
byte
BOOLEAN_TRUE
=
65
;
private
static
final
byte
INT_NEG
=
66
;
private
static
final
byte
LONG_NEG
=
67
;
private
static
final
byte
STRING_0_31
=
68
;
private
static
final
int
BYTES_0_31
=
100
;
private
static
final
int
LOCAL_TIME
=
132
;
private
static
final
int
LOCAL_DATE
=
133
;
...
...
@@ -421,32 +443,32 @@ public class Data {
public
void
writeValue
(
Value
v
)
{
int
start
=
pos
;
if
(
v
==
ValueNull
.
INSTANCE
)
{
data
[
pos
++]
=
0
;
data
[
pos
++]
=
NULL
;
return
;
}
int
type
=
v
.
getValueType
();
switch
(
type
)
{
case
Value
.
BOOLEAN
:
writeByte
(
(
byte
)
(
v
.
getBoolean
()
?
BOOLEAN_TRUE
:
BOOLEAN_FALSE
)
);
writeByte
(
v
.
getBoolean
()
?
BOOLEAN_TRUE
:
BOOLEAN_FALSE
);
break
;
case
Value
.
BYTE
:
writeByte
(
(
byte
)
type
);
writeByte
(
BYTE
);
writeByte
(
v
.
getByte
());
break
;
case
Value
.
SHORT
:
writeByte
(
(
byte
)
type
);
writeByte
(
SHORT
);
writeShortInt
(
v
.
getShort
());
break
;
case
Value
.
ENUM
:
case
Value
.
INT
:
{
int
x
=
v
.
getInt
();
if
(
x
<
0
)
{
writeByte
(
(
byte
)
INT_NEG
);
writeByte
(
INT_NEG
);
writeVarInt
(-
x
);
}
else
if
(
x
<
16
)
{
writeByte
((
byte
)
(
INT_0_15
+
x
));
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
type
==
Value
.
INT
?
INT
:
ENUM
);
writeVarInt
(
x
);
}
break
;
...
...
@@ -454,12 +476,12 @@ public class Data {
case
Value
.
LONG
:
{
long
x
=
v
.
getLong
();
if
(
x
<
0
)
{
writeByte
(
(
byte
)
LONG_NEG
);
writeByte
(
LONG_NEG
);
writeVarLong
(-
x
);
}
else
if
(
x
<
8
)
{
writeByte
((
byte
)
(
LONG_0_7
+
x
));
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
LONG
);
writeVarLong
(
x
);
}
break
;
...
...
@@ -467,7 +489,7 @@ public class Data {
case
Value
.
DECIMAL
:
{
BigDecimal
x
=
v
.
getBigDecimal
();
if
(
BigDecimal
.
ZERO
.
equals
(
x
))
{
writeByte
(
(
byte
)
DECIMAL_0_1
);
writeByte
(
DECIMAL_0_1
);
}
else
if
(
BigDecimal
.
ONE
.
equals
(
x
))
{
writeByte
((
byte
)
(
DECIMAL_0_1
+
1
));
}
else
{
...
...
@@ -476,15 +498,15 @@ public class Data {
int
bits
=
b
.
bitLength
();
if
(
bits
<=
63
)
{
if
(
scale
==
0
)
{
writeByte
(
(
byte
)
DECIMAL_SMALL_0
);
writeByte
(
DECIMAL_SMALL_0
);
writeVarLong
(
b
.
longValue
());
}
else
{
writeByte
(
(
byte
)
DECIMAL_SMALL
);
writeByte
(
DECIMAL_SMALL
);
writeVarInt
(
scale
);
writeVarLong
(
b
.
longValue
());
}
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
DECIMAL
);
writeVarInt
(
scale
);
byte
[]
bytes
=
b
.
toByteArray
();
writeVarInt
(
bytes
.
length
);
...
...
@@ -503,7 +525,7 @@ public class Data {
writeVarLong
(
millis
);
writeVarLong
(
nanos
);
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
TIME
);
writeVarLong
(
DateTimeUtils
.
getTimeLocalWithoutDst
(
v
.
getTime
()));
}
break
;
...
...
@@ -513,7 +535,7 @@ public class Data {
long
x
=
((
ValueDate
)
v
).
getDateValue
();
writeVarLong
(
x
);
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
DATE
);
long
x
=
DateTimeUtils
.
getTimeLocalWithoutDst
(
v
.
getDate
());
writeVarLong
(
x
/
MILLIS_PER_MINUTE
);
}
...
...
@@ -532,7 +554,7 @@ public class Data {
writeVarLong
(
nanos
);
}
else
{
Timestamp
ts
=
v
.
getTimestamp
();
writeByte
(
(
byte
)
type
);
writeByte
(
TIMESTAMP
);
writeVarLong
(
DateTimeUtils
.
getTimeLocalWithoutDst
(
ts
));
writeVarInt
(
ts
.
getNanos
()
%
1_000_000
);
}
...
...
@@ -540,7 +562,7 @@ public class Data {
}
case
Value
.
TIMESTAMP_TZ
:
{
ValueTimestampTimeZone
ts
=
(
ValueTimestampTimeZone
)
v
;
writeByte
(
(
byte
)
type
);
writeByte
(
TIMESTAMP_TZ
);
writeVarLong
(
ts
.
getDateValue
());
writeVarLong
(
ts
.
getTimeNanos
());
writeVarInt
(
ts
.
getTimeZoneOffsetMins
());
...
...
@@ -549,7 +571,7 @@ public class Data {
case
Value
.
GEOMETRY
:
// fall though
case
Value
.
JAVA_OBJECT
:
{
writeByte
(
(
byte
)
type
);
writeByte
(
type
==
Value
.
GEOMETRY
?
GEOMETRY
:
JAVA_OBJECT
);
byte
[]
b
=
v
.
getBytesNoCopy
();
int
len
=
b
.
length
;
writeVarInt
(
len
);
...
...
@@ -563,14 +585,14 @@ public class Data {
writeByte
((
byte
)
(
BYTES_0_31
+
len
));
write
(
b
,
0
,
len
);
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
BYTES
);
writeVarInt
(
len
);
write
(
b
,
0
,
len
);
}
break
;
}
case
Value
.
UUID
:
{
writeByte
(
(
byte
)
type
);
writeByte
(
UUID
);
ValueUuid
uuid
=
(
ValueUuid
)
v
;
writeLong
(
uuid
.
getHigh
());
writeLong
(
uuid
.
getLow
());
...
...
@@ -583,14 +605,17 @@ public class Data {
writeByte
((
byte
)
(
STRING_0_31
+
len
));
writeStringWithoutLength
(
s
,
len
);
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
STRING
);
writeString
(
s
);
}
break
;
}
case
Value
.
STRING_IGNORECASE
:
writeByte
(
STRING_IGNORECASE
);
writeString
(
v
.
getString
());
break
;
case
Value
.
STRING_FIXED
:
writeByte
(
(
byte
)
type
);
writeByte
(
STRING_FIXED
);
writeString
(
v
.
getString
());
break
;
case
Value
.
DOUBLE
:
{
...
...
@@ -600,9 +625,9 @@ public class Data {
}
else
{
long
d
=
Double
.
doubleToLongBits
(
x
);
if
(
d
==
ValueDouble
.
ZERO_BITS
)
{
writeByte
(
(
byte
)
DOUBLE_0_1
);
writeByte
(
DOUBLE_0_1
);
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
DOUBLE
);
writeVarLong
(
Long
.
reverse
(
d
));
}
}
...
...
@@ -615,9 +640,9 @@ public class Data {
}
else
{
int
f
=
Float
.
floatToIntBits
(
x
);
if
(
f
==
ValueFloat
.
ZERO_BITS
)
{
writeByte
(
(
byte
)
FLOAT_0_1
);
writeByte
(
FLOAT_0_1
);
}
else
{
writeByte
(
(
byte
)
type
);
writeByte
(
FLOAT
);
writeVarInt
(
Integer
.
reverse
(
f
));
}
}
...
...
@@ -625,7 +650,7 @@ public class Data {
}
case
Value
.
BLOB
:
case
Value
.
CLOB
:
{
writeByte
(
(
byte
)
type
);
writeByte
(
type
==
Value
.
BLOB
?
BLOB
:
CLOB
);
if
(
v
instanceof
ValueLob
)
{
ValueLob
lob
=
(
ValueLob
)
v
;
byte
[]
small
=
lob
.
getSmall
();
...
...
@@ -663,7 +688,7 @@ public class Data {
}
case
Value
.
ARRAY
:
case
Value
.
ROW
:
{
writeByte
(
(
byte
)
(
type
==
Value
.
ARRAY
?
Value
.
ARRAY
:
/* Special storage type for ValueRow */
ROW
)
);
writeByte
(
type
==
Value
.
ARRAY
?
ARRAY
:
ROW
);
Value
[]
list
=
((
ValueCollectionBase
)
v
).
getList
();
writeVarInt
(
list
.
length
);
for
(
Value
x
:
list
)
{
...
...
@@ -672,7 +697,7 @@ public class Data {
break
;
}
case
Value
.
RESULT_SET
:
{
writeByte
(
(
byte
)
type
);
writeByte
(
RESULT_SET
);
ResultInterface
result
=
((
ValueResultSet
)
v
).
getResult
();
result
.
reset
();
int
columnCount
=
result
.
getVisibleColumnCount
();
...
...
@@ -705,7 +730,7 @@ public class Data {
if
(
interval
.
isNegative
())
{
ordinal
=
~
ordinal
;
}
writeByte
(
(
byte
)
Value
.
INTERVAL_YEAR
);
writeByte
(
INTERVAL
);
writeByte
((
byte
)
ordinal
);
writeVarLong
(
interval
.
getLeading
());
break
;
...
...
@@ -723,7 +748,7 @@ public class Data {
if
(
interval
.
isNegative
())
{
ordinal
=
~
ordinal
;
}
writeByte
(
(
byte
)
Value
.
INTERVAL_YEAR
);
writeByte
(
INTERVAL
);
writeByte
((
byte
)
ordinal
);
writeVarLong
(
interval
.
getLeading
());
writeVarLong
(
interval
.
getRemaining
());
...
...
@@ -732,7 +757,7 @@ public class Data {
default
:
if
(
JdbcUtils
.
customDataTypesHandler
!=
null
)
{
byte
[]
b
=
v
.
getBytesNoCopy
();
writeByte
(
CUSTOM_DATA_TYPE
);
writeByte
(
(
byte
)
CUSTOM_DATA_TYPE
);
writeVarInt
(
type
);
writeVarInt
(
b
.
length
);
write
(
b
,
0
,
b
.
length
);
...
...
@@ -752,7 +777,7 @@ public class Data {
public
Value
readValue
()
{
int
type
=
data
[
pos
++]
&
255
;
switch
(
type
)
{
case
Value
.
NULL
:
case
NULL:
return
ValueNull
.
INSTANCE
;
case
BOOLEAN_TRUE:
return
ValueBoolean
.
TRUE
;
...
...
@@ -760,16 +785,16 @@ public class Data {
return
ValueBoolean
.
FALSE
;
case
INT_NEG:
return
ValueInt
.
get
(-
readVarInt
());
case
Value
.
ENUM
:
case
Value
.
INT
:
case
ENUM:
case
INT:
return
ValueInt
.
get
(
readVarInt
());
case
LONG_NEG:
return
ValueLong
.
get
(-
readVarLong
());
case
Value
.
LONG
:
return
ValueLong
.
get
(
readVarLong
());
case
Value
.
BYTE
:
case
BYTE:
return
ValueByte
.
get
(
readByte
());
case
Value
.
SHORT
:
case
SHORT:
return
ValueShort
.
get
(
readShortInt
());
case
DECIMAL_0_1:
return
(
ValueDecimal
)
ValueDecimal
.
ZERO
;
...
...
@@ -781,7 +806,7 @@ public class Data {
int
scale
=
readVarInt
();
return
ValueDecimal
.
get
(
BigDecimal
.
valueOf
(
readVarLong
(),
scale
));
}
case
Value
.
DECIMAL
:
{
case
DECIMAL:
{
int
scale
=
readVarInt
();
int
len
=
readVarInt
();
byte
[]
buff
=
Utils
.
newBytes
(
len
);
...
...
@@ -792,7 +817,7 @@ public class Data {
case
LOCAL_DATE:
{
return
ValueDate
.
fromDateValue
(
readVarLong
());
}
case
Value
.
DATE
:
{
case
DATE:
{
long
x
=
readVarLong
()
*
MILLIS_PER_MINUTE
;
return
ValueDate
.
fromMillis
(
DateTimeUtils
.
getTimeUTCWithoutDst
(
x
));
}
...
...
@@ -800,7 +825,7 @@ public class Data {
long
nanos
=
readVarLong
()
*
1_000_000
+
readVarLong
();
return
ValueTime
.
fromNanos
(
nanos
);
}
case
Value
.
TIME
:
case
TIME:
// need to normalize the year, month and day
return
ValueTime
.
fromMillis
(
DateTimeUtils
.
getTimeUTCWithoutDst
(
readVarLong
()));
...
...
@@ -809,42 +834,42 @@ public class Data {
long
nanos
=
readVarLong
()
*
1_000_000
+
readVarLong
();
return
ValueTimestamp
.
fromDateValueAndNanos
(
dateValue
,
nanos
);
}
case
Value
.
TIMESTAMP
:
{
case
TIMESTAMP:
{
return
ValueTimestamp
.
fromMillisNanos
(
DateTimeUtils
.
getTimeUTCWithoutDst
(
readVarLong
()),
readVarInt
()
%
1_000_000
);
}
case
Value
.
TIMESTAMP_TZ
:
{
case
TIMESTAMP_TZ:
{
long
dateValue
=
readVarLong
();
long
nanos
=
readVarLong
();
short
tz
=
(
short
)
readVarInt
();
return
ValueTimestampTimeZone
.
fromDateValueAndNanos
(
dateValue
,
nanos
,
tz
);
}
case
Value
.
BYTES
:
{
case
BYTES:
{
int
len
=
readVarInt
();
byte
[]
b
=
Utils
.
newBytes
(
len
);
read
(
b
,
0
,
len
);
return
ValueBytes
.
getNoCopy
(
b
);
}
case
Value
.
GEOMETRY
:
{
case
GEOMETRY:
{
int
len
=
readVarInt
();
byte
[]
b
=
Utils
.
newBytes
(
len
);
read
(
b
,
0
,
len
);
return
ValueGeometry
.
get
(
b
);
}
case
Value
.
JAVA_OBJECT
:
{
case
JAVA_OBJECT:
{
int
len
=
readVarInt
();
byte
[]
b
=
Utils
.
newBytes
(
len
);
read
(
b
,
0
,
len
);
return
ValueJavaObject
.
getNoCopy
(
null
,
b
,
handler
);
}
case
Value
.
UUID
:
case
UUID:
return
ValueUuid
.
get
(
readLong
(),
readLong
());
case
Value
.
STRING
:
case
STRING:
return
ValueString
.
get
(
readString
());
case
Value
.
STRING_IGNORECASE
:
case
STRING_IGNORECASE:
return
ValueStringIgnoreCase
.
get
(
readString
());
case
Value
.
STRING_FIXED
:
case
STRING_FIXED:
return
ValueStringFixed
.
get
(
readString
());
case
FLOAT_0_1:
return
ValueFloat
.
ZERO
;
...
...
@@ -854,24 +879,22 @@ public class Data {
return
ValueDouble
.
ZERO
;
case
DOUBLE_0_1
+
1
:
return
ValueDouble
.
ONE
;
case
Value
.
DOUBLE
:
return
ValueDouble
.
get
(
Double
.
longBitsToDouble
(
Long
.
reverse
(
readVarLong
())));
case
Value
.
FLOAT
:
return
ValueFloat
.
get
(
Float
.
intBitsToFloat
(
Integer
.
reverse
(
readVarInt
())));
case
Value
.
BLOB
:
case
Value
.
CLOB
:
{
case
DOUBLE:
return
ValueDouble
.
get
(
Double
.
longBitsToDouble
(
Long
.
reverse
(
readVarLong
())));
case
FLOAT:
return
ValueFloat
.
get
(
Float
.
intBitsToFloat
(
Integer
.
reverse
(
readVarInt
())));
case
BLOB:
case
CLOB:
{
int
smallLen
=
readVarInt
();
if
(
smallLen
>=
0
)
{
byte
[]
small
=
Utils
.
newBytes
(
smallLen
);
read
(
small
,
0
,
smallLen
);
return
ValueLobDb
.
createSmallLob
(
type
,
small
);
return
ValueLobDb
.
createSmallLob
(
type
==
BLOB
?
Value
.
BLOB
:
Value
.
CLOB
,
small
);
}
else
if
(
smallLen
==
-
3
)
{
int
tableId
=
readVarInt
();
long
lobId
=
readVarLong
();
long
precision
=
readVarLong
();
return
ValueLobDb
.
create
(
type
,
handler
,
tableId
,
return
ValueLobDb
.
create
(
type
==
BLOB
?
Value
.
BLOB
:
Value
.
CLOB
,
handler
,
tableId
,
lobId
,
null
,
precision
);
}
else
{
int
tableId
=
readVarInt
();
...
...
@@ -886,14 +909,14 @@ public class Data {
}
if
(
smallLen
==
-
2
)
{
String
filename
=
readString
();
return
ValueLob
.
openUnlinked
(
type
,
handler
,
tableId
,
return
ValueLob
.
openUnlinked
(
type
==
BLOB
?
Value
.
BLOB
:
Value
.
CLOB
,
handler
,
tableId
,
objectId
,
precision
,
compression
,
filename
);
}
return
ValueLob
.
openLinked
(
type
,
handler
,
tableId
,
return
ValueLob
.
openLinked
(
type
==
BLOB
?
Value
.
BLOB
:
Value
.
CLOB
,
handler
,
tableId
,
objectId
,
precision
,
compression
);
}
}
case
Value
.
ARRAY
:
case
ARRAY:
case
ROW:
// Special storage type for ValueRow
{
int
len
=
readVarInt
();
...
...
@@ -901,9 +924,9 @@ public class Data {
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
list
[
i
]
=
readValue
();
}
return
type
==
Value
.
ARRAY
?
ValueArray
.
get
(
list
)
:
ValueRow
.
get
(
list
);
return
type
==
ARRAY
?
ValueArray
.
get
(
list
)
:
ValueRow
.
get
(
list
);
}
case
Value
.
RESULT_SET
:
{
case
RESULT_SET:
{
SimpleResult
rs
=
new
SimpleResult
();
int
columns
=
readVarInt
();
for
(
int
i
=
0
;
i
<
columns
;
i
++)
{
...
...
@@ -918,7 +941,7 @@ public class Data {
}
return
ValueResultSet
.
get
(
rs
);
}
case
Value
.
INTERVAL_YEAR
:
{
case
INTERVAL
:
{
int
ordinal
=
readByte
();
boolean
negative
=
ordinal
<
0
;
if
(
negative
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论