mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-13 16:18:51 +08:00
CB-2328 data export output params
This commit is contained in:
+21
@@ -14,6 +14,23 @@ type DataTransferProcessorInfo {
|
||||
isHTML: Boolean
|
||||
}
|
||||
|
||||
input DataTransferOutputSettingsInput {
|
||||
insertBom: Boolean
|
||||
encoding: Boolean
|
||||
timestampPattern: Boolean
|
||||
}
|
||||
|
||||
type DataTransferOutputSettings {
|
||||
insertBom: Boolean!
|
||||
encoding: Boolean!
|
||||
timestampPattern: Boolean!
|
||||
}
|
||||
|
||||
type DataTransferDefaultExportSettings {
|
||||
outputSettings : DataTransferOutputSettings!
|
||||
supportedEncodings: [String!]!
|
||||
}
|
||||
|
||||
input DataTransferParameters {
|
||||
# Processor ID
|
||||
processorId: ID!
|
||||
@@ -22,6 +39,8 @@ input DataTransferParameters {
|
||||
settings: Object
|
||||
# Processor properties. See DataTransferProcessorInfo.properties
|
||||
processorProperties: Object!
|
||||
# Consumer properties. See StreamConsumerSettings
|
||||
outputSettings: DataTransferOutputSettingsInput
|
||||
# Data filter settings
|
||||
filter: SQLDataFilter
|
||||
}
|
||||
@@ -31,6 +50,8 @@ extend type Query {
|
||||
# Available transfer processors
|
||||
dataTransferAvailableStreamProcessors: [ DataTransferProcessorInfo! ]!
|
||||
|
||||
dataTransferDefaultExportSettings: DataTransferDefaultExportSettings!
|
||||
|
||||
dataTransferExportDataFromContainer(
|
||||
projectId: ID,
|
||||
connectionId: ID!,
|
||||
|
||||
+2
@@ -21,6 +21,7 @@ import io.cloudbeaver.DBWebException;
|
||||
import io.cloudbeaver.WebAction;
|
||||
import io.cloudbeaver.model.WebAsyncTaskInfo;
|
||||
import io.cloudbeaver.model.session.WebSession;
|
||||
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferDefaultExportSettings;
|
||||
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferParameters;
|
||||
import io.cloudbeaver.service.data.transfer.impl.WebDataTransferStreamProcessor;
|
||||
import io.cloudbeaver.service.sql.WebSQLContextInfo;
|
||||
@@ -51,4 +52,5 @@ public interface DBWServiceDataTransfer extends DBWService {
|
||||
@WebAction
|
||||
Boolean dataTransferRemoveDataFile(WebSession session, String dataFileId) throws DBWebException;
|
||||
|
||||
WebDataTransferDefaultExportSettings defaultExportSettings();
|
||||
}
|
||||
|
||||
+1
@@ -56,6 +56,7 @@ public class WebServiceBindingDataTransfer extends WebServiceBindingBase<DBWServ
|
||||
getWebSession(env),
|
||||
env.getArgument("dataFileId")
|
||||
))
|
||||
.dataFetcher("dataTransferDefaultExportSettings", env -> getService(env).defaultExportSettings())
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package io.cloudbeaver.service.data.transfer.impl;
|
||||
|
||||
import org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Set;
|
||||
|
||||
public class WebDataTransferDefaultExportSettings {
|
||||
private final WebDataTransferOutputSettings outputSettings;
|
||||
private final Set<String> supportedEncodings;
|
||||
|
||||
public WebDataTransferDefaultExportSettings() {
|
||||
var defConsumerSettings = new StreamConsumerSettings();
|
||||
this.outputSettings = new WebDataTransferOutputSettings(
|
||||
false,
|
||||
defConsumerSettings.getOutputEncoding(),
|
||||
defConsumerSettings.getOutputTimestampPattern()
|
||||
);
|
||||
this.supportedEncodings = Charset.availableCharsets().keySet();
|
||||
}
|
||||
|
||||
public WebDataTransferOutputSettings getOutputSettings() {
|
||||
return outputSettings;
|
||||
}
|
||||
|
||||
public Set<String> getSupportedEncodings() {
|
||||
return supportedEncodings;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package io.cloudbeaver.service.data.transfer.impl;
|
||||
|
||||
import org.jkiss.dbeaver.model.data.json.JSONUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class WebDataTransferOutputSettings {
|
||||
private final boolean insertBom;
|
||||
private final String encoding;
|
||||
private final String timestampPattern;
|
||||
|
||||
public WebDataTransferOutputSettings(Map<String, Object> outputSettings) {
|
||||
this.insertBom = JSONUtils.getBoolean(outputSettings, "insertBom", false);
|
||||
this.encoding = JSONUtils.getString(outputSettings, "encoding");
|
||||
this.timestampPattern = JSONUtils.getString(outputSettings, "timestampPattern");
|
||||
}
|
||||
|
||||
public WebDataTransferOutputSettings(boolean insertBom, String encoding, String timestampPattern) {
|
||||
this.insertBom = insertBom;
|
||||
this.encoding = encoding;
|
||||
this.timestampPattern = timestampPattern;
|
||||
}
|
||||
|
||||
public boolean isInsertBom() {
|
||||
return insertBom;
|
||||
}
|
||||
|
||||
public String getEncoding() {
|
||||
return encoding;
|
||||
}
|
||||
|
||||
public String getTimestampPattern() {
|
||||
return timestampPattern;
|
||||
}
|
||||
}
|
||||
+14
-6
@@ -2,24 +2,28 @@ package io.cloudbeaver.service.data.transfer.impl;
|
||||
|
||||
import io.cloudbeaver.service.sql.WebSQLDataFilter;
|
||||
import org.jkiss.dbeaver.model.data.json.JSONUtils;
|
||||
import org.jkiss.dbeaver.tools.transfer.stream.StreamConsumerSettings;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class WebDataTransferParameters {
|
||||
|
||||
private String processorId;
|
||||
private Map<String, Object> settings;
|
||||
private Map<String, Object> dbProducerSettings;
|
||||
private Map<String, Object> processorProperties;
|
||||
private WebSQLDataFilter filter;
|
||||
private WebDataTransferOutputSettings outputSettings;
|
||||
|
||||
public WebDataTransferParameters() {
|
||||
}
|
||||
|
||||
public WebDataTransferParameters(Map<String, Object> params) {
|
||||
this.processorId = JSONUtils.getString(params, "processorId");
|
||||
this.settings = JSONUtils.getObject(params, "settings");
|
||||
this.dbProducerSettings = JSONUtils.getObject(params, "settings");
|
||||
this.processorProperties = JSONUtils.getObject(params, "processorProperties");
|
||||
this.filter = new WebSQLDataFilter(JSONUtils.getObject(params, "filter"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public String getProcessorId() {
|
||||
@@ -30,12 +34,12 @@ public class WebDataTransferParameters {
|
||||
this.processorId = processorId;
|
||||
}
|
||||
|
||||
public Map<String, Object> getSettings() {
|
||||
return settings;
|
||||
public Map<String, Object> getDbProducerSettings() {
|
||||
return dbProducerSettings;
|
||||
}
|
||||
|
||||
public void setSettings(Map<String, Object> settings) {
|
||||
this.settings = settings;
|
||||
public void setDbProducerSettings(Map<String, Object> dbProducerSettings) {
|
||||
this.dbProducerSettings = dbProducerSettings;
|
||||
}
|
||||
|
||||
public Map<String, Object> getProcessorProperties() {
|
||||
@@ -53,4 +57,8 @@ public class WebDataTransferParameters {
|
||||
public void setFilter(WebSQLDataFilter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public WebDataTransferOutputSettings getOutputSettings() {
|
||||
return outputSettings;
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -142,6 +142,11 @@ public class WebServiceDataTransfer implements DBWServiceDataTransfer {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebDataTransferDefaultExportSettings defaultExportSettings() {
|
||||
return new WebDataTransferDefaultExportSettings();
|
||||
}
|
||||
|
||||
private WebAsyncTaskInfo asyncExportFromDataContainer(WebSQLProcessor sqlProcessor, WebDataTransferParameters parameters, DBSDataContainer dataContainer,
|
||||
@Nullable WebSQLResultsInfo resultsInfo) {
|
||||
sqlProcessor.getWebSession().addInfoMessage("Export data");
|
||||
@@ -213,10 +218,18 @@ public class WebServiceDataTransfer implements DBWServiceDataTransfer {
|
||||
|
||||
StreamConsumerSettings settings = new StreamConsumerSettings();
|
||||
|
||||
settings.setOutputEncodingBOM(false);
|
||||
settings.setOutputFolder(exportFile.getParent().toAbsolutePath().toString());
|
||||
settings.setOutputFilePattern(exportFile.getFileName().toString());
|
||||
|
||||
WebDataTransferOutputSettings outputSettings = parameters.getOutputSettings();
|
||||
settings.setOutputEncodingBOM(outputSettings.isInsertBom());
|
||||
if (!CommonUtils.isEmpty(outputSettings.getEncoding())) {
|
||||
settings.setOutputEncoding(outputSettings.getEncoding());
|
||||
}
|
||||
if (!CommonUtils.isEmpty(outputSettings.getTimestampPattern())) {
|
||||
settings.setOutputTimestampPattern(outputSettings.getTimestampPattern());
|
||||
}
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
Map<String, Object> processorProperties = parameters.getProcessorProperties();
|
||||
@@ -241,7 +254,7 @@ public class WebServiceDataTransfer implements DBWServiceDataTransfer {
|
||||
DatabaseProducerSettings producerSettings = new DatabaseProducerSettings();
|
||||
producerSettings.setExtractType(DatabaseProducerSettings.ExtractType.SINGLE_QUERY);
|
||||
producerSettings.setQueryRowCount(false);
|
||||
producerSettings.setOpenNewConnections(CommonUtils.getOption(parameters.getSettings(), "openNewConnection"));
|
||||
producerSettings.setOpenNewConnections(CommonUtils.getOption(parameters.getDbProducerSettings(), "openNewConnection"));
|
||||
|
||||
producer.transferData(monitor, consumer, null, producerSettings, null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user