Search in sources :

Example 6 with DatabaseTransferConsumer

use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer in project dbeaver by dbeaver.

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)

Example 7 with DatabaseTransferConsumer

use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer 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);
}
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 8 with DatabaseTransferConsumer

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

the class StreamImporterAbstract method applyTransformHints.

protected void applyTransformHints(StreamTransferResultSet resultSet, IDataTransferConsumer consumer, Map<String, Object> properties, String formatPropName, String zoneIdPropName) throws DBException {
    DateTimeFormatter tsFormat = formatPropName == null ? null : getTimeStampFormat(properties, formatPropName);
    ZoneId tsZoneId = null;
    if (zoneIdPropName != null) {
        String zoneId = CommonUtils.toString(properties.get(zoneIdPropName));
        if (!CommonUtils.isEmpty(zoneId)) {
            tsZoneId = ZoneId.of(zoneId);
        }
    }
    if (tsFormat != null) {
        resultSet.setDateTimeFormat(tsFormat, tsZoneId);
    }
    // Do it only for valid String mappings
    if (consumer instanceof DatabaseTransferConsumer) {
        for (DatabaseTransferConsumer.ColumnMapping cm : ((DatabaseTransferConsumer) consumer).getColumnMappings()) {
            if (cm == null) {
                continue;
            }
            for (StreamDataImporterColumnInfo attributeMapping : resultSet.getAttributeMappings()) {
                if (cm.targetAttr.getMappingType().isValid()) {
                    if (cm.sourceAttr.getDataKind() == DBPDataKind.STRING && cm.sourceAttr.getName().equals(attributeMapping.getName())) {
                        // Gotcha
                        DBSEntityAttribute targetAttr = cm.targetAttr.getTarget();
                        if (targetAttr != null) {
                            switch(targetAttr.getDataKind()) {
                                case DATETIME:
                                case NUMERIC:
                                case BOOLEAN:
                                    attributeMapping.setDataKind(targetAttr.getDataKind());
                                    break;
                            }
                        }
                    }
                }
            }
        }
        Object targetObject = consumer.getTargetObject();
        if (targetObject instanceof DBSEntity) {
        }
    }
}
Also used : DatabaseTransferConsumer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer) ZoneId(java.time.ZoneId) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) StreamDataImporterColumnInfo(org.jkiss.dbeaver.tools.transfer.stream.StreamDataImporterColumnInfo) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 9 with DatabaseTransferConsumer

use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer 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 10 with DatabaseTransferConsumer

use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer 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)

Aggregations

DatabaseTransferConsumer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer)10 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)4 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)4 DBSDataManipulator (org.jkiss.dbeaver.model.struct.DBSDataManipulator)4 DatabaseTransferProducer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer)4 File (java.io.File)2 ZoneId (java.time.ZoneId)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 DBException (org.jkiss.dbeaver.DBException)2 DBPObject (org.jkiss.dbeaver.model.DBPObject)2 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)2 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)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