Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
e7f6f1b3
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,发现更多精彩内容 >>
未验证
提交
e7f6f1b3
编写于
5月 07, 2018
作者:
S
Serge Rider
提交者:
GitHub
5月 07, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3430 from henriklen/copy-as-dbunit-dataset
Support for export in DbUnit dataset format
上级
98a72f58
11c0239e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
225 addition
and
0 deletion
+225
-0
plugins/org.jkiss.dbeaver.core/OSGI-INF/l10n/bundle.properties
...ns/org.jkiss.dbeaver.core/OSGI-INF/l10n/bundle.properties
+8
-0
plugins/org.jkiss.dbeaver.core/plugin.xml
plugins/org.jkiss.dbeaver.core/plugin.xml
+14
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/IStreamDataExporterSite.java
...beaver/tools/transfer/stream/IStreamDataExporterSite.java
+2
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/StreamTransferConsumer.java
...dbeaver/tools/transfer/stream/StreamTransferConsumer.java
+5
-0
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/impl/DataExporterDbUnit.java
...beaver/tools/transfer/stream/impl/DataExporterDbUnit.java
+196
-0
未找到文件。
plugins/org.jkiss.dbeaver.core/OSGI-INF/l10n/bundle.properties
浏览文件 @
e7f6f1b3
...
@@ -445,6 +445,14 @@ dataTransfer.processor.xml.description=Export to XML file(s)
...
@@ -445,6 +445,14 @@ dataTransfer.processor.xml.description=Export to XML file(s)
dataTransfer.processor.xml.propertyGroup.general.label
=
General
dataTransfer.processor.xml.propertyGroup.general.label
=
General
dataTransfer.processor.xml.property.extension.label
=
File extension
dataTransfer.processor.xml.property.extension.label
=
File extension
dataTransfer.processor.xml.property.format.label
=
Dates/numbers format
dataTransfer.processor.xml.property.format.label
=
Dates/numbers format
dataTransfer.processor.dbunit.name
=
DbUnit
dataTransfer.processor.dbunit.description
=
Export to DbUnit XML file(s)
dataTransfer.processor.dbunit.propertyGroup.general.label
=
General
dataTransfer.processor.dbunit.property.extension.label
=
File extension
dataTransfer.processor.dbunit.property.uppercase.table.name.label
=
Force upper case table name
dataTransfer.processor.dbunit.property.uppercase.column.names.label
=
Force upper case column names
dataTransfer.processor.dbunit.property.include.null.values.label
=
Include NULL values in export
dataTransfer.processor.dbunit.property.null.value.string.label
=
Replace NULL values with
dataTransfer.processor.json.name
=
JSON
dataTransfer.processor.json.name
=
JSON
dataTransfer.processor.json.description
=
Export to JSON file(s)
dataTransfer.processor.json.description
=
Export to JSON file(s)
dataTransfer.processor.json.propertyGroup.general.label
=
General
dataTransfer.processor.json.propertyGroup.general.label
=
General
...
...
plugins/org.jkiss.dbeaver.core/plugin.xml
浏览文件 @
e7f6f1b3
...
@@ -3551,6 +3551,20 @@
...
@@ -3551,6 +3551,20 @@
<property
id=
"extension"
label=
"%dataTransfer.processor.xml.property.extension.label"
defaultValue=
"xml"
/>
<property
id=
"extension"
label=
"%dataTransfer.processor.xml.property.extension.label"
defaultValue=
"xml"
/>
</propertyGroup>
</propertyGroup>
</processor>
</processor>
<processor
id=
"stream.dbunit"
class=
"org.jkiss.dbeaver.tools.transfer.stream.impl.DataExporterDbUnit"
description=
"%dataTransfer.processor.dbunit.description"
icon=
"icons/misc/xml.png"
label=
"%dataTransfer.processor.dbunit.name"
>
<propertyGroup
label=
"%dataTransfer.processor.dbunit.propertyGroup.general.label"
>
<property
id=
"upperCaseTableName"
label=
"%dataTransfer.processor.dbunit.property.uppercase.table.name.label"
type=
"boolean"
defaultValue=
"true"
/>
<property
id=
"upperCaseColumnNames"
label=
"%dataTransfer.processor.dbunit.property.uppercase.column.names.label"
type=
"boolean"
defaultValue=
"true"
/>
<property
id=
"extension"
label=
"%dataTransfer.processor.dbunit.property.extension.label"
defaultValue=
"xml"
/>
<property
id=
"includeNullValues"
label=
"%dataTransfer.processor.dbunit.property.include.null.values.label"
type=
"boolean"
defaultValue=
"true"
/>
<property
id=
"nullValueString"
label=
"%dataTransfer.processor.dbunit.property.null.value.string.label"
defaultValue=
"[NULL]"
/>
</propertyGroup>
</processor>
<processor
<processor
id=
"stream.json"
id=
"stream.json"
class=
"org.jkiss.dbeaver.tools.transfer.stream.impl.DataExporterJSON"
class=
"org.jkiss.dbeaver.tools.transfer.stream.impl.DataExporterJSON"
...
...
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/IStreamDataExporterSite.java
浏览文件 @
e7f6f1b3
...
@@ -48,5 +48,7 @@ public interface IStreamDataExporterSite {
...
@@ -48,5 +48,7 @@ public interface IStreamDataExporterSite {
void
flush
()
throws
IOException
;
void
flush
()
throws
IOException
;
void
writeBinaryData
(
@NotNull
DBDContentStorage
cs
)
throws
IOException
;
void
writeBinaryData
(
@NotNull
DBDContentStorage
cs
)
throws
IOException
;
String
getOutputEncoding
();
}
}
\ No newline at end of file
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/StreamTransferConsumer.java
浏览文件 @
e7f6f1b3
...
@@ -549,5 +549,10 @@ public class StreamTransferConsumer implements IDataTransferConsumer<StreamConsu
...
@@ -549,5 +549,10 @@ public class StreamTransferConsumer implements IDataTransferConsumer<StreamConsu
}
}
}
}
}
}
@Override
public
String
getOutputEncoding
()
{
return
settings
==
null
?
null
:
settings
.
getOutputEncoding
();
}
}
}
}
}
plugins/org.jkiss.dbeaver.core/src/org/jkiss/dbeaver/tools/transfer/stream/impl/DataExporterDbUnit.java
0 → 100644
浏览文件 @
e7f6f1b3
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2012 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.tools.transfer.stream.impl
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.PrintWriter
;
import
java.io.Reader
;
import
java.util.List
;
import
org.jkiss.code.Nullable
;
import
org.jkiss.dbeaver.DBException
;
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.exec.DBCSession
;
import
org.jkiss.dbeaver.model.impl.jdbc.exec.JDBCColumnMetaData
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
import
org.jkiss.dbeaver.model.struct.DBSAttributeBase
;
import
org.jkiss.dbeaver.tools.transfer.stream.IStreamDataExporterSite
;
import
org.jkiss.dbeaver.utils.ContentUtils
;
import
org.jkiss.utils.Base64
;
import
org.jkiss.utils.CommonUtils
;
/**
* DbUnit Dataset Exporter
*
* DbUnit is a framwork for populating a database with test data before
* running an integration test. This export uses the format used by FlatXmlDataSet/ReplacementDataSet
* described at http://dbunit.sourceforge.net/components.html
*/
public
class
DataExporterDbUnit
extends
StreamExporterAbstract
{
private
static
final
String
PROP_UPPER_CASE_TABLE_NAME
=
"upperCaseTableName"
;
private
static
final
String
PROP_NULL_VALUE_STRING
=
"nullValueString"
;
private
static
final
String
PROP_UPPER_CASE_COLUMN_NAMES
=
"upperCaseColumnNames"
;
private
static
final
String
PROP_INCLUDE_NULL_VALUES
=
"includeNullValues"
;
private
PrintWriter
out
;
private
List
<
DBDAttributeBinding
>
columns
;
private
String
tableName
;
private
boolean
upperCaseTableName
;
private
boolean
upperCaseColumnNames
;
private
boolean
includeNullValues
;
@Override
public
void
init
(
IStreamDataExporterSite
site
)
throws
DBException
{
super
.
init
(
site
);
out
=
site
.
getWriter
();
upperCaseTableName
=
CommonUtils
.
getBoolean
(
site
.
getProperties
().
get
(
PROP_UPPER_CASE_TABLE_NAME
),
true
);
upperCaseColumnNames
=
CommonUtils
.
getBoolean
(
site
.
getProperties
().
get
(
PROP_UPPER_CASE_COLUMN_NAMES
),
true
);
includeNullValues
=
CommonUtils
.
getBoolean
(
site
.
getProperties
().
get
(
PROP_INCLUDE_NULL_VALUES
),
true
);
}
@Override
public
void
dispose
()
{
out
=
null
;
tableName
=
null
;
columns
=
null
;
super
.
dispose
();
}
private
String
getTableName
()
{
String
result
=
"UNKNOWN_TABLE_NAME"
;
if
(
getSite
()
==
null
||
getSite
().
getAttributes
()
==
null
||
getSite
().
getAttributes
().
isEmpty
())
{
return
result
;
}
DBSAttributeBase
metaAttribute
=
getSite
().
getAttributes
().
get
(
0
).
getMetaAttribute
();
if
(
metaAttribute
!=
null
&&
metaAttribute
instanceof
JDBCColumnMetaData
)
{
JDBCColumnMetaData
metaData
=
(
JDBCColumnMetaData
)
metaAttribute
;
result
=
metaData
.
getEntityName
();
}
if
(
upperCaseTableName
)
{
result
=
result
==
null
?
null
:
result
.
toUpperCase
();
}
return
result
;
}
@Override
public
void
exportHeader
(
DBCSession
session
)
throws
DBException
,
IOException
{
columns
=
getSite
().
getAttributes
();
tableName
=
getTableName
();
String
outputEncoding
=
getSite
().
getOutputEncoding
()
==
null
||
getSite
().
getOutputEncoding
().
length
()
==
0
?
"UTF-8"
:
getSite
().
getOutputEncoding
();
out
.
append
(
"<?xml version=\"1.0\" encoding=\""
).
append
(
outputEncoding
).
append
(
"\"?>"
).
append
(
CommonUtils
.
getLineSeparator
());
out
.
append
(
"<dataset>"
).
append
(
CommonUtils
.
getLineSeparator
());
}
@Override
public
void
exportRow
(
DBCSession
session
,
Object
[]
row
)
throws
DBException
,
IOException
{
out
.
write
(
" <"
+
tableName
);
for
(
int
i
=
0
;
i
<
row
.
length
;
i
++)
{
if
(
DBUtils
.
isNullValue
(
row
[
i
])
&&
!
includeNullValues
)
{
continue
;
}
DBDAttributeBinding
column
=
columns
.
get
(
i
);
String
columnName
=
escapeXmlElementName
(
column
.
getName
());
if
(
columnName
!=
null
&&
upperCaseColumnNames
)
{
columnName
=
columnName
.
toUpperCase
();
}
out
.
write
(
" "
+
columnName
+
"=\""
);
if
(
DBUtils
.
isNullValue
(
row
[
i
]))
{
writeTextCell
(
""
+
getSite
().
getProperties
().
get
(
PROP_NULL_VALUE_STRING
));
}
else
if
(
row
[
i
]
instanceof
DBDContent
)
{
// Content
// Inline textual content and handle binaries in some special way
DBDContent
content
=
(
DBDContent
)
row
[
i
];
try
{
DBDContentStorage
cs
=
content
.
getContents
(
session
.
getProgressMonitor
());
if
(
cs
!=
null
)
{
if
(
ContentUtils
.
isTextContent
(
content
))
{
try
(
Reader
reader
=
cs
.
getContentReader
())
{
writeCellValue
(
reader
);
}
}
else
{
// BLOB format http://dbunit.sourceforge.net/datatypes.html
out
.
write
(
"[BASE64]"
);
try
(
final
InputStream
stream
=
cs
.
getContentStream
())
{
Base64
.
encode
(
stream
,
cs
.
getContentLength
(),
getSite
().
getWriter
());
}
}
}
}
finally
{
content
.
release
();
}
}
else
{
writeTextCell
(
super
.
getValueDisplayString
(
column
,
row
[
i
]));
}
out
.
write
(
"\""
);
}
out
.
write
(
">"
+
CommonUtils
.
getLineSeparator
());
}
@Override
public
void
exportFooter
(
DBRProgressMonitor
monitor
)
throws
IOException
{
out
.
write
(
"</dataset>\n"
);
}
private
void
writeTextCell
(
@Nullable
String
value
)
{
if
(
value
!=
null
)
{
value
=
value
.
replace
(
"<"
,
"<"
).
replace
(
">"
,
">"
).
replace
(
"&"
,
"&"
);
out
.
write
(
value
);
}
}
private
void
writeCellValue
(
Reader
reader
)
throws
IOException
{
// Copy reader
char
buffer
[]
=
new
char
[
2000
];
for
(;;)
{
int
count
=
reader
.
read
(
buffer
);
if
(
count
<=
0
)
{
break
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
if
(
buffer
[
i
]
==
'<'
)
{
out
.
write
(
"<"
);
}
else
if
(
buffer
[
i
]
==
'>'
)
{
out
.
write
(
">"
);
}
else
if
(
buffer
[
i
]
==
'&'
)
{
out
.
write
(
"&"
);
}
else
{
out
.
write
(
buffer
[
i
]);
}
}
}
}
private
String
escapeXmlElementName
(
String
name
)
{
return
name
.
replaceAll
(
"[^\\p{Alpha}\\p{Digit}]+"
,
"_"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录