Search in sources :

Example 1 with DatabaseTransferConsumer

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

the class DataImportHandler method adaptTransferNode.

@Override
protected IDataTransferNode adaptTransferNode(Object object) {
    final DBSDataManipulator adapted = RuntimeUtils.getObjectAdapter(object, DBSDataManipulator.class);
    if (adapted != null) {
        return new DatabaseTransferConsumer(adapted);
    } else {
        IFile file = RuntimeUtils.getObjectAdapter(object, IFile.class);
        if (file != null) {
            return getNodeByFile(file);
        }
        DBSObjectContainer objectContainer = RuntimeUtils.getObjectAdapter(object, DBSObjectContainer.class);
        if (objectContainer == null) {
            if (object instanceof DBSWrapper) {
                object = ((DBSWrapper) object).getObject();
            }
            if (object instanceof DBPObject) {
                object = DBUtils.getPublicObject((DBSObject) object);
            }
            if (object instanceof DBSObjectContainer) {
                objectContainer = (DBSObjectContainer) object;
            }
        }
        if (objectContainer != null) {
            if (isObjectContainerSupportsImport(objectContainer)) {
                return new DatabaseTransferConsumer(objectContainer);
            } else {
                DBWorkbench.getPlatformUI().showError("Wrong container", objectContainer.getName() + " doesn't support direct data import");
            }
        }
        return null;
    }
}
Also used : DatabaseTransferConsumer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer) DBPObject(org.jkiss.dbeaver.model.DBPObject) IFile(org.eclipse.core.resources.IFile)

Example 2 with DatabaseTransferConsumer

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

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

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

the class DataImportHandler method adaptTransferNode.

@Override
protected IDataTransferNode adaptTransferNode(Object object) {
    final DBSDataManipulator adapted = RuntimeUtils.getObjectAdapter(object, DBSDataManipulator.class);
    if (adapted != null) {
        return new DatabaseTransferConsumer(adapted);
    } else {
        IFile file = RuntimeUtils.getObjectAdapter(object, IFile.class);
        if (file != null) {
            return getNodeByFile(file);
        }
        DBSObjectContainer objectContainer = RuntimeUtils.getObjectAdapter(object, DBSObjectContainer.class);
        if (objectContainer == null) {
            if (object instanceof DBSWrapper) {
                object = ((DBSWrapper) object).getObject();
            }
            if (object instanceof DBPObject) {
                object = DBUtils.getPublicObject((DBSObject) object);
            }
            if (object instanceof DBSObjectContainer) {
                objectContainer = (DBSObjectContainer) object;
            }
        }
        if (objectContainer != null) {
            if (isObjectContainerSupportsImport(objectContainer)) {
                return new DatabaseTransferConsumer(objectContainer);
            } else {
                DBWorkbench.getPlatformUI().showError("Wrong container", objectContainer.getName() + " doesn't support direct data import");
            }
        }
        return null;
    }
}
Also used : DatabaseTransferConsumer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer) DBPObject(org.jkiss.dbeaver.model.DBPObject) IFile(org.eclipse.core.resources.IFile)

Example 4 with DatabaseTransferConsumer

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

Example 5 with DatabaseTransferConsumer

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

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)

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