Search in sources :

Example 11 with DatabaseConsumerSettings

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

the class DatabaseConsumerPageLoadSettings method createControl.

@Override
public void createControl(Composite parent) {
    initializeDialogUnits(parent);
    Composite composite = UIUtils.createComposite(parent, 1);
    final DatabaseConsumerSettings settings = getSettings();
    {
        loadSettings = UIUtils.createControlGroup(composite, DTUIMessages.database_consumer_wizard_name, 2, GridData.FILL_HORIZONTAL, 0);
        transferAutoGeneratedColumns = UIUtils.createCheckbox(loadSettings, DTUIMessages.database_consumer_wizard_transfer_checkbox_label, DTUIMessages.database_consumer_wizard_transfer_checkbox_tooltip, settings.isTransferAutoGeneratedColumns(), 2);
        transferAutoGeneratedColumns.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setTransferAutoGeneratedColumns(transferAutoGeneratedColumns.getSelection());
            }
        });
        truncateTargetTable = UIUtils.createCheckbox(loadSettings, DTUIMessages.database_consumer_wizard_truncate_checkbox_label, DTUIMessages.database_consumer_wizard_truncate_checkbox_description, settings.isTruncateBeforeLoad(), 2);
        truncateTargetTable.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (truncateTargetTable.getSelection() && !confirmDataTruncate()) {
                    truncateTargetTable.setSelection(false);
                    return;
                }
                settings.setTruncateBeforeLoad(truncateTargetTable.getSelection());
            }
        });
        UIUtils.createControlLabel(loadSettings, DTUIMessages.database_consumer_wizard_on_duplicate_key_insert_method_text);
        onDuplicateKeyInsertMethods = new Combo(loadSettings, SWT.DROP_DOWN | SWT.READ_ONLY);
        onDuplicateKeyInsertMethods.setLayoutData(new GridData(GridData.FILL, GridData.VERTICAL_ALIGN_BEGINNING, true, false, 1, 1));
        Link urlLabel = UIUtils.createLink(loadSettings, "<a href=\"" + REPLACE_METHOD_LINK + "\">" + DTUIMessages.database_consumer_wizard_link_label_replace_method_wiki + "</a>", new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                UIUtils.launchProgram(REPLACE_METHOD_LINK);
            }
        });
        urlLabel.setLayoutData(new GridData(GridData.FILL, GridData.VERTICAL_ALIGN_BEGINNING, false, false, 2, 1));
    }
    {
        Group performanceSettings = UIUtils.createControlGroup(composite, DTUIMessages.database_consumer_wizard_performance_group_label, 4, GridData.FILL_HORIZONTAL, 0);
        final Button newConnectionCheckbox = UIUtils.createCheckbox(performanceSettings, DTMessages.data_transfer_wizard_output_checkbox_new_connection, null, settings.isOpenNewConnections(), 4);
        newConnectionCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setOpenNewConnections(newConnectionCheckbox.getSelection());
            }
        });
        final Button useTransactionsCheck = UIUtils.createCheckbox(performanceSettings, DTUIMessages.database_consumer_wizard_transactions_checkbox_label, null, settings.isUseTransactions(), 4);
        useTransactionsCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setUseTransactions(useTransactionsCheck.getSelection());
            }
        });
        final Spinner commitAfterEdit = UIUtils.createLabelSpinner(performanceSettings, DTUIMessages.database_consumer_wizard_commit_spinner_label, settings.getCommitAfterRows(), 1, Integer.MAX_VALUE);
        commitAfterEdit.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setCommitAfterRows(commitAfterEdit.getSelection());
            }
        });
        commitAfterEdit.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_BEGINNING, false, false, 3, 1));
        final Button useBatchCheck = UIUtils.createCheckbox(performanceSettings, DTUIMessages.database_consumer_wizard_disable_import_batches_label, DTUIMessages.database_consumer_wizard_disable_import_batches_description, settings.isDisableUsingBatches(), 4);
        useBatchCheck.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setDisableUsingBatches(useBatchCheck.getSelection());
            }
        });
    }
    {
        Group generalSettings = UIUtils.createControlGroup(composite, DTUIMessages.database_consumer_wizard_general_group_label, 4, GridData.FILL_HORIZONTAL, 0);
        final Button showTableCheckbox = UIUtils.createCheckbox(generalSettings, DTUIMessages.database_consumer_wizard_table_checkbox_label, null, settings.isOpenTableOnFinish(), 4);
        showTableCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                settings.setOpenTableOnFinish(showTableCheckbox.getSelection());
            }
        });
        final Button showFinalMessageCheckbox = UIUtils.createCheckbox(generalSettings, DTUIMessages.database_consumer_wizard_final_message_checkbox_label, null, getWizard().getSettings().isShowFinalMessage(), 4);
        showFinalMessageCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                getWizard().getSettings().setShowFinalMessage(showFinalMessageCheckbox.getSelection());
            }
        });
    }
    setControl(composite);
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DatabaseConsumerSettings(org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData)

Example 12 with DatabaseConsumerSettings

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

the class DatabaseConsumerPageLoadSettings method loadSettings.

private void loadSettings() {
    DatabaseConsumerSettings settings = getSettings();
    if (settings.isTruncateBeforeLoad() && !confirmDataTruncate()) {
        truncateTargetTable.setSelection(false);
        settings.setTruncateBeforeLoad(false);
    }
    loadInsertMethods();
}
Also used : DatabaseConsumerSettings(org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings)

Example 13 with DatabaseConsumerSettings

use of org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings 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);
}
Also used : StreamTransferProducer(org.jkiss.dbeaver.tools.transfer.stream.StreamTransferProducer) DatabaseTransferConsumer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer) DBException(org.jkiss.dbeaver.DBException) ArrayList(java.util.ArrayList) StreamProducerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamProducerSettings) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseConsumerSettings(org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings) StreamEntityMapping(org.jkiss.dbeaver.tools.transfer.stream.StreamEntityMapping) DatabaseMappingContainer(org.jkiss.dbeaver.tools.transfer.database.DatabaseMappingContainer) File(java.io.File) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 14 with DatabaseConsumerSettings

use of org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings 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();
}
Also used : StreamTransferProducer(org.jkiss.dbeaver.tools.transfer.stream.StreamTransferProducer) StreamProducerSettings(org.jkiss.dbeaver.tools.transfer.stream.StreamProducerSettings) DatabaseConsumerSettings(org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseMappingContainer(org.jkiss.dbeaver.tools.transfer.database.DatabaseMappingContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DatabaseConsumerSettings (org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings)14 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 DatabaseMappingContainer (org.jkiss.dbeaver.tools.transfer.database.DatabaseMappingContainer)6 StreamProducerSettings (org.jkiss.dbeaver.tools.transfer.stream.StreamProducerSettings)6 StreamTransferProducer (org.jkiss.dbeaver.tools.transfer.stream.StreamTransferProducer)6 ArrayList (java.util.ArrayList)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 DBException (org.jkiss.dbeaver.DBException)4 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 DatabaseTransferConsumer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer)4 StreamEntityMapping (org.jkiss.dbeaver.tools.transfer.stream.StreamEntityMapping)4 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBCSession (org.jkiss.dbeaver.model.exec.DBCSession)2 SQLDialectDescriptor (org.jkiss.dbeaver.model.sql.registry.SQLDialectDescriptor)2 SQLInsertReplaceMethodDescriptor (org.jkiss.dbeaver.model.sql.registry.SQLInsertReplaceMethodDescriptor)2 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)2