提交 5cee28a0 编写于 作者: S Serge Rider

#5384 Virtual FKs in ERD


Former-commit-id: 22f5606c
上级 c4359c23
......@@ -30,6 +30,7 @@ import org.jkiss.dbeaver.model.exec.DBExecUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.IActiveWorkbenchPart;
import org.jkiss.dbeaver.ui.LoadingJob;
......@@ -246,7 +247,7 @@ public class ERDEditorEmbedded extends ERDEditorPart implements IDatabaseEditor,
result.add(rootTable);
try {
monitor.subTask("Read foreign keys");
Collection<? extends DBSEntityAssociation> fks = rootTable.getAssociations(monitor);
Collection<? extends DBSEntityAssociation> fks = DBVUtils.getAllAssociations(monitor, rootTable);
if (fks != null) {
for (DBSEntityAssociation fk : fks) {
DBSEntity associatedEntity = fk.getAssociatedEntity();
......@@ -264,7 +265,7 @@ public class ERDEditorEmbedded extends ERDEditorPart implements IDatabaseEditor,
}
try {
monitor.subTask("Read references");
Collection<? extends DBSEntityAssociation> refs = rootTable.getReferences(monitor);
Collection<? extends DBSEntityAssociation> refs = DBVUtils.getAllReferences(monitor, rootTable);
if (refs != null) {
for (DBSEntityAssociation ref : refs) {
result.add(ref.getParentObject());
......
......@@ -31,6 +31,7 @@ import org.jkiss.dbeaver.ext.erd.editor.ERDEditPartFactory;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.utils.CommonUtils;
......@@ -146,12 +147,12 @@ public class ERDDecoratorDefault implements ERDDecorator {
if (attributeVisibility == ERDAttributeVisibility.KEYS) {
keyColumns = new HashSet<>();
try {
for (DBSEntityAssociation assoc : CommonUtils.safeCollection(entity.getAssociations(monitor))) {
for (DBSEntityAssociation assoc : DBVUtils.getAllAssociations(monitor, entity)) {
if (assoc instanceof DBSEntityReferrer) {
keyColumns.addAll(DBUtils.getEntityAttributes(monitor, (DBSEntityReferrer) assoc));
}
}
for (DBSEntityConstraint constraint : CommonUtils.safeCollection(entity.getConstraints(monitor))) {
for (DBSEntityConstraint constraint : DBVUtils.getAllConstraints(monitor, entity)) {
if (constraint instanceof DBSEntityReferrer) {
keyColumns.addAll(DBUtils.getEntityAttributes(monitor, (DBSEntityReferrer) constraint));
}
......
......@@ -28,6 +28,7 @@ import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.utils.CommonUtils;
import java.util.*;
......@@ -156,7 +157,7 @@ public class ERDEntity extends ERDElement<DBSEntity> {
try {
Set<DBSEntityAttribute> fkAttrs = new HashSet<>();
// Make associations
Collection<? extends DBSEntityAssociation> fks = getObject().getAssociations(monitor);
Collection<? extends DBSEntityAssociation> fks = DBVUtils.getAllAssociations(monitor, getObject());
if (fks != null) {
for (DBSEntityAssociation fk : fks) {
if (fk instanceof DBSEntityReferrer) {
......
......@@ -249,6 +249,26 @@ public abstract class DBVUtils {
return result;
}
@NotNull
public static List<DBSEntityAssociation> getAllReferences(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity onEntity) throws DBException {
List<DBSEntityAssociation> result = new ArrayList<>();
final Collection<? extends DBSEntityAssociation> realConstraints = onEntity.getReferences(monitor);
if (!CommonUtils.isEmpty(realConstraints)) {
result.addAll(realConstraints);
}
/*
DBVEntity vEntity = getVirtualEntity(entity, false);
if (vEntity != null) {
List<DBVEntityForeignKey> vFKs = vEntity.getForeignKeys();
if (!CommonUtils.isEmpty(vFKs)) {
result.addAll(vFKs);
}
}
*/
return result;
}
@NotNull
public static DBSEntity getRealEntity(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity entity) throws DBException {
if (entity instanceof DBVEntity) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册