Search in sources :

Example 1 with DataTransferPipe

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

the class DatabaseConsumerPageMapping method showPreview.

private void showPreview(DatabaseMappingContainer mappingContainer) {
    DataTransferPipe pipe = getPipe(mappingContainer);
    DataTransferSettings dtSettings = getWizard().getSettings();
    PreviewMappingDialog previewDialog = new PreviewMappingDialog(getShell(), pipe, mappingContainer, dtSettings);
    previewDialog.open();
}
Also used : DataTransferSettings(org.jkiss.dbeaver.tools.transfer.DataTransferSettings) DataTransferPipe(org.jkiss.dbeaver.tools.transfer.DataTransferPipe)

Example 2 with DataTransferPipe

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

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 3 with DataTransferPipe

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

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)

Example 4 with DataTransferPipe

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

the class DatabaseProducerPageInputObjects method activatePage.

@Override
public void activatePage() {
    // final DatabaseProducerSettings settings = getWizard().getPageSettings(this, DatabaseProducerSettings.class);
    DataTransferSettings settings = getWizard().getSettings();
    mappingTable.removeAll();
    for (DataTransferPipe pipe : settings.getDataPipes()) {
        TableItem item = new TableItem(mappingTable, SWT.NONE);
        item.setData(pipe);
        updateItemData(item, pipe);
    }
    updatePageCompletion();
}
Also used : DataTransferSettings(org.jkiss.dbeaver.tools.transfer.DataTransferSettings) DataTransferPipe(org.jkiss.dbeaver.tools.transfer.DataTransferPipe)

Example 5 with DataTransferPipe

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

the class DatabaseProducerPageInputObjects method autoAssignMappings.

private void autoAssignMappings(List<DBSObject> containerObjects) {
    boolean chooseConsumer = getWizard().getSettings().isConsumerOptional();
    for (TableItem item : mappingTable.getItems()) {
        DataTransferPipe pipe = (DataTransferPipe) item.getData();
        if ((chooseConsumer && (pipe.getConsumer() == null || pipe.getConsumer().getDatabaseObject() == null)) || (!chooseConsumer && (pipe.getProducer() == null || pipe.getProducer().getDatabaseObject() == null))) {
            DBSObject objectToMap = chooseConsumer ? pipe.getProducer().getDatabaseObject() : pipe.getConsumer().getDatabaseObject();
            if (objectToMap == null) {
                continue;
            }
            DBSObject object = DBUtils.findObject(containerObjects, objectToMap.getName());
            if (object != null) {
                if (chooseConsumer) {
                    if (object instanceof DBSDataManipulator) {
                        pipe.setConsumer(new DatabaseTransferConsumer((DBSDataManipulator) object));
                    }
                } else {
                    if (object instanceof DBSDataContainer) {
                        pipe.setProducer(new DatabaseTransferProducer((DBSDataContainer) object));
                    }
                }
                updateItemData(item, pipe);
            }
        }
    }
    updatePageCompletion();
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseTransferConsumer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer) DBSDataManipulator(org.jkiss.dbeaver.model.struct.DBSDataManipulator) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) 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