Search in sources :

Example 6 with DataTransferPipe

use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by serge-rider.

the class DTTaskHandlerTransfer method executeWithSettings.

public void executeWithSettings(@NotNull DBRRunnableContext runnableContext, DBTTask task, @NotNull Locale locale, @NotNull Log log, @NotNull DBTTaskExecutionListener listener, DataTransferSettings settings) throws DBException {
    // Start consumers
    listener.taskStarted(settings);
    List<DataTransferPipe> dataPipes = settings.getDataPipes();
    try {
        runnableContext.run(true, false, monitor -> {
            monitor.beginTask("Initialize pipes", dataPipes.size());
            try {
                for (int i = 0; i < dataPipes.size(); i++) {
                    DataTransferPipe pipe = dataPipes.get(i);
                    pipe.initPipe(settings, i, dataPipes.size());
                    pipe.getConsumer().startTransfer(monitor);
                    monitor.worked(1);
                }
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        throw new DBException("Error starting data transfer", e.getTargetException());
    } catch (InterruptedException e) {
        return;
    }
    // Schedule jobs for data providers
    int totalJobs = settings.getDataPipes().size();
    if (totalJobs > settings.getMaxJobCount()) {
        totalJobs = settings.getMaxJobCount();
    }
    Throwable error = null;
    for (int i = 0; i < totalJobs; i++) {
        DataTransferJob job = new DataTransferJob(settings, task, locale, log, listener);
        try {
            runnableContext.run(true, true, job);
        } catch (InvocationTargetException e) {
            error = e.getTargetException();
        } catch (InterruptedException e) {
            break;
        }
        listener.subTaskFinished(error);
    }
    listener.taskFinished(settings, error);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DataTransferJob(org.jkiss.dbeaver.tools.transfer.DataTransferJob) DataTransferPipe(org.jkiss.dbeaver.tools.transfer.DataTransferPipe) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with DataTransferPipe

use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by dbeaver.

the class DatabaseConsumerPageMapping method activatePage.

@Override
public void activatePage() {
    final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
    // Detect producer container (e.g. schema)
    DBSObjectContainer producerContainer = null;
    for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
        if (pipe.getProducer() != null) {
            DBSObject producerObject = pipe.getProducer().getDatabaseObject();
            if (producerObject instanceof DBSDataContainer) {
                DBSObject container = producerObject.getParentObject();
                if (container instanceof DBSObjectContainer) {
                    producerContainer = (DBSObjectContainer) container;
                }
            }
        }
    }
    settings.loadNode(getWizard().getRunnableContext(), getWizard().getSettings(), producerContainer);
    DBNDatabaseNode containerNode = settings.getContainerNode();
    if (containerNode != null) {
        try {
            containerPanel.checkValidContainerNode(containerNode);
            containerPanel.setContainerInfo(containerNode);
        } catch (DBException e) {
            setErrorMessage(e.getMessage());
        }
    }
    boolean newMappings = false;
    {
        // Load columns model. Update it only if mapping have different set of source columns
        // Otherwise we keep current mappings (to allow wizard page navigation without loosing mappings)
        List<DatabaseMappingContainer> model = new ArrayList<>();
        for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
            if (pipe.getProducer() == null || !(pipe.getProducer().getDatabaseObject() instanceof DBSDataContainer)) {
                continue;
            }
            DBSDataContainer sourceDataContainer = (DBSDataContainer) pipe.getProducer().getDatabaseObject();
            DatabaseMappingContainer mapping = settings.getDataMapping(sourceDataContainer);
            {
                // Create new mapping for source object
                DatabaseMappingContainer newMapping;
                if (pipe.getConsumer() instanceof DatabaseTransferConsumer && ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject() != null) {
                    try {
                        newMapping = new DatabaseMappingContainer(getWizard().getRunnableContext(), getDatabaseConsumerSettings(), sourceDataContainer, ((DatabaseTransferConsumer) pipe.getConsumer()).getTargetObject());
                    } catch (DBException e) {
                        setMessage(e.getMessage(), IMessageProvider.ERROR);
                        newMapping = new DatabaseMappingContainer(getDatabaseConsumerSettings(), sourceDataContainer);
                    }
                } else {
                    newMapping = new DatabaseMappingContainer(getDatabaseConsumerSettings(), sourceDataContainer);
                }
                newMapping.getAttributeMappings(getWizard().getRunnableContext());
                // Update current mapping if it differs from new one
                if (mapping == null || !mapping.isSameMapping(newMapping)) {
                    mapping = newMapping;
                    settings.addDataMappings(getWizard().getRunnableContext(), sourceDataContainer, mapping);
                }
            }
            model.add(mapping);
            newMappings = mapping.getMappingType() == DatabaseMappingType.unspecified;
        }
        mappingViewer.setInput(model);
        if (!model.isEmpty()) {
            // Select first element
            mappingViewer.setSelection(new StructuredSelection(model.get(0)));
        }
        if (newMappings) {
            autoAssignMappings();
        }
        Tree table = mappingViewer.getTree();
        int totalWidth = table.getClientArea().width;
        TreeColumn[] columns = table.getColumns();
        columns[0].setWidth(totalWidth * 40 / 100);
        columns[1].setWidth(totalWidth * 40 / 100);
        columns[2].setWidth(totalWidth * 20 / 100);
    }
    updatePageCompletion();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DataTransferPipe(org.jkiss.dbeaver.tools.transfer.DataTransferPipe) ArrayList(java.util.ArrayList) List(java.util.List) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 8 with DataTransferPipe

use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by dbeaver.

the class DatabaseProducerPageInputObjects method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = UIUtils.createComposite(parent, 1);
    DataTransferSettings settings = getWizard().getSettings();
    {
        Group tablesGroup = UIUtils.createControlGroup(composite, DTMessages.data_transfer_wizard_mappings_name, 3, GridData.FILL_BOTH, 0);
        mappingTable = new Table(tablesGroup, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
        mappingTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        mappingTable.setHeaderVisible(true);
        mappingTable.setLinesVisible(true);
        UIUtils.createTableColumn(mappingTable, SWT.LEFT, DTUIMessages.data_transfer_wizard_final_column_source);
        UIUtils.createTableColumn(mappingTable, SWT.LEFT, DTUIMessages.data_transfer_wizard_final_column_target);
        mappingTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (mappingTable.getSelectionIndex() < 0) {
                    return;
                }
                TableItem item = mappingTable.getItem(mappingTable.getSelectionIndex());
                DataTransferPipe pipe = (DataTransferPipe) item.getData();
                if (chooseEntity(pipe)) {
                    updateItemData(item, pipe);
                    updatePageCompletion();
                }
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        UIUtils.asyncExec(() -> UIUtils.packColumns(mappingTable, true));
    }
    {
        Composite controlGroup = UIUtils.createComposite(composite, 1);
        Button autoAssignButton = new Button(controlGroup, SWT.PUSH);
        autoAssignButton.setImage(DBeaverIcons.getImage(UIIcon.ASTERISK));
        autoAssignButton.setText(DTMessages.data_transfer_db_consumer_auto_assign);
        autoAssignButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                autoAssignMappings();
            }
        });
    }
    setControl(composite);
}
Also used : DataTransferSettings(org.jkiss.dbeaver.tools.transfer.DataTransferSettings) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataTransferPipe(org.jkiss.dbeaver.tools.transfer.DataTransferPipe)

