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