use of org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey in project dbeaver by serge-rider.
the class AssociationDeleteCommand method execute.
/**
* Removes the relationship
*/
@Override
public void execute() {
DBSEntityAssociation entityAssociation = association.getObject();
if (entityAssociation instanceof DBVEntityForeignKey) {
if (!UIUtils.confirmAction("Delete logical key", "Are you sure you want to delete logical key '" + part.getAssociation().getName() + "'?")) {
return;
}
DBVEntity vEntity = DBVUtils.getVirtualEntity(entityAssociation.getParentObject(), false);
if (vEntity == null) {
UIUtils.showMessageBox(UIUtils.getActiveWorkbenchShell(), "No virtual entity", "Can't find association owner virtual entity", SWT.ICON_ERROR);
return;
}
vEntity.removeForeignKey((DBVEntityForeignKey) entityAssociation);
}
part.markAssociatedAttributes(EditPart.SELECTED_NONE);
targetEntity.removeReferenceAssociation(association, true);
sourceEntity.removeAssociation(association, true);
association.setSourceEntity(null);
association.setTargetEntity(null);
}
use of org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey in project dbeaver by serge-rider.
the class AssociationCreateCommand method execute.
@Override
public void execute() {
if (sourceEntity instanceof ERDEntity && targetEntity instanceof ERDEntity) {
DBSEntity srcEntityObject = ((ERDEntity) sourceEntity).getObject();
DBSEntity targetEntityObject = ((ERDEntity) targetEntity).getObject();
List<DBSEntityAttribute> srcAttrs = ERDUtils.getObjectsFromERD(sourceAttributes);
List<DBSEntityAttribute> refAttrs = ERDUtils.getObjectsFromERD(targetAttributes);
DBVEntity vEntity = DBVUtils.getVirtualEntity(srcEntityObject, true);
DBVEntityForeignKey vfk = EditForeignKeyPage.createVirtualForeignKey(vEntity, targetEntityObject, new EditForeignKeyPage.FKType[] { EditForeignKeyPage.FK_TYPE_LOGICAL }, srcAttrs, refAttrs);
if (vfk == null) {
return;
}
vEntity.persistConfiguration();
association = new ERDAssociation(vfk, (ERDEntity) sourceEntity, (ERDEntity) targetEntity, true);
} else {
association = createAssociation(sourceEntity, targetEntity, true);
}
}
use of org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey in project dbeaver by serge-rider.
the class AssociationDeleteCommand method undo.
/**
* Restores the relationship
*/
@Override
public void undo() {
if (association.getSourceEntity() != null) {
return;
}
DBSEntityAssociation entityAssociation = association.getObject();
if (entityAssociation instanceof DBVEntityForeignKey) {
DBVEntity vEntity = DBVUtils.getVirtualEntity(entityAssociation.getParentObject(), false);
if (vEntity != null) {
vEntity.addForeignKey((DBVEntityForeignKey) entityAssociation);
}
}
association.setSourceEntity(sourceEntity);
association.setTargetEntity(targetEntity);
sourceEntity.addAssociation(association, true);
targetEntity.addReferenceAssociation(association, true);
}
use of org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey in project dbeaver by serge-rider.
the class PostgreFDWConfigWizard method collectAvailableDataSources.
void collectAvailableDataSources(DBRProgressMonitor monitor) {
if (availableDataSources != null) {
return;
}
Set<DBPDataSourceContainer> dataSources = new LinkedHashSet<>();
Set<DBSEntity> entities = new LinkedHashSet<>();
DBPDataSourceContainer curDataSource = database.getDataSource().getContainer();
// Find all virtual connections
DBVModel vModel = curDataSource.getVirtualModel();
monitor.beginTask("Check virtual foreign keys", 1);
collectAvailableDataSources(monitor, vModel, dataSources, entities);
monitor.done();
DBNModel navModel = DBWorkbench.getPlatform().getNavigatorModel();
// Check global FK references cache
Map<String, List<DBVEntityForeignKey>> grCache = DBVModel.getGlobalReferenceCache();
monitor.beginTask("Check external references", grCache.size());
for (Map.Entry<String, List<DBVEntityForeignKey>> grEntry : grCache.entrySet()) {
DBNDataSource refDataSource = navModel.getDataSourceByPath(database.getDataSource().getContainer().getProject(), grEntry.getKey());
if (refDataSource != null && refDataSource.getDataSourceContainer() == curDataSource) {
try {
for (DBVEntityForeignKey rfk : grEntry.getValue()) {
monitor.subTask("Check " + rfk.getEntity().getFullyQualifiedName(DBPEvaluationContext.UI));
DBSEntity refEntity = rfk.getEntity().getRealEntity(monitor);
if (refEntity != null) {
dataSources.add(refEntity.getDataSource().getContainer());
entities.add(refEntity);
}
}
} catch (DBException e) {
log.debug("Error getting referenced entity", e);
}
}
monitor.worked(1);
}
monitor.done();
// Check already configured FDW
// Done
availableDataSources = new ArrayList<>(dataSources);
proposedEntities = new ArrayList<>(entities);
}
use of org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey in project dbeaver by serge-rider.
the class DBDAttributeBinding method findVirtualReferrers.
protected List<DBSEntityReferrer> findVirtualReferrers() {
DBSDataContainer dataContainer = getDataContainer();
if (dataContainer instanceof DBSEntity) {
DBSEntity attrEntity = (DBSEntity) dataContainer;
DBVEntity vEntity = DBVUtils.getVirtualEntity(attrEntity, false);
if (vEntity != null) {
List<DBVEntityForeignKey> foreignKeys = vEntity.getForeignKeys();
if (!CommonUtils.isEmpty(foreignKeys)) {
List<DBSEntityReferrer> referrers = null;
for (DBVEntityForeignKey vfk : foreignKeys) {
for (DBVEntityForeignKeyColumn vfkc : vfk.getAttributes()) {
if (CommonUtils.equalObjects(vfkc.getAttributeName(), getFullyQualifiedName(DBPEvaluationContext.DML))) {
if (referrers == null) {
referrers = new ArrayList<>();
}
referrers.add(vfk);
}
}
}
return referrers;
}
}
}
return null;
}
Aggregations