Example 9 with DataTransferPipe

use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by dbeaver.

the class DataTransferPageSettings method createSettingsPages.

private void createSettingsPages(Composite composite) {
    DataTransferSettings dtSettings = getWizard().getSettings();
    {
        DataTransferPipe dataPipe = dtSettings.getDataPipes().get(0);
        StringBuilder title = new StringBuilder();
        title.append(DTMessages.data_transfer_wizard_settings_title).append(" (").append(dtSettings.getProducer().getName()).append(" to ").append(dtSettings.getConsumer().getName());
        if (dtSettings.getProcessor() != null) {
            title.append(", ").append(dtSettings.getProcessor().getName());
        }
        title.append(")");
        setTitle(title.toString());
        producerSettingsPage = getSettingsPage(dataPipe.getProducer());
        consumerSettingsPage = getSettingsPage(dataPipe.getConsumer());
    }
    Composite settingsComposite = composite;
    if (producerSettingsPage != null && consumerSettingsPage != null) {
        SashForm sash = new SashForm(composite, SWT.HORIZONTAL);
        sash.setLayoutData(new GridData(GridData.FILL_BOTH));
        settingsComposite = sash;
    }
    if (producerSettingsPage != null) {
        producerSettingsPage.setWizard(getWizard());
        Composite producerGroup = UIUtils.createPlaceholder(settingsComposite, 1);
        UIUtils.createInfoLabel(producerGroup, producerSettingsPage.getTitle());
        Composite settingPanel = new Composite(producerGroup, SWT.NONE);
        settingPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
        settingPanel.setLayout(new FillLayout());
        producerSettingsPage.createControl(settingPanel);
        if (producerSettingsPage instanceof ActiveWizardPage) {
            ((ActiveWizardPage) producerSettingsPage).activatePage();
        }
    }
    if (consumerSettingsPage != null) {
        consumerSettingsPage.setWizard(getWizard());
        Composite consumerGroup = UIUtils.createPlaceholder(settingsComposite, 1);
        UIUtils.createInfoLabel(consumerGroup, consumerSettingsPage.getTitle());
        Composite settingPanel = new Composite(consumerGroup, SWT.NONE);
        settingPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
        settingPanel.setLayout(new FillLayout());
        consumerSettingsPage.createControl(settingPanel);
        if (consumerSettingsPage instanceof ActiveWizardPage) {
            ((ActiveWizardPage) consumerSettingsPage).activatePage();
        }
    }
}
Also used : DataTransferSettings(org.jkiss.dbeaver.tools.transfer.DataTransferSettings) SashForm(org.eclipse.swt.custom.SashForm) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) DataTransferPipe(org.jkiss.dbeaver.tools.transfer.DataTransferPipe) ActiveWizardPage(org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage)

