Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
4136b7c0
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4136b7c0
编写于
3月 22, 2018
作者:
S
serge-rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#3189 Triggers in DDL. SQL script generation enhancement. Comment lines
上级
e1ad93ed
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
96 addition
and
19 deletion
+96
-19
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreTableManager.java
...kiss/dbeaver/ext/postgresql/edit/PostgreTableManager.java
+50
-17
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/edit/DBEPersistAction.java
...el/src/org/jkiss/dbeaver/model/edit/DBEPersistAction.java
+2
-1
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/edit/AbstractCommandContext.java
...jkiss/dbeaver/model/impl/edit/AbstractCommandContext.java
+4
-0
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/edit/SQLDatabasePersistActionComment.java
...aver/model/impl/edit/SQLDatabasePersistActionComment.java
+32
-0
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
...eaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
+8
-1
未找到文件。
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreTableManager.java
浏览文件 @
4136b7c0
...
...
@@ -27,6 +27,7 @@ import org.jkiss.dbeaver.model.edit.DBEObjectRenamer;
import
org.jkiss.dbeaver.model.edit.DBEPersistAction
;
import
org.jkiss.dbeaver.model.impl.DBSObjectCache
;
import
org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction
;
import
org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistActionComment
;
import
org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLTableManager
;
import
org.jkiss.dbeaver.model.messages.ModelMessages
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
...
...
@@ -34,6 +35,7 @@ import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import
org.jkiss.dbeaver.model.sql.SQLUtils
;
import
org.jkiss.utils.CommonUtils
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -86,31 +88,62 @@ public class PostgreTableManager extends SQLTableManager<PostgreTableBase, Postg
@Override
protected
void
addObjectExtraActions
(
List
<
DBEPersistAction
>
actions
,
NestedObjectCommand
<
PostgreTableBase
,
PropertyHandler
>
command
,
Map
<
String
,
Object
>
options
)
{
PostgreTableBase
table
=
command
.
getObject
();
// Add comments
if
(!
CommonUtils
.
isEmpty
(
command
.
getObject
()
.
getDescription
()))
{
if
(!
CommonUtils
.
isEmpty
(
table
.
getDescription
()))
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Comment table"
,
"COMMENT ON TABLE "
+
command
.
getObject
()
.
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
+
" IS "
+
SQLUtils
.
quoteString
(
command
.
getObject
(),
command
.
getObject
()
.
getDescription
())));
"COMMENT ON TABLE "
+
table
.
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
+
" IS "
+
SQLUtils
.
quoteString
(
table
,
table
.
getDescription
())));
}
DBRProgressMonitor
monitor
=
new
VoidProgressMonitor
();
try
{
for
(
PostgreTableColumn
column
:
command
.
getObject
().
getAttributes
(
monitor
))
{
if
(!
CommonUtils
.
isEmpty
(
column
.
getDescription
()))
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Set column comment"
,
"COMMENT ON COLUMN "
+
DBUtils
.
getObjectFullName
(
command
.
getObject
(),
DBPEvaluationContext
.
DDL
)
+
"."
+
DBUtils
.
getQuotedIdentifier
(
column
)
+
" IS "
+
SQLUtils
.
quoteString
(
column
,
column
.
getDescription
())));
{
// Column comments
boolean
hasComments
=
false
;
for
(
PostgreTableColumn
column
:
table
.
getAttributes
(
monitor
))
{
if
(!
CommonUtils
.
isEmpty
(
column
.
getDescription
()))
{
if
(!
hasComments
)
{
actions
.
add
(
new
SQLDatabasePersistActionComment
(
table
.
getDataSource
(),
"Column comments"
));
}
actions
.
add
(
new
SQLDatabasePersistAction
(
"Set column comment"
,
"COMMENT ON COLUMN "
+
DBUtils
.
getObjectFullName
(
table
,
DBPEvaluationContext
.
DDL
)
+
"."
+
DBUtils
.
getQuotedIdentifier
(
column
)
+
" IS "
+
SQLUtils
.
quoteString
(
column
,
column
.
getDescription
())));
hasComments
=
true
;
}
}
}
for
(
PostgrePermission
permission
:
command
.
getObject
().
getPermissions
(
monitor
))
{
if
(
permission
.
hasAllPrivileges
(
command
.
getObject
()))
{
Collections
.
addAll
(
actions
,
new
PostgreCommandGrantPrivilege
(
permission
.
getOwner
(),
true
,
permission
,
PostgrePrivilegeType
.
ALL
)
.
getPersistActions
(
options
));
}
else
{
for
(
PostgrePermission
.
ObjectPermission
op
:
permission
.
getPermissions
())
{
PostgreCommandGrantPrivilege
grant
=
new
PostgreCommandGrantPrivilege
(
permission
.
getOwner
(),
true
,
permission
,
op
.
getPrivilegeType
());
Collections
.
addAll
(
actions
,
grant
.
getPersistActions
(
options
));
// Triggers
if
(
table
instanceof
PostgreTableReal
)
{
Collection
<
PostgreTrigger
>
triggers
=
((
PostgreTableReal
)
table
).
getTriggers
(
monitor
);
if
(!
CommonUtils
.
isEmpty
(
triggers
))
{
actions
.
add
(
new
SQLDatabasePersistActionComment
(
table
.
getDataSource
(),
"Table Triggers"
));
for
(
PostgreTrigger
trigger
:
triggers
)
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Create trigger"
,
trigger
.
getObjectDefinitionText
(
monitor
,
options
)));
}
}
}
{
// Permissions
Collection
<
PostgrePermission
>
permissions
=
table
.
getPermissions
(
monitor
);
if
(!
CommonUtils
.
isEmpty
(
permissions
))
{
actions
.
add
(
new
SQLDatabasePersistActionComment
(
table
.
getDataSource
(),
"Permissions"
));
for
(
PostgrePermission
permission
:
permissions
)
{
if
(
permission
.
hasAllPrivileges
(
table
))
{
Collections
.
addAll
(
actions
,
new
PostgreCommandGrantPrivilege
(
permission
.
getOwner
(),
true
,
permission
,
PostgrePrivilegeType
.
ALL
)
.
getPersistActions
(
options
));
}
else
{
for
(
PostgrePermission
.
ObjectPermission
op
:
permission
.
getPermissions
())
{
PostgreCommandGrantPrivilege
grant
=
new
PostgreCommandGrantPrivilege
(
permission
.
getOwner
(),
true
,
permission
,
op
.
getPrivilegeType
());
Collections
.
addAll
(
actions
,
grant
.
getPersistActions
(
options
));
}
}
}
}
}
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/edit/DBEPersistAction.java
浏览文件 @
4136b7c0
...
...
@@ -29,7 +29,8 @@ public interface DBEPersistAction {
INITIALIZER
,
NORMAL
,
OPTIONAL
,
FINALIZER
FINALIZER
,
COMMENT
}
String
getTitle
();
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/edit/AbstractCommandContext.java
浏览文件 @
4136b7c0
...
...
@@ -163,6 +163,10 @@ public abstract class AbstractCommandContext implements DBECommandContext {
DBException
error
=
null
;
for
(
PersistInfo
persistInfo
:
cmd
.
persistActions
)
{
DBEPersistAction
.
ActionType
actionType
=
persistInfo
.
action
.
getType
();
if
(
actionType
==
DBEPersistAction
.
ActionType
.
COMMENT
)
{
// Skip pure comments
continue
;
}
if
(
persistInfo
.
executed
&&
actionType
==
DBEPersistAction
.
ActionType
.
NORMAL
)
{
continue
;
}
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/edit/SQLDatabasePersistActionComment.java
0 → 100644
浏览文件 @
4136b7c0
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jkiss.dbeaver.model.impl.edit
;
import
org.jkiss.dbeaver.model.sql.SQLDataSource
;
/**
* Comment action
*/
public
class
SQLDatabasePersistActionComment
extends
SQLDatabasePersistAction
{
public
SQLDatabasePersistActionComment
(
SQLDataSource
dataSource
,
String
comment
)
{
super
(
"Comment"
,
"\n"
+
dataSource
.
getSQLDialect
().
getSingleLineComments
()[
0
]
+
" "
+
comment
+
"\n"
,
ActionType
.
COMMENT
,
false
);
}
}
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/sql/SQLUtils.java
浏览文件 @
4136b7c0
...
...
@@ -806,7 +806,14 @@ public final class SQLUtils {
script
.
append
(
delimiter
).
append
(
lineSeparator
);
}
script
.
append
(
scriptLine
);
script
.
append
(
" "
).
append
(
delimiter
).
append
(
lineSeparator
);
if
(
action
.
getType
()
!=
DBEPersistAction
.
ActionType
.
COMMENT
)
{
char
lastChar
=
scriptLine
.
charAt
(
scriptLine
.
length
()
-
1
);
if
(!
Character
.
isWhitespace
(
lastChar
)
&&
!
Character
.
isLetterOrDigit
(
lastChar
))
{
script
.
append
(
" "
);
}
script
.
append
(
delimiter
);
}
script
.
append
(
lineSeparator
);
if
(
action
.
isComplex
()
&&
redefiner
!=
null
)
{
script
.
append
(
redefiner
).
append
(
" "
).
append
(
sqlDialect
.
getScriptDelimiter
()).
append
(
lineSeparator
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录