Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
7f1b8720
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
提交
7f1b8720
编写于
4月 12, 2018
作者:
E
Evgeny Fradkin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Mock Data. Monitor usages are reworked - VoidMonitor is avoid.
上级
efcbd5da
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
84 deletion
+79
-84
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataExecuteWizard.java
...org/jkiss/dbeaver/ext/mockdata/MockDataExecuteWizard.java
+1
-2
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataSettings.java
.../src/org/jkiss/dbeaver/ext/mockdata/MockDataSettings.java
+25
-37
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataWizardPageSettings.java
...kiss/dbeaver/ext/mockdata/MockDataWizardPageSettings.java
+53
-45
未找到文件。
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataExecuteWizard.java
浏览文件 @
7f1b8720
...
...
@@ -33,7 +33,6 @@ import org.jkiss.dbeaver.model.edit.DBEPersistAction;
import
org.jkiss.dbeaver.model.exec.*
;
import
org.jkiss.dbeaver.model.impl.AbstractExecutionSource
;
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.DBSAttributeBase
;
import
org.jkiss.dbeaver.model.struct.DBSDataManipulator
;
...
...
@@ -84,7 +83,7 @@ public class MockDataExecuteWizard extends AbstractToolWizard<DBSDataManipulato
public
boolean
canFinish
()
{
try
{
Collection
<?
extends
DBSEntityAttribute
>
attributes
=
mockDataSettings
.
getEntity
().
getAttributes
(
new
VoidProgress
Monitor
());
mockDataSettings
.
getEntity
().
getAttributes
(
mockDataSettings
.
get
Monitor
());
return
super
.
canFinish
()
&&
!
CommonUtils
.
isEmpty
(
DBUtils
.
getRealAttributes
(
attributes
));
}
catch
(
DBException
ex
)
{
log
.
error
(
"Error accessing DB entity "
+
mockDataSettings
.
getEntity
().
getName
(),
ex
);
...
...
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataSettings.java
浏览文件 @
7f1b8720
...
...
@@ -19,20 +19,16 @@ package org.jkiss.dbeaver.ext.mockdata;
import
org.eclipse.jface.dialogs.IDialogSettings
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.core.DBeaverUI
;
import
org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorDescriptor
;
import
org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorRegistry
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress
;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.*
;
import
org.jkiss.dbeaver.runtime.properties.PropertySourceCustom
;
import
org.jkiss.dbeaver.runtime.ui.DBUserInterface
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.utils.CommonUtils
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.*
;
public
class
MockDataSettings
{
...
...
@@ -49,6 +45,7 @@ public class MockDataSettings {
private
DBSEntity
entity
;
private
Collection
<
DBSAttributeBase
>
attributes
;
private
DBRProgressMonitor
monitor
;
private
boolean
removeOldData
;
private
long
rowsNumber
=
1000
;
...
...
@@ -58,45 +55,32 @@ public class MockDataSettings {
private
Map
<
String
,
AttributeGeneratorProperties
>
attributeGenerators
=
new
HashMap
<>();
// attribute.name -> generators properties
// populate attribute generators properties map
public
void
init
(
MockDataExecuteWizard
wizard
)
throws
DBException
{
public
void
init
(
DBRProgressMonitor
monitor
,
MockDataExecuteWizard
wizard
)
throws
DBException
{
this
.
monitor
=
monitor
;
List
<
DBSDataManipulator
>
databaseObjects
=
wizard
.
getDatabaseObjects
();
DBSDataManipulator
dataManipulator
=
databaseObjects
.
iterator
().
next
();
// TODO only the first
entity
=
(
DBSEntity
)
dataManipulator
;
attributes
=
new
ArrayList
<>();
try
{
DBeaverUI
.
run
(
wizard
.
getContainer
(),
true
,
true
,
new
DBRRunnableWithProgress
()
{
@Override
public
void
run
(
DBRProgressMonitor
monitor
)
throws
InvocationTargetException
,
InterruptedException
{
try
{
attributes
.
addAll
(
DBUtils
.
getRealAttributes
(
entity
.
getAttributes
(
monitor
)));
MockGeneratorRegistry
generatorRegistry
=
MockGeneratorRegistry
.
getInstance
();
for
(
DBSAttributeBase
attribute
:
attributes
)
{
AttributeGeneratorProperties
generatorProperties
=
new
AttributeGeneratorProperties
(
attribute
);
attributeGenerators
.
put
(
attribute
.
getName
(),
generatorProperties
);
//((JDBCColumnKeyType) attribute).isInUniqueKey()
List
<
DBSEntityReferrer
>
attributeReferrers
=
DBUtils
.
getAttributeReferrers
(
monitor
,
(
DBSEntityAttribute
)
attribute
);
if
(!
CommonUtils
.
isEmpty
(
attributeReferrers
))
{
MockGeneratorDescriptor
generator
=
generatorRegistry
.
getGenerator
(
FK_GENERATOR_ID
);
putGenerator
(
generatorProperties
,
generator
);
}
else
{
List
<
MockGeneratorDescriptor
>
generators
=
generatorRegistry
.
findAllGenerators
(
dataManipulator
.
getDataSource
(),
attribute
);
for
(
MockGeneratorDescriptor
generator
:
generators
)
{
putGenerator
(
generatorProperties
,
generator
);
}
}
}
}
catch
(
DBException
e
)
{
throw
new
InvocationTargetException
(
e
);
}
attributes
.
addAll
(
DBUtils
.
getRealAttributes
(
entity
.
getAttributes
(
monitor
)));
MockGeneratorRegistry
generatorRegistry
=
MockGeneratorRegistry
.
getInstance
();
for
(
DBSAttributeBase
attribute
:
attributes
)
{
AttributeGeneratorProperties
generatorProperties
=
new
AttributeGeneratorProperties
(
attribute
);
attributeGenerators
.
put
(
attribute
.
getName
(),
generatorProperties
);
//((JDBCColumnKeyType) attribute).isInUniqueKey()
List
<
DBSEntityReferrer
>
attributeReferrers
=
DBUtils
.
getAttributeReferrers
(
monitor
,
(
DBSEntityAttribute
)
attribute
);
if
(!
CommonUtils
.
isEmpty
(
attributeReferrers
))
{
MockGeneratorDescriptor
generator
=
generatorRegistry
.
getGenerator
(
FK_GENERATOR_ID
);
putGenerator
(
generatorProperties
,
generator
);
}
else
{
List
<
MockGeneratorDescriptor
>
generators
=
generatorRegistry
.
findAllGenerators
(
dataManipulator
.
getDataSource
(),
attribute
);
for
(
MockGeneratorDescriptor
generator
:
generators
)
{
putGenerator
(
generatorProperties
,
generator
);
}
});
}
catch
(
InvocationTargetException
e
)
{
DBUserInterface
.
getInstance
().
showError
(
"Transfer init failed"
,
"Can't start data transfer"
,
e
.
getTargetException
());
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
...
...
@@ -160,6 +144,10 @@ public class MockDataSettings {
return
attributeGenerators
.
get
(
attribute
.
getName
());
}
public
DBRProgressMonitor
getMonitor
()
{
return
monitor
;
}
public
void
loadFrom
(
IDialogSettings
dialogSettings
)
{
removeOldData
=
dialogSettings
.
getBoolean
(
PROP_REMOVE_OLD_DATA
);
try
{
...
...
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataWizardPageSettings.java
浏览文件 @
7f1b8720
...
...
@@ -35,7 +35,6 @@ import org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorDescriptor;
import
org.jkiss.dbeaver.model.DBPEvaluationContext
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.dbeaver.model.DBValueFormatting
;
import
org.jkiss.dbeaver.model.runtime.VoidProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.DBSAttributeBase
;
import
org.jkiss.dbeaver.runtime.properties.PropertySourceCustom
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
...
...
@@ -46,6 +45,7 @@ import org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage;
import
org.jkiss.dbeaver.ui.properties.PropertyTreeViewer
;
import
org.jkiss.utils.CommonUtils
;
import
java.lang.reflect.InvocationTargetException
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.List
;
...
...
@@ -177,7 +177,6 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
}
});
VoidProgressMonitor
monitor
=
new
VoidProgressMonitor
();
// TODO VoidProgressMonitor
CellLabelProvider
labelProvider
=
new
CellLabelProvider
()
{
@Override
public
void
update
(
ViewerCell
cell
)
{
...
...
@@ -187,7 +186,7 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
cell
.
setImage
(
DBeaverIcons
.
getImage
(
DBValueFormatting
.
getTypeImage
(
attribute
)));
cell
.
setText
(
attribute
.
getName
());
try
{
if
(
DBUtils
.
checkUnique
(
mo
nitor
,
mockDataSettings
.
getEntity
(),
attribute
))
{
if
(
DBUtils
.
checkUnique
(
mo
ckDataSettings
.
getMonitor
()
,
mockDataSettings
.
getEntity
(),
attribute
))
{
cell
.
setFont
(
boldFont
);
}
}
catch
(
DBException
e
)
{
...
...
@@ -384,54 +383,63 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
@Override
public
void
activatePage
()
{
try
{
// init the generators properties
if
(
firstInit
)
{
firstInit
=
false
;
MockDataExecuteWizard
wizard
=
getWizard
();
mockDataSettings
.
init
(
wizard
);
wizard
.
loadSettings
();
removeOldDataCheck
.
setSelection
(
mockDataSettings
.
isRemoveOldData
());
rowsText
.
setText
(
String
.
valueOf
(
mockDataSettings
.
getRowsNumber
()));
generatorsTableViewer
.
setInput
(
mockDataSettings
.
getAttributes
());
// init the generators properties
if
(
firstInit
)
{
try
{
DBeaverUI
.
run
(
this
.
getContainer
(),
true
,
true
,
monitor
->
{
try
{
firstInit
=
false
;
MockDataExecuteWizard
wizard
=
getWizard
();
mockDataSettings
.
init
(
monitor
,
wizard
);
wizard
.
loadSettings
();
}
catch
(
DBException
ex
)
{
throw
new
InvocationTargetException
(
ex
);
}
});
}
catch
(
InvocationTargetException
ex
)
{
log
.
error
(
"Error Mock Data Settings initialization"
,
ex
.
getTargetException
());
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"Mock Data Settings initialization interrupted"
,
e
);
}
entityNameText
.
setText
(
DBUtils
.
getObjectFullName
(
mockDataSettings
.
getEntity
(),
DBPEvaluationContext
.
DML
));
propsEditor
.
getControl
().
setFocus
();
removeOldDataCheck
.
setSelection
(
mockDataSettings
.
isRemoveOldData
());
rowsText
.
setText
(
String
.
valueOf
(
mockDataSettings
.
getRowsNumber
()));
generatorsTableViewer
.
setInput
(
mockDataSettings
.
getAttributes
());
}
// select the attributes table item
final
Table
table
=
generatorsTableViewer
.
getTable
();
if
(
table
.
getItemCount
()
>
0
)
{
int
selectedItemIndex
=
0
;
TableItem
selectedItem
=
null
;
String
selectedAttribute
=
mockDataSettings
.
getSelectedAttribute
();
if
(
selectedAttribute
!=
null
)
{
for
(
int
i
=
0
;
i
<
table
.
getItemCount
();
i
++)
{
if
(
selectedAttribute
.
equals
(
table
.
getItem
(
i
).
getText
()))
{
selectedItemIndex
=
i
;
selectedItem
=
table
.
getItem
(
i
);
break
;
}
entityNameText
.
setText
(
DBUtils
.
getObjectFullName
(
mockDataSettings
.
getEntity
(),
DBPEvaluationContext
.
DML
));
propsEditor
.
getControl
().
setFocus
();
// select the attributes table item
final
Table
table
=
generatorsTableViewer
.
getTable
();
if
(
table
.
getItemCount
()
>
0
)
{
int
selectedItemIndex
=
0
;
TableItem
selectedItem
=
null
;
String
selectedAttribute
=
mockDataSettings
.
getSelectedAttribute
();
if
(
selectedAttribute
!=
null
)
{
for
(
int
i
=
0
;
i
<
table
.
getItemCount
();
i
++)
{
if
(
selectedAttribute
.
equals
(
table
.
getItem
(
i
).
getText
()))
{
selectedItemIndex
=
i
;
selectedItem
=
table
.
getItem
(
i
);
break
;
}
}
table
.
select
(
selectedItemIndex
);
if
(
selectedItem
!=
null
)
{
table
.
showItem
(
selectedItem
);
}
// and notify the listeners
Event
event
=
new
Event
();
event
.
widget
=
table
;
event
.
display
=
table
.
getDisplay
();
event
.
item
=
table
.
getItem
(
selectedItemIndex
);
event
.
type
=
SWT
.
Selection
;
table
.
notifyListeners
(
SWT
.
Selection
,
event
);
}
else
{
noGeneratorInfoLabel
.
setText
(
"No attributes in the table"
);
noGeneratorInfoLabel
.
setVisible
(
true
);
}
}
catch
(
DBException
ex
)
{
log
.
error
(
"Error of initializing the Mock Data settings"
,
ex
);
table
.
select
(
selectedItemIndex
);
if
(
selectedItem
!=
null
)
{
table
.
showItem
(
selectedItem
);
}
// and notify the listeners
Event
event
=
new
Event
();
event
.
widget
=
table
;
event
.
display
=
table
.
getDisplay
();
event
.
item
=
table
.
getItem
(
selectedItemIndex
);
event
.
type
=
SWT
.
Selection
;
table
.
notifyListeners
(
SWT
.
Selection
,
event
);
}
else
{
noGeneratorInfoLabel
.
setText
(
"No attributes in the table"
);
noGeneratorInfoLabel
.
setVisible
(
true
);
}
updatePageCompletion
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录