Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
0f7126fd
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,发现更多精彩内容 >>
提交
0f7126fd
编写于
8月 09, 2018
作者:
S
serge-rider
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#130 Column transfer mapping type edit
上级
a9445fcb
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
135 addition
and
14 deletion
+135
-14
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/StreamProducerPagePreview.java
...aver/tools/transfer/stream/StreamProducerPagePreview.java
+120
-10
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/StreamProducerSettings.java
...dbeaver/tools/transfer/stream/StreamProducerSettings.java
+12
-2
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/StreamTransferResultSet.java
...beaver/tools/transfer/stream/StreamTransferResultSet.java
+3
-2
未找到文件。
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/StreamProducerPagePreview.java
浏览文件 @
0f7126fd
...
...
@@ -48,6 +48,7 @@ import org.jkiss.dbeaver.tools.transfer.wizard.DataTransferPipe;
import
org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard
;
import
org.jkiss.dbeaver.ui.DBeaverIcons
;
import
org.jkiss.dbeaver.ui.UIUtils
;
import
org.jkiss.dbeaver.ui.controls.CustomTableEditor
;
import
org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage
;
import
org.jkiss.utils.CommonUtils
;
...
...
@@ -124,6 +125,56 @@ public class StreamProducerPagePreview extends ActiveWizardPage<DataTransferWiza
UIUtils
.
createTableColumn
(
mappingsTable
,
SWT
.
LEFT
,
DTMessages
.
data_transfer_wizard_final_column_target
);
UIUtils
.
createTableColumn
(
mappingsTable
,
SWT
.
LEFT
,
DTMessages
.
data_transfer_wizard_final_column_source
);
UIUtils
.
createTableColumn
(
mappingsTable
,
SWT
.
LEFT
,
DTMessages
.
data_transfer_wizard_settings_column_mapping_type
);
final
CustomTableEditor
tableEditor
=
new
CustomTableEditor
(
mappingsTable
)
{
@Override
protected
Control
createEditor
(
Table
table
,
final
int
index
,
final
TableItem
item
)
{
if
(
index
==
2
)
{
StreamProducerSettings
.
AttributeMapping
am
=
(
StreamProducerSettings
.
AttributeMapping
)
item
.
getData
();
final
Combo
mappingCombo
=
new
Combo
(
table
,
SWT
.
DROP_DOWN
|
SWT
.
READ_ONLY
);
for
(
StreamProducerSettings
.
AttributeMapping
.
MappingType
mapping
:
StreamProducerSettings
.
AttributeMapping
.
MappingType
.
values
())
{
mappingCombo
.
add
(
mapping
.
getTitle
());
}
mappingCombo
.
setText
(
am
.
getMappingType
().
getTitle
());
return
mappingCombo
;
}
return
null
;
}
@Override
protected
void
saveEditorValue
(
Control
control
,
int
index
,
TableItem
item
)
{
StreamProducerSettings
.
AttributeMapping
am
=
(
StreamProducerSettings
.
AttributeMapping
)
item
.
getData
();
if
(
index
==
2
)
{
final
Combo
mappingCombo
=
(
Combo
)
control
;
StreamProducerSettings
.
AttributeMapping
.
MappingType
newMapping
=
null
;
String
newTypeTitle
=
mappingCombo
.
getText
();
for
(
StreamProducerSettings
.
AttributeMapping
.
MappingType
mapping
:
StreamProducerSettings
.
AttributeMapping
.
MappingType
.
values
())
{
if
(
newTypeTitle
.
equals
(
mapping
.
getTitle
()))
{
newMapping
=
mapping
;
break
;
}
}
if
(
newMapping
!=
null
&&
newMapping
!=
am
.
getMappingType
())
{
item
.
setText
(
2
,
newMapping
.
getTitle
());
am
.
setMappingType
(
newMapping
);
updatePageCompletion
();
if
(
currentObject
instanceof
DBSEntity
)
{
final
DBSEntity
entity
=
(
DBSEntity
)
currentObject
;
final
StreamProducerSettings
settings
=
getWizard
().
getPageSettings
(
StreamProducerPagePreview
.
this
,
StreamProducerSettings
.
class
);
StreamProducerSettings
.
EntityMapping
entityMapping
=
settings
.
getEntityMapping
(
entity
);
UIUtils
.
asyncExec
(()
->
{
refreshPreviewTable
(
entityMapping
);
});
}
}
}
}
};
}
mapSash
.
setWeights
(
new
int
[]
{
300
,
700
}
);
...
...
@@ -241,7 +292,7 @@ public class StreamProducerPagePreview extends ActiveWizardPage<DataTransferWiza
monitor
.
done
();
}
catch
(
DBException
e
)
{
}
catch
(
Throwable
e
)
{
throw
new
InvocationTargetException
(
e
);
}
});
...
...
@@ -261,6 +312,58 @@ public class StreamProducerPagePreview extends ActiveWizardPage<DataTransferWiza
});
}
private
void
refreshPreviewTable
(
StreamProducerSettings
.
EntityMapping
entityMapping
)
{
previewTable
.
removeAll
();
for
(
TableColumn
column
:
previewTable
.
getColumns
())
{
column
.
dispose
();
}
for
(
StreamProducerSettings
.
AttributeMapping
am
:
entityMapping
.
getAttributeMappings
())
{
if
(!
am
.
isValuable
())
{
continue
;
}
// Create preview column
UIUtils
.
createTableColumn
(
previewTable
,
SWT
.
LEFT
,
am
.
getTargetAttributeName
());
}
DataTransferProcessorDescriptor
processor
=
getWizard
().
getSettings
().
getProcessor
();
final
DBSEntity
entity
=
(
DBSEntity
)
currentObject
;
StreamTransferProducer
currentProducer
=
(
StreamTransferProducer
)
getCurrentPipe
().
getProducer
();
Throwable
error
=
null
;
try
{
getWizard
().
getContainer
().
run
(
true
,
true
,
mon
->
{
try
{
IDataTransferProcessor
importer
=
processor
.
getInstance
();
DBRProgressMonitor
monitor
=
new
DefaultProgressMonitor
(
mon
);
monitor
.
beginTask
(
"Load preview"
,
1
);
// Load preview
monitor
.
subTask
(
"Load import preview"
);
if
(
importer
instanceof
IStreamDataImporter
)
{
loadImportPreview
(
monitor
,
(
IStreamDataImporter
)
importer
,
entity
,
currentProducer
);
}
monitor
.
worked
(
1
);
monitor
.
done
();
}
catch
(
Throwable
e
)
{
throw
new
InvocationTargetException
(
e
);
}
});
}
catch
(
InvocationTargetException
e
)
{
error
=
e
.
getTargetException
();
}
catch
(
InterruptedException
e
)
{
// Ignore
}
Throwable
finalError
=
error
;
UIUtils
.
asyncExec
(()
->
{
UIUtils
.
packColumns
(
previewTable
,
false
);
if
(
finalError
!=
null
)
{
DBUserInterface
.
getInstance
().
showError
(
"OReview data"
,
"Can't load preview data"
,
finalError
);
}
});
}
private
void
updateAttributeMappings
(
StreamProducerSettings
.
EntityMapping
entityMapping
)
{
for
(
StreamProducerSettings
.
AttributeMapping
am
:
entityMapping
.
getAttributeMappings
())
{
// Create mapping item
...
...
@@ -277,10 +380,12 @@ public class StreamProducerPagePreview extends ActiveWizardPage<DataTransferWiza
mappingItem
.
setText
(
1
,
sourceName
);
mappingItem
.
setText
(
2
,
am
.
getMappingType
().
getTitle
());
if
(
am
.
isValuable
())
{
// Create preview column
UIUtils
.
createTableColumn
(
previewTable
,
SWT
.
LEFT
,
am
.
getTargetAttributeName
());
}
}
}
public
DataTransferPipe
getCurrentPipe
()
{
return
pipeList
.
get
(
tableList
.
getSelectionIndex
());
...
...
@@ -340,7 +445,6 @@ public class StreamProducerPagePreview extends ActiveWizardPage<DataTransferWiza
private
void
loadImportPreview
(
DBRProgressMonitor
monitor
,
IStreamDataImporter
importer
,
DBSEntity
entity
,
StreamTransferProducer
currentProducer
)
throws
DBException
{
final
StreamProducerSettings
settings
=
getWizard
().
getPageSettings
(
this
,
StreamProducerSettings
.
class
);
final
Map
<
Object
,
Object
>
processorProperties
=
getWizard
().
getSettings
().
getProcessorProperties
();
PreviewConsumer
previewConsumer
=
new
PreviewConsumer
(
settings
,
entity
);
...
...
@@ -360,11 +464,16 @@ public class StreamProducerPagePreview extends ActiveWizardPage<DataTransferWiza
List
<
StreamProducerSettings
.
AttributeMapping
>
attributeMappings
=
previewConsumer
.
getEntityMapping
().
getAttributeMappings
();
for
(
Object
[]
row
:
rows
)
{
String
[]
strRow
=
new
String
[
row
.
length
];
int
columnIndex
=
0
;
for
(
int
i
=
0
;
i
<
attributeMappings
.
size
();
i
++)
{
StreamProducerSettings
.
AttributeMapping
attr
=
attributeMappings
.
get
(
i
);
Object
value
=
attr
.
getTargetValueHandler
().
getValueFromObject
(
session
,
attr
.
getTargetAttribute
(),
row
[
i
],
false
);
if
(!
attr
.
isValuable
())
{
continue
;
}
Object
value
=
attr
.
getTargetValueHandler
().
getValueFromObject
(
session
,
attr
.
getTargetAttribute
(),
row
[
columnIndex
],
false
);
String
valueStr
=
attr
.
getTargetValueHandler
().
getValueDisplayString
(
attr
.
getTargetAttribute
(),
value
,
DBDDisplayFormat
.
UI
);
strRow
[
i
]
=
valueStr
;
strRow
[
columnIndex
]
=
valueStr
;
columnIndex
++;
}
strRows
.
add
(
strRow
);
}
...
...
@@ -417,11 +526,13 @@ public class StreamProducerPagePreview extends ActiveWizardPage<DataTransferWiza
private
DBSEntity
sampleObject
;
private
final
StreamProducerSettings
.
EntityMapping
entityMapping
;
private
DBCResultSetMetaData
meta
;
private
final
List
<
StreamProducerSettings
.
AttributeMapping
>
attributes
;
public
PreviewConsumer
(
StreamProducerSettings
settings
,
DBSEntity
sampleObject
)
{
this
.
settings
=
settings
;
this
.
sampleObject
=
sampleObject
;
this
.
entityMapping
=
this
.
settings
.
getEntityMapping
(
sampleObject
);
this
.
attributes
=
entityMapping
.
getValuableAttributeMappings
();
}
public
StreamProducerSettings
.
EntityMapping
getEntityMapping
()
{
...
...
@@ -450,16 +561,15 @@ public class StreamProducerPagePreview extends ActiveWizardPage<DataTransferWiza
@Override
public
void
fetchStart
(
DBCSession
session
,
DBCResultSet
resultSet
,
long
offset
,
long
maxRows
)
throws
DBCException
{
meta
=
resultSet
.
getMeta
();
if
(
meta
.
getAttributes
().
size
()
!=
entityMapping
.
getAttributeMappings
().
size
())
{
if
(
meta
.
getAttributes
().
size
()
!=
entityMapping
.
get
Valuable
AttributeMappings
().
size
())
{
throw
new
DBCException
(
"Corrupted stream source metadata. Attribute number ("
+
meta
.
getAttributes
().
size
()
+
") doesn't match target entity attribute number ("
+
entityMapping
.
getAttributeMappings
().
size
()
+
")"
);
}
}
@Override
public
void
fetchRow
(
DBCSession
session
,
DBCResultSet
resultSet
)
throws
DBCException
{
List
<
StreamProducerSettings
.
AttributeMapping
>
attrs
=
entityMapping
.
getAttributeMappings
();
Object
[]
row
=
new
Object
[
attrs
.
size
()];
for
(
int
i
=
0
;
i
<
attrs
.
size
();
i
++)
{
Object
[]
row
=
new
Object
[
attributes
.
size
()];
for
(
int
i
=
0
;
i
<
attributes
.
size
();
i
++)
{
row
[
i
]
=
resultSet
.
getAttributeValue
(
i
);
}
rows
.
add
(
row
);
...
...
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/StreamProducerSettings.java
浏览文件 @
0f7126fd
...
...
@@ -59,8 +59,14 @@ public class StreamProducerSettings implements IDataTransferSettings {
return
attributeMappings
;
}
public
void
setAttributeMappings
(
List
<
AttributeMapping
>
attributeMappings
)
{
this
.
attributeMappings
=
attributeMappings
;
public
List
<
AttributeMapping
>
getValuableAttributeMappings
()
{
List
<
AttributeMapping
>
result
=
new
ArrayList
<>();
for
(
AttributeMapping
am
:
attributeMappings
)
{
if
(
am
.
isValuable
())
{
result
.
add
(
am
);
}
}
return
result
;
}
public
AttributeMapping
getAttributeMapping
(
DBSEntityAttribute
attr
)
{
...
...
@@ -193,6 +199,10 @@ public class StreamProducerSettings implements IDataTransferSettings {
this
.
sourceColumn
=
sourceColumn
;
}
public
boolean
isValuable
()
{
return
mappingType
==
MappingType
.
IMPORT
||
mappingType
==
MappingType
.
DEFAULT_VALUE
;
}
}
private
Map
<
String
,
EntityMapping
>
entityMapping
=
new
HashMap
<>();
...
...
plugins/org.jkiss.dbeaver.data.transfer/src/org/jkiss/dbeaver/tools/transfer/stream/StreamTransferResultSet.java
浏览文件 @
0f7126fd
...
...
@@ -36,12 +36,13 @@ public class StreamTransferResultSet implements DBCResultSet {
private
StreamProducerSettings
.
EntityMapping
entityMapping
;
private
List
<
DBCAttributeMetaData
>
metaAttrs
;
private
Object
[]
streamRow
;
private
final
List
<
StreamProducerSettings
.
AttributeMapping
>
attributeMappings
;
public
StreamTransferResultSet
(
StreamTransferSession
session
,
DBCStatement
statement
,
StreamProducerSettings
.
EntityMapping
entityMapping
)
{
this
.
session
=
session
;
this
.
statement
=
statement
;
this
.
entityMapping
=
entityMapping
;
List
<
StreamProducerSettings
.
AttributeMapping
>
attributeMappings
=
this
.
entityMapping
.
get
AttributeMappings
();
this
.
attributeMappings
=
this
.
entityMapping
.
getValuable
AttributeMappings
();
this
.
metaAttrs
=
new
ArrayList
<>(
attributeMappings
.
size
());
for
(
int
i
=
0
;
i
<
attributeMappings
.
size
();
i
++)
{
StreamProducerSettings
.
AttributeMapping
attr
=
attributeMappings
.
get
(
i
);
...
...
@@ -65,7 +66,7 @@ public class StreamTransferResultSet implements DBCResultSet {
@Override
public
Object
getAttributeValue
(
int
index
)
throws
DBCException
{
StreamProducerSettings
.
AttributeMapping
attr
=
entityMapping
.
getAttributeMappings
()
.
get
(
index
);
StreamProducerSettings
.
AttributeMapping
attr
=
this
.
attributeMappings
.
get
(
index
);
StreamDataImporterColumnInfo
sourceColumn
=
attr
.
getSourceColumn
();
if
(
sourceColumn
!=
null
)
{
return
streamRow
[
sourceColumn
.
getColumnIndex
()];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录