Merge branch 'devel' of https://github.com/dbeaver/cloudbeaver into devel

This commit is contained in:
Wroud
2021-06-08 20:33:58 +03:00
3 changed files with 44 additions and 14 deletions
@@ -385,6 +385,7 @@ public class WebSQLProcessor {
for (int i = 0; i < updateAttributes.length; i++) {
DBDAttributeBinding updateAttribute = updateAttributes[i];
Object cellRawValue = updateValues.get(String.valueOf(updateAttribute.getOrdinalPosition()));
cellRawValue = WebSQLUtils.makePlainCellValue(cellRawValue);
Object realCellValue = updateAttribute.getValueHandler().getValueFromObject(session, updateAttribute, cellRawValue, false, true);
rowValues[i] = realCellValue;
finalRow[updateAttribute.getOrdinalPosition()] = WebSQLUtils.makeWebCellValue(webSession, null, realCellValue, dataFormat);
@@ -46,6 +46,16 @@ public class WebSQLUtils {
public static final int BINARY_PREVIEW_LENGTH = 255;
public static final int BINARY_MAX_LENGTH = 1 * 1024 * 1024;
public static final String VALUE_TYPE_ATTR = "$type";
public static final String VALUE_TYPE_COLLECTION = "collection";
public static final String VALUE_TYPE_MAP = "map";
public static final String VALUE_TYPE_DOCUMENT = "document";
public static final String VALUE_TYPE_CONTENT = "content";
public static final String VALUE_TYPE_GEOMETRY = "geometry";
public static final String ATTR_TEXT = "text";
public static final String ATTR_BINARY = "binary";
public static Object makeWebCellValue(WebSession session, DBSTypedObject type, Object cellValue, WebDataFormat dataFormat) throws DBCException {
if (cellValue instanceof Date) {
return CBConstants.ISO_DATE_FORMAT.format(cellValue);
@@ -77,7 +87,7 @@ public class WebSQLUtils {
items[i] = makeWebCellValue(session, collection.getComponentType(), collection.getItem(i), dataFormat);
}
Map<String, Object> map = createMapOfType("collection");
Map<String, Object> map = createMapOfType(VALUE_TYPE_COLLECTION);
map.put("value", items);
return map;
} else if (value instanceof DBDComposite) {
@@ -87,7 +97,7 @@ public class WebSQLUtils {
struct.put(attr.getName(), makeWebCellValue(session, attr, composite.getAttributeValue(attr), dataFormat));
}
Map<String, Object> map = createMapOfType("map");
Map<String, Object> map = createMapOfType(VALUE_TYPE_MAP);
map.put("value", struct);
return map;
}
@@ -97,7 +107,7 @@ public class WebSQLUtils {
@NotNull
private static Map<String, Object> createMapOfType(String type) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("$type", type);
map.put(VALUE_TYPE_ATTR, type);
return map;
}
@@ -111,7 +121,7 @@ public class WebSQLUtils {
throw new DBCException("Error serializing document", e);
}
Map<String, Object> map = createMapOfType("document");
Map<String, Object> map = createMapOfType(VALUE_TYPE_DOCUMENT);
map.put("id", CommonUtils.toString(document.getDocumentId()));
map.put("contentType", document.getDocumentContentType());
map.put("properties", Collections.emptyMap());
@@ -121,27 +131,27 @@ public class WebSQLUtils {
private static Object serializeContentValue(WebSession session, DBDContent value) throws DBCException {
Map<String, Object> map = createMapOfType("content");
Map<String, Object> map = createMapOfType(VALUE_TYPE_CONTENT);
if (ContentUtils.isTextContent(value)) {
String stringValue = ContentUtils.getContentStringValue(session.getProgressMonitor(), value);
map.put("text", stringValue);
map.put(ATTR_TEXT, stringValue);
} else {
map.put("binary", true);
map.put(ATTR_BINARY, true);
byte[] binaryValue = ContentUtils.getContentBinaryValue(session.getProgressMonitor(), value);
if (binaryValue != null) {
byte[] previewValue = binaryValue;
if (previewValue.length > BINARY_PREVIEW_LENGTH) {
previewValue = Arrays.copyOf(previewValue, BINARY_PREVIEW_LENGTH);
}
map.put("text", GeneralUtils.convertToString(binaryValue, 0, binaryValue.length));
map.put(ATTR_TEXT, GeneralUtils.convertToString(binaryValue, 0, binaryValue.length));
byte[] inlineValue = binaryValue;
if (inlineValue.length > BINARY_MAX_LENGTH) {
inlineValue = Arrays.copyOf(inlineValue, BINARY_PREVIEW_LENGTH);
}
map.put("binary", Base64.encode(inlineValue));
map.put(ATTR_BINARY, Base64.encode(inlineValue));
} else {
map.put("text", null);
map.put(ATTR_TEXT, null);
}
}
map.put("contentType", value.getContentType());
@@ -150,9 +160,9 @@ public class WebSQLUtils {
}
private static Object serializeGeometryValue(DBGeometry value) {
Map<String, Object> map = createMapOfType("geometry");
Map<String, Object> map = createMapOfType(VALUE_TYPE_GEOMETRY);
map.put("srid", value.getSRID());
map.put("text", value.toString());
map.put(ATTR_TEXT, value.toString());
map.put("properties", value.getProperties());
DBGeometry xValue = GisTransformUtils.transformToSRID(value, GisConstants.SRID_4326);
@@ -162,4 +172,23 @@ public class WebSQLUtils {
return map;
}
public static Object makePlainCellValue(Object value) throws DBCException {
if (value instanceof Map) {
Map<String, Object> map = (Map<String, Object>) value;
Object typeAttr = map.get(VALUE_TYPE_ATTR);
if (typeAttr instanceof String) {
switch ((String)typeAttr) {
case VALUE_TYPE_CONTENT:
if (map.get(ATTR_BINARY) != null) {
throw new DBCException("Binary content edit is not supported yet");
}
value = map.get(ATTR_TEXT);
break;
default:
throw new DBCException("Type '" + typeAttr + "' edit is not supported yet");
}
}
}
return value;
}
}
+2 -2
View File
@@ -18,12 +18,12 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
<version>42.2.20</version>
</dependency>
<dependency>
<groupId>net.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
<version>2.2.1</version>
<version>2.5.0</version>
</dependency>
</dependencies>