Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
bde4cba1
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,发现更多精彩内容 >>
未验证
提交
bde4cba1
编写于
9月 22, 2020
作者:
S
Serge Rider
提交者:
GitHub
9月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9832 from dbeaver/#9653-postgre-trigger
#9653 Postgre trigger refactor
上级
895b05fb
a4af9087
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
72 deletion
+44
-72
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/ui/config/PostgreTriggerConfigurator.java
.../ext/postgresql/ui/config/PostgreTriggerConfigurator.java
+5
-31
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreTriggerManager.java
...ss/dbeaver/ext/postgresql/edit/PostgreTriggerManager.java
+21
-8
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTrigger.java
...rg/jkiss/dbeaver/ext/postgresql/model/PostgreTrigger.java
+17
-33
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditorNested.java
...src/org/jkiss/dbeaver/ui/editors/sql/SQLEditorNested.java
+1
-0
未找到文件。
plugins/org.jkiss.dbeaver.ext.postgresql.ui/src/org/jkiss/dbeaver/ext/postgresql/ui/config/PostgreTriggerConfigurator.java
浏览文件 @
bde4cba1
...
...
@@ -24,13 +24,10 @@ import org.eclipse.swt.layout.GridData;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Control
;
import
org.eclipse.swt.widgets.Text
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure
;
import
org.jkiss.dbeaver.ext.postgresql.model.PostgreTrigger
;
import
org.jkiss.dbeaver.model.DBIcon
;
import
org.jkiss.dbeaver.model.DBPEvaluationContext
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.dbeaver.model.edit.DBEObjectConfigurator
;
import
org.jkiss.dbeaver.model.navigator.DBNDatabaseNode
;
import
org.jkiss.dbeaver.model.navigator.DBNModel
;
...
...
@@ -50,7 +47,7 @@ import org.jkiss.dbeaver.ui.editors.object.struct.EntityEditPage;
* Postgre sequence configurator
*/
public
class
PostgreTriggerConfigurator
implements
DBEObjectConfigurator
<
PostgreTrigger
>
{
protected
static
final
Log
log
=
Log
.
getLog
(
PostgreTriggerConfigurator
.
class
);
@Override
...
...
@@ -63,20 +60,8 @@ public class PostgreTriggerConfigurator implements DBEObjectConfigurator<Postgre
if
(!
editPage
.
edit
())
{
return
null
;
}
try
{
trigger
.
setName
(
editPage
.
getEntityName
());
trigger
.
setFunction
(
editPage
.
selectedFunction
);
String
procName
=
"X"
;
PostgreProcedure
function
=
trigger
.
getFunction
(
monitor
);
if
(
function
!=
null
)
{
procName
=
function
.
getFullQualifiedSignature
();
}
trigger
.
setObjectDefinitionText
(
"CREATE TRIGGER "
+
DBUtils
.
getQuotedIdentifier
(
trigger
)
+
"\n"
+
"BEFORE UPDATE"
+
" "
+
"\n"
+
"ON "
+
trigger
.
getTable
().
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
+
" FOR EACH ROW"
+
"\n"
+
"EXECUTE PROCEDURE "
+
(
function
==
null
?
procName
:
function
.
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
))+
"()\n"
);
}
catch
(
DBException
e
)
{
log
.
error
(
e
);
}
trigger
.
setName
(
editPage
.
getEntityName
());
trigger
.
setFunction
(
editPage
.
selectedFunction
);
return
trigger
;
}
}.
execute
();
...
...
@@ -87,18 +72,11 @@ public class PostgreTriggerConfigurator implements DBEObjectConfigurator<Postgre
PostgreTrigger
trigger
;
CSmartSelector
functionCombo
;
PostgreProcedure
selectedFunction
;
Text
processIdText
;
public
TriggerEditPage
editPage
;
public
TriggerEditPage
(
PostgreTrigger
trigger
)
{
super
(
trigger
.
getDataSource
(),
DBSEntityType
.
TRIGGER
);
this
.
trigger
=
trigger
;
}
public
TriggerEditPage
getEditPage
()
{
return
editPage
;
}
@Override
protected
Control
createPageContents
(
Composite
parent
)
{
...
...
@@ -142,8 +120,8 @@ public class PostgreTriggerConfigurator implements DBEObjectConfigurator<Postgre
:
navigatorModel
.
getNodeByObject
(
selectedFunction
);
DBNNode
node
=
DBWorkbench
.
getPlatformUI
().
selectObject
(
parent
.
getShell
(),
"Select function for "
,
dsNode
,
curNode
,
new
Class
[]
{
DBSInstance
.
class
,
DBSObjectContainer
.
class
,
PostgreProcedure
.
class
},
new
Class
[]
{
PostgreProcedure
.
class
},
null
);
new
Class
[]{
DBSInstance
.
class
,
DBSObjectContainer
.
class
,
PostgreProcedure
.
class
},
new
Class
[]{
PostgreProcedure
.
class
},
null
);
if
(
node
instanceof
DBNDatabaseNode
&&
((
DBNDatabaseNode
)
node
).
getObject
()
instanceof
PostgreProcedure
)
{
functionCombo
.
removeAll
();
...
...
@@ -151,13 +129,9 @@ public class PostgreTriggerConfigurator implements DBEObjectConfigurator<Postgre
functionCombo
.
addItem
(
selectedFunction
);
functionCombo
.
select
(
selectedFunction
);
}
}
}
}
}
}
}
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/edit/PostgreTriggerManager.java
浏览文件 @
bde4cba1
...
...
@@ -76,16 +76,29 @@ public class PostgreTriggerManager extends SQLTriggerManager<PostgreTrigger, Pos
@Override
protected
void
createOrReplaceTriggerQuery
(
DBRProgressMonitor
monitor
,
DBCExecutionContext
executionContext
,
List
<
DBEPersistAction
>
actions
,
PostgreTrigger
trigger
,
boolean
create
)
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Create trigger"
,
trigger
.
getBody
(),
true
));
if
(!
create
)
return
;
try
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Create trigger"
,
"CREATE TRIGGER "
+
DBUtils
.
getQuotedIdentifier
(
trigger
)
+
"\n AFTER INSERT"
+
"\n ON "
+
trigger
.
getTable
().
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
+
"\n FOR EACH ROW"
+
"\n EXECUTE PROCEDURE "
+
trigger
.
getFunction
(
monitor
).
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
+
"()"
,
true
));
}
catch
(
DBException
e
)
{
log
.
error
(
e
);
}
}
@Override
protected
void
addObjectDeleteActions
(
DBRProgressMonitor
monitor
,
DBCExecutionContext
executionContext
,
List
<
DBEPersistAction
>
actions
,
ObjectDeleteCommand
command
,
Map
<
String
,
Object
>
options
)
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Drop trigger"
,
"DROP TRIGGER "
+
DBUtils
.
getQuotedIdentifier
(
command
.
getObject
())
+
" ON "
+
command
.
getObject
().
getTable
().
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
))
);
protected
void
addObjectDeleteActions
(
DBRProgressMonitor
monitor
,
DBCExecutionContext
executionContext
,
List
<
DBEPersistAction
>
actions
,
ObjectDeleteCommand
command
,
Map
<
String
,
Object
>
options
)
{
actions
.
add
(
new
SQLDatabasePersistAction
(
"Drop trigger"
,
"DROP TRIGGER "
+
DBUtils
.
getQuotedIdentifier
(
command
.
getObject
())
+
" ON "
+
command
.
getObject
().
getTable
().
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)
));
}
}
plugins/org.jkiss.dbeaver.ext.postgresql/src/org/jkiss/dbeaver/ext/postgresql/model/PostgreTrigger.java
浏览文件 @
bde4cba1
...
...
@@ -20,7 +20,6 @@ import org.jkiss.code.NotNull;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.ext.postgresql.PostgreConstants
;
import
org.jkiss.dbeaver.ext.postgresql.PostgreUtils
;
import
org.jkiss.dbeaver.model.*
;
import
org.jkiss.dbeaver.model.exec.DBCException
;
...
...
@@ -30,7 +29,6 @@ import org.jkiss.dbeaver.model.meta.IPropertyValueTransformer;
import
org.jkiss.dbeaver.model.meta.Property
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.sql.SQLUtils
;
import
org.jkiss.dbeaver.model.sql.format.SQLFormatUtils
;
import
org.jkiss.dbeaver.model.struct.DBSActionTiming
;
import
org.jkiss.dbeaver.model.struct.DBSEntityElement
;
import
org.jkiss.dbeaver.model.struct.DBSObjectState
;
...
...
@@ -66,15 +64,13 @@ public class PostgreTrigger implements DBSTrigger, DBSEntityElement, DBPQualifie
private
String
whenExpression
;
private
long
functionSchemaId
;
private
long
functionId
;
private
String
body
;
protected
String
name
;
private
DBSActionTiming
actionTiming
;
private
DBSManipulationType
[]
manipulationTypes
;
private
PostgreTriggerType
type
;
private
boolean
persisted
;
private
PostgreTableColumn
[]
columnRefs
;
protected
String
description
;
protected
String
name
;
public
PostgreTrigger
(
DBRProgressMonitor
monitor
,
...
...
@@ -157,11 +153,6 @@ public class PostgreTrigger implements DBSTrigger, DBSEntityElement, DBPQualifie
this
.
name
=
name
;
}
public
String
getBody
()
{
return
body
;
}
@Property
(
viewable
=
true
,
order
=
2
)
public
DBSActionTiming
getActionTiming
()
{
return
actionTiming
;
...
...
@@ -259,39 +250,32 @@ public class PostgreTrigger implements DBSTrigger, DBSEntityElement, DBPQualifie
}
@Override
@Property
(
hidden
=
true
,
editable
=
true
,
updatable
=
true
,
order
=
-
1
)
public
String
getObjectDefinitionText
(
DBRProgressMonitor
monitor
,
Map
<
String
,
Object
>
options
)
throws
DBException
{
if
(
body
==
null
)
{
StringBuilder
ddl
=
new
StringBuilder
();
ddl
.
append
(
"-- DROP TRIGGER "
).
append
(
DBUtils
.
getQuotedIdentifier
(
this
)).
append
(
" ON "
)
public
String
getObjectDefinitionText
(
DBRProgressMonitor
monitor
,
Map
<
String
,
Object
>
options
)
throws
DBException
{
StringBuilder
ddl
=
new
StringBuilder
();
ddl
.
append
(
"-- DROP TRIGGER "
)
.
append
(
DBUtils
.
getQuotedIdentifier
(
this
)).
append
(
" ON "
)
.
append
(
getTable
().
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)).
append
(
";\n\n"
);
try
(
JDBCSession
session
=
DBUtils
.
openMetaSession
(
monitor
,
this
,
"Read trigger definition"
))
{
String
triggerSource
=
JDBCUtils
.
queryString
(
session
,
"SELECT pg_catalog.pg_get_triggerdef(?)"
,
objectId
);
if
(
triggerSource
!=
null
)
{
triggerSource
=
SQLFormatUtils
.
formatSQL
(
getDataSource
(),
triggerSource
);
ddl
.
append
(
triggerSource
).
append
(
";"
);
}
}
catch
(
SQLException
e
)
{
throw
new
DBException
(
e
,
getDataSource
());
}
ddl
.
append
(
"CREATE TRIGGER "
).
append
(
DBUtils
.
getQuotedIdentifier
(
this
))
.
append
(
"\n AFTER INSERT"
)
.
append
(
"\n ON "
).
append
(
table
.
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
))
.
append
(
"\n FOR EACH ROW"
)
.
append
(
"\n EXECUTE PROCEDURE "
).
append
(
getFunction
(
monitor
).
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
)).
append
(
"();\n"
);
if
(!
CommonUtils
.
isEmpty
(
getDescription
())
&&
CommonUtils
.
getOption
(
options
,
DBPScriptObject
.
OPTION_INCLUDE_COMMENTS
))
{
ddl
.
append
(
"\n"
)
.
append
(
"\nCOMMENT ON TRIGGER "
).
append
(
DBUtils
.
getQuotedIdentifier
(
this
))
if
(!
CommonUtils
.
isEmpty
(
getDescription
())
&&
CommonUtils
.
getOption
(
options
,
DBPScriptObject
.
OPTION_INCLUDE_COMMENTS
))
{
ddl
.
append
(
"\nCOMMENT ON TRIGGER "
).
append
(
DBUtils
.
getQuotedIdentifier
(
this
))
.
append
(
" ON "
).
append
(
getTable
().
getFullyQualifiedName
(
DBPEvaluationContext
.
DDL
))
.
append
(
" IS "
)
.
append
(
SQLUtils
.
quoteString
(
this
,
getDescription
())).
append
(
";"
);
}
this
.
body
=
ddl
.
toString
();
}
return
body
;
return
ddl
.
toString
();
}
@Override
public
void
setObjectDefinitionText
(
String
sourceText
)
throws
DBException
{
body
=
sourceText
;
public
void
setObjectDefinitionText
(
String
sourceText
)
throws
DBException
{
throw
new
DBException
(
"Trigger DDL is read-only"
);
}
@Override
...
...
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditorNested.java
浏览文件 @
bde4cba1
...
...
@@ -280,6 +280,7 @@ public abstract class SQLEditorNested<T extends DBSObject>
});
return
Status
.
OK_STATUS
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
);
sourceText
=
"/* ERROR WHILE READING SOURCE:\n\n"
+
e
.
getMessage
()
+
"\n*/"
;
return
Status
.
CANCEL_STATUS
;
}
finally
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录