Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
9e18b5c8
提交
9e18b5c8
authored
9月 16, 2016
作者:
Noel Grandin
提交者:
GitHub
9月 16, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #353 from royrwood/master
Add support for converting JAVA_OBJECT to UUID
上级
f44a74c8
9b040084
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
45 行增加
和
4 行删除
+45
-4
Value.java
h2/src/main/org/h2/value/Value.java
+10
-2
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+23
-0
TestValue.java
h2/src/test/org/h2/test/unit/TestValue.java
+12
-2
没有找到文件。
h2/src/main/org/h2/value/Value.java
浏览文件 @
9e18b5c8
...
...
@@ -314,9 +314,9 @@ public abstract class Value {
return
40
;
case
BLOB:
return
41
;
case
UUID:
return
42
;
case
JAVA_OBJECT:
return
42
;
case
UUID:
return
43
;
case
GEOMETRY:
return
44
;
...
...
@@ -910,6 +910,14 @@ public abstract class Value {
case
BYTES:
return
ValueUuid
.
get
(
getBytesNoCopy
());
case
JAVA_OBJECT:
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
());
}
else
{
throw
DbException
.
get
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
getString
());
}
case
TIMESTAMP_TZ:
throw
DbException
.
get
(
ErrorCode
.
DATA_CONVERSION_ERROR_1
,
getString
());
...
...
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
9e18b5c8
...
...
@@ -58,6 +58,7 @@ public class TestPreparedStatement extends TestBase {
testExecuteUpdateCall
(
conn
);
testPrepareExecute
(
conn
);
testUUID
(
conn
);
testUUIDAsJavaObject
(
conn
);
testScopedGeneratedKey
(
conn
);
testLobTempFiles
(
conn
);
testExecuteErrorTwice
(
conn
);
...
...
@@ -458,6 +459,28 @@ public class TestPreparedStatement extends TestBase {
stat
.
execute
(
"drop table test_uuid"
);
}
private
void
testUUIDAsJavaObject
(
Connection
conn
)
throws
SQLException
{
String
uuidStr
=
"12345678-1234-4321-8765-123456789012"
;
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test_uuid(id uuid primary key)"
);
UUID
origUUID
=
UUID
.
fromString
(
uuidStr
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test_uuid values(?)"
);
prep
.
setObject
(
1
,
origUUID
,
java
.
sql
.
Types
.
JAVA_OBJECT
);
prep
.
execute
();
prep
=
conn
.
prepareStatement
(
"select * from test_uuid where id=?"
);
prep
.
setObject
(
1
,
origUUID
,
java
.
sql
.
Types
.
JAVA_OBJECT
);
ResultSet
rs
=
prep
.
executeQuery
();
rs
.
next
();
Object
o
=
rs
.
getObject
(
1
);
assertTrue
(
o
instanceof
UUID
);
UUID
selectedUUID
=
(
UUID
)
o
;
assertTrue
(
selectedUUID
.
toString
().
equals
(
uuidStr
));
assertTrue
(
selectedUUID
.
equals
(
origUUID
));
stat
.
execute
(
"drop table test_uuid"
);
}
private
void
testUUIDGeneratedKeys
(
Connection
conn
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST_UUID(id UUID DEFAULT "
+
...
...
h2/src/test/org/h2/test/unit/TestValue.java
浏览文件 @
9e18b5c8
...
...
@@ -285,8 +285,18 @@ public class TestValue extends TestBase {
ValueUuid
min
=
ValueUuid
.
get
(
minHigh
,
minLow
);
assertEquals
(
"00000000-0000-4000-8000-000000000000"
,
min
.
getString
());
ValueJavaObject
vo
=
ValueJavaObject
.
getNoCopy
(
UUID
.
randomUUID
(),
null
,
null
);
assertThrows
(
DbException
.
class
,
vo
).
convertTo
(
Value
.
UUID
);
// Test conversion from ValueJavaObject to ValueUuid
String
uuidStr
=
"12345678-1234-4321-8765-123456789012"
;
UUID
origUUID
=
UUID
.
fromString
(
uuidStr
);
ValueJavaObject
valObj
=
ValueJavaObject
.
getNoCopy
(
origUUID
,
null
,
null
);
Value
valUUID
=
valObj
.
convertTo
(
Value
.
UUID
);
assertTrue
(
valUUID
instanceof
ValueUuid
);
assertTrue
((
valUUID
.
getString
().
equals
(
uuidStr
)));
assertTrue
(
valUUID
.
getObject
().
equals
(
origUUID
));
ValueJavaObject
vo_string
=
ValueJavaObject
.
getNoCopy
(
new
String
(
"This is not a ValueUuid object"
),
null
,
null
);
assertThrows
(
DbException
.
class
,
vo_string
).
convertTo
(
Value
.
UUID
);
}
private
void
testModulusDouble
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论