use of org.jkiss.dbeaver.tools.transfer.stream.StreamTransferProducer in project dbeaver by serge-rider.
the class StreamProducerPageSettings method reloadPipes.
private void reloadPipes() {
boolean firstTime = filesTable.getItemCount() == 0;
DataTransferSettings settings = getWizard().getSettings();
filesTable.removeAll();
List<DataTransferPipe> dataPipes = settings.getDataPipes();
for (DataTransferPipe pipe : dataPipes) {
TableItem item = new TableItem(filesTable, SWT.NONE);
item.setData(pipe);
updateItemData(item, pipe);
}
if (firstTime && !dataPipes.isEmpty()) {
DataTransferPipe pipe = dataPipes.get(0);
if (pipe.getProducer() instanceof StreamTransferProducer && ((StreamTransferProducer) pipe.getProducer()).getInputFile() == null) {
chooseSourceFile(pipe);
}
}
}
use of org.jkiss.dbeaver.tools.transfer.stream.StreamTransferProducer in project dbeaver by serge-rider.
the class StreamProducerPageSettings method updateMultiConsumers.
private void updateMultiConsumers(DBRProgressMonitor monitor, DataTransferPipe pipe, File[] files) {
final StreamProducerSettings producerSettings = getWizard().getPageSettings(this, StreamProducerSettings.class);
IDataTransferConsumer<?, ?> originalConsumer = pipe.getConsumer();
DataTransferSettings dtSettings = getWizard().getSettings();
List<DataTransferPipe> newPipes = new ArrayList<>(dtSettings.getDataPipes());
newPipes.remove(pipe);
for (File file : files) {
StreamTransferProducer producer = new StreamTransferProducer(new StreamEntityMapping(file));
IDataTransferConsumer<?, ?> consumer = new DatabaseTransferConsumer();
DataTransferPipe singlePipe = new DataTransferPipe(producer, consumer);
try {
singlePipe.initPipe(dtSettings, newPipes.size(), newPipes.size());
} catch (DBException e) {
log.error(e);
continue;
}
newPipes.add(singlePipe);
producerSettings.updateProducerSettingsFromStream(monitor, producer, dtSettings);
IDataTransferSettings consumerSettings = dtSettings.getNodeSettings(dtSettings.getConsumer());
if (consumerSettings instanceof DatabaseConsumerSettings) {
DatabaseConsumerSettings dcs = (DatabaseConsumerSettings) consumerSettings;
if (originalConsumer != null && originalConsumer.getTargetObjectContainer() instanceof DBSObject) {
DBNDatabaseNode containerNode = DBNUtils.getNodeByObject(monitor, (DBSObject) originalConsumer.getTargetObjectContainer(), false);
if (containerNode != null) {
dcs.setContainerNode(containerNode);
}
}
DatabaseMappingContainer mapping = new DatabaseMappingContainer(dcs, producer.getDatabaseObject());
// mapping.setTarget(null);
mapping.setTargetName(generateTableName(producer.getInputFile()));
dcs.addDataMappings(getWizard().getRunnableContext(), producer.getDatabaseObject(), mapping);
}
}
dtSettings.setDataPipes(newPipes, false);
dtSettings.setPipeChangeRestricted(true);
}
use of org.jkiss.dbeaver.tools.transfer.stream.StreamTransferProducer in project dbeaver by serge-rider.
the class StreamProducerPageSettings method deactivatePage.
@Override
public void deactivatePage() {
// Save settings.
// It is a producer so it must prepare data for consumers
// Save processor properties
propsEditor.saveEditorValues();
Map<String, Object> processorProperties = propertySource.getPropertiesWithDefaults();
DataTransferSettings dtSettings = getWizard().getSettings();
dtSettings.setProcessorProperties(processorProperties);
final StreamProducerSettings producerSettings = getWizard().getPageSettings(this, StreamProducerSettings.class);
if (producerSettings != null) {
producerSettings.setProcessorProperties(processorProperties);
}
// Update column mappings for database consumers
IDataTransferSettings consumerSettings = getWizard().getSettings().getNodeSettings(getWizard().getSettings().getConsumer());
try {
getWizard().getRunnableContext().run(true, true, monitor -> {
for (DataTransferPipe pipe : dtSettings.getDataPipes()) {
if (pipe.getProducer() instanceof StreamTransferProducer) {
StreamTransferProducer producer = (StreamTransferProducer) pipe.getProducer();
producerSettings.updateProducerSettingsFromStream(monitor, producer, dtSettings);
if (consumerSettings instanceof DatabaseConsumerSettings) {
DatabaseMappingContainer mapping = ((DatabaseConsumerSettings) consumerSettings).getDataMapping(producer.getDatabaseObject());
if (mapping != null) {
mapping.getAttributeMappings(monitor);
}
}
}
}
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Error updating stream settings", "Error updating settings", e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
super.deactivatePage();
}
Aggregations