Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5a2c152e
提交
5a2c152e
authored
9月 24, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Linked tables that point to the same database now share the connection.
上级
272423cb
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
118 行增加
和
67 行删除
+118
-67
Database.java
h2/src/main/org/h2/engine/Database.java
+18
-0
LinkedIndex.java
h2/src/main/org/h2/index/LinkedIndex.java
+64
-56
TableLink.java
h2/src/main/org/h2/table/TableLink.java
+21
-7
ObjectUtils.java
h2/src/main/org/h2/util/ObjectUtils.java
+10
-0
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+0
-2
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+1
-1
TestLinkedTable.java
h2/src/test/org/h2/test/db/TestLinkedTable.java
+3
-0
TestListener.java
h2/src/test/org/h2/test/db/TestListener.java
+1
-1
没有找到文件。
h2/src/main/org/h2/engine/Database.java
浏览文件 @
5a2c152e
...
...
@@ -49,6 +49,7 @@ import org.h2.table.IndexColumn;
import
org.h2.table.MetaTable
;
import
org.h2.table.Table
;
import
org.h2.table.TableData
;
import
org.h2.table.TableLinkConnection
;
import
org.h2.table.TableView
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Server
;
...
...
@@ -160,6 +161,7 @@ public class Database implements DataHandler {
private
boolean
autoServerMode
;
private
Object
reserveMemory
;
private
Server
server
;
private
HashMap
linkConnections
;
public
Database
(
String
name
,
ConnectionInfo
ci
,
String
cipher
)
throws
SQLException
{
this
.
compareMode
=
new
CompareMode
(
null
,
null
,
0
);
...
...
@@ -2054,4 +2056,20 @@ public class Database implements DataHandler {
reserveMemory
=
null
;
}
/**
* Open a new connection or get an existing connection to another database.
*
* @param driver the database driver or null
* @param url the database URL
* @param user the user name
* @param password the password
* @return the connection
*/
public
TableLinkConnection
getLinkConnection
(
String
driver
,
String
url
,
String
user
,
String
password
)
throws
SQLException
{
if
(
linkConnections
==
null
)
{
linkConnections
=
new
HashMap
();
}
return
TableLinkConnection
.
open
(
linkConnections
,
driver
,
url
,
user
,
password
);
}
}
h2/src/main/org/h2/index/LinkedIndex.java
浏览文件 @
5a2c152e
...
...
@@ -67,6 +67,7 @@ public class LinkedIndex extends BaseIndex {
}
buff
.
append
(
')'
);
String
sql
=
buff
.
toString
();
synchronized
(
link
.
getConnection
())
{
try
{
PreparedStatement
prep
=
link
.
getPreparedStatement
(
sql
);
for
(
int
i
=
0
,
j
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
...
...
@@ -82,6 +83,7 @@ public class LinkedIndex extends BaseIndex {
throw
wrapException
(
sql
,
e
);
}
}
}
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
throws
SQLException
{
StringBuffer
buff
=
new
StringBuffer
();
...
...
@@ -114,6 +116,7 @@ public class LinkedIndex extends BaseIndex {
}
buff
.
insert
(
0
,
"SELECT * FROM "
+
targetTableName
+
" T"
);
String
sql
=
buff
.
toString
();
synchronized
(
link
.
getConnection
())
{
try
{
PreparedStatement
prep
=
link
.
getPreparedStatement
(
sql
);
int
j
=
0
;
...
...
@@ -137,6 +140,7 @@ public class LinkedIndex extends BaseIndex {
throw
wrapException
(
sql
,
e
);
}
}
}
private
void
addParameter
(
StringBuffer
buff
,
Column
col
)
{
if
(
col
.
getType
()
==
Value
.
STRING_FIXED
&&
link
.
isOracle
())
{
...
...
@@ -202,6 +206,7 @@ public class LinkedIndex extends BaseIndex {
}
}
String
sql
=
buff
.
toString
();
synchronized
(
link
.
getConnection
())
{
try
{
PreparedStatement
prep
=
link
.
getPreparedStatement
(
sql
);
for
(
int
i
=
0
,
j
=
0
;
i
<
row
.
getColumnCount
();
i
++)
{
...
...
@@ -217,6 +222,7 @@ public class LinkedIndex extends BaseIndex {
throw
wrapException
(
sql
,
e
);
}
}
}
/**
* Update a row using a UPDATE statement. This method is to be called if the
...
...
@@ -251,6 +257,7 @@ public class LinkedIndex extends BaseIndex {
}
}
String
sql
=
buff
.
toString
();
synchronized
(
link
.
getConnection
())
{
try
{
int
j
=
1
;
PreparedStatement
prep
=
link
.
getPreparedStatement
(
sql
);
...
...
@@ -272,6 +279,7 @@ public class LinkedIndex extends BaseIndex {
throw
wrapException
(
sql
,
e
);
}
}
}
private
SQLException
wrapException
(
String
sql
,
SQLException
e
)
{
return
Message
.
getSQLException
(
ErrorCode
.
ERROR_ACCESSING_LINKED_TABLE_2
,
new
String
[]
{
sql
,
e
.
toString
()
},
e
);
...
...
h2/src/main/org/h2/table/TableLink.java
浏览文件 @
5a2c152e
...
...
@@ -6,7 +6,6 @@
*/
package
org
.
h2
.
table
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
...
...
@@ -40,7 +39,7 @@ import org.h2.value.DataType;
public
class
TableLink
extends
Table
{
private
String
driver
,
url
,
user
,
password
,
originalSchema
,
originalTable
,
qualifiedTableName
;
private
Connection
conn
;
private
TableLink
Connection
conn
;
private
HashMap
prepared
=
new
HashMap
();
private
final
ObjectArray
indexes
=
new
ObjectArray
();
private
final
boolean
emitUpdates
;
...
...
@@ -77,8 +76,20 @@ public class TableLink extends Table {
}
private
void
connect
()
throws
SQLException
{
conn
=
JdbcUtils
.
getConnection
(
driver
,
url
,
user
,
password
);
DatabaseMetaData
meta
=
conn
.
getMetaData
();
conn
=
database
.
getLinkConnection
(
driver
,
url
,
user
,
password
);
synchronized
(
conn
)
{
try
{
readMetaData
();
}
catch
(
SQLException
e
)
{
conn
.
close
();
conn
=
null
;
throw
e
;
}
}
}
private
void
readMetaData
()
throws
SQLException
{
DatabaseMetaData
meta
=
conn
.
getConnection
().
getMetaData
();
storesLowerCase
=
meta
.
storesLowerCaseIdentifiers
();
storesMixedCase
=
meta
.
storesMixedCaseIdentifiers
();
supportsMixedCaseIdentifiers
=
meta
.
supportsMixedCaseIdentifiers
();
...
...
@@ -129,7 +140,7 @@ public class TableLink extends Table {
// check if the table is accessible
Statement
stat
=
null
;
try
{
stat
=
conn
.
createStatement
();
stat
=
conn
.
getConnection
().
createStatement
();
rs
=
stat
.
executeQuery
(
"SELECT * FROM "
+
qualifiedTableName
+
" T WHERE 1=0"
);
if
(
columnList
.
size
()
==
0
)
{
// alternative solution
...
...
@@ -359,7 +370,7 @@ public class TableLink extends Table {
}
PreparedStatement
prep
=
(
PreparedStatement
)
prepared
.
get
(
sql
);
if
(
prep
==
null
)
{
prep
=
conn
.
prepareStatement
(
sql
);
prep
=
conn
.
getConnection
().
prepareStatement
(
sql
);
prepared
.
put
(
sql
,
prep
);
}
return
prep
;
...
...
@@ -399,7 +410,6 @@ public class TableLink extends Table {
database
.
removeMeta
(
session
,
getId
());
driver
=
null
;
url
=
user
=
password
=
originalTable
=
null
;
conn
=
null
;
prepared
=
null
;
invalidate
();
}
...
...
@@ -457,4 +467,8 @@ public class TableLink extends Table {
this
.
readOnly
=
readOnly
;
}
public
TableLinkConnection
getConnection
()
{
return
conn
;
}
}
h2/src/main/org/h2/util/ObjectUtils.java
浏览文件 @
5a2c152e
...
...
@@ -195,4 +195,14 @@ public class ObjectUtils {
}
}
/**
* Calculate the hash code of the given object. The object may be null.
*
* @param the object
* @return the hash code, or 0 if the object is null
*/
public
static
int
hashCode
(
Object
o
)
{
return
o
==
null
?
0
:
o
.
hashCode
();
}
}
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
5a2c152e
...
...
@@ -276,8 +276,6 @@ java org.h2.test.TestAll timer
test on linux
main methods for the tests and make that work
TestMVCC:
Concurrent update in table test: another transaction has updated or
deleted the same row when exactly does it occur in other databases
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
5a2c152e
...
...
@@ -41,7 +41,7 @@ public abstract class TestBase {
*/
protected
TestAll
config
;
pr
ivate
long
start
;
pr
otected
long
start
;
/**
* Get the test directory for this test.
...
...
h2/src/test/org/h2/test/db/TestLinkedTable.java
浏览文件 @
5a2c152e
...
...
@@ -73,6 +73,7 @@ public class TestLinkedTable extends TestBase {
sa
.
execute
(
"CREATE SCHEMA P"
);
sa
.
execute
(
"CREATE TABLE P.TEST(X INT)"
);
sa
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
sa
.
execute
(
"INSERT INTO P.TEST VALUES(2)"
);
try
{
sb
.
execute
(
"CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')"
);
fail
();
...
...
@@ -81,6 +82,8 @@ public class TestLinkedTable extends TestBase {
}
sb
.
execute
(
"CREATE LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC', 'TEST')"
);
sb
.
execute
(
"CREATE LINKED TABLE T2(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'P', 'TEST')"
);
assertSingleValue
(
sb
,
"SELECT * FROM T"
,
1
);
assertSingleValue
(
sb
,
"SELECT * FROM T2"
,
2
);
sa
.
execute
(
"DROP ALL OBJECTS"
);
sb
.
execute
(
"DROP ALL OBJECTS"
);
ca
.
close
();
...
...
h2/src/test/org/h2/test/db/TestListener.java
浏览文件 @
5a2c152e
...
...
@@ -21,7 +21,7 @@ import org.h2.util.JdbcUtils;
*/
public
class
TestListener
extends
TestBase
implements
DatabaseEventListener
{
private
long
last
,
start
;
private
long
last
;
private
int
lastState
=
-
1
;
private
String
url
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论