提交 574774ee 编写于 作者: S Serge Rider

#1140 Use virtual unique key in resulset SQL generator.

上级 b0e65bc8
......@@ -32,6 +32,7 @@ import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.*;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.data.DBDRowIdentifier;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -154,7 +155,7 @@ public class GenerateSQLContributor extends CompoundContributionItem {
{
for (ResultSetRow firstRow : selectedRows) {
Collection<? extends DBSEntityAttribute> keyAttributes = getKeyAttributes(monitor, object);
Collection<DBDAttributeBinding> keyAttributes = getKeyAttributes(monitor, object);
sql.append("SELECT ");
boolean hasAttr = false;
for (DBSAttributeBase attr : getValueAttributes(monitor, object, keyAttributes)) {
......@@ -165,15 +166,10 @@ public class GenerateSQLContributor extends CompoundContributionItem {
sql.append("\nFROM ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
sql.append("\nWHERE ");
hasAttr = false;
for (DBSEntityAttribute attr : keyAttributes) {
for (DBDAttributeBinding binding : keyAttributes) {
if (hasAttr) sql.append(" AND ");
DBDAttributeBinding binding = rsv.getModel().getAttributeBinding(attr);
sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
if (binding == null) {
appendDefaultValue(sql, attr);
} else {
appendAttributeValue(rsv, sql, binding, firstRow);
}
sql.append(DBUtils.getObjectFullName(binding.getAttribute(), DBPEvaluationContext.DML)).append("=");
appendAttributeValue(rsv, sql, binding, firstRow);
hasAttr = true;
}
sql.append(";\n");
......@@ -223,19 +219,14 @@ public class GenerateSQLContributor extends CompoundContributionItem {
{
for (ResultSetRow firstRow : selectedRows) {
Collection<? extends DBSEntityAttribute> keyAttributes = getKeyAttributes(monitor, object);
Collection<DBDAttributeBinding> keyAttributes = getKeyAttributes(monitor, object);
sql.append("DELETE FROM ").append(DBUtils.getObjectFullName(entity, DBPEvaluationContext.DML));
sql.append("\nWHERE ");
boolean hasAttr = false;
for (DBSEntityAttribute attr : keyAttributes) {
for (DBDAttributeBinding binding : keyAttributes) {
if (hasAttr) sql.append(" AND ");
DBDAttributeBinding binding = rsv.getModel().getAttributeBinding(attr);
sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
if (binding == null) {
appendDefaultValue(sql, attr);
} else {
appendAttributeValue(rsv, sql, binding, firstRow);
}
sql.append(DBUtils.getObjectFullName(binding.getAttribute(), DBPEvaluationContext.DML)).append("=");
appendAttributeValue(rsv, sql, binding, firstRow);
hasAttr = true;
}
sql.append(";\n");
......@@ -379,14 +370,26 @@ public class GenerateSQLContributor extends CompoundContributionItem {
return object.getVisibleAttributes();
}
protected Collection<? extends DBSEntityAttribute> getKeyAttributes(DBRProgressMonitor monitor, ResultSetModel object) throws DBException
protected List<DBDAttributeBinding> getKeyAttributes(DBRProgressMonitor monitor, ResultSetModel object) throws DBException
{
final DBSEntity singleSource = object.getSingleSource();
if (singleSource == null) {
final DBDRowIdentifier rowIdentifier = getDefaultRowIdentifier(object);
if (rowIdentifier == null) {
return Collections.emptyList();
}
return DBUtils.getBestTableIdentifier(monitor, singleSource);
return rowIdentifier.getAttributes();
}
@Nullable
private DBDRowIdentifier getDefaultRowIdentifier(ResultSetModel object) {
for (DBDAttributeBinding attr : object.getAttributes()) {
DBDRowIdentifier rowIdentifier = attr.getRowIdentifier();
if (rowIdentifier != null) {
return rowIdentifier;
}
}
return null;
}
}
private static ContributionItem makeAction(String text, final DBRRunnableWithResult<String> runnable)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册