diff --git a/config/sample-databases/DefaultConfiguration/cloudbeaver.conf b/config/sample-databases/DefaultConfiguration/cloudbeaver.conf index c534259957..d436fb50d1 100644 --- a/config/sample-databases/DefaultConfiguration/cloudbeaver.conf +++ b/config/sample-databases/DefaultConfiguration/cloudbeaver.conf @@ -46,7 +46,9 @@ dataExportFileSizeLimit: 10000000, sqlMaxRunningQueries: 100, sqlResultSetRowsLimit: 100000, - sqlResultSetMemoryLimit: 2000000 + sqlResultSetMemoryLimit: 2000000, + sqlTextPreviewMaxLength: 4096, + sqlBinaryPreviewMaxLength: 261120, }, disabledDrivers: [ diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/service/sql/WebSQLConstants.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/service/sql/WebSQLConstants.java index 434eb10ba8..ec5a2ea1b1 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/service/sql/WebSQLConstants.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/service/sql/WebSQLConstants.java @@ -24,9 +24,11 @@ public class WebSQLConstants { public static final String QUOTA_PROP_ROW_LIMIT = "sqlResultSetRowsLimit"; public static final String QUOTA_PROP_MEMORY_LIMIT = "sqlResultSetMemoryLimit"; public static final String QUOTA_PROP_QUERY_LIMIT = "sqlMaxRunningQueries"; + public static final String QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH = "sqlTextPreviewMaxLength"; + public static final String QUOTA_PROP_BINARY_PREVIEW_MAX_LENGTH = "sqlBinaryPreviewMaxLength"; - public static final int BINARY_PREVIEW_LENGTH = 255; - public static final int BINARY_MAX_LENGTH = 1 * 1024 * 1024; + public static final int TEXT_PREVIEW_MAX_LENGTH = 4 * 1024; + public static final int BINARY_PREVIEW_MAX_LENGTH = 255 * 1024; public static final String VALUE_TYPE_ATTR = "$type"; diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBAppConfig.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBAppConfig.java index afd385e881..63776e94ae 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBAppConfig.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBAppConfig.java @@ -294,6 +294,14 @@ public class CBAppConfig implements WebAppConfiguration { return (T) resourceQuotas.get(quotaId); } + public T getResourceQuota(String quotaId, T defaultValue) { + if (resourceQuotas.containsKey(quotaId)) { + return (T) resourceQuotas.get(quotaId); + } else { + return defaultValue; + } + } + //////////////////////////////////////////// // Auth provider configs diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLUtils.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLUtils.java index 5c52ccd753..964f65ee6d 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLUtils.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLUtils.java @@ -18,9 +18,10 @@ package io.cloudbeaver.service.sql; import io.cloudbeaver.model.session.WebSession; import io.cloudbeaver.registry.WebServiceRegistry; +import io.cloudbeaver.server.CBAppConfig; +import io.cloudbeaver.server.CBApplication; import io.cloudbeaver.utils.CBModelConstants; import org.jkiss.code.NotNull; -import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.model.data.*; import org.jkiss.dbeaver.model.data.storage.ExternalContentStorage; @@ -41,7 +42,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.*; /** @@ -156,14 +156,25 @@ public class WebSQLUtils { byte[] binaryValue = ContentUtils.getContentBinaryValue(session.getProgressMonitor(), value); if (binaryValue != null) { byte[] previewValue = binaryValue; - if (previewValue.length > WebSQLConstants.BINARY_PREVIEW_LENGTH) { - previewValue = Arrays.copyOf(previewValue, WebSQLConstants.BINARY_PREVIEW_LENGTH); + // gets parameters from the configuration file + CBAppConfig config = CBApplication.getInstance().getAppConfiguration(); + // the max length of the text preview + int textPreviewMaxLength = CommonUtils.toInt( + config.getResourceQuota( + WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH, + WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH)); + if (previewValue.length > textPreviewMaxLength) { + previewValue = Arrays.copyOf(previewValue, textPreviewMaxLength); } map.put(WebSQLConstants.ATTR_TEXT, GeneralUtils.convertToString(previewValue, 0, previewValue.length)); - + // the max length of the binary preview + int binaryPreviewMaxLength = CommonUtils.toInt( + config.getResourceQuota( + WebSQLConstants.QUOTA_PROP_BINARY_PREVIEW_MAX_LENGTH, + WebSQLConstants.BINARY_PREVIEW_MAX_LENGTH)); byte[] inlineValue = binaryValue; - if (inlineValue.length > WebSQLConstants.BINARY_MAX_LENGTH) { - inlineValue = Arrays.copyOf(inlineValue, WebSQLConstants.BINARY_PREVIEW_LENGTH); + if (inlineValue.length > binaryPreviewMaxLength) { + inlineValue = Arrays.copyOf(inlineValue, textPreviewMaxLength); } map.put(WebSQLConstants.ATTR_BINARY, Base64.encode(inlineValue)); } else {