Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
f305a477
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,发现更多精彩内容 >>
提交
f305a477
编写于
3月 25, 2018
作者:
S
serge-rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#3024 PG: constraint comments (read/write, table DDL)
上级
386f020d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
107 addition
and
49 deletion
+107
-49
plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties
...ss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties
+6
-4
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreConstraintManager.java
...dbeaver/ext/postgresql/edit/PostgreConstraintManager.java
+22
-0
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreIndexManager.java
...kiss/dbeaver/ext/postgresql/edit/PostgreIndexManager.java
+8
-4
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreTableColumnManager.java
...beaver/ext/postgresql/edit/PostgreTableColumnManager.java
+9
-4
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreTableManagerBase.java
.../dbeaver/ext/postgresql/edit/PostgreTableManagerBase.java
+50
-36
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSchema.java
...org/jkiss/dbeaver/ext/postgresql/model/PostgreSchema.java
+2
-1
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableConstraintBase.java
...aver/ext/postgresql/model/PostgreTableConstraintBase.java
+10
-0
未找到文件。
plugins/org.jkiss.dbeaver.ext.postgresql/OSGI-INF/l10n/bundle.properties
浏览文件 @
f305a477
...
...
@@ -47,7 +47,7 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.dataType.name=Data
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.dataType.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.defaultValue.name
=
Default
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.defaultValue.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.description.name
=
Description
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.description.name
=
Comment
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.description.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.maxLength.name
=
Length
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute.maxLength.description
=
...
...
@@ -204,7 +204,7 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.checkXMin.name=Check X
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.checkXMin.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.clustered.name
=
Clustered
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.clustered.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.description.name
=
Description
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.description.name
=
Comment
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.description.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.exclusion.name
=
Exclusion
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreIndex.exclusion.description
=
...
...
@@ -294,7 +294,7 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.database.name=Database
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.database.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.name.name
=
Name
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.name.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.description.name
=
Description
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.description.name
=
Comment
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.description.description
=
Schema comment
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.owner.name
=
Owner
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema.owner.description
=
...
...
@@ -320,10 +320,12 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.objectId.name=ID
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.objectId.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.owner.name
=
Owner
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.owner.description
=
Table owner (creator)
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.description.name
=
Description
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.description.name
=
Comment
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase.description.description
=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintBase.objectDefinitionText.name
=
DDL
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintBase.objectDefinitionText.description
=
Constraint definition text
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintBase.description.name
=
Comment
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintBase.description.description
=
Constraint comment
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraint.source.name
=
Expression
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraint.source.description
=
Expression of CHECK constraints
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintColumn.attribute.name
=
Attribute
...
...
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreConstraintManager.java
浏览文件 @
f305a477
...
...
@@ -20,13 +20,19 @@ import org.jkiss.code.NotNull;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.ext.postgresql.model.*
;
import
org.jkiss.dbeaver.model.DBConstants
;
import
org.jkiss.dbeaver.model.DBPEvaluationContext
;
import
org.jkiss.dbeaver.model.DBPScriptObject
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.dbeaver.model.edit.DBECommandContext
;
import
org.jkiss.dbeaver.model.edit.DBEPersistAction
;
import
org.jkiss.dbeaver.model.impl.DBSObjectCache
;
import
org.jkiss.dbeaver.model.impl.edit.DBECommandAbstract
;
import
org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction
;
import
org.jkiss.dbeaver.model.impl.sql.edit.struct.SQLConstraintManager
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
import
org.jkiss.dbeaver.model.sql.SQLUtils
;
import
org.jkiss.dbeaver.model.struct.DBSEntityAttribute
;
import
org.jkiss.dbeaver.model.struct.DBSEntityConstraintType
;
import
org.jkiss.dbeaver.ui.UITask
;
...
...
@@ -34,6 +40,7 @@ import org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage;
import
org.jkiss.utils.CommonUtils
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
/**
...
...
@@ -123,6 +130,21 @@ public class PostgreConstraintManager extends SQLConstraintManager<PostgreTableC
}
}
@Override
protected
void
addObjectModifyActions
(
List
<
DBEPersistAction
>
actionList
,
ObjectChangeCommand
command
,
Map
<
String
,
Object
>
options
)
{
if
(
command
.
getProperty
(
DBConstants
.
PROP_ID_DESCRIPTION
)
!=
null
)
{
addConstraintCommentAction
(
actionList
,
command
.
getObject
());
}
}
static
void
addConstraintCommentAction
(
List
<
DBEPersistAction
>
actionList
,
PostgreTableConstraintBase
constr
)
{
actionList
.
add
(
new
SQLDatabasePersistAction
(
"Comment sequence"
,
"COMMENT ON CONSTRAINT "
+
DBUtils
.
getQuotedIdentifier
(
constr
)
+
" ON "
+
constr
.
getTable
().
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
+
" IS "
+
SQLUtils
.
quoteString
(
constr
,
constr
.
getDescription
())));
}
@Override
protected
String
getDropConstraintPattern
(
PostgreTableConstraintBase
constraint
)
{
...
...
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreIndexManager.java
浏览文件 @
f305a477
...
...
@@ -140,10 +140,14 @@ public class PostgreIndexManager extends SQLIndexManager<PostgreIndex, PostgreTa
super
.
addObjectCreateActions
(
actions
,
command
,
options
);
}
if
(!
CommonUtils
.
isEmpty
(
index
.
getDescription
()))
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Comment index"
,
"COMMENT ON INDEX "
+
index
.
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
+
" IS "
+
SQLUtils
.
quoteString
(
index
,
index
.
getDescription
())));
addIndexCommentAction
(
actions
,
index
);
}
}
static
void
addIndexCommentAction
(
List
<
DBEPersistAction
>
actions
,
PostgreIndex
index
)
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Comment index"
,
"COMMENT ON INDEX "
+
index
.
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
+
" IS "
+
SQLUtils
.
quoteString
(
index
,
index
.
getDescription
())));
}
}
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreTableColumnManager.java
浏览文件 @
f305a477
...
...
@@ -20,6 +20,7 @@ import org.jkiss.code.Nullable;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.ext.postgresql.PostgreConstants
;
import
org.jkiss.dbeaver.ext.postgresql.model.*
;
import
org.jkiss.dbeaver.model.DBConstants
;
import
org.jkiss.dbeaver.model.DBPEvaluationContext
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.dbeaver.model.edit.DBECommandContext
;
...
...
@@ -213,13 +214,17 @@ public class PostgreTableColumnManager extends SQLTableColumnManager<PostgreTabl
actionList
.
add
(
new
SQLDatabasePersistAction
(
"Set column default"
,
prefix
+
"SET DEFAULT "
+
column
.
getDefaultValue
()));
}
}
if
(
command
.
getProperty
(
"description"
)
!=
null
)
{
actionList
.
add
(
new
SQLDatabasePersistAction
(
"Set column comment"
,
"COMMENT ON COLUMN "
+
DBUtils
.
getObjectFullName
(
column
.
getTable
(),
DBPEvaluationContext
.
DDL
)
+
"."
+
DBUtils
.
getQuotedIdentifier
(
column
)
+
" IS "
+
SQLUtils
.
quoteString
(
column
,
CommonUtils
.
notEmpty
(
column
.
getDescription
()))));
if
(
command
.
getProperty
(
DBConstants
.
PROP_ID_DESCRIPTION
)
!=
null
)
{
addColumnCommentAction
(
actionList
,
column
);
}
}
static
void
addColumnCommentAction
(
List
<
DBEPersistAction
>
actionList
,
PostgreAttribute
column
)
{
actionList
.
add
(
new
SQLDatabasePersistAction
(
"Set column comment"
,
"COMMENT ON COLUMN "
+
DBUtils
.
getObjectFullName
(
column
.
getTable
(),
DBPEvaluationContext
.
DDL
)
+
"."
+
DBUtils
.
getQuotedIdentifier
(
column
)
+
" IS "
+
SQLUtils
.
quoteString
(
column
,
CommonUtils
.
notEmpty
(
column
.
getDescription
()))));
}
@Override
public
void
renameObject
(
DBECommandContext
commandContext
,
PostgreTableColumn
object
,
String
newName
)
throws
DBException
{
processObjectRename
(
commandContext
,
object
,
newName
);
...
...
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreTableManagerBase.java
浏览文件 @
f305a477
...
...
@@ -53,54 +53,68 @@ public abstract class PostgreTableManagerBase extends SQLTableManager<PostgreTab
" IS "
+
SQLUtils
.
quoteString
(
table
,
table
.
getDescription
())));
}
DBRProgressMonitor
monitor
=
new
VoidProgressMonitor
();
try
{
if
(
isDDL
)
{
// 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"
));
if
(
isDDL
)
{
try
{
{
// 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"
));
}
PostgreTableColumnManager
.
addColumnCommentAction
(
actions
,
column
);
hasComments
=
true
;
}
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
;
}
}
}
// Triggers
if
(
isDDL
&&
table
instanceof
PostgreTableReal
)
{
Collection
<
PostgreTrigger
>
triggers
=
((
PostgreTableReal
)
table
).
getTriggers
(
monitor
);
if
(!
CommonUtils
.
isEmpty
(
triggers
))
{
actions
.
add
(
new
SQLDatabasePersistActionComment
(
table
.
getDataSource
(),
"Table Triggers"
));
{
// Constraint comments
boolean
hasComments
=
false
;
for
(
PostgreTableConstraintBase
constr
:
table
.
getConstraints
(
monitor
))
{
if
(!
CommonUtils
.
isEmpty
(
constr
.
getDescription
()))
{
if
(!
hasComments
)
{
actions
.
add
(
new
SQLDatabasePersistActionComment
(
table
.
getDataSource
(),
"Constraint comments"
));
}
PostgreConstraintManager
.
addConstraintCommentAction
(
actions
,
constr
);
hasComments
=
true
;
}
}
}
for
(
PostgreTrigger
trigger
:
triggers
)
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Create trigger"
,
trigger
.
getObjectDefinitionText
(
monitor
,
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
)));
}
}
}
}
if
(
isDDL
&&
CommonUtils
.
getOption
(
options
,
PostgreConstants
.
OPTION_DDL_SHOW_PERMISSIONS
))
{
// 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
{
PostgreCommandGrantPrivilege
grant
=
new
PostgreCommandGrantPrivilege
(
permission
.
getOwner
(),
true
,
permission
,
permission
.
getPrivileges
());
Collections
.
addAll
(
actions
,
grant
.
getPersistActions
(
options
));
if
(
CommonUtils
.
getOption
(
options
,
PostgreConstants
.
OPTION_DDL_SHOW_PERMISSIONS
))
{
// 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
{
PostgreCommandGrantPrivilege
grant
=
new
PostgreCommandGrantPrivilege
(
permission
.
getOwner
(),
true
,
permission
,
permission
.
getPrivileges
());
Collections
.
addAll
(
actions
,
grant
.
getPersistActions
(
options
));
}
}
}
}
}
catch
(
DBException
e
)
{
log
.
error
(
e
);
}
}
catch
(
DBException
e
)
{
log
.
error
(
e
);
}
}
}
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreSchema.java
浏览文件 @
f305a477
...
...
@@ -500,10 +500,11 @@ public class PostgreSchema implements DBSSchema, DBPNamedObject2, DBPSaveableObj
@Override
protected
JDBCStatement
prepareObjectsStatement
(
JDBCSession
session
,
PostgreSchema
schema
,
PostgreTableBase
forParent
)
throws
SQLException
{
StringBuilder
sql
=
new
StringBuilder
(
"SELECT c.oid,c.*,t.relname as tabrelname,rt.relnamespace as refnamespace"
+
"SELECT c.oid,c.*,t.relname as tabrelname,rt.relnamespace as refnamespace
,d.description
"
+
"\nFROM pg_catalog.pg_constraint c"
+
"\nINNER JOIN pg_catalog.pg_class t ON t.oid=c.conrelid"
+
"\nLEFT OUTER JOIN pg_catalog.pg_class rt ON rt.oid=c.confrelid"
+
"\nLEFT OUTER JOIN pg_catalog.pg_description d ON d.objoid=c.oid AND d.objsubid=0"
+
"\nWHERE "
);
if
(
forParent
==
null
)
{
sql
.
append
(
"t.relnamespace=?"
);
...
...
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTableConstraintBase.java
浏览文件 @
f305a477
...
...
@@ -17,6 +17,7 @@
package
org.jkiss.dbeaver.ext.postgresql.model
;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.DBPEvaluationContext
;
...
...
@@ -48,6 +49,7 @@ public abstract class PostgreTableConstraintBase extends JDBCTableConstraint<Pos
super
(
table
,
name
,
null
,
constraintType
,
true
);
this
.
oid
=
JDBCUtils
.
safeGetLong
(
resultSet
,
"oid"
);
this
.
description
=
JDBCUtils
.
safeGetString
(
resultSet
,
"description"
);
}
public
PostgreTableConstraintBase
(
PostgreTableBase
table
,
String
constraintName
,
DBSEntityConstraintType
constraintType
)
{
...
...
@@ -82,6 +84,14 @@ public abstract class PostgreTableConstraintBase extends JDBCTableConstraint<Pos
return
oid
;
}
@Property
(
viewable
=
true
,
editable
=
true
,
updatable
=
true
,
order
=
100
)
@Nullable
@Override
public
String
getDescription
()
{
return
super
.
getDescription
();
}
abstract
void
cacheAttributes
(
DBRProgressMonitor
monitor
,
List
<?
extends
PostgreTableConstraintColumn
>
children
,
boolean
secondPass
);
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录