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();
}
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);
}
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) {
}
}
}
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;
}
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);
}
Aggregations