diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/service/sql/WebSQLResultsInfo.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/service/sql/WebSQLResultsInfo.java index 3fd68da3c2..77a3aeae1b 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/service/sql/WebSQLResultsInfo.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/service/sql/WebSQLResultsInfo.java @@ -22,9 +22,7 @@ import org.jkiss.dbeaver.model.DBUtils; import org.jkiss.dbeaver.model.data.DBDAttributeBinding; import org.jkiss.dbeaver.model.data.DBDRowIdentifier; -import org.jkiss.dbeaver.model.struct.DBSAttributeBase; -import org.jkiss.dbeaver.model.struct.DBSDataContainer; -import org.jkiss.dbeaver.model.struct.DBSTypedObject; +import org.jkiss.dbeaver.model.struct.*; import java.util.HashSet; import java.util.List; @@ -126,4 +124,12 @@ public DBSTypedObject getAttributeByPosition(int pos) { return null; } + public boolean canRefreshResults() { + DBSEntity entity = getDefaultRowIdentifier().getEntity(); + // FIXME: do not refresh documents for now. Can be solved by extracting document ID attributes + // FIXME: but it will require to provide dynamic document metadata. + return entity == null || entity.getDataSource() == null || + (!(entity instanceof DBSDocumentContainer) && !entity.getDataSource().getInfo().isDynamicMetadata()); + } + } 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 eef4bc19f6..c58d93e43a 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 @@ -58,6 +58,7 @@ import java.nio.file.Path; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; /** * Web SQL processor. @@ -417,13 +418,22 @@ private void getUpdatedRowsInfo( DBCExecutionPurpose.UTIL, "Refresh row(s) after insert/update") ) { + boolean canRefreshResults = resultsInfo.canRefreshResults(); for (Object[] row : newResultSetRows) { if (row.length == 0) { continue; } + if (!canRefreshResults) { + makeWebCellRow(resultsInfo, row, dataFormat); + continue; + } List constraints = new ArrayList<>(); boolean hasKey = true; - for (DBDAttributeBinding attr : resultsInfo.getAttributes()) { + // get attributes only from row identifiers + Set idAttributes = resultsInfo.getRowIdentifiers().stream() + .flatMap(r -> r.getAttributes().stream()) + .collect(Collectors.toSet()); + for (DBDAttributeBinding attr : idAttributes) { if (attr.getRowIdentifier() == null) { continue; } @@ -439,6 +449,7 @@ private void getUpdatedRowsInfo( } if (!hasKey) { // No key value for this row + makeWebCellRow(resultsInfo, row, dataFormat); continue; } DBDDataFilter filter = new DBDDataFilter(constraints); @@ -457,6 +468,20 @@ private void getUpdatedRowsInfo( } } + private void makeWebCellRow( + @NotNull WebSQLResultsInfo resultsInfo, + @NotNull Object[] row, + @Nullable WebDataFormat dataFormat + ) throws DBCException { + for (int i = 0; i < row.length; i++) { + row[i] = WebSQLUtils.makeWebCellValue( + webSession, + resultsInfo.getAttributeByPosition(i), + row[i], + dataFormat); + } + } + public String generateResultsDataUpdateScript( @NotNull DBRProgressMonitor monitor, @NotNull WebSQLContextInfo contextInfo,