Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
727ef022
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,发现更多精彩内容 >>
提交
727ef022
编写于
3月 08, 2018
作者:
S
serge-rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JSON date/time type support fix
上级
efd6b9b8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
106 addition
and
46 deletion
+106
-46
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/impl/DataExporterJSON.java
.../dbeaver/tools/transfer/stream/impl/DataExporterJSON.java
+6
-46
plugins/org.jkiss.dbeaver.model/META-INF/MANIFEST.MF
plugins/org.jkiss.dbeaver.model/META-INF/MANIFEST.MF
+1
-0
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/data/json/JSONUtils.java
...odel/src/org/jkiss/dbeaver/model/data/json/JSONUtils.java
+99
-0
未找到文件。
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/impl/DataExporterJSON.java
浏览文件 @
727ef022
...
...
@@ -24,6 +24,7 @@ import org.jkiss.dbeaver.model.DBUtils;
import
org.jkiss.dbeaver.model.data.DBDAttributeBinding
;
import
org.jkiss.dbeaver.model.data.DBDContent
;
import
org.jkiss.dbeaver.model.data.DBDContentStorage
;
import
org.jkiss.dbeaver.model.data.json.JSONUtils
;
import
org.jkiss.dbeaver.model.exec.DBCSession
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.tools.transfer.stream.IStreamDataExporterSite
;
...
...
@@ -51,7 +52,6 @@ public class DataExporterJSON extends StreamExporterAbstract {
private
List
<
DBDAttributeBinding
>
columns
;
private
String
tableName
;
private
int
rowNum
=
0
;
private
DateFormat
dateFormat
;
private
boolean
printTableName
=
true
;
private
boolean
formatDateISO
=
true
;
...
...
@@ -63,10 +63,6 @@ public class DataExporterJSON extends StreamExporterAbstract {
out
=
site
.
getWriter
();
formatDateISO
=
CommonUtils
.
getBoolean
(
site
.
getProperties
().
get
(
PROP_FORMAT_DATE_ISO
),
true
);
printTableName
=
CommonUtils
.
getBoolean
(
site
.
getProperties
().
get
(
PROP_PRINT_TABLE_NAME
),
true
);
TimeZone
tz
=
TimeZone
.
getTimeZone
(
"UTC"
);
dateFormat
=
new
SimpleDateFormat
(
DBConstants
.
DEFAULT_ISO_TIMESTAMP_FORMAT
);
dateFormat
.
setTimeZone
(
tz
);
}
@Override
...
...
@@ -88,7 +84,7 @@ public class DataExporterJSON extends StreamExporterAbstract {
{
if
(
printTableName
)
{
out
.
write
(
"{\n"
);
out
.
write
(
"\""
+
escapeJsonString
(
tableName
)
+
"\": "
);
out
.
write
(
"\""
+
JSONUtils
.
escapeJsonString
(
tableName
)
+
"\": "
);
}
out
.
write
(
"[\n"
);
}
...
...
@@ -107,7 +103,7 @@ public class DataExporterJSON extends StreamExporterAbstract {
if
(
CommonUtils
.
isEmpty
(
columnName
))
{
columnName
=
column
.
getName
();
}
out
.
write
(
"\t\t\""
+
escapeJsonString
(
columnName
)
+
"\" : "
);
out
.
write
(
"\t\t\""
+
JSONUtils
.
escapeJsonString
(
columnName
)
+
"\" : "
);
Object
cellValue
=
row
[
i
];
if
(
DBUtils
.
isNullValue
(
cellValue
))
{
writeTextCell
(
null
);
...
...
@@ -136,7 +132,7 @@ public class DataExporterJSON extends StreamExporterAbstract {
if
(
cellValue
instanceof
Number
||
cellValue
instanceof
Boolean
)
{
out
.
write
(
cellValue
.
toString
());
}
else
if
(
cellValue
instanceof
Date
&&
formatDateISO
)
{
writeTextCell
(
dateFormat
.
format
(
cellValue
));
writeTextCell
(
JSONUtils
.
formatDate
((
Date
)
cellValue
));
}
else
{
writeTextCell
(
super
.
getValueDisplayString
(
column
,
cellValue
));
}
...
...
@@ -162,7 +158,7 @@ public class DataExporterJSON extends StreamExporterAbstract {
private
void
writeTextCell
(
@Nullable
String
value
)
{
if
(
value
!=
null
)
{
out
.
write
(
"\""
+
escapeJsonString
(
value
)
+
"\""
);
out
.
write
(
"\""
+
JSONUtils
.
escapeJsonString
(
value
)
+
"\""
);
}
else
{
out
.
write
(
"null"
);
}
...
...
@@ -177,44 +173,8 @@ public class DataExporterJSON extends StreamExporterAbstract {
if
(
count
<=
0
)
{
break
;
}
out
.
write
(
escapeJsonString
(
new
String
(
buffer
,
0
,
count
)));
}
}
private
static
String
escapeJsonString
(
String
str
)
{
if
(
str
==
null
)
{
return
null
;
}
StringBuilder
result
=
new
StringBuilder
(
str
.
length
());
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++)
{
char
c
=
str
.
charAt
(
i
);
switch
(
c
)
{
case
'\n'
:
result
.
append
(
"\\n"
);
break
;
case
'\r'
:
result
.
append
(
"\\r"
);
break
;
case
'\t'
:
result
.
append
(
"\\t"
);
break
;
case
'\f'
:
result
.
append
(
"\\f"
);
break
;
case
'\b'
:
result
.
append
(
"\\b"
);
break
;
case
'"'
:
case
'\\'
:
case
'/'
:
result
.
append
(
"\\"
).
append
(
c
);
break
;
default
:
result
.
append
(
c
);
break
;
}
out
.
write
(
JSONUtils
.
escapeJsonString
(
new
String
(
buffer
,
0
,
count
)));
}
return
result
.
toString
();
}
}
plugins/org.jkiss.dbeaver.model/META-INF/MANIFEST.MF
浏览文件 @
727ef022
...
...
@@ -18,6 +18,7 @@ Export-Package: org.jkiss.dbeaver,
org.jkiss.dbeaver.model.data,
org.jkiss.dbeaver.model.data.aggregate,
org.jkiss.dbeaver.model.data.document,
org.jkiss.dbeaver.model.data.json,
org.jkiss.dbeaver.model.edit,
org.jkiss.dbeaver.model.edit.prop,
org.jkiss.dbeaver.model.exec,
...
...
plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/data/json/JSONUtils.java
0 → 100644
浏览文件 @
727ef022
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* 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.model.data.json
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.DBConstants
;
import
org.jkiss.dbeaver.model.DBUtils
;
import
org.jkiss.utils.CommonUtils
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.TimeZone
;
/**
* JSON utils
*/
public
class
JSONUtils
{
private
static
final
Log
log
=
Log
.
getLog
(
JSONUtils
.
class
);
private
static
SimpleDateFormat
dateFormat
;
static
{
TimeZone
tz
=
TimeZone
.
getTimeZone
(
"UTC"
);
dateFormat
=
new
SimpleDateFormat
(
DBConstants
.
DEFAULT_ISO_TIMESTAMP_FORMAT
);
dateFormat
.
setTimeZone
(
tz
);
}
public
static
String
formatDate
(
Date
date
)
{
return
dateFormat
.
format
(
date
);
}
public
static
Date
parseDate
(
String
str
)
{
if
(
CommonUtils
.
isEmpty
(
str
))
{
return
null
;
}
try
{
return
dateFormat
.
parse
(
str
);
}
catch
(
ParseException
e
)
{
log
.
error
(
"Error parsing date"
);
return
new
Date
(
0
l
);
}
}
public
static
String
formatISODate
(
Date
date
)
{
return
"ISODate(\""
+
formatDate
(
date
)
+
"\")"
;
//$NON-NLS-1$//$NON-NLS-2$
}
public
static
String
escapeJsonString
(
String
str
)
{
if
(
str
==
null
)
{
return
null
;
}
StringBuilder
result
=
new
StringBuilder
(
str
.
length
());
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++)
{
char
c
=
str
.
charAt
(
i
);
switch
(
c
)
{
case
'\n'
:
result
.
append
(
"\\n"
);
break
;
case
'\r'
:
result
.
append
(
"\\r"
);
break
;
case
'\t'
:
result
.
append
(
"\\t"
);
break
;
case
'\f'
:
result
.
append
(
"\\f"
);
break
;
case
'\b'
:
result
.
append
(
"\\b"
);
break
;
case
'"'
:
case
'\\'
:
case
'/'
:
result
.
append
(
"\\"
).
append
(
c
);
break
;
default
:
result
.
append
(
c
);
break
;
}
}
return
result
.
toString
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录