diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java index c64cd90374..64d27eb6ff 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java @@ -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); 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 517f693c76..9b3fbcfecf 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 @@ -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 map = createMapOfType("collection"); + Map 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 map = createMapOfType("map"); + Map map = createMapOfType(VALUE_TYPE_MAP); map.put("value", struct); return map; } @@ -97,7 +107,7 @@ public class WebSQLUtils { @NotNull private static Map createMapOfType(String type) { Map 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 map = createMapOfType("document"); + Map 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 map = createMapOfType("content"); + Map 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 map = createMapOfType("geometry"); + Map 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 map = (Map) 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; + } } diff --git a/server/drivers/postgresql/pom.xml b/server/drivers/postgresql/pom.xml index 9768530a95..c6e1b9c82b 100644 --- a/server/drivers/postgresql/pom.xml +++ b/server/drivers/postgresql/pom.xml @@ -18,12 +18,12 @@ org.postgresql postgresql - 42.2.5 + 42.2.20 net.postgis postgis-jdbc - 2.2.1 + 2.5.0