Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
6e0922a2
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,发现更多精彩内容 >>
提交
6e0922a2
编写于
5月 10, 2018
作者:
S
Serge Rider
提交者:
GitHub
5月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3454 from dbeaver/3425-mock-data
3425-mock-data Former-commit-id:
5901cae5
上级
ee56bb5c
7ba40f86
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
81 addition
and
11 deletion
+81
-11
plugins/org.jkiss.dbeaver.ext.mockdata/plugin.xml
plugins/org.jkiss.dbeaver.ext.mockdata/plugin.xml
+1
-1
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataExecuteWizard.java
...org/jkiss/dbeaver/ext/mockdata/MockDataExecuteWizard.java
+41
-4
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataWizardPageSettings.java
...kiss/dbeaver/ext/mockdata/MockDataWizardPageSettings.java
+1
-1
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/generator/AbstractMockValueGenerator.java
...er/ext/mockdata/generator/AbstractMockValueGenerator.java
+1
-1
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/generator/FKGenerator.java
...org/jkiss/dbeaver/ext/mockdata/generator/FKGenerator.java
+1
-1
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/DBUtils.java
...ss.dbeaver.model/src/org/jkiss/dbeaver/model/DBUtils.java
+22
-3
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/data/DBDAttributeValue.java
...l/src/org/jkiss/dbeaver/model/data/DBDAttributeValue.java
+14
-0
未找到文件。
plugins/org.jkiss.dbeaver.ext.mockdata/plugin.xml
浏览文件 @
6e0922a2
...
...
@@ -216,7 +216,7 @@
label=
"UUID"
description=
"UUID random values"
class=
"org.jkiss.dbeaver.ext.mockdata.generator.StringUuidGenerator"
tags=
"uuid"
>
tags=
"
id,
uuid"
>
<type
kind=
"STRING"
/>
</generator>
...
...
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataExecuteWizard.java
浏览文件 @
6e0922a2
...
...
@@ -34,10 +34,7 @@ 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.sql.SQLUtils
;
import
org.jkiss.dbeaver.model.struct.DBSAttributeBase
;
import
org.jkiss.dbeaver.model.struct.DBSDataManipulator
;
import
org.jkiss.dbeaver.model.struct.DBSEntity
;
import
org.jkiss.dbeaver.model.struct.DBSEntityAttribute
;
import
org.jkiss.dbeaver.model.struct.*
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.dialogs.tools.AbstractToolWizard
;
import
org.jkiss.utils.CommonUtils
;
...
...
@@ -239,6 +236,21 @@ public class MockDataExecuteWizard extends AbstractToolWizard<DBSDataManipulato
monitor
.
beginTask
(
"Insert data"
,
(
int
)
rowsNumber
);
boolean
hasMiltiUniqs
=
false
;
Set
<
String
>
miltiUniqColumns
=
new
HashSet
<>();
for
(
DBSAttributeBase
attribute
:
attributes
)
{
if
(
DBUtils
.
checkUnique
(
monitor
,
dbsEntity
,
attribute
)
==
DBUtils
.
UNIQ_TYPE
.
MULTI
)
{
hasMiltiUniqs
=
true
;
// collect the columns from multi-uniqs
DBSEntityReferrer
constraint
=
(
DBSEntityReferrer
)
DBUtils
.
getConstraint
(
monitor
,
dbsEntity
,
attribute
);
for
(
DBSEntityAttributeRef
attributeRef
:
constraint
.
getAttributeReferences
(
monitor
))
{
miltiUniqColumns
.
add
(
attributeRef
.
getAttribute
().
getName
());
}
}
}
List
<
List
<
DBDAttributeValue
>>
valuesCacheForUniqs
=
new
ArrayList
<>();
// generate and insert the data
session
.
enableLogging
(
false
);
DBSDataManipulator
.
ExecuteBatch
batch
=
null
;
...
...
@@ -275,6 +287,31 @@ public class MockDataExecuteWizard extends AbstractToolWizard<DBSDataManipulato
return
true
;
}
// skip duplicate records for uniqs
if
(
hasMiltiUniqs
)
{
boolean
collision
=
false
;
for
(
List
<
DBDAttributeValue
>
valueList
:
valuesCacheForUniqs
)
{
boolean
theSame
=
true
;
for
(
int
j
=
0
;
j
<
valueList
.
size
();
j
++)
{
if
(
miltiUniqColumns
.
contains
(
valueList
.
get
(
j
).
getAttribute
().
getName
()))
{
if
(!
CommonUtils
.
equalObjects
(
valueList
.
get
(
j
),
attributeValues
.
get
(
j
)))
{
theSame
=
false
;
break
;
}
}
}
if
(
theSame
)
{
collision
=
true
;
break
;
}
}
if
(
collision
)
{
continue
;
}
else
{
valuesCacheForUniqs
.
add
(
attributeValues
);
}
}
if
(
batch
==
null
)
{
batch
=
dataManipulator
.
insertData
(
session
,
...
...
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataWizardPageSettings.java
浏览文件 @
6e0922a2
...
...
@@ -186,7 +186,7 @@ public class MockDataWizardPageSettings extends ActiveWizardPage<MockDataExecute
cell
.
setImage
(
DBeaverIcons
.
getImage
(
DBValueFormatting
.
getTypeImage
(
attribute
)));
cell
.
setText
(
attribute
.
getName
());
try
{
if
(
DBUtils
.
checkUnique
(
mockDataSettings
.
getMonitor
(),
mockDataSettings
.
getEntity
(),
attribute
))
{
if
(
DBUtils
.
checkUnique
(
mockDataSettings
.
getMonitor
(),
mockDataSettings
.
getEntity
(),
attribute
)
!=
null
)
{
cell
.
setFont
(
boldFont
);
}
}
catch
(
DBException
e
)
{
...
...
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/generator/AbstractMockValueGenerator.java
浏览文件 @
6e0922a2
...
...
@@ -81,7 +81,7 @@ public abstract class AbstractMockValueGenerator implements MockValueGenerator {
public
Object
generateValue
(
DBRProgressMonitor
monitor
)
throws
DBException
,
IOException
{
if
(
isFirstRun
)
{
isFirstRun
=
false
;
isUnique
=
DBUtils
.
checkUnique
(
monitor
,
dbsEntity
,
attribute
);
isUnique
=
(
DBUtils
.
checkUnique
(
monitor
,
dbsEntity
,
attribute
)
==
DBUtils
.
UNIQ_TYPE
.
SINGLE
);
if
(
isUnique
&&
(
attribute
instanceof
DBSAttributeEnumerable
))
{
uniqueValues
=
new
HashSet
<>();
Collection
<
DBDLabelValuePair
>
valuePairs
=
readColumnValues
(
monitor
,
dbsEntity
.
getDataSource
(),
(
DBSAttributeEnumerable
)
attribute
,
UNIQUE_VALUES_SET_SIZE
);
...
...
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/generator/FKGenerator.java
浏览文件 @
6e0922a2
...
...
@@ -72,7 +72,7 @@ public class FKGenerator extends AbstractMockValueGenerator
throw
new
DBException
(
"Can't find reference column for '"
+
attribute
.
getName
()
+
"'"
);
}
int
numberRefRecords
=
DBUtils
.
checkUnique
(
monitor
,
dbsEntity
,
attribute
)
?
UNIQ_REF_RECORDS_LIMIT
:
REF_RECORDS_LIMIT
;
int
numberRefRecords
=
(
DBUtils
.
checkUnique
(
monitor
,
dbsEntity
,
attribute
)
==
DBUtils
.
UNIQ_TYPE
.
SINGLE
)
?
UNIQ_REF_RECORDS_LIMIT
:
REF_RECORDS_LIMIT
;
Collection
<
DBDLabelValuePair
>
values
=
readColumnValues
(
monitor
,
fk
.
getDataSource
(),
(
DBSAttributeEnumerable
)
column
.
getReferencedColumn
(),
numberRefRecords
);
for
(
DBDLabelValuePair
value
:
values
)
{
refValues
.
add
(
value
.
getValue
());
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/DBUtils.java
浏览文件 @
6e0922a2
...
...
@@ -1554,16 +1554,35 @@ public final class DBUtils {
return
true
;
}
public
static
boolean
checkUnique
(
DBRProgressMonitor
monitor
,
DBSEntity
dbsEntity
,
DBSAttributeBase
attribute
)
throws
DBException
{
public
enum
UNIQ_TYPE
{
SINGLE
,
MULTI
}
public
static
UNIQ_TYPE
checkUnique
(
DBRProgressMonitor
monitor
,
DBSEntity
dbsEntity
,
DBSAttributeBase
attribute
)
throws
DBException
{
for
(
DBSEntityConstraint
constraint
:
dbsEntity
.
getConstraints
(
monitor
))
{
DBSEntityConstraintType
constraintType
=
constraint
.
getConstraintType
();
if
(
constraintType
.
isUnique
())
{
DBSEntityAttributeRef
constraintAttribute
=
getConstraintAttribute
(
monitor
,
((
DBSEntityReferrer
)
constraint
),
attribute
.
getName
());
if
(
constraintAttribute
!=
null
&&
constraintAttribute
.
getAttribute
()
==
attribute
)
{
return
true
;
List
<?
extends
DBSEntityAttributeRef
>
refColumns
=
((
DBSEntityReferrer
)
constraint
).
getAttributeReferences
(
monitor
);
if
(
refColumns
.
size
()
>
1
)
{
return
UNIQ_TYPE
.
MULTI
;
}
else
{
return
UNIQ_TYPE
.
SINGLE
;
}
}
}
}
return
false
;
return
null
;
}
public
static
DBSEntityConstraint
getConstraint
(
DBRProgressMonitor
monitor
,
DBSEntity
dbsEntity
,
DBSAttributeBase
attribute
)
throws
DBException
{
for
(
DBSEntityConstraint
constraint
:
dbsEntity
.
getConstraints
(
monitor
))
{
DBSEntityAttributeRef
constraintAttribute
=
getConstraintAttribute
(
monitor
,
((
DBSEntityReferrer
)
constraint
),
attribute
.
getName
());
if
(
constraintAttribute
!=
null
&&
constraintAttribute
.
getAttribute
()
==
attribute
)
{
return
constraint
;
}
}
return
null
;
}
}
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/data/DBDAttributeValue.java
浏览文件 @
6e0922a2
...
...
@@ -19,6 +19,7 @@ package org.jkiss.dbeaver.model.data;
import
org.jkiss.code.NotNull
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.model.struct.DBSAttributeBase
;
import
org.jkiss.utils.CommonUtils
;
import
java.util.List
;
...
...
@@ -71,4 +72,17 @@ public class DBDAttributeValue {
return
values
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
obj
==
null
||
!(
obj
instanceof
DBDAttributeValue
))
{
return
false
;
}
if
(!
CommonUtils
.
equalObjects
(
value
,
((
DBDAttributeValue
)
obj
).
value
))
{
return
false
;
}
if
(!
CommonUtils
.
equalObjects
(
attribute
.
getName
(),
((
DBDAttributeValue
)
obj
).
attribute
.
getName
()))
{
return
false
;
}
return
true
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录