Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1a04f20c
提交
1a04f20c
authored
7月 13, 2017
作者:
Noel Grandin
提交者:
GitHub
7月 13, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #559 from NiklasMehner/master
Update synonym implementation
上级
424af0db
433056a5
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
74 行增加
和
7 行删除
+74
-7
CreateSynonym.java
h2/src/main/org/h2/command/ddl/CreateSynonym.java
+2
-0
AbstractTable.java
h2/src/main/org/h2/table/AbstractTable.java
+14
-0
Table.java
h2/src/main/org/h2/table/Table.java
+29
-0
TableSynonym.java
h2/src/main/org/h2/table/TableSynonym.java
+24
-2
TestSynonymForTable.java
h2/src/test/org/h2/test/db/TestSynonymForTable.java
+5
-5
没有找到文件。
h2/src/main/org/h2/command/ddl/CreateSynonym.java
浏览文件 @
1a04f20c
...
@@ -84,6 +84,7 @@ public class CreateSynonym extends SchemaCommand {
...
@@ -84,6 +84,7 @@ public class CreateSynonym extends SchemaCommand {
table
.
updateData
(
data
);
table
.
updateData
(
data
);
table
.
setComment
(
comment
);
table
.
setComment
(
comment
);
table
.
setModified
();
table
.
setModified
();
db
.
updateMeta
(
session
,
table
);
}
else
{
}
else
{
data
.
id
=
getObjectId
();
data
.
id
=
getObjectId
();
table
=
getSchema
().
createSynonym
(
data
);
table
=
getSchema
().
createSynonym
(
data
);
...
@@ -91,6 +92,7 @@ public class CreateSynonym extends SchemaCommand {
...
@@ -91,6 +92,7 @@ public class CreateSynonym extends SchemaCommand {
db
.
addSchemaObject
(
session
,
table
);
db
.
addSchemaObject
(
session
,
table
);
}
}
table
.
updateSynonymFor
();
return
0
;
return
0
;
}
}
...
...
h2/src/main/org/h2/table/AbstractTable.java
浏览文件 @
1a04f20c
...
@@ -379,6 +379,13 @@ public abstract class AbstractTable extends SchemaObjectBase {
...
@@ -379,6 +379,13 @@ public abstract class AbstractTable extends SchemaObjectBase {
*/
*/
public
abstract
void
removeView
(
TableView
view
);
public
abstract
void
removeView
(
TableView
view
);
/**
* Remove the given synonym from the list.
*
* @param synonym the synonym to remove
*/
public
abstract
void
removeSynonym
(
TableSynonym
synonym
);
/**
/**
* Remove the given constraint from the list.
* Remove the given constraint from the list.
*
*
...
@@ -407,6 +414,13 @@ public abstract class AbstractTable extends SchemaObjectBase {
...
@@ -407,6 +414,13 @@ public abstract class AbstractTable extends SchemaObjectBase {
*/
*/
public
abstract
void
addView
(
TableView
view
);
public
abstract
void
addView
(
TableView
view
);
/**
* Add a synonym to this table.
*
* @param synonym the synonym to add
*/
public
abstract
void
addSynonym
(
TableSynonym
synonym
);
/**
/**
* Add a constraint to the table.
* Add a constraint to the table.
*
*
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
1a04f20c
...
@@ -72,6 +72,7 @@ public abstract class Table extends AbstractTable {
...
@@ -72,6 +72,7 @@ public abstract class Table extends AbstractTable {
private
ArrayList
<
Constraint
>
constraints
;
private
ArrayList
<
Constraint
>
constraints
;
private
ArrayList
<
Sequence
>
sequences
;
private
ArrayList
<
Sequence
>
sequences
;
private
ArrayList
<
TableView
>
views
;
private
ArrayList
<
TableView
>
views
;
private
ArrayList
<
TableSynonym
>
synonyms
;
private
boolean
checkForeignKeyConstraints
=
true
;
private
boolean
checkForeignKeyConstraints
=
true
;
private
boolean
onCommitDrop
,
onCommitTruncate
;
private
boolean
onCommitDrop
,
onCommitTruncate
;
private
volatile
Row
nullRow
;
private
volatile
Row
nullRow
;
...
@@ -249,6 +250,9 @@ public abstract class Table extends AbstractTable {
...
@@ -249,6 +250,9 @@ public abstract class Table extends AbstractTable {
if
(
views
!=
null
)
{
if
(
views
!=
null
)
{
children
.
addAll
(
views
);
children
.
addAll
(
views
);
}
}
if
(
synonyms
!=
null
)
{
children
.
addAll
(
synonyms
);
}
ArrayList
<
Right
>
rights
=
database
.
getAllRights
();
ArrayList
<
Right
>
rights
=
database
.
getAllRights
();
for
(
Right
right
:
rights
)
{
for
(
Right
right
:
rights
)
{
if
(
right
.
getGrantedObject
()
==
this
)
{
if
(
right
.
getGrantedObject
()
==
this
)
{
...
@@ -379,6 +383,11 @@ public abstract class Table extends AbstractTable {
...
@@ -379,6 +383,11 @@ public abstract class Table extends AbstractTable {
views
.
remove
(
0
);
views
.
remove
(
0
);
database
.
removeSchemaObject
(
session
,
view
);
database
.
removeSchemaObject
(
session
,
view
);
}
}
while
(
synonyms
!=
null
&&
synonyms
.
size
()
>
0
)
{
TableSynonym
synonym
=
synonyms
.
get
(
0
);
synonyms
.
remove
(
0
);
database
.
removeSchemaObject
(
session
,
synonym
);
}
while
(
triggers
!=
null
&&
triggers
.
size
()
>
0
)
{
while
(
triggers
!=
null
&&
triggers
.
size
()
>
0
)
{
TriggerObject
trigger
=
triggers
.
get
(
0
);
TriggerObject
trigger
=
triggers
.
get
(
0
);
triggers
.
remove
(
0
);
triggers
.
remove
(
0
);
...
@@ -702,6 +711,16 @@ public abstract class Table extends AbstractTable {
...
@@ -702,6 +711,16 @@ public abstract class Table extends AbstractTable {
remove
(
views
,
view
);
remove
(
views
,
view
);
}
}
/**
* Remove the given view from the list.
*
* @param synonym the synonym to remove
*/
@Override
public
void
removeSynonym
(
TableSynonym
synonym
)
{
remove
(
synonyms
,
synonym
);
}
/**
/**
* Remove the given constraint from the list.
* Remove the given constraint from the list.
*
*
...
@@ -742,6 +761,16 @@ public abstract class Table extends AbstractTable {
...
@@ -742,6 +761,16 @@ public abstract class Table extends AbstractTable {
views
=
add
(
views
,
view
);
views
=
add
(
views
,
view
);
}
}
/**
* Add a synonym to this table.
*
* @param synonym the synonym to add
*/
@Override
public
void
addSynonym
(
TableSynonym
synonym
)
{
synonyms
=
add
(
synonyms
,
synonym
);
}
/**
/**
* Add a constraint to the table.
* Add a constraint to the table.
*
*
...
...
h2/src/main/org/h2/table/TableSynonym.java
浏览文件 @
1a04f20c
...
@@ -29,6 +29,8 @@ public class TableSynonym extends AbstractTable {
...
@@ -29,6 +29,8 @@ public class TableSynonym extends AbstractTable {
private
CreateSynonymData
data
;
private
CreateSynonymData
data
;
private
AbstractTable
synonymFor
;
public
TableSynonym
(
CreateSynonymData
data
)
{
public
TableSynonym
(
CreateSynonymData
data
)
{
initSchemaObjectBase
(
data
.
schema
,
data
.
id
,
data
.
synonymName
,
Trace
.
TABLE
);
initSchemaObjectBase
(
data
.
schema
,
data
.
id
,
data
.
synonymName
,
Trace
.
TABLE
);
this
.
data
=
data
;
this
.
data
=
data
;
...
@@ -39,7 +41,7 @@ public class TableSynonym extends AbstractTable {
...
@@ -39,7 +41,7 @@ public class TableSynonym extends AbstractTable {
}
}
private
AbstractTable
getSynonymFor
()
{
private
AbstractTable
getSynonymFor
()
{
return
data
.
synonymForSchema
.
getTableOrView
(
data
.
session
,
data
.
synonymFor
)
;
return
synonymFor
;
}
}
@Override
@Override
...
@@ -55,7 +57,7 @@ public class TableSynonym extends AbstractTable {
...
@@ -55,7 +57,7 @@ public class TableSynonym extends AbstractTable {
@Override
@Override
public
int
getType
()
{
public
int
getType
()
{
return
getSynonymFor
().
getType
()
;
return
TABLE_OR_VIEW
;
}
}
@Override
@Override
...
@@ -265,6 +267,7 @@ public class TableSynonym extends AbstractTable {
...
@@ -265,6 +267,7 @@ public class TableSynonym extends AbstractTable {
@Override
@Override
public
void
removeChildrenAndResources
(
Session
session
)
{
public
void
removeChildrenAndResources
(
Session
session
)
{
synonymFor
.
removeSynonym
(
this
);
database
.
removeMeta
(
session
,
getId
());
database
.
removeMeta
(
session
,
getId
());
}
}
...
@@ -411,6 +414,11 @@ public class TableSynonym extends AbstractTable {
...
@@ -411,6 +414,11 @@ public class TableSynonym extends AbstractTable {
getSynonymFor
().
removeView
(
view
);
getSynonymFor
().
removeView
(
view
);
}
}
@Override
public
void
removeSynonym
(
TableSynonym
synonym
)
{
throw
DbException
.
getUnsupportedException
(
"SYNONYM"
);
}
@Override
@Override
public
void
removeConstraint
(
Constraint
constraint
)
{
public
void
removeConstraint
(
Constraint
constraint
)
{
getSynonymFor
().
removeConstraint
(
constraint
);
getSynonymFor
().
removeConstraint
(
constraint
);
...
@@ -426,6 +434,11 @@ public class TableSynonym extends AbstractTable {
...
@@ -426,6 +434,11 @@ public class TableSynonym extends AbstractTable {
getSynonymFor
().
addView
(
view
);
getSynonymFor
().
addView
(
view
);
}
}
@Override
public
void
addSynonym
(
TableSynonym
synonym
)
{
throw
DbException
.
getUnsupportedException
(
"SYNONYM"
);
}
@Override
@Override
public
void
addConstraint
(
Constraint
constraint
)
{
public
void
addConstraint
(
Constraint
constraint
)
{
getSynonymFor
().
addConstraint
(
constraint
);
getSynonymFor
().
addConstraint
(
constraint
);
...
@@ -471,9 +484,18 @@ public class TableSynonym extends AbstractTable {
...
@@ -471,9 +484,18 @@ public class TableSynonym extends AbstractTable {
getSynonymFor
().
fireAfterRow
(
session
,
oldRow
,
newRow
,
rollback
);
getSynonymFor
().
fireAfterRow
(
session
,
oldRow
,
newRow
,
rollback
);
}
}
public
void
updateSynonymFor
()
{
if
(
synonymFor
!=
null
)
{
synonymFor
.
removeSynonym
(
this
);
}
synonymFor
=
data
.
synonymForSchema
.
getTableOrView
(
data
.
session
,
data
.
synonymFor
);
synonymFor
.
addSynonym
(
this
);
}
@Override
@Override
public
boolean
isGlobalTemporary
()
{
public
boolean
isGlobalTemporary
()
{
return
getSynonymFor
().
isGlobalTemporary
();
return
getSynonymFor
().
isGlobalTemporary
();
}
}
}
}
h2/src/test/org/h2/test/db/TestSynonymForTable.java
浏览文件 @
1a04f20c
...
@@ -84,14 +84,12 @@ public class TestSynonymForTable extends TestBase {
...
@@ -84,14 +84,12 @@ public class TestSynonymForTable extends TestBase {
// Backing table does not exist anymore.
// Backing table does not exist anymore.
assertThrows
(
JdbcSQLException
.
class
,
stat
).
execute
(
"SELECT id FROM testsynonym"
);
assertThrows
(
JdbcSQLException
.
class
,
stat
).
execute
(
"SELECT id FROM testsynonym"
);
//
Meta data should show INVALID
//
Synonym should be dropped as well
ResultSet
synonyms
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.SYNONYMS WHERE SYNONYM_NAME='TESTSYNONYM'"
);
ResultSet
synonyms
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.SYNONYMS WHERE SYNONYM_NAME='TESTSYNONYM'"
);
assertTrue
(
synonyms
.
next
());
assertFalse
(
synonyms
.
next
());
assertEquals
(
"TESTSYNONYM"
,
synonyms
.
getString
(
"SYNONYM_NAME"
));
assertEquals
(
"INVALID"
,
synonyms
.
getString
(
"STATUS"
));
conn
.
close
();
conn
.
close
();
// Reopening should work with
invali
d synonym
// Reopening should work with
droppe
d synonym
Connection
conn2
=
getConnection
(
"synonym"
);
Connection
conn2
=
getConnection
(
"synonym"
);
assertThrows
(
JdbcSQLException
.
class
,
stat
).
execute
(
"SELECT id FROM testsynonym"
);
assertThrows
(
JdbcSQLException
.
class
,
stat
).
execute
(
"SELECT id FROM testsynonym"
);
conn2
.
close
();
conn2
.
close
();
...
@@ -112,6 +110,7 @@ public class TestSynonymForTable extends TestBase {
...
@@ -112,6 +110,7 @@ public class TestSynonymForTable extends TestBase {
// Without "if exists" the command should fail if the synonym does not exist.
// Without "if exists" the command should fail if the synonym does not exist.
assertThrows
(
JdbcSQLException
.
class
,
stat
).
execute
(
"DROP SYNONYM testsynonym"
);
assertThrows
(
JdbcSQLException
.
class
,
stat
).
execute
(
"DROP SYNONYM testsynonym"
);
conn
.
close
();
}
}
private
void
testSynonymInDifferentSchema
()
throws
SQLException
{
private
void
testSynonymInDifferentSchema
()
throws
SQLException
{
...
@@ -124,6 +123,7 @@ public class TestSynonymForTable extends TestBase {
...
@@ -124,6 +123,7 @@ public class TestSynonymForTable extends TestBase {
stat
.
execute
(
"CREATE OR REPLACE SYNONYM testsynonym FOR s1.backingtable"
);
stat
.
execute
(
"CREATE OR REPLACE SYNONYM testsynonym FOR s1.backingtable"
);
stat
.
execute
(
"INSERT INTO s1.backingtable VALUES(15)"
);
stat
.
execute
(
"INSERT INTO s1.backingtable VALUES(15)"
);
assertSynonymContains
(
conn
,
15
);
assertSynonymContains
(
conn
,
15
);
conn
.
close
();
}
}
private
void
testCreateOrReplaceExistingTable
()
throws
SQLException
{
private
void
testCreateOrReplaceExistingTable
()
throws
SQLException
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论