Example 10 with DataTransferPipe

use of org.jkiss.dbeaver.tools.transfer.DataTransferPipe in project dbeaver by dbeaver.

the class DatabaseConsumerPageMapping method getPipe.

private DataTransferPipe getPipe(DatabaseMappingContainer mappingContainer) {
    final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
    for (DataTransferPipe pipe : getWizard().getSettings().getDataPipes()) {
        if (pipe.getProducer() == null) {
            continue;
        }
        DBSDataContainer sourceObject = (DBSDataContainer) pipe.getProducer().getDatabaseObject();
        DatabaseMappingContainer mapping = settings.getDataMapping(sourceObject);
        if (mapping == mappingContainer) {
            return pipe;
        }
    }
    return null;
}
Also used : DataTransferPipe(org.jkiss.dbeaver.tools.transfer.DataTransferPipe)

Aggregations

DataTransferPipe (org.jkiss.dbeaver.tools.transfer.DataTransferPipe)16 DataTransferSettings (org.jkiss.dbeaver.tools.transfer.DataTransferSettings)8 GridData (org.eclipse.swt.layout.GridData)4 DBException (org.jkiss.dbeaver.DBException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SashForm (org.eclipse.swt.custom.SashForm)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)2 DBSDataManipulator (org.jkiss.dbeaver.model.struct.DBSDataManipulator)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 DataTransferJob (org.jkiss.dbeaver.tools.transfer.DataTransferJob)2 DatabaseTransferConsumer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer)2 DatabaseTransferProducer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer)2 ActiveWizardPage (org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage)2