Skip to content

Commit

Permalink
CB-4328 hotfix json values update (#2201)
Browse files Browse the repository at this point in the history
* CB-4328 get updated rows info only using key identifier attributes

* CB-4328 do not refresh row for nosql db
  • Loading branch information
yagudin10 authored Dec 5, 2023
1 parent 4ea74d9 commit e38a7a9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<DBDAttributeConstraint> constraints = new ArrayList<>();
boolean hasKey = true;
for (DBDAttributeBinding attr : resultsInfo.getAttributes()) {
// get attributes only from row identifiers
Set<DBDAttributeBinding> idAttributes = resultsInfo.getRowIdentifiers().stream()
.flatMap(r -> r.getAttributes().stream())
.collect(Collectors.toSet());
for (DBDAttributeBinding attr : idAttributes) {
if (attr.getRowIdentifier() == null) {
continue;
}
Expand All @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit e38a7a9

Please sign in to comment.