Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
63f85f38
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,发现更多精彩内容 >>
提交
63f85f38
编写于
2月 16, 2018
作者:
E
Evgeny Fradkin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#1599 Mock Data. Advanced Mock Data plugin support.
上级
582ae0ac
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
4 addition
and
121 deletion
+4
-121
plugins/org.jkiss.dbeaver.ext.mockdata/META-INF/MANIFEST.MF
plugins/org.jkiss.dbeaver.ext.mockdata/META-INF/MANIFEST.MF
+3
-0
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataGenerator.java
...src/org/jkiss/dbeaver/ext/mockdata/MockDataGenerator.java
+0
-120
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/META-INF/MANIFEST.MF
浏览文件 @
63f85f38
...
...
@@ -16,3 +16,6 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: %Bundle-Vendor
Bundle-ClassPath: .
Export-Package: org.jkiss.dbeaver.ext.mockdata,
org.jkiss.dbeaver.ext.mockdata.generator,
org.jkiss.dbeaver.ext.mockdata.model
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/MockDataGenerator.java
已删除
100644 → 0
浏览文件 @
582ae0ac
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2010-2017 Eugene Fradkin (eugene.fradkin@gmail.com)
*
* 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.ext.mockdata
;
import
java.math.BigDecimal
;
import
java.util.Date
;
import
java.util.Random
;
public
class
MockDataGenerator
{
private
static
final
String
LOREM_IPSUM
=
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "
+
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
+
"ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in "
+
"voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non "
+
"proident, sunt in culpa qui officia deserunt mollit anim id est laborum. "
;
private
static
int
LOREM_IPSUM_LENGTH
=
LOREM_IPSUM
.
length
();
private
static
int
LONG_PRECISION
=
String
.
valueOf
(
Long
.
MAX_VALUE
).
length
();
// 19
private
static
int
INTEGER_PRECISION
=
String
.
valueOf
(
Integer
.
MAX_VALUE
).
length
();
// 10
private
static
int
SHORT_PRECISION
=
String
.
valueOf
(
Short
.
MAX_VALUE
).
length
();
// 5
private
static
int
BYTE_PRECISION
=
String
.
valueOf
(
Byte
.
MAX_VALUE
).
length
();
// 3
private
static
Random
random
=
new
Random
();
public
static
String
generateTextUpTo
(
int
length
)
{
return
generateText
(
random
.
nextInt
(
length
));
}
public
static
String
generateText
(
int
length
)
{
int
start
=
random
.
nextInt
(
LOREM_IPSUM_LENGTH
);
if
(
start
+
length
<
LOREM_IPSUM_LENGTH
)
{
return
LOREM_IPSUM
.
substring
(
start
,
start
+
length
);
}
else
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
LOREM_IPSUM
.
substring
(
start
));
int
newlength
=
length
-
(
LOREM_IPSUM_LENGTH
-
start
);
for
(
int
i
=
0
;
i
<
newlength
/
LOREM_IPSUM_LENGTH
;
i
++)
{
sb
.
append
(
LOREM_IPSUM
);
}
sb
.
append
(
LOREM_IPSUM
.
substring
(
0
,
newlength
%
LOREM_IPSUM_LENGTH
));
return
sb
.
toString
();
}
}
private
static
int
degree
(
int
d
)
{
int
result
=
10
;
for
(
int
i
=
0
;
i
<
d
-
1
;
i
++)
{
result
*=
10
;
}
return
result
;
}
private
static
int
r
(
int
i
)
{
return
random
.
nextInt
(
i
);
}
public
static
Object
generateNumeric
(
int
length
,
Integer
precision
,
Integer
scale
)
{
// Integers
if
((
scale
==
null
||
scale
==
0
)
&&
(
precision
!=
null
&&
precision
!=
0
))
{
if
(
precision
<
BYTE_PRECISION
)
{
return
new
Byte
((
byte
)
random
.
nextInt
(
degree
(
r
(
precision
))));
}
if
(
precision
<
SHORT_PRECISION
)
{
return
new
Short
((
short
)
random
.
nextInt
(
degree
(
r
(
precision
))));
}
if
(
precision
<
INTEGER_PRECISION
)
{
return
new
Integer
(
random
.
nextInt
(
degree
(
r
(
precision
))));
}
if
(
precision
<
LONG_PRECISION
)
{
return
new
Long
(
random
.
nextLong
());
}
// Default integer number
return
null
;
// TODO new BigInteger();
}
// Non-integers
else
{
if
(
precision
!=
null
&&
precision
>
0
)
{
int
scl
=
scale
!=
null
?
scale
:
0
;
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
precision
;
i
++)
{
sb
.
append
(
random
.
nextInt
(
10
));
if
(
i
==
scale
)
{
sb
.
append
(
'.'
);
}
}
return
new
BigDecimal
(
sb
.
reverse
().
toString
());
}
else
{
return
new
BigDecimal
(
random
.
nextLong
());
// TODO
}
}
}
public
static
Date
generateDate
()
{
// Get an Epoch value roughly between 1940 and 2010
// -946771200000L = January 1, 1940
// Add up to 70 years to it (using modulus on the next long)
long
ms
=
-
946771200000L
+
(
Math
.
abs
(
random
.
nextLong
())
%
(
70L
*
365
*
24
*
60
*
60
*
1000
));
return
new
Date
(
ms
);
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
">> "
+
generateText
(
500
)
+
" <<"
);
}
}
plugins/org.jkiss.dbeaver.ext.mockdata/src/org/jkiss/dbeaver/ext/mockdata/generator/AbstractMockValueGenerator.java
浏览文件 @
63f85f38
...
...
@@ -24,7 +24,7 @@ public abstract class AbstractMockValueGenerator implements MockValueGenerator {
protected
DBSEntity
dbsEntity
;
protected
DBSAttributeBase
attribute
;
protected
static
Random
random
=
new
Random
();
protected
Random
random
=
new
Random
();
protected
int
nullsPersent
=
10
;
private
boolean
isFirstRun
=
true
;
private
boolean
isUnique
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录