use of org.jkiss.dbeaver.tools.transfer.stream.StreamEntityMapping in project dbeaver by serge-rider.
the class StreamProducerPageSettings method updateSingleConsumer.
private void updateSingleConsumer(DBRProgressMonitor monitor, DataTransferPipe pipe, File file) {
final StreamProducerSettings producerSettings = getWizard().getPageSettings(this, StreamProducerSettings.class);
final StreamTransferProducer oldProducer = pipe.getProducer() instanceof StreamTransferProducer ? (StreamTransferProducer) pipe.getProducer() : null;
final StreamTransferProducer newProducer = new StreamTransferProducer(new StreamEntityMapping(file));
pipe.setProducer(newProducer);
producerSettings.updateProducerSettingsFromStream(monitor, newProducer, getWizard().getSettings());
IDataTransferSettings consumerSettings = getWizard().getSettings().getNodeSettings(getWizard().getSettings().getConsumer());
if (consumerSettings instanceof DatabaseConsumerSettings) {
DatabaseConsumerSettings settings = (DatabaseConsumerSettings) consumerSettings;
DatabaseMappingContainer mapping = new DatabaseMappingContainer(settings, newProducer.getDatabaseObject());
if (pipe.getConsumer() != null && pipe.getConsumer().getDatabaseObject() instanceof DBSDataManipulator) {
DBSDataManipulator databaseObject = (DBSDataManipulator) pipe.getConsumer().getDatabaseObject();
DBNDatabaseNode databaseNode = DBNUtils.getNodeByObject(monitor, databaseObject.getParentObject(), false);
if (databaseNode != null) {
settings.setContainerNode(databaseNode);
}
mapping.setTarget(databaseObject);
} else {
mapping.setTarget(null);
mapping.setTargetName(generateTableName(newProducer.getInputFile()));
}
if (oldProducer != null) {
// Remove old mapping because we're just replaced file
DatabaseMappingContainer oldMappingContainer = settings.getDataMappings().remove(oldProducer.getDatabaseObject());
if (oldMappingContainer != null && oldMappingContainer.getSource() instanceof StreamEntityMapping) {
StreamEntityMapping oldEntityMapping = (StreamEntityMapping) oldMappingContainer.getSource();
// Copy mappings from old producer if columns are the same
if (oldEntityMapping.isSameColumns(newProducer.getEntityMapping())) {
StreamEntityMapping entityMapping = new StreamEntityMapping(file);
settings.addDataMappings(getWizard().getRunnableContext(), entityMapping, new DatabaseMappingContainer(oldMappingContainer, entityMapping));
StreamTransferProducer producer = new StreamTransferProducer(entityMapping);
pipe.setProducer(producer);
producerSettings.updateProducerSettingsFromStream(monitor, producer, getWizard().getSettings());
return;
}
}
}
settings.addDataMappings(getWizard().getRunnableContext(), newProducer.getDatabaseObject(), mapping);
}
}
use of org.jkiss.dbeaver.tools.transfer.stream.StreamEntityMapping 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.StreamEntityMapping in project dbeaver by dbeaver.
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.StreamEntityMapping in project dbeaver by dbeaver.
the class StreamProducerPageSettings method updateSingleConsumer.
private void updateSingleConsumer(DBRProgressMonitor monitor, DataTransferPipe pipe, File file) {
final StreamProducerSettings producerSettings = getWizard().getPageSettings(this, StreamProducerSettings.class);
final StreamTransferProducer oldProducer = pipe.getProducer() instanceof StreamTransferProducer ? (StreamTransferProducer) pipe.getProducer() : null;
final StreamTransferProducer newProducer = new StreamTransferProducer(new StreamEntityMapping(file));
pipe.setProducer(newProducer);
producerSettings.updateProducerSettingsFromStream(monitor, newProducer, getWizard().getSettings());
IDataTransferSettings consumerSettings = getWizard().getSettings().getNodeSettings(getWizard().getSettings().getConsumer());
if (consumerSettings instanceof DatabaseConsumerSettings) {
DatabaseConsumerSettings settings = (DatabaseConsumerSettings) consumerSettings;
DatabaseMappingContainer mapping = new DatabaseMappingContainer(settings, newProducer.getDatabaseObject());
if (pipe.getConsumer() != null && pipe.getConsumer().getDatabaseObject() instanceof DBSDataManipulator) {
DBSDataManipulator databaseObject = (DBSDataManipulator) pipe.getConsumer().getDatabaseObject();
DBNDatabaseNode databaseNode = DBNUtils.getNodeByObject(monitor, databaseObject.getParentObject(), false);
if (databaseNode != null) {
settings.setContainerNode(databaseNode);
}
mapping.setTarget(databaseObject);
} else {
mapping.setTarget(null);
mapping.setTargetName(generateTableName(newProducer.getInputFile()));
}
if (oldProducer != null) {
// Remove old mapping because we're just replaced file
DatabaseMappingContainer oldMappingContainer = settings.getDataMappings().remove(oldProducer.getDatabaseObject());
if (oldMappingContainer != null && oldMappingContainer.getSource() instanceof StreamEntityMapping) {
StreamEntityMapping oldEntityMapping = (StreamEntityMapping) oldMappingContainer.getSource();
// Copy mappings from old producer if columns are the same
if (oldEntityMapping.isSameColumns(newProducer.getEntityMapping())) {
StreamEntityMapping entityMapping = new StreamEntityMapping(file);
settings.addDataMappings(getWizard().getRunnableContext(), entityMapping, new DatabaseMappingContainer(oldMappingContainer, entityMapping));
StreamTransferProducer producer = new StreamTransferProducer(entityMapping);
pipe.setProducer(producer);
producerSettings.updateProducerSettingsFromStream(monitor, producer, getWizard().getSettings());
return;
}
}
}
settings.addDataMappings(getWizard().getRunnableContext(), newProducer.getDatabaseObject(), mapping);
}
}
Aggregations