Search in sources :

Example 1 with FDWConfigDescriptor

use of org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigDescriptor in project dbeaver by serge-rider.

the class PostgreFDWConfigWizardPageConfig method loadSettings.

private void loadSettings() {
    DBPDataSourceContainer targetDataSource = getWizard().getSelectedDataSource();
    if (targetDataSource == null) {
        setErrorMessage("No target data source");
        return;
    }
    // Fill FDW list
    try {
        getWizard().getRunnableContext().run(false, true, monitor -> {
            try {
                schemaList = new ArrayList<>();
                schemaList.addAll(getWizard().getDatabase().getSchemas(monitor));
                // Fill from both installed FDW and pre-configured FDW
                fdwList = new ArrayList<>();
                for (PostgreForeignDataWrapper fdw : CommonUtils.safeCollection(getWizard().getDatabase().getForeignDataWrappers(monitor))) {
                    PostgreFDWConfigWizard.FDWInfo fdwInfo = new PostgreFDWConfigWizard.FDWInfo();
                    fdwInfo.installedFDW = fdw;
                    fdwList.add(fdwInfo);
                }
                for (FDWConfigDescriptor fdw : FDWConfigRegistry.getInstance().getConfigDescriptors()) {
                    boolean found = false;
                    for (PostgreFDWConfigWizard.FDWInfo fdwInfo : fdwList) {
                        if (fdwInfo.getId().equals(fdw.getFdwId())) {
                            fdwInfo.fdwDescriptor = fdw;
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        PostgreFDWConfigWizard.FDWInfo fdwInfo = new PostgreFDWConfigWizard.FDWInfo();
                        fdwInfo.fdwDescriptor = fdw;
                        fdwList.add(fdwInfo);
                    }
                }
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        });
    } catch (InvocationTargetException e) {
        log.debug(e.getTargetException());
        setErrorMessage(e.getTargetException().getMessage());
        return;
    } catch (InterruptedException e) {
        return;
    }
    setErrorMessage(null);
    // Detect FDW from target container
    PostgreFDWConfigWizard.FDWInfo fdwInfo = getWizard().getSelectedFDW();
    if (fdwInfo == null) {
        FDWConfigDescriptor fdwConfig = FDWConfigRegistry.getInstance().findFirstMatch(targetDataSource);
        if (fdwConfig != null) {
            for (PostgreFDWConfigWizard.FDWInfo fdw : fdwList) {
                if (fdw.fdwDescriptor == fdwConfig) {
                    fdwInfo = fdw;
                    break;
                }
            }
        }
    }
    fdwCombo.removeAll();
    for (PostgreFDWConfigWizard.FDWInfo fdw : fdwList) {
        String fdwName = fdw.getId();
        if (!CommonUtils.isEmpty(fdw.getDescription())) {
            fdwName += " (" + fdw.getDescription() + ")";
        }
        fdwCombo.add(fdwName);
    }
    if (fdwInfo != null) {
        getWizard().setSelectedFDW(fdwInfo);
        fdwCombo.setText(fdwInfo.getId());
    }
    schemaCombo.removeAll();
    for (PostgreSchema schema : schemaList) {
        schemaCombo.add(schema.getName());
    }
    PostgreSchema selectedSchema = getWizard().getSelectedSchema();
    if (selectedSchema != null) {
        schemaCombo.setText(selectedSchema.getName());
    } else {
        PostgreSchema publicSchema = DBUtils.findObject(schemaList, PostgreConstants.PUBLIC_SCHEMA_NAME);
        if (publicSchema != null) {
            schemaCombo.setText(publicSchema.getName());
            getWizard().setSelectedSchema(publicSchema);
        }
    }
    refreshFDWProperties();
    if (CommonUtils.isEmpty(fdwServerText.getText())) {
        String fdwServerId = (fdwInfo == null ? targetDataSource.getDriver().getId() : fdwInfo.getId()) + "_srv";
        getWizard().setFdwServerId(fdwServerId);
        fdwServerText.setText(fdwServerId);
    }
    // Fill entities
    targetDataSourceText.setText(targetDataSource.getName());
    targetDriverText.setText(targetDataSource.getDriver().getName());
    entityTable.removeAll();
    for (DBNDatabaseNode entityNode : getWizard().getSelectedEntities()) {
        TableItem item = new TableItem(entityTable, SWT.NONE);
        item.setImage(0, DBeaverIcons.getImage(entityNode.getNodeIconDefault()));
        item.setText(0, entityNode.getNodeFullName());
    }
    UIUtils.packColumns(entityTable, false);
    propsEditor.repackColumns();
    updatePageCompletion();
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreForeignDataWrapper(org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper) InvocationTargetException(java.lang.reflect.InvocationTargetException) FDWConfigDescriptor(org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigDescriptor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 2 with FDWConfigDescriptor

use of org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigDescriptor in project dbeaver by dbeaver.

the class PostgreFDWConfigWizardPageConfig method loadSettings.

private void loadSettings() {
    DBPDataSourceContainer targetDataSource = getWizard().getSelectedDataSource();
    if (targetDataSource == null) {
        setErrorMessage("No target data source");
        return;
    }
    // Fill FDW list
    try {
        getWizard().getRunnableContext().run(false, true, monitor -> {
            try {
                schemaList = new ArrayList<>();
                schemaList.addAll(getWizard().getDatabase().getSchemas(monitor));
                // Fill from both installed FDW and pre-configured FDW
                fdwList = new ArrayList<>();
                for (PostgreForeignDataWrapper fdw : CommonUtils.safeCollection(getWizard().getDatabase().getForeignDataWrappers(monitor))) {
                    PostgreFDWConfigWizard.FDWInfo fdwInfo = new PostgreFDWConfigWizard.FDWInfo();
                    fdwInfo.installedFDW = fdw;
                    fdwList.add(fdwInfo);
                }
                for (FDWConfigDescriptor fdw : FDWConfigRegistry.getInstance().getConfigDescriptors()) {
                    boolean found = false;
                    for (PostgreFDWConfigWizard.FDWInfo fdwInfo : fdwList) {
                        if (fdwInfo.getId().equals(fdw.getFdwId())) {
                            fdwInfo.fdwDescriptor = fdw;
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        PostgreFDWConfigWizard.FDWInfo fdwInfo = new PostgreFDWConfigWizard.FDWInfo();
                        fdwInfo.fdwDescriptor = fdw;
                        fdwList.add(fdwInfo);
                    }
                }
            } catch (DBException e) {
                throw new InvocationTargetException(e);
            }
        });
    } catch (InvocationTargetException e) {
        log.debug(e.getTargetException());
        setErrorMessage(e.getTargetException().getMessage());
        return;
    } catch (InterruptedException e) {
        return;
    }
    setErrorMessage(null);
    // Detect FDW from target container
    PostgreFDWConfigWizard.FDWInfo fdwInfo = getWizard().getSelectedFDW();
    if (fdwInfo == null) {
        FDWConfigDescriptor fdwConfig = FDWConfigRegistry.getInstance().findFirstMatch(targetDataSource);
        if (fdwConfig != null) {
            for (PostgreFDWConfigWizard.FDWInfo fdw : fdwList) {
                if (fdw.fdwDescriptor == fdwConfig) {
                    fdwInfo = fdw;
                    break;
                }
            }
        }
    }
    fdwCombo.removeAll();
    for (PostgreFDWConfigWizard.FDWInfo fdw : fdwList) {
        String fdwName = fdw.getId();
        if (!CommonUtils.isEmpty(fdw.getDescription())) {
            fdwName += " (" + fdw.getDescription() + ")";
        }
        fdwCombo.add(fdwName);
    }
    if (fdwInfo != null) {
        getWizard().setSelectedFDW(fdwInfo);
        fdwCombo.setText(fdwInfo.getId());
    }
    schemaCombo.removeAll();
    for (PostgreSchema schema : schemaList) {
        schemaCombo.add(schema.getName());
    }
    PostgreSchema selectedSchema = getWizard().getSelectedSchema();
    if (selectedSchema != null) {
        schemaCombo.setText(selectedSchema.getName());
    } else {
        PostgreSchema publicSchema = DBUtils.findObject(schemaList, PostgreConstants.PUBLIC_SCHEMA_NAME);
        if (publicSchema != null) {
            schemaCombo.setText(publicSchema.getName());
            getWizard().setSelectedSchema(publicSchema);
        }
    }
    refreshFDWProperties();
    if (CommonUtils.isEmpty(fdwServerText.getText())) {
        String fdwServerId = (fdwInfo == null ? targetDataSource.getDriver().getId() : fdwInfo.getId()) + "_srv";
        getWizard().setFdwServerId(fdwServerId);
        fdwServerText.setText(fdwServerId);
    }
    // Fill entities
    targetDataSourceText.setText(targetDataSource.getName());
    targetDriverText.setText(targetDataSource.getDriver().getName());
    entityTable.removeAll();
    for (DBNDatabaseNode entityNode : getWizard().getSelectedEntities()) {
        TableItem item = new TableItem(entityTable, SWT.NONE);
        item.setImage(0, DBeaverIcons.getImage(entityNode.getNodeIconDefault()));
        item.setText(0, entityNode.getNodeFullName());
    }
    UIUtils.packColumns(entityTable, false);
    propsEditor.repackColumns();
    updatePageCompletion();
}
Also used : DBException(org.jkiss.dbeaver.DBException) PostgreForeignDataWrapper(org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper) InvocationTargetException(java.lang.reflect.InvocationTargetException) FDWConfigDescriptor(org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigDescriptor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DBException (org.jkiss.dbeaver.DBException)2 PostgreForeignDataWrapper (org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper)2 PostgreSchema (org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)2 FDWConfigDescriptor (org.jkiss.dbeaver.ext.postgresql.model.fdw.FDWConfigDescriptor)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2