Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
c5968d67
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,发现更多精彩内容 >>
提交
c5968d67
编写于
1月 27, 2020
作者:
M
Marat Kalibekov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7593- Use enum for find out strategy
Former-commit-id:
2a0923be
上级
1e2f7697
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
19 deletion
+44
-19
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/exporter/DataExporterCSV.java
...eaver/tools/transfer/stream/exporter/DataExporterCSV.java
+13
-19
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/exporter/QuoteStrategy.java
...dbeaver/tools/transfer/stream/exporter/QuoteStrategy.java
+31
-0
未找到文件。
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/exporter/DataExporterCSV.java
浏览文件 @
c5968d67
...
...
@@ -16,7 +16,6 @@
*/
package
org.jkiss.dbeaver.tools.transfer.stream.exporter
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.model.DBConstants
;
import
org.jkiss.dbeaver.model.DBPDataKind
;
...
...
@@ -69,7 +68,7 @@ public class DataExporterCSV extends StreamExporterAbstract {
private
String
delimiter
;
private
char
quoteChar
=
'"'
;
private
boolean
useQuotes
=
true
;
private
String
quoteAlways
=
"default"
;
private
QuoteStrategy
quoteStrategy
=
QuoteStrategy
.
DISABLED
;
private
String
rowDelimiter
;
private
String
nullString
;
private
HeaderPosition
headerPosition
;
...
...
@@ -99,7 +98,10 @@ public class DataExporterCSV extends StreamExporterAbstract {
Object
nullStringProp
=
properties
.
get
(
PROP_NULL_STRING
);
nullString
=
nullStringProp
==
null
?
null
:
nullStringProp
.
toString
();
useQuotes
=
quoteChar
!=
' '
;
quoteAlways
=
CommonUtils
.
toString
(
properties
.
get
(
PROP_QUOTE_ALWAYS
));
String
quoteStrategyStr
=
CommonUtils
.
toString
(
properties
.
get
(
PROP_QUOTE_ALWAYS
));
if
(
quoteStrategyStr
!=
null
)
{
quoteStrategy
=
QuoteStrategy
.
fromValue
(
quoteStrategyStr
);
}
try
{
headerPosition
=
HeaderPosition
.
valueOf
(
String
.
valueOf
(
properties
.
get
(
PROP_HEADER
)));
}
catch
(
Exception
e
)
{
...
...
@@ -181,28 +183,20 @@ public class DataExporterCSV extends StreamExporterAbstract {
}
else
{
String
stringValue
=
super
.
getValueDisplayString
(
column
,
row
[
i
]);
boolean
quote
=
false
;
boolean
isNumber
=
NumberUtils
.
isNumber
(
stringValue
);
boolean
isEmpty
=
stringValue
.
isEmpty
();
boolean
rowIsDate
=
row
[
i
]
instanceof
Date
;
boolean
rowIsNumber
=
row
[
i
]
instanceof
Number
;
boolean
startsWithDigit
=
Character
.
isDigit
(
stringValue
.
charAt
(
0
));
if
(
quote
Always
.
equalsIgnoreCase
(
"disabled"
)
||
quoteAlways
.
equalsIgnoreCase
(
"false"
)
)
{
if
(!
isEmpty
&&
!
rowIsNumber
&&
!
rowIsDate
&&
startsWithDigit
)
{
if
(
quote
Strategy
==
QuoteStrategy
.
DISABLED
)
{
if
(!
stringValue
.
isEmpty
()
&&
!(
row
[
i
]
instanceof
Number
)
&&
!(
row
[
i
]
instanceof
Date
)
&&
Character
.
isDigit
(
stringValue
.
charAt
(
0
))
)
{
// Quote string values which starts from number
quote
=
true
;
}
}
else
if
(
quoteAlways
.
equalsIgnoreCase
(
"all"
)
||
quoteAlways
.
equalsIgnoreCase
(
"true"
))
{
quote
=
true
;
}
else
if
(
quoteAlways
.
equalsIgnoreCase
(
"strings"
))
{
if
(!
rowIsNumber
&&
!
isNumber
)
{
}
else
if
(
quoteStrategy
==
QuoteStrategy
.
STRINGS
)
{
if
(!
stringValue
.
isEmpty
()
&&
!(
row
[
i
]
instanceof
Number
)
&&
!(
row
[
i
]
instanceof
Date
))
{
quote
=
true
;
}
}
else
if
(
quote
Always
.
equalsIgnoreCase
(
"all but numbers"
)
)
{
if
(
rowIsNumber
||
isNumber
)
{
quote
=
fals
e
;
}
else
if
(
quote
Strategy
==
QuoteStrategy
.
ALL_BUT_NUMBERS
)
{
if
(
!(
row
[
i
]
instanceof
Number
)
)
{
quote
=
tru
e
;
}
quote
=
true
;
}
writeCellValue
(
stringValue
,
quote
);
}
...
...
@@ -228,7 +222,7 @@ public class DataExporterCSV extends StreamExporterAbstract {
// check for needed quote
final
boolean
hasQuotes
=
useQuotes
&&
value
.
indexOf
(
quoteChar
)
!=
-
1
;
if
(
quote
Always
.
equalsIgnoreCase
(
"all"
)
||
(
useQuotes
&&
value
.
isEmpty
()))
{
if
(
quote
Strategy
==
QuoteStrategy
.
ALL
||
(
useQuotes
&&
value
.
isEmpty
()))
{
quote
=
true
;
}
else
if
(!
quote
)
{
if
(
hasQuotes
||
...
...
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/exporter/QuoteStrategy.java
0 → 100644
浏览文件 @
c5968d67
package
org.jkiss.dbeaver.tools.transfer.stream.exporter
;
public
enum
QuoteStrategy
{
DISABLED
(
"disabled"
),
ALL
(
"all"
),
STRINGS
(
"strings"
),
ALL_BUT_NUMBERS
(
"all but numbers"
);
private
final
String
value
;
QuoteStrategy
(
String
v
)
{
value
=
v
;
}
public
String
value
()
{
return
value
;
}
public
static
QuoteStrategy
fromValue
(
String
v
)
{
for
(
QuoteStrategy
s:
QuoteStrategy
.
values
())
{
if
(
s
.
value
.
equals
(
v
))
{
return
s
;
}
}
// backward compability
if
(
"true"
.
equalsIgnoreCase
(
v
))
{
return
ALL
;
}
else
if
(
"false"
.
equalsIgnoreCase
(
v
))
{
return
DISABLED
;
}
throw
new
IllegalArgumentException
(
v
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录