Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
96b953d6
提交
96b953d6
authored
12月 10, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve code coverage.
上级
7e16c976
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
80 行增加
和
14 行删除
+80
-14
changelog.html
h2/src/docsrc/html/changelog.html
+3
-1
JdbcDataSourceFactory.java
h2/src/main/org/h2/jdbcx/JdbcDataSourceFactory.java
+4
-1
TestConnectionPool.java
h2/src/test/org/h2/test/jdbcx/TestConnectionPool.java
+38
-4
TestDataSource.java
h2/src/test/org/h2/test/jdbcx/TestDataSource.java
+35
-8
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
96b953d6
...
@@ -18,7 +18,9 @@ Change Log
...
@@ -18,7 +18,9 @@ Change Log
<h1>
Change Log
</h1>
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The database upgrade (to upgrade from H2 version 1.1.x) has been simplified.
<ul><li>
The built-in connection pool was simplified a bit.
The dispose() method no longer throws an exception (it only logs it).
</li><li>
The database upgrade (to upgrade from H2 version 1.1.x) has been simplified.
</li><li>
The feature to log all errors (system properties h2.logAllErrors and h2.logAllErrorsFile) has been removed.
</li><li>
The feature to log all errors (system properties h2.logAllErrors and h2.logAllErrorsFile) has been removed.
</li><li>
When starting the H2 Console, the properties file can now be completely disabled.
</li><li>
When starting the H2 Console, the properties file can now be completely disabled.
</li><li>
Server.openBrowser no longer writes to System.out directly if opening the URL failed.
</li><li>
Server.openBrowser no longer writes to System.out directly if opening the URL failed.
...
...
h2/src/main/org/h2/jdbcx/JdbcDataSourceFactory.java
浏览文件 @
96b953d6
...
@@ -78,7 +78,10 @@ implements ObjectFactory
...
@@ -78,7 +78,10 @@ implements ObjectFactory
}
}
//## Java 1.4 end ##
//## Java 1.4 end ##
private
TraceSystem
getTraceSystem
()
{
/**
* INTERNAL
*/
public
static
TraceSystem
getTraceSystem
()
{
synchronized
(
JdbcDataSourceFactory
.
class
)
{
synchronized
(
JdbcDataSourceFactory
.
class
)
{
if
(
cachedTraceSystem
==
null
)
{
if
(
cachedTraceSystem
==
null
)
{
cachedTraceSystem
=
new
TraceSystem
(
SysProperties
.
CLIENT_TRACE_DIRECTORY
+
"h2datasource"
+
Constants
.
SUFFIX_TRACE_FILE
);
cachedTraceSystem
=
new
TraceSystem
(
SysProperties
.
CLIENT_TRACE_DIRECTORY
+
"h2datasource"
+
Constants
.
SUFFIX_TRACE_FILE
);
...
...
h2/src/test/org/h2/test/jdbcx/TestConnectionPool.java
浏览文件 @
96b953d6
...
@@ -34,6 +34,7 @@ public class TestConnectionPool extends TestBase {
...
@@ -34,6 +34,7 @@ public class TestConnectionPool extends TestBase {
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
deleteDb
(
"connectionPool"
);
deleteDb
(
"connectionPool"
);
testShutdown
();
testWrongUrl
();
testWrongUrl
();
testTimeout
();
testTimeout
();
testUncommittedTransaction
();
testUncommittedTransaction
();
...
@@ -42,6 +43,21 @@ public class TestConnectionPool extends TestBase {
...
@@ -42,6 +43,21 @@ public class TestConnectionPool extends TestBase {
testConnect
();
testConnect
();
testThreads
();
testThreads
();
deleteDb
(
"connectionPool"
);
deleteDb
(
"connectionPool"
);
deleteDb
(
"connectionPool2"
);
}
private
void
testShutdown
()
throws
SQLException
{
String
url
=
getURL
(
"connectionPool2"
,
true
),
user
=
getUser
(),
password
=
getPassword
();
JdbcConnectionPool
cp
=
JdbcConnectionPool
.
create
(
url
,
user
,
password
);
StringWriter
w
=
new
StringWriter
();
cp
.
setLogWriter
(
new
PrintWriter
(
w
));
Connection
conn1
=
cp
.
getConnection
();
Connection
conn2
=
cp
.
getConnection
();
conn1
.
close
();
conn2
.
createStatement
().
execute
(
"shutdown immediately"
);
cp
.
dispose
();
assertTrue
(
w
.
toString
().
length
()
>
0
);
cp
.
dispose
();
}
}
private
void
testWrongUrl
()
throws
SQLException
{
private
void
testWrongUrl
()
throws
SQLException
{
...
@@ -58,6 +74,12 @@ public class TestConnectionPool extends TestBase {
...
@@ -58,6 +74,12 @@ public class TestConnectionPool extends TestBase {
String
url
=
getURL
(
"connectionPool"
,
true
),
user
=
getUser
(),
password
=
getPassword
();
String
url
=
getURL
(
"connectionPool"
,
true
),
user
=
getUser
(),
password
=
getPassword
();
final
JdbcConnectionPool
man
=
JdbcConnectionPool
.
create
(
url
,
user
,
password
);
final
JdbcConnectionPool
man
=
JdbcConnectionPool
.
create
(
url
,
user
,
password
);
man
.
setLoginTimeout
(
1
);
man
.
setLoginTimeout
(
1
);
try
{
man
.
setMaxConnections
(-
1
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
// expected
}
man
.
setMaxConnections
(
2
);
man
.
setMaxConnections
(
2
);
// connection 1 (of 2)
// connection 1 (of 2)
Connection
conn
=
man
.
getConnection
();
Connection
conn
=
man
.
getConnection
();
...
@@ -129,8 +151,8 @@ public class TestConnectionPool extends TestBase {
...
@@ -129,8 +151,8 @@ public class TestConnectionPool extends TestBase {
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
man
.
getConnection
().
close
();
man
.
getConnection
().
close
();
}
}
trace
((
int
)
(
System
.
currentTimeMillis
()
-
time
));
man
.
dispose
();
man
.
dispose
();
trace
((
int
)
(
System
.
currentTimeMillis
()
-
time
));
time
=
System
.
currentTimeMillis
();
time
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
DriverManager
.
getConnection
(
url
,
user
,
password
).
close
();
DriverManager
.
getConnection
(
url
,
user
,
password
).
close
();
...
@@ -203,12 +225,24 @@ public class TestConnectionPool extends TestBase {
...
@@ -203,12 +225,24 @@ public class TestConnectionPool extends TestBase {
}
}
private
void
testConnect
()
throws
SQLException
{
private
void
testConnect
()
throws
SQLException
{
JdbcConnectionPool
man
=
getConnectionPool
(
3
);
JdbcConnectionPool
pool
=
getConnectionPool
(
3
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
Connection
conn
=
man
.
getConnection
();
Connection
conn
=
pool
.
getConnection
();
conn
.
close
();
conn
.
close
();
}
}
man
.
dispose
();
pool
.
dispose
();
try
{
pool
.
getConnection
();
fail
();
}
catch
(
IllegalStateException
e
)
{
// expected
}
try
{
pool
.
getConnection
(
null
,
null
);
fail
();
}
catch
(
UnsupportedOperationException
e
)
{
// expected
}
}
}
}
}
h2/src/test/org/h2/test/jdbcx/TestDataSource.java
浏览文件 @
96b953d6
...
@@ -22,6 +22,7 @@ import javax.transaction.xa.Xid;
...
@@ -22,6 +22,7 @@ import javax.transaction.xa.Xid;
import
org.h2.jdbcx.JdbcDataSource
;
import
org.h2.jdbcx.JdbcDataSource
;
import
org.h2.jdbcx.JdbcDataSourceFactory
;
import
org.h2.jdbcx.JdbcDataSourceFactory
;
import
org.h2.jdbcx.JdbcXAConnection
;
import
org.h2.jdbcx.JdbcXAConnection
;
import
org.h2.message.TraceSystem
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
/**
/**
...
@@ -63,6 +64,11 @@ public class TestDataSource extends TestBase {
...
@@ -63,6 +64,11 @@ public class TestDataSource extends TestBase {
// }
// }
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
if
(
config
.
traceLevelFile
>
0
)
{
TraceSystem
sys
=
JdbcDataSourceFactory
.
getTraceSystem
();
sys
.
setFileName
(
getBaseDir
()
+
"/test/trace"
);
sys
.
setLevelFile
(
3
);
}
testDataSourceFactory
();
testDataSourceFactory
();
testDataSource
();
testDataSource
();
testXAConnection
();
testXAConnection
();
...
@@ -82,6 +88,7 @@ public class TestDataSource extends TestBase {
...
@@ -82,6 +88,7 @@ public class TestDataSource extends TestBase {
ref
.
add
(
new
StringRefAddr
(
"description"
,
"test"
));
ref
.
add
(
new
StringRefAddr
(
"description"
,
"test"
));
JdbcDataSource
ds
=
(
JdbcDataSource
)
factory
.
getObjectInstance
(
ref
,
null
,
null
,
null
);
JdbcDataSource
ds
=
(
JdbcDataSource
)
factory
.
getObjectInstance
(
ref
,
null
,
null
,
null
);
assertEquals
(
1
,
ds
.
getLoginTimeout
());
assertEquals
(
1
,
ds
.
getLoginTimeout
());
assertEquals
(
"test"
,
ds
.
getDescription
());
assertEquals
(
"jdbc:h2:mem:"
,
ds
.
getURL
());
assertEquals
(
"jdbc:h2:mem:"
,
ds
.
getURL
());
assertEquals
(
"u"
,
ds
.
getUser
());
assertEquals
(
"u"
,
ds
.
getUser
());
assertEquals
(
"p"
,
ds
.
getPassword
());
assertEquals
(
"p"
,
ds
.
getPassword
());
...
@@ -97,17 +104,31 @@ public class TestDataSource extends TestBase {
...
@@ -97,17 +104,31 @@ public class TestDataSource extends TestBase {
}
}
private
void
testXAConnection
()
throws
Exception
{
private
void
testXAConnection
()
throws
Exception
{
testXAConnection
(
false
);
testXAConnection
(
true
);
}
private
void
testXAConnection
(
boolean
userInDataSource
)
throws
Exception
{
deleteDb
(
"dataSource"
);
deleteDb
(
"dataSource"
);
JdbcDataSource
ds
=
new
JdbcDataSource
();
JdbcDataSource
ds
=
new
JdbcDataSource
();
String
url
=
getURL
(
"dataSource"
,
true
);
String
url
=
getURL
(
"dataSource"
,
true
);
String
user
=
getUser
();
String
user
=
getUser
();
ds
.
setURL
(
url
);
ds
.
setURL
(
url
);
if
(
userInDataSource
)
{
ds
.
setUser
(
user
);
ds
.
setUser
(
user
);
ds
.
setPassword
(
getPassword
());
ds
.
setPassword
(
getPassword
());
}
if
(
userInDataSource
)
{
assertEquals
(
"ds"
+
ds
.
getTraceId
()
+
": url="
+
url
+
" user="
+
user
,
ds
.
toString
());
assertEquals
(
"ds"
+
ds
.
getTraceId
()
+
": url="
+
url
+
" user="
+
user
,
ds
.
toString
());
}
else
{
XAConnection
xaConn
=
ds
.
getXAConnection
();
assertEquals
(
"ds"
+
ds
.
getTraceId
()
+
": url="
+
url
+
" user="
,
ds
.
toString
());
}
XAConnection
xaConn
;
if
(
userInDataSource
)
{
xaConn
=
ds
.
getXAConnection
();
}
else
{
xaConn
=
ds
.
getXAConnection
(
user
,
getPassword
());
}
int
traceId
=
((
JdbcXAConnection
)
xaConn
).
getTraceId
();
int
traceId
=
((
JdbcXAConnection
)
xaConn
).
getTraceId
();
assertTrue
(
xaConn
.
toString
().
startsWith
(
"xads"
+
traceId
+
": conn"
));
assertTrue
(
xaConn
.
toString
().
startsWith
(
"xads"
+
traceId
+
": conn"
));
...
@@ -129,6 +150,7 @@ public class TestDataSource extends TestBase {
...
@@ -129,6 +150,7 @@ public class TestDataSource extends TestBase {
assertFalse
(
res
.
isSameRM
(
null
));
assertFalse
(
res
.
isSameRM
(
null
));
Connection
conn
=
xaConn
.
getConnection
();
Connection
conn
=
xaConn
.
getConnection
();
assertEquals
(
user
.
toUpperCase
(),
conn
.
getMetaData
().
getUserName
());
Xid
[]
list
=
res
.
recover
(
XAResource
.
TMSTARTRSCAN
);
Xid
[]
list
=
res
.
recover
(
XAResource
.
TMSTARTRSCAN
);
assertEquals
(
0
,
list
.
length
);
assertEquals
(
0
,
list
.
length
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
...
@@ -146,10 +168,15 @@ public class TestDataSource extends TestBase {
...
@@ -146,10 +168,15 @@ public class TestDataSource extends TestBase {
ds
.
setURL
(
getURL
(
"dataSource"
,
true
));
ds
.
setURL
(
getURL
(
"dataSource"
,
true
));
ds
.
setUser
(
getUser
());
ds
.
setUser
(
getUser
());
ds
.
setPassword
(
getPassword
());
ds
.
setPassword
(
getPassword
());
Connection
conn
=
ds
.
getConnection
();
Connection
conn
;
Statement
stat
=
conn
.
createStatement
();
conn
=
ds
.
getConnection
();
Statement
stat
;
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM DUAL"
);
stat
.
execute
(
"SELECT * FROM DUAL"
);
conn
.
close
();
conn
.
close
();
conn
=
ds
.
getConnection
(
getUser
(),
getPassword
());
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM DUAL"
);
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论