Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
6d3600e2
Unverified
提交
6d3600e2
authored
1月 13, 2018
作者:
Noel Grandin
提交者:
GitHub
1月 13, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #757 from katzyn/UUID
Fix handling of UUID in Datatype.readValue()
上级
605f3973
58382255
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
90 行增加
和
20 行删除
+90
-20
TableFunction.java
h2/src/main/org/h2/expression/TableFunction.java
+4
-0
SimpleResultSet.java
h2/src/main/org/h2/tools/SimpleResultSet.java
+2
-3
Utils.java
h2/src/main/org/h2/util/Utils.java
+23
-0
DataType.java
h2/src/main/org/h2/value/DataType.java
+19
-8
Value.java
h2/src/main/org/h2/value/Value.java
+1
-3
ValueUuid.java
h2/src/main/org/h2/value/ValueUuid.java
+11
-6
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+30
-0
没有找到文件。
h2/src/main/org/h2/expression/TableFunction.java
浏览文件 @
6d3600e2
...
...
@@ -136,6 +136,10 @@ public class TableFunction extends Function {
simple
.
setAutoClose
(
false
);
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
String
name
=
rs
.
getColumnName
(
i
);
/*
* TODO Some types, such as Value.BYTES and Value.UUID are mapped to the same
* SQL type and we can lose real type here.
*/
int
sqlType
=
DataType
.
convertTypeToSQLType
(
rs
.
getColumnType
(
i
));
int
precision
=
MathUtils
.
convertLongToInt
(
rs
.
getColumnPrecision
(
i
));
int
scale
=
rs
.
getColumnScale
(
i
);
...
...
h2/src/main/org/h2/tools/SimpleResultSet.java
浏览文件 @
6d3600e2
...
...
@@ -36,8 +36,8 @@ import org.h2.message.DbException;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.Utils
;
import
org.h2.value.DataType
;
import
org.h2.value.ValueUuid
;
/**
* This class is a simple result set and meta data implementation.
...
...
@@ -534,8 +534,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
return
(
byte
[])
o
;
}
if
(
o
instanceof
UUID
)
{
final
UUID
u
=
(
UUID
)
o
;
return
ValueUuid
.
get
(
u
.
getMostSignificantBits
(),
u
.
getLeastSignificantBits
()).
getBytes
();
return
Utils
.
uuidToBytes
((
UUID
)
o
);
}
return
JdbcUtils
.
serialize
(
o
,
null
);
}
...
...
h2/src/main/org/h2/util/Utils.java
浏览文件 @
6d3600e2
...
...
@@ -18,6 +18,7 @@ import java.util.Arrays;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipInputStream
;
...
...
@@ -92,6 +93,28 @@ public class Utils {
(
readInt
(
buff
,
pos
+
4
)
&
0xffffffff
L
);
}
/**
* @param uuid UUID value
* @return byte array representation
*/
public
static
byte
[]
uuidToBytes
(
UUID
uuid
)
{
return
uuidToBytes
(
uuid
.
getMostSignificantBits
(),
uuid
.
getLeastSignificantBits
());
}
/**
* @param msb most significant part of UUID
* @param lsb least significant part of UUID
* @return byte array representation
*/
public
static
byte
[]
uuidToBytes
(
long
msb
,
long
lsb
)
{
byte
[]
buff
=
new
byte
[
16
];
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
buff
[
i
]
=
(
byte
)
((
msb
>>
(
8
*
(
7
-
i
)))
&
255
);
buff
[
8
+
i
]
=
(
byte
)
((
lsb
>>
(
8
*
(
7
-
i
)))
&
255
);
}
return
buff
;
}
/**
* Calculate the index of the first occurrence of the pattern in the byte
* array, starting with the given index. This methods returns -1 if the
...
...
h2/src/main/org/h2/value/DataType.java
浏览文件 @
6d3600e2
...
...
@@ -514,15 +514,27 @@ public class DataType {
return
ValueNull
.
INSTANCE
;
}
case
Value
.
BYTES
:
{
byte
[]
buff
=
rs
.
getBytes
(
columnIndex
);
v
=
buff
==
null
?
(
Value
)
ValueNull
.
INSTANCE
:
ValueBytes
.
getNoCopy
(
buff
);
/*
* Both BINARY and UUID may be mapped to Value.BYTES. getObject() returns byte[]
* for SQL BINARY, UUID for SQL UUID and null for SQL NULL.
*/
Object
o
=
rs
.
getObject
(
columnIndex
);
if
(
o
instanceof
byte
[])
{
v
=
ValueBytes
.
getNoCopy
((
byte
[])
o
);
}
else
if
(
o
!=
null
)
{
v
=
ValueUuid
.
get
((
UUID
)
o
);
}
else
v
=
ValueNull
.
INSTANCE
;
break
;
}
case
Value
.
UUID
:
{
byte
[]
buff
=
rs
.
getBytes
(
columnIndex
);
v
=
buff
==
null
?
(
Value
)
ValueNull
.
INSTANCE
:
ValueUuid
.
get
(
buff
);
Object
o
=
rs
.
getObject
(
columnIndex
);
if
(
o
instanceof
UUID
)
{
v
=
ValueUuid
.
get
((
UUID
)
o
);
}
else
if
(
o
!=
null
)
v
=
ValueUuid
.
get
((
byte
[])
o
);
else
v
=
ValueNull
.
INSTANCE
;
break
;
}
case
Value
.
BOOLEAN
:
{
...
...
@@ -1100,8 +1112,7 @@ public class DataType {
}
return
ValueResultSet
.
getCopy
((
ResultSet
)
x
,
Integer
.
MAX_VALUE
);
}
else
if
(
x
instanceof
UUID
)
{
UUID
u
=
(
UUID
)
x
;
return
ValueUuid
.
get
(
u
.
getMostSignificantBits
(),
u
.
getLeastSignificantBits
());
return
ValueUuid
.
get
((
UUID
)
x
);
}
else
if
(
x
instanceof
Object
[])
{
// (a.getClass().isArray());
// (a.getClass().getComponentType().isPrimitive());
...
...
h2/src/main/org/h2/value/Value.java
浏览文件 @
6d3600e2
...
...
@@ -944,9 +944,7 @@ public abstract class Value {
Object
object
=
JdbcUtils
.
deserialize
(
getBytesNoCopy
(),
getDataHandler
());
if
(
object
instanceof
java
.
util
.
UUID
)
{
java
.
util
.
UUID
uuid
=
(
java
.
util
.
UUID
)
object
;
return
ValueUuid
.
get
(
uuid
.
getMostSignificantBits
(),
uuid
.
getLeastSignificantBits
());
return
ValueUuid
.
get
((
java
.
util
.
UUID
)
object
);
}
throw
DbException
.
get
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
getString
());
case
TIMESTAMP_TZ:
...
...
h2/src/main/org/h2/value/ValueUuid.java
浏览文件 @
6d3600e2
...
...
@@ -84,6 +84,16 @@ public class ValueUuid extends Value {
return
(
ValueUuid
)
Value
.
cache
(
new
ValueUuid
(
high
,
low
));
}
/**
* Get or create a UUID for the given Java UUID.
*
* @param uuid Java UUID
* @return the UUID
*/
public
static
ValueUuid
get
(
UUID
uuid
)
{
return
get
(
uuid
.
getMostSignificantBits
(),
uuid
.
getLeastSignificantBits
());
}
/**
* Get or create a UUID for the given text representation.
*
...
...
@@ -176,12 +186,7 @@ public class ValueUuid extends Value {
@Override
public
byte
[]
getBytes
()
{
byte
[]
buff
=
new
byte
[
16
];
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
buff
[
i
]
=
(
byte
)
((
high
>>
(
8
*
(
7
-
i
)))
&
255
);
buff
[
8
+
i
]
=
(
byte
)
((
low
>>
(
8
*
(
7
-
i
)))
&
255
);
}
return
buff
;
return
Utils
.
uuidToBytes
(
high
,
low
);
}
@Override
...
...
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
6d3600e2
...
...
@@ -8,17 +8,21 @@ package org.h2.test.unit;
import
java.math.BigDecimal
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.sql.Types
;
import
java.util.Arrays
;
import
java.util.UUID
;
import
org.h2.api.ErrorCode
;
import
org.h2.message.DbException
;
import
org.h2.test.TestBase
;
import
org.h2.test.utils.AssertThrows
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.Utils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -50,6 +54,7 @@ public class TestValue extends TestBase {
@Override
public
void
test
()
throws
SQLException
{
testResultSetOperations
();
testBinaryAndUuid
();
testCastTrim
();
testValueResultSet
();
testDataType
();
...
...
@@ -87,6 +92,7 @@ public class TestValue extends TestBase {
testResultSetOperation
(
new
Time
(
7
));
testResultSetOperation
(
new
Timestamp
(
8
));
testResultSetOperation
(
new
BigDecimal
(
"9"
));
testResultSetOperation
(
UUID
.
randomUUID
());
SimpleResultSet
rs2
=
new
SimpleResultSet
();
rs2
.
setAutoClose
(
false
);
...
...
@@ -114,6 +120,30 @@ public class TestValue extends TestBase {
}
}
private
void
testBinaryAndUuid
()
throws
SQLException
{
Connection
conn
=
getConnection
(
"binaryAndUuid"
);
try
{
UUID
uuid
=
UUID
.
randomUUID
();
PreparedStatement
prep
;
ResultSet
rs
;
// Check conversion to byte[]
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TABLE(X BINARY=?)"
);
prep
.
setObject
(
1
,
new
Object
[]
{
uuid
});
rs
=
prep
.
executeQuery
();
rs
.
next
();
assertTrue
(
Arrays
.
equals
(
Utils
.
uuidToBytes
(
uuid
),
(
byte
[])
rs
.
getObject
(
1
)));
// Check that type is not changed
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TABLE(X UUID=?)"
);
prep
.
setObject
(
1
,
new
Object
[]
{
uuid
});
rs
=
prep
.
executeQuery
();
rs
.
next
();
assertEquals
(
uuid
,
rs
.
getObject
(
1
));
}
finally
{
conn
.
close
();
deleteDb
(
"binaryAndUuid"
);
}
}
private
void
testCastTrim
()
{
Value
v
;
String
spaces
=
new
String
(
new
char
[
100
]).
replace
((
char
)
0
,
' '
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论