提交 43e91fed 编写于 作者: S serge-rider

dbeaver/dbeaver#342 Data comparator


Former-commit-id: 6bcd1a3f
上级 a8f8511e
......@@ -33,6 +33,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* Row identifier.
......@@ -105,4 +106,10 @@ public class DBDRowIdentifier implements DBPObject {
public void clearAttributes() {
attributes.clear();
}
@Override
public String toString() {
return entity.getName() + "." + entityIdentifier.getName() + "(" +
attributes.stream().map(DBDAttributeBinding::getName).collect(Collectors.joining(",")) + ")";
}
}
......@@ -279,6 +279,17 @@ public class ResultSetModel {
return null;
}
@Nullable
public DBDRowIdentifier getDefaultRowIdentifier() {
for (DBDAttributeBinding column : attributes) {
DBDRowIdentifier rowIdentifier = column.getRowIdentifier();
if (rowIdentifier != null) {
return rowIdentifier;
}
}
return null;
}
void refreshValueHandlersConfiguration() {
for (DBDAttributeBinding binding : attributes) {
DBDValueHandler valueHandler = binding.getValueHandler();
......
......@@ -188,7 +188,7 @@ class ResultSetPersister {
// Nothing to refresh
return false;
}
final DBDRowIdentifier rowIdentifier = getDefaultRowIdentifier();
final DBDRowIdentifier rowIdentifier = model.getDefaultRowIdentifier();
if (rowIdentifier == null || rowIdentifier.getAttributes().isEmpty()) {
// No key - can't refresh
return false;
......@@ -256,7 +256,7 @@ class ResultSetPersister {
private void prepareDeleteStatements(@NotNull DBRProgressMonitor monitor, boolean deleteCascade, boolean deepCascade)
throws DBException {
// Make delete statements
DBDRowIdentifier rowIdentifier = getDefaultRowIdentifier();
DBDRowIdentifier rowIdentifier = model.getDefaultRowIdentifier();
if (rowIdentifier == null) {
throw new DBCException("Internal error: can't find entity identifier, delete is not possible");
}
......@@ -497,17 +497,6 @@ class ResultSetPersister {
}
}
@Nullable
public DBDRowIdentifier getDefaultRowIdentifier() {
for (DBDAttributeBinding column : columns) {
DBDRowIdentifier rowIdentifier = column.getRowIdentifier();
if (rowIdentifier != null) {
return rowIdentifier;
}
}
return null;
}
@NotNull
private DBSDataManipulator getDataManipulator(DBSEntity entity) throws DBCException {
if (entity instanceof DBSDataManipulator) {
......@@ -550,7 +539,7 @@ class ResultSetPersister {
List<DBDAttributeBinding> updatedAttributes = this.getUpdatedAttributes();
if (this.hasDeletes()) {
DBDRowIdentifier defIdentifier = this.getDefaultRowIdentifier();
DBDRowIdentifier defIdentifier = model.getDefaultRowIdentifier();
if (defIdentifier == null) {
throw new DBCException("No unique row identifier is result set. Cannot proceed with row(s) delete.");
} else if (!defIdentifier.isValidIdentifier()) {
......@@ -584,7 +573,7 @@ class ResultSetPersister {
private DBCSavepoint savepoint;
private Throwable error;
protected DataUpdaterJob(boolean generateScript, @NotNull ResultSetSaveSettings settings, @Nullable DataUpdateListener listener, @NotNull DBCExecutionContext executionContext) {
DataUpdaterJob(boolean generateScript, @NotNull ResultSetSaveSettings settings, @Nullable DataUpdateListener listener, @NotNull DBCExecutionContext executionContext) {
super(ResultSetMessages.controls_resultset_viewer_job_update, executionContext);
this.generateScript = generateScript;
this.settings = settings;
......
......@@ -108,14 +108,14 @@ public class ResultSetRow {
return changes != null && changes.containsKey(attr);
}
void addChange(DBDAttributeBinding attr, @Nullable Object oldValue) {
public void addChange(DBDAttributeBinding attr, @Nullable Object oldValue) {
if (changes == null) {
changes = new IdentityHashMap<>();
}
changes.put(attr, oldValue);
}
void resetChange(DBDAttributeBinding attr) {
public void resetChange(DBDAttributeBinding attr) {
assert changes != null;
changes.remove(attr);
if (changes.isEmpty()) {
......
......@@ -1815,6 +1815,16 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
}
}
switch (row.getState()) {
case ResultSetRow.STATE_ADDED:
return backgroundAdded;
case ResultSetRow.STATE_REMOVED:
return backgroundDeleted;
}
if (row.changes != null && row.changes.containsKey(attribute)) {
return backgroundModified;
}
Color bg = controller.getLabelProvider().getCellBackground(attribute, row);
if (bg != null) {
return bg;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册