mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-1914 add binary value quotas to the configuration file (#765)
* CB-1914 add binary value quotas to the configuration file * CB-1914 formatting the configuration file * CB-1914 add default values to the resource quotas * CB-1914 add default values to the resource quotas * CB-1914 change default values of binary preview
This commit is contained in:
@@ -46,7 +46,9 @@
|
||||
dataExportFileSizeLimit: 10000000,
|
||||
sqlMaxRunningQueries: 100,
|
||||
sqlResultSetRowsLimit: 100000,
|
||||
sqlResultSetMemoryLimit: 2000000
|
||||
sqlResultSetMemoryLimit: 2000000,
|
||||
sqlTextPreviewMaxLength: 4096,
|
||||
sqlBinaryPreviewMaxLength: 261120,
|
||||
},
|
||||
|
||||
disabledDrivers: [
|
||||
|
||||
+4
-2
@@ -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";
|
||||
|
||||
|
||||
@@ -294,6 +294,14 @@ public class CBAppConfig implements WebAppConfiguration {
|
||||
return (T) resourceQuotas.get(quotaId);
|
||||
}
|
||||
|
||||
public <T> T getResourceQuota(String quotaId, T defaultValue) {
|
||||
if (resourceQuotas.containsKey(quotaId)) {
|
||||
return (T) resourceQuotas.get(quotaId);
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////
|
||||
// Auth provider configs
|
||||
|
||||
+18
-7
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user