Search in sources :

Example 11 with DBSDataManipulator

use of org.jkiss.dbeaver.model.struct.DBSDataManipulator 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);
    }
}
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) DBSDataManipulator(org.jkiss.dbeaver.model.struct.DBSDataManipulator) StreamEntityMapping(org.jkiss.dbeaver.tools.transfer.stream.StreamEntityMapping) DatabaseMappingContainer(org.jkiss.dbeaver.tools.transfer.database.DatabaseMappingContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 12 with DBSDataManipulator

use of org.jkiss.dbeaver.model.struct.DBSDataManipulator in project dbeaver by serge-rider.

the class DatabaseProducerPageInputObjects method chooseEntity.

protected boolean chooseEntity(DataTransferPipe pipe) {
    DataTransferSettings settings = getWizard().getSettings();
    final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
    final DBNNode rootNode = DBWorkbench.getPlatform().getWorkspace().getProjects().size() == 1 ? navigatorModel.getRoot().getProjectNode(DBWorkbench.getPlatform().getWorkspace().getActiveProject()) : navigatorModel.getRoot();
    boolean chooseConsumer = settings.isConsumerOptional();
    DBNNode node = DBWorkbench.getPlatformUI().selectObject(UIUtils.getActiveWorkbenchShell(), chooseConsumer ? NLS.bind(DTUIMessages.database_producer_page_input_objects_node_select_target, pipe.getProducer().getDatabaseObject().getName()) : NLS.bind(DTUIMessages.database_producer_page_input_objects_node_select_source, pipe.getConsumer().getObjectName()), rootNode, lastSelection, new Class[] { DBSObjectContainer.class, DBSDataContainer.class }, new Class[] { chooseConsumer ? DBSDataManipulator.class : DBSDataContainer.class }, null);
    if (node instanceof DBNDatabaseNode) {
        lastSelection = (DBNDatabaseNode) node;
        DBSObject object = ((DBNDatabaseNode) node).getObject();
        if (chooseConsumer) {
            if (object instanceof DBSDataManipulator) {
                pipe.setConsumer(new DatabaseTransferConsumer((DBSDataManipulator) object));
            }
        } else {
            if (object instanceof DBSDataContainer) {
                pipe.setProducer(new DatabaseTransferProducer((DBSDataContainer) object));
            }
        }
        return true;
    }
    return false;
}
Also used : DataTransferSettings(org.jkiss.dbeaver.tools.transfer.DataTransferSettings) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseTransferConsumer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSDataManipulator(org.jkiss.dbeaver.model.struct.DBSDataManipulator) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 13 with DBSDataManipulator

use of org.jkiss.dbeaver.model.struct.DBSDataManipulator in project dbeaver by serge-rider.

the class DatabaseConsumerSettings method loadSettings.

@Override
public void loadSettings(DBRRunnableContext runnableContext, DataTransferSettings dataTransferSettings, Map<String, Object> settings) {
    this.dialogSettings = settings;
    containerNodePath = CommonUtils.toString(settings.get("container"), containerNodePath);
    openNewConnections = CommonUtils.getBoolean(settings.get("openNewConnections"), openNewConnections);
    useTransactions = CommonUtils.getBoolean(settings.get("useTransactions"), useTransactions);
    onDuplicateKeyInsertMethodId = CommonUtils.toString(settings.get("onDuplicateKeyMethod"), onDuplicateKeyInsertMethodId);
    commitAfterRows = CommonUtils.toInt(settings.get("commitAfterRows"), commitAfterRows);
    disableUsingBatches = CommonUtils.getBoolean(settings.get("disableUsingBatches"), disableUsingBatches);
    transferAutoGeneratedColumns = CommonUtils.getBoolean(settings.get("transferAutoGeneratedColumns"), transferAutoGeneratedColumns);
    truncateBeforeLoad = CommonUtils.getBoolean(settings.get("truncateBeforeLoad"), truncateBeforeLoad);
    openTableOnFinish = CommonUtils.getBoolean(settings.get("openTableOnFinish"), openTableOnFinish);
    List<DataTransferPipe> dataPipes = dataTransferSettings.getDataPipes();
    {
        if (!dataPipes.isEmpty()) {
            IDataTransferConsumer consumer = dataPipes.get(0).getConsumer();
            if (consumer instanceof DatabaseTransferConsumer) {
                final DBSDataManipulator targetObject = ((DatabaseTransferConsumer) consumer).getTargetObject();
                if (targetObject != null) {
                    containerNode = DBWorkbench.getPlatform().getNavigatorModel().findNode(targetObject.getParentObject());
                }
            }
        }
        checkContainerConnection(runnableContext);
    }
    loadNode(runnableContext, dataTransferSettings, null);
    // Load mapping for current objects
    Map<String, Object> mappings = (Map<String, Object>) settings.get("mappings");
    if (mappings != null) {
        if (!dataMappings.isEmpty()) {
            for (DatabaseMappingContainer dmc : dataMappings.values()) {
                DBSDataContainer sourceDatacontainer = dmc.getSource();
                if (sourceDatacontainer != null) {
                    Map<String, Object> dmcSettings = (Map<String, Object>) mappings.get(DBUtils.getObjectFullId(sourceDatacontainer));
                    if (dmcSettings != null) {
                        dmc.loadSettings(runnableContext, dmcSettings);
                    }
                }
            }
        } else if (!dataPipes.isEmpty()) {
            for (DataTransferPipe pipe : dataPipes) {
                IDataTransferProducer producer = pipe.getProducer();
                if (producer != null) {
                    DBSObject dbObject = producer.getDatabaseObject();
                    if (dbObject instanceof DBSDataContainer) {
                        DBSDataContainer sourceDC = (DBSDataContainer) dbObject;
                        Map<String, Object> dmcSettings = (Map<String, Object>) mappings.get(DBUtils.getObjectFullId(dbObject));
                        if (dmcSettings != null) {
                            DatabaseMappingContainer dmc = new DatabaseMappingContainer(this, sourceDC);
                            dmc.loadSettings(runnableContext, dmcSettings);
                            dataMappings.put(sourceDC, dmc);
                        }
                    }
                }
            }
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSDataManipulator(org.jkiss.dbeaver.model.struct.DBSDataManipulator) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

DBSDataManipulator (org.jkiss.dbeaver.model.struct.DBSDataManipulator)13 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)8 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)7 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 DatabaseTransferConsumer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer)4 DatabaseTransferProducer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer)4 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 DBException (org.jkiss.dbeaver.DBException)2 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 DataTransferPipe (org.jkiss.dbeaver.tools.transfer.DataTransferPipe)2 DataTransferSettings (org.jkiss.dbeaver.tools.transfer.DataTransferSettings)2 DatabaseConsumerSettings (org.jkiss.dbeaver.tools.transfer.database.DatabaseConsumerSettings)2 DatabaseMappingContainer (org.jkiss.dbeaver.tools.transfer.database.DatabaseMappingContainer)2 StreamEntityMapping (org.jkiss.dbeaver.tools.transfer.stream.StreamEntityMapping)2 StreamProducerSettings (org.jkiss.dbeaver.tools.transfer.stream.StreamProducerSettings)2 StreamTransferProducer (org.jkiss.dbeaver.tools.transfer.stream.StreamTransferProducer)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1