Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b4aedbcf
提交
b4aedbcf
authored
16 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto-Reconnect
上级
3d7f8f3a
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
13 行删除
+39
-13
UpdatableRow.java
h2/src/main/org/h2/result/UpdatableRow.java
+4
-8
DataType.java
h2/src/main/org/h2/value/DataType.java
+2
-2
TestFileLockSerialized.java
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
+33
-3
没有找到文件。
h2/src/main/org/h2/result/UpdatableRow.java
浏览文件 @
b4aedbcf
...
@@ -6,14 +6,13 @@
...
@@ -6,14 +6,13 @@
*/
*/
package
org
.
h2
.
result
;
package
org
.
h2
.
result
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.DatabaseMetaData
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.
engine.SessionInterface
;
import
org.h2.
jdbc.JdbcConnection
;
import
org.h2.message.Message
;
import
org.h2.message.Message
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.ObjectArray
;
import
org.h2.util.ObjectArray
;
...
@@ -28,8 +27,7 @@ import org.h2.value.ValueNull;
...
@@ -28,8 +27,7 @@ import org.h2.value.ValueNull;
*/
*/
public
class
UpdatableRow
{
public
class
UpdatableRow
{
private
final
SessionInterface
session
;
private
final
JdbcConnection
conn
;
private
final
Connection
conn
;
private
final
DatabaseMetaData
meta
;
private
final
DatabaseMetaData
meta
;
private
final
ResultInterface
result
;
private
final
ResultInterface
result
;
private
final
int
columnCount
;
private
final
int
columnCount
;
...
@@ -44,13 +42,11 @@ public class UpdatableRow {
...
@@ -44,13 +42,11 @@ public class UpdatableRow {
*
*
* @param conn the database connection
* @param conn the database connection
* @param result the result
* @param result the result
* @param session the session
*/
*/
public
UpdatableRow
(
Connection
conn
,
ResultInterface
result
,
SessionInterface
session
)
throws
SQLException
{
public
UpdatableRow
(
JdbcConnection
conn
,
ResultInterface
result
)
throws
SQLException
{
this
.
conn
=
conn
;
this
.
conn
=
conn
;
this
.
meta
=
conn
.
getMetaData
();
this
.
meta
=
conn
.
getMetaData
();
this
.
result
=
result
;
this
.
result
=
result
;
this
.
session
=
session
;
columnCount
=
result
.
getVisibleColumnCount
();
columnCount
=
result
.
getVisibleColumnCount
();
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
String
t
=
result
.
getTableName
(
i
);
String
t
=
result
.
getTableName
(
i
);
...
@@ -197,7 +193,7 @@ public class UpdatableRow {
...
@@ -197,7 +193,7 @@ public class UpdatableRow {
Value
[]
newRow
=
new
Value
[
columnCount
];
Value
[]
newRow
=
new
Value
[
columnCount
];
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
int
type
=
result
.
getColumnType
(
i
);
int
type
=
result
.
getColumnType
(
i
);
newRow
[
i
]
=
DataType
.
readValue
(
session
,
rs
,
i
+
1
,
type
);
newRow
[
i
]
=
DataType
.
readValue
(
conn
.
getSession
()
,
rs
,
i
+
1
,
type
);
}
}
return
newRow
;
return
newRow
;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/DataType.java
浏览文件 @
b4aedbcf
...
@@ -963,9 +963,9 @@ public class DataType {
...
@@ -963,9 +963,9 @@ public class DataType {
public
static
Object
convertTo
(
SessionInterface
session
,
JdbcConnection
conn
,
Value
v
,
Class
paramClass
)
public
static
Object
convertTo
(
SessionInterface
session
,
JdbcConnection
conn
,
Value
v
,
Class
paramClass
)
throws
SQLException
{
throws
SQLException
{
if
(
paramClass
==
java
.
sql
.
Blob
.
class
)
{
if
(
paramClass
==
java
.
sql
.
Blob
.
class
)
{
return
new
JdbcBlob
(
session
,
conn
,
v
,
0
);
return
new
JdbcBlob
(
conn
,
v
,
0
);
}
else
if
(
paramClass
==
Clob
.
class
)
{
}
else
if
(
paramClass
==
Clob
.
class
)
{
return
new
JdbcClob
(
session
,
conn
,
v
,
0
);
return
new
JdbcClob
(
conn
,
v
,
0
);
}
else
{
}
else
{
throw
Message
.
getUnsupportedException
();
throw
Message
.
getUnsupportedException
();
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/unit/TestFileLockSerialized.java
浏览文件 @
b4aedbcf
...
@@ -8,9 +8,11 @@ package org.h2.test.unit;
...
@@ -8,9 +8,11 @@ package org.h2.test.unit;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
/**
/**
...
@@ -28,9 +30,36 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -28,9 +30,36 @@ public class TestFileLockSerialized extends TestBase {
}
}
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testKillWriter
();
testConcurrentReadWrite
();
}
// TODO support long running queries
private
void
testKillWriter
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized"
;
String
writeUrl
=
url
+
";FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE;WRITE_DELAY=0"
;
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key)"
);
((
JdbcConnection
)
conn
).
setPowerOffCount
(
1
);
try
{
stat
.
execute
(
"insert into test values(1)"
);
fail
();
}
catch
(
SQLException
e
)
{
// ignore
}
Connection
conn2
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat2
=
conn2
.
createStatement
();
stat2
.
execute
(
"insert into test values(1)"
);
printResult
(
stat2
,
"select * from test"
);
conn2
.
close
();
}
private
void
testConcurrentReadWrite
()
throws
Exception
{
deleteDb
(
"fileLockSerialized"
);
deleteDb
(
"fileLockSerialized"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized"
;
String
url
=
"jdbc:h2:"
+
baseDir
+
"/fileLockSerialized"
;
...
@@ -45,7 +74,7 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -45,7 +74,7 @@ public class TestFileLockSerialized extends TestBase {
stat
.
execute
(
"create table test(id int primary key)"
);
stat
.
execute
(
"create table test(id int primary key)"
);
Connection
conn3
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Connection
conn3
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat3
=
conn3
.
createStatement
(
);
PreparedStatement
prep3
=
conn3
.
prepareStatement
(
"insert into test values(?)"
);
Connection
conn2
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Connection
conn2
=
DriverManager
.
getConnection
(
writeUrl
,
"sa"
,
"sa"
);
Statement
stat2
=
conn2
.
createStatement
();
Statement
stat2
=
conn2
.
createStatement
();
...
@@ -57,7 +86,8 @@ public class TestFileLockSerialized extends TestBase {
...
@@ -57,7 +86,8 @@ public class TestFileLockSerialized extends TestBase {
trace
(
"insert row 1"
);
trace
(
"insert row 1"
);
stat
.
execute
(
"insert into test values(1)"
);
stat
.
execute
(
"insert into test values(1)"
);
trace
(
"insert row 2"
);
trace
(
"insert row 2"
);
stat3
.
execute
(
"insert into test values(2)"
);
prep3
.
setInt
(
1
,
2
);
prep3
.
execute
();
printResult
(
stat2
,
"select * from test"
);
printResult
(
stat2
,
"select * from test"
);
printResult
(
stat2
,
"select * from temp"
);
printResult
(
stat2
,
"select * from temp"
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论