Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
78c9c1d6
提交
78c9c1d6
authored
8 年前
作者:
Sergi Vladykin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support for setSchema/getSchema in JdbcConnection
上级
e635e003
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
87 行增加
和
13 行删除
+87
-13
Session.java
h2/src/main/org/h2/engine/Session.java
+5
-0
SessionInterface.java
h2/src/main/org/h2/engine/SessionInterface.java
+6
-0
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+5
-0
JdbcConnection.java
h2/src/main/org/h2/jdbc/JdbcConnection.java
+37
-7
JdbcConnectionBackwardsCompat.java
h2/src/main/org/h2/jdbc/JdbcConnectionBackwardsCompat.java
+6
-5
TestConnection.java
h2/src/test/org/h2/test/jdbc/TestConnection.java
+28
-1
没有找到文件。
h2/src/main/org/h2/engine/Session.java
浏览文件 @
78c9c1d6
...
...
@@ -1649,6 +1649,11 @@ public class Session extends SessionWithState {
}
}
@Override
public
boolean
isRemote
()
{
return
false
;
}
/**
* Represents a savepoint (a position in a transaction to where one can roll
* back to).
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/SessionInterface.java
浏览文件 @
78c9c1d6
...
...
@@ -134,4 +134,10 @@ public interface SessionInterface extends Closeable {
*/
void
addTemporaryLob
(
Value
v
);
/**
* Check if this session is remote or embedded.
*
* @return true if this session is remote
*/
boolean
isRemote
();
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
78c9c1d6
...
...
@@ -853,4 +853,9 @@ public class SessionRemote extends SessionWithState implements DataHandler {
public
CompareMode
getCompareMode
()
{
return
compareMode
;
}
@Override
public
boolean
isRemote
()
{
return
true
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcConnection.java
浏览文件 @
78c9c1d6
...
...
@@ -37,13 +37,16 @@ import org.h2.api.ErrorCode;
import
org.h2.command.CommandInterface
;
import
org.h2.engine.ConnectionInfo
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Mode
;
import
org.h2.engine.Session
;
import
org.h2.engine.SessionInterface
;
import
org.h2.engine.SessionRemote
;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.message.TraceObject
;
import
org.h2.result.ResultInterface
;
import
org.h2.schema.Schema
;
import
org.h2.util.CloseWatcher
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.Utils
;
...
...
@@ -1888,21 +1891,48 @@ public class JdbcConnection extends TraceObject implements Connection, JdbcConne
}
/**
* [Not supported]
* Sets the given schema name to access. Current implementation is case sensitive,
* i.e. requires schema name to be passed in correct case.
*
* @param schema the schema
* @param schema the schema
name
*/
@Override
public
void
setSchema
(
String
schema
)
{
// not supported
public
void
setSchema
(
String
schema
)
throws
SQLException
{
try
{
if
(
isDebugEnabled
())
{
debugCodeCall
(
"setSchema"
,
schema
);
}
checkClosed
();
if
(
session
.
isRemote
())
{
throw
DbException
.
getUnsupportedException
(
"setSchema && remote session"
);
}
Database
database
=
(
Database
)
session
.
getDataHandler
();
Schema
s
=
database
.
getSchema
(
schema
);
((
Session
)
session
).
setCurrentSchema
(
s
);
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
* [Not supported]
* Retrieves this current schema name for this connection.
*
* @return current schema name
*/
@Override
public
String
getSchema
()
{
return
null
;
public
String
getSchema
()
throws
SQLException
{
try
{
if
(
isDebugEnabled
())
{
debugCodeCall
(
"getSchema"
);
}
checkClosed
();
if
(
session
.
isRemote
())
{
throw
DbException
.
getUnsupportedException
(
"getSchema && remote session"
);
}
return
((
Session
)
session
).
getCurrentSchemaName
();
}
catch
(
Exception
e
)
{
throw
logAndConvert
(
e
);
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcConnectionBackwardsCompat.java
浏览文件 @
78c9c1d6
...
...
@@ -5,6 +5,7 @@
*/
package
org
.
h2
.
jdbc
;
import
java.sql.SQLException
;
import
java.util.concurrent.Executor
;
/**
...
...
@@ -12,13 +13,13 @@ import java.util.concurrent.Executor;
*/
public
interface
JdbcConnectionBackwardsCompat
{
void
setSchema
(
String
schema
);
void
setSchema
(
String
schema
)
throws
SQLException
;
String
getSchema
();
String
getSchema
()
throws
SQLException
;
void
abort
(
Executor
executor
);
void
abort
(
Executor
executor
)
throws
SQLException
;
void
setNetworkTimeout
(
Executor
executor
,
int
milliseconds
);
void
setNetworkTimeout
(
Executor
executor
,
int
milliseconds
)
throws
SQLException
;
int
getNetworkTimeout
();
int
getNetworkTimeout
()
throws
SQLException
;
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/jdbc/TestConnection.java
浏览文件 @
78c9c1d6
...
...
@@ -5,11 +5,13 @@
*/
package
org
.
h2
.
test
.
jdbc
;
import
org.h2.api.ErrorCode
;
import
org.h2.jdbc.JdbcConnectionBackwardsCompat
;
import
org.h2.test.TestBase
;
import
java.sql.Connection
;
import
java.sql.SQLClientInfoException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
/**
...
...
@@ -34,6 +36,7 @@ public class TestConnection extends TestBase {
testSetSupportedClientInfoProperties
();
testSetUnsupportedClientInfoProperties
();
testSetInternalProperty
();
testSetGetSchema
();
}
private
void
testSetInternalProperty
()
throws
SQLException
{
...
...
@@ -85,4 +88,28 @@ public class TestConnection extends TestBase {
assertNull
(
conn
.
getClientInfo
(
"UnknownProperty"
));
}
private
void
testSetGetSchema
()
throws
SQLException
{
if
(
config
.
networked
)
{
return
;
}
deleteDb
(
"schemaSetGet"
);
Connection
conn
=
getConnection
(
"schemaSetGet"
);
Statement
s
=
conn
.
createStatement
();
s
.
executeUpdate
(
"create schema my_test_schema"
);
s
.
executeUpdate
(
"create table my_test_schema.my_test_table(id uuid, nave varchar)"
);
JdbcConnectionBackwardsCompat
connx
=
(
JdbcConnectionBackwardsCompat
)
conn
;
assertEquals
(
"PUBLIC"
,
connx
.
getSchema
());
assertThrows
(
ErrorCode
.
TABLE_OR_VIEW_NOT_FOUND_1
,
s
,
"select * from my_test_table"
);
assertThrows
(
ErrorCode
.
SCHEMA_NOT_FOUND_1
,
connx
).
setSchema
(
"my_test_table"
);
connx
.
setSchema
(
"MY_TEST_SCHEMA"
);
assertEquals
(
"MY_TEST_SCHEMA"
,
connx
.
getSchema
());
s
.
executeQuery
(
"select * from my_test_table"
);
assertThrows
(
ErrorCode
.
SCHEMA_NOT_FOUND_1
,
connx
).
setSchema
(
"NON_EXISTING_SCHEMA"
);
assertEquals
(
"MY_TEST_SCHEMA"
,
connx
.
getSchema
());
s
.
executeUpdate
(
"create schema \"otheR_schEma\""
);
connx
.
setSchema
(
"otheR_schEma"
);
assertEquals
(
"otheR_schEma"
,
connx
.
getSchema
());
s
.
close
();
conn
.
close
();
}
}
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论