From 2f4052ee8ab318a809b1f9bcdd701f257adab378 Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Thu, 1 Jun 2023 14:07:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dblob=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BC=96=E8=BE=91=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edittabledata/IEditTableExecuteQuery.java | 8 ++- .../mppdbide/utils/MPPDBIDEConstants.java | 12 ++++ .../component/grid/DSGridToolTipProvider.java | 38 +++++++++--- .../DSHtmlEscapedMarkupDisplayConverter.java | 37 +++++++----- .../grid/EditTableGridStyleConfiguration.java | 20 +++++-- .../grid/GridSelectionLayerPortData.java | 12 ++++ .../view/component/grid/GridViewPortData.java | 58 ++++++++++++------- .../grid/IEditTableGridStyleLabelFactory.java | 15 +++++ 8 files changed, 150 insertions(+), 50 deletions(-) diff --git a/code/datastudio/src/org.opengauss.mppdbide.presentation/src/org/opengauss/mppdbide/presentation/edittabledata/IEditTableExecuteQuery.java b/code/datastudio/src/org.opengauss.mppdbide.presentation/src/org/opengauss/mppdbide/presentation/edittabledata/IEditTableExecuteQuery.java index 401626d0..d2dcc74e 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.presentation/src/org/opengauss/mppdbide/presentation/edittabledata/IEditTableExecuteQuery.java +++ b/code/datastudio/src/org.opengauss.mppdbide.presentation/src/org/opengauss/mppdbide/presentation/edittabledata/IEditTableExecuteQuery.java @@ -303,14 +303,18 @@ public interface IEditTableExecuteQuery { */ static Blob convertToBlob(Connection con, Object value) { - if (null == value || !(value instanceof byte[])) { + if (value == null || !(value instanceof byte[] || value instanceof String)) { return null; } Blob createBlob = null; try { createBlob = con.createBlob(); - createBlob.setBytes(1, (byte[]) value); + if (value instanceof byte[]) { + createBlob.setBytes(1, (byte[]) value); + } else { + createBlob.setBytes(1, ((String) value).getBytes()); + } } catch (SQLException exception) { MPPDBIDELoggerUtility.error("Failed to convert bytes to blob object", exception); } diff --git a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/MPPDBIDEConstants.java b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/MPPDBIDEConstants.java index f4d8566b..8e9c4486 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/MPPDBIDEConstants.java +++ b/code/datastudio/src/org.opengauss.mppdbide.utils/src/org/opengauss/mppdbide/utils/MPPDBIDEConstants.java @@ -412,6 +412,18 @@ public interface MPPDBIDEConstants { String BLOB = "BLOB"; String BLOB_WATERMARK = "[BLOB]"; + + String TINYBLOB = "TINYBLOB"; + + String TINYBLOB_WATERMARK = "[TINYBLOB]"; + + String MEDIUMBLOB = "MEDIUMBLOB"; + + String MEDIUMBLOB_WATERMARK = "[MEIDUMBLOB]"; + + String LONGBLOB = "LONGBLOB"; + + String LONGBLOB_WATERMARK = "[LONGBLOB]"; String BYTEA = "bytea"; diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/DSGridToolTipProvider.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/DSGridToolTipProvider.java index a6daeb8e..08243139 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/DSGridToolTipProvider.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/DSGridToolTipProvider.java @@ -149,8 +149,19 @@ public class DSGridToolTipProvider extends NatTableContentTooltip { String convertedDataType = CellDisplayConversionUtils.convertDataType(cell, getToolTipConfigRegistry()); String columnDataType = dataProvider.getColumnDataProvider().getColumnDataTypeName(cell.getColumnIndex()); - if (MPPDBIDEConstants.BLOB.equalsIgnoreCase(columnDataType) && !convertedDataType.isEmpty()) { - return MPPDBIDEConstants.BLOB_WATERMARK; + if (!convertedDataType.isEmpty()) { + if (MPPDBIDEConstants.BLOB.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.BLOB_WATERMARK; + } + if (MPPDBIDEConstants.TINYBLOB.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.TINYBLOB_WATERMARK; + } + if (MPPDBIDEConstants.MEDIUMBLOB.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.MEDIUMBLOB_WATERMARK; + } + if (MPPDBIDEConstants.LONGBLOB.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.LONGBLOB_WATERMARK; + } } Object cellValue = cell.getDataValue(); int dataType = dataProvider.getColumnDataProvider().getColumnDatatype(cell.getColumnIndex()); @@ -199,13 +210,24 @@ public class DSGridToolTipProvider extends NatTableContentTooltip { } private String getToolTipForLabelAsBody(String convertedDataType, String columnDataType) { - if (MPPDBIDEConstants.BLOB.equalsIgnoreCase(columnDataType) && !convertedDataType.isEmpty()) { - return MPPDBIDEConstants.BLOB_WATERMARK; - } else if (MPPDBIDEConstants.BYTEA.equalsIgnoreCase(columnDataType) && !convertedDataType.isEmpty()) { - return MPPDBIDEConstants.BYTEA_WATERMARK; - } else { - return getConvertedColumnData(convertedDataType, columnDataType); + if (!convertedDataType.isEmpty()) { + if (MPPDBIDEConstants.BLOB.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.BLOB_WATERMARK; + } + if (MPPDBIDEConstants.TINYBLOB.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.TINYBLOB_WATERMARK; + } + if (MPPDBIDEConstants.MEDIUMBLOB.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.MEDIUMBLOB_WATERMARK; + } + if (MPPDBIDEConstants.LONGBLOB.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.LONGBLOB_WATERMARK; + } + if (MPPDBIDEConstants.BYTEA.equalsIgnoreCase(columnDataType)) { + return MPPDBIDEConstants.BYTEA_WATERMARK; + } } + return getConvertedColumnData(convertedDataType, columnDataType); } private String getExplainAnalyzePlanTooltip(ILayerCell cell, LabelStack cellLabels) { diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/DSHtmlEscapedMarkupDisplayConverter.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/DSHtmlEscapedMarkupDisplayConverter.java index eb8c76b3..e7508303 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/DSHtmlEscapedMarkupDisplayConverter.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/DSHtmlEscapedMarkupDisplayConverter.java @@ -69,22 +69,29 @@ public class DSHtmlEscapedMarkupDisplayConverter extends MarkupDisplayConverter Object canonicalValue = canonicalValueParam; IDSGridDataProvider dataProvider = dataGridContext.getDataProvider(); - if (Types.OTHER == dataProvider.getColumnDataProvider() - .getColumnDatatype(dataProvider.getColumnDataProvider().getColumnCount() - 1) - && canonicalValueParam != null && canonicalValue instanceof List) { - return MPPDBIDEConstants.CURSOR_WATERMARK; + if (canonicalValueParam != null) { + if (Types.OTHER == dataProvider.getColumnDataProvider() + .getColumnDatatype(dataProvider.getColumnDataProvider().getColumnCount() - 1) + && canonicalValue instanceof List) { + return MPPDBIDEConstants.CURSOR_WATERMARK; - } - - if (MPPDBIDEConstants.BLOB - .equalsIgnoreCase(dataProvider.getColumnDataProvider().getColumnDataTypeName(cell.getColumnIndex())) - && canonicalValueParam != null) { - return MPPDBIDEConstants.BLOB_WATERMARK; - } - if (MPPDBIDEConstants.BYTEA - .equalsIgnoreCase(dataProvider.getColumnDataProvider().getColumnDataTypeName(cell.getColumnIndex())) - && canonicalValueParam != null) { - return MPPDBIDEConstants.BYTEA_WATERMARK; + } + String colTypeName = dataProvider.getColumnDataProvider().getColumnDataTypeName(cell.getColumnIndex()); + if (MPPDBIDEConstants.BLOB.equalsIgnoreCase(colTypeName)) { + return MPPDBIDEConstants.BLOB_WATERMARK; + } + if (MPPDBIDEConstants.TINYBLOB.equalsIgnoreCase(colTypeName)) { + return MPPDBIDEConstants.TINYBLOB_WATERMARK; + } + if (MPPDBIDEConstants.MEDIUMBLOB.equalsIgnoreCase(colTypeName)) { + return MPPDBIDEConstants.MEDIUMBLOB_WATERMARK; + } + if (MPPDBIDEConstants.LONGBLOB.equalsIgnoreCase(colTypeName)) { + return MPPDBIDEConstants.LONGBLOB_WATERMARK; + } + if (MPPDBIDEConstants.BYTEA.equalsIgnoreCase(colTypeName)) { + return MPPDBIDEConstants.BYTEA_WATERMARK; + } } if (dataProvider instanceof DSObjectPropertiesGridDataProvider && canonicalValue == null) { diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/EditTableGridStyleConfiguration.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/EditTableGridStyleConfiguration.java index dbfc8aae..b817d2bf 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/EditTableGridStyleConfiguration.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/EditTableGridStyleConfiguration.java @@ -77,6 +77,7 @@ public class EditTableGridStyleConfiguration extends AbstractRegistryConfigurati implements IEditTableGridStyleLabelFactory { private static final String COL_LABEL_TIMESTAMP = "TIMESTAMP"; private static HashSet extraTypes = new HashSet<>(); + private static HashMap typeCell = new HashMap<>(); static { @@ -93,6 +94,10 @@ public class EditTableGridStyleConfiguration extends AbstractRegistryConfigurati extraTypes.add("point"); extraTypes.add("polygon"); extraTypes.add("binary"); + + typeCell.put(MPPDBIDEConstants.TINYBLOB, COL_LABEL_TINYBLOB_TYPE_CELL); + typeCell.put(MPPDBIDEConstants.MEDIUMBLOB, COL_LABEL_MEDIUMBLOB_TYPE_CELL); + typeCell.put(MPPDBIDEConstants.LONGBLOB, COL_LABEL_LONGBLOB_TYPE_CELL); } /** * Configure registry. @@ -385,7 +390,7 @@ public class EditTableGridStyleConfiguration extends AbstractRegistryConfigurati private void handleCommonColumnConfigureForBlob(IConfigRegistry configRegistry, IDSGridDataProvider dataProvider, int i) { if (MPPDBIDEConstants.BLOB.equals(dataProvider.getColumnDataProvider().getColumnDataTypeName(i))) { - blobConfiguration(configRegistry, dataProvider); + blobConfiguration(configRegistry, dataProvider, COL_LABEL_BLOB_TYPE_CELL); } else { configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new DSTextCellEditor(), DisplayMode.NORMAL, COL_LABEL_COPY_READONLY_CELL); @@ -395,6 +400,11 @@ public class EditTableGridStyleConfiguration extends AbstractRegistryConfigurati private void handleCommonColumnConfigureForOther(IConfigRegistry configRegistry, IDSGridDataProvider dataProvider, HashMap dolphinTypes, int i) { String colDatatypeName = dataProvider.getColumnDataProvider().getColumnDataTypeName(i); + String cell = typeCell.get(colDatatypeName); + if (cell != null) { + blobConfiguration(configRegistry, dataProvider, cell); + return; + } if (extraTypes.contains(colDatatypeName) || (dolphinTypes != null && dolphinTypes.containsKey(colDatatypeName))) { configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new DSTextCellEditor(), @@ -422,11 +432,13 @@ public class EditTableGridStyleConfiguration extends AbstractRegistryConfigurati * * @param configRegistry the config registry * @param dataProvider the data provider + * @param cell the data label */ - public static void blobConfiguration(IConfigRegistry configRegistry, IDSGridDataProvider dataProvider) { + public static void blobConfiguration(IConfigRegistry configRegistry, IDSGridDataProvider dataProvider, + String cell) { configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new DSBlobCellEditor(), - DisplayMode.NORMAL, COL_LABEL_BLOB_TYPE_CELL); - linkStyleConfiguration(configRegistry, COL_LABEL_BLOB_TYPE_CELL); + DisplayMode.NORMAL, cell); + linkStyleConfiguration(configRegistry, cell); } /** diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/GridSelectionLayerPortData.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/GridSelectionLayerPortData.java index 14875ba1..96a7c4b7 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/GridSelectionLayerPortData.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/GridSelectionLayerPortData.java @@ -193,6 +193,18 @@ public class GridSelectionLayerPortData { cellDataValue[i + 1] = MPPDBIDEConstants.BLOB_WATERMARK; continue; } + case MPPDBIDEConstants.TINYBLOB: { + cellDataValue[i + 1] = MPPDBIDEConstants.TINYBLOB_WATERMARK; + continue; + } + case MPPDBIDEConstants.MEDIUMBLOB: { + cellDataValue[i + 1] = MPPDBIDEConstants.MEDIUMBLOB_WATERMARK; + continue; + } + case MPPDBIDEConstants.LONGBLOB: { + cellDataValue[i + 1] = MPPDBIDEConstants.LONGBLOB_WATERMARK; + continue; + } case MPPDBIDEConstants.BYTEA: { cellDataValue[i + 1] = MPPDBIDEConstants.BYTEA_WATERMARK; continue; diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/GridViewPortData.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/GridViewPortData.java index 513055ad..293a9e21 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/GridViewPortData.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/GridViewPortData.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.NoSuchElementException; import org.eclipse.nebula.widgets.nattable.layer.ILayer; +import org.eclipse.nebula.widgets.nattable.layer.LabelStack; import org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand; import org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOnCommand; import org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider; @@ -147,29 +148,44 @@ public class GridViewPortData implements Iterable { // As we operate on Grid Layer, Skip the row number column for (int i = 1; i < this.colCount; i++) { - // If the datatype is Blob, [BLOB] watermark is added - // instead of the content since it can be huge - if (this.viewport.getConfigLabelsByPosition(i, this.dataReadIndex) - .hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_BLOB_TYPE_CELL) - && this.viewport.getDataValueByPosition(i, this.dataReadIndex) != null) { - rowData[i - 1] = MPPDBIDEConstants.BLOB_WATERMARK; - continue; - } + Object dataValue = this.viewport.getDataValueByPosition(i, this.dataReadIndex); + if (dataValue != null) { + LabelStack stack = this.viewport.getConfigLabelsByPosition(i, this.dataReadIndex); + + // If the datatype is Blob, [BLOB] watermark is added + // instead of the content since it can be huge + if (stack.hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_BLOB_TYPE_CELL)) { + rowData[i - 1] = MPPDBIDEConstants.BLOB_WATERMARK; + continue; + } - if (this.viewport.getConfigLabelsByPosition(i, this.dataReadIndex) - .hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_CURSOR_TYPE_CELL) - && this.viewport.getDataValueByPosition(i, this.dataReadIndex) != null - && this.viewport.getDataValueByPosition(i, this.dataReadIndex) instanceof List) { - rowData[i - 1] = MPPDBIDEConstants.CURSOR_WATERMARK; - continue; - } - if (this.viewport.getConfigLabelsByPosition(i, this.dataReadIndex) - .hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_BYTEA_TYPE_CELL) - && this.viewport.getDataValueByPosition(i, this.dataReadIndex) != null) { - rowData[i - 1] = MPPDBIDEConstants.BYTEA_WATERMARK; - continue; + if (stack.hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_TINYBLOB_TYPE_CELL)) { + rowData[i - 1] = MPPDBIDEConstants.TINYBLOB_WATERMARK; + continue; + } + + if (stack.hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_MEDIUMBLOB_TYPE_CELL)) { + rowData[i - 1] = MPPDBIDEConstants.MEDIUMBLOB_WATERMARK; + continue; + } + + if (stack.hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_LONGBLOB_TYPE_CELL)) { + rowData[i - 1] = MPPDBIDEConstants.LONGBLOB_WATERMARK; + continue; + } + + if (stack.hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_CURSOR_TYPE_CELL) + && dataValue instanceof List) { + rowData[i - 1] = MPPDBIDEConstants.CURSOR_WATERMARK; + continue; + } + + if (stack.hasLabel(IEditTableGridStyleLabelFactory.COL_LABEL_BYTEA_TYPE_CELL)) { + rowData[i - 1] = MPPDBIDEConstants.BYTEA_WATERMARK; + continue; + } } - rowData[i - 1] = getObjectString(this.viewport.getDataValueByPosition(i, this.dataReadIndex)); + rowData[i - 1] = getObjectString(dataValue); } this.dataReadIndex++; return rowData; diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/IEditTableGridStyleLabelFactory.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/IEditTableGridStyleLabelFactory.java index 74e3f9c7..6fbe1990 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/IEditTableGridStyleLabelFactory.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/component/grid/IEditTableGridStyleLabelFactory.java @@ -159,6 +159,21 @@ public interface IEditTableGridStyleLabelFactory { */ String COL_LABEL_BLOB_TYPE_CELL = "COL_LABEL_BLOB_TYPE_CELL"; + /** + * The col label tinyblob type cell. + */ + String COL_LABEL_TINYBLOB_TYPE_CELL = "COL_LABEL_TINYBLOB_TYPE_CELL"; + + /** + * The col label mediumblob type cell. + */ + String COL_LABEL_MEDIUMBLOB_TYPE_CELL = "COL_LABEL_MEDIUMBLOB_TYPE_CELL"; + + /** + * The col label longblob type cell. + */ + String COL_LABEL_LONGBLOB_TYPE_CELL = "COL_LABEL_LONGBLOB_TYPE_CELL"; + /** * The col label cursor type cell. */ -- Gitee