Search in sources :

Example 36 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.

the class SQLScriptTaskPageSettings method updateSelectedScripts.

private void updateSelectedScripts() {
    DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
    Set<DBPDataSourceContainer> dataSources = new LinkedHashSet<>();
    for (DBNResource element : selectedScripts) {
        Collection<DBPDataSourceContainer> resDS = element.getAssociatedDataSources();
        if (!CommonUtils.isEmpty(resDS)) {
            dataSources.addAll(resDS);
        }
    }
    if (!dataSources.isEmpty()) {
        List<DBNDataSource> checkedDataSources = new ArrayList<>();
        for (DBPDataSourceContainer ds : dataSources) {
            DBNDataSource dsNode = projectNode.getDatabases().getDataSource(ds);
            if (dsNode != null) {
                checkedDataSources.add(dsNode);
            }
        }
        if (!checkedDataSources.isEmpty()) {
            refreshDataSources();
            for (DBNDataSource dsNode : checkedDataSources) {
                if (!selectedDataSources.contains(dsNode)) {
                    selectedDataSources.add(dsNode);
                }
            }
        }
    }
    refreshDataSources();
    updatePageCompletion();
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBNProject(org.jkiss.dbeaver.model.navigator.DBNProject) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 37 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.

the class SQLScriptTaskPageSettings method saveSettings.

public void saveSettings() {
    if (sqlWizard == null) {
        return;
    }
    SQLScriptExecuteSettings settings = sqlWizard.getSettings();
    List<String> scriptPaths = new ArrayList<>();
    for (DBNResource resource : selectedScripts) {
        IResource res = resource.getResource();
        if (res instanceof IFile) {
            scriptPaths.add(res.getFullPath().toString());
        }
    }
    settings.setScriptFiles(scriptPaths);
    List<DBPDataSourceContainer> dsList = new ArrayList<>();
    for (DBNDataSource dsNode : selectedDataSources) {
        dsList.add(dsNode.getDataSourceContainer());
    }
    settings.setDataSources(dsList);
    settings.setIgnoreErrors(ignoreErrorsCheck.getSelection());
    settings.setDumpQueryResultsToLog(dumpQueryCheck.getSelection());
    settings.setAutoCommit(autoCommitCheck.getSelection());
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) IFile(org.eclipse.core.resources.IFile) SQLScriptExecuteSettings(org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IResource(org.eclipse.core.resources.IResource)

Example 38 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource 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);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBVEntityForeignKey(org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBVModel(org.jkiss.dbeaver.model.virtual.DBVModel) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 39 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.

the class SQLEditorHandlerOpenEditor method getDataSourceContainers.

private static List<DBPDataSourceContainer> getDataSourceContainers(ExecutionEvent event) {
    List<DBPDataSourceContainer> containers = new ArrayList<>();
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        for (Object obj : ((IStructuredSelection) selection).toArray()) {
            if (obj instanceof DBNLocalFolder) {
                for (DBNDataSource ds : ((DBNLocalFolder) obj).getDataSources()) {
                    containers.add(ds.getDataSourceContainer());
                }
            } else {
                DBSObject selectedObject = DBUtils.getFromObject(obj);
                if (selectedObject != null) {
                    if (selectedObject instanceof DBPDataSourceContainer) {
                        containers.add((DBPDataSourceContainer) selectedObject);
                    } else {
                        containers.add(selectedObject.getDataSource().getContainer());
                    }
                }
            }
        }
    }
    if (containers.isEmpty()) {
        IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
        DBPDataSourceContainer partContainer = getDataSourceContainers(activePart);
        if (partContainer != null) {
            containers.add(partContainer);
        }
    }
    return containers;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNLocalFolder(org.jkiss.dbeaver.model.navigator.DBNLocalFolder) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 40 with DBNDataSource

use of org.jkiss.dbeaver.model.navigator.DBNDataSource in project dbeaver by serge-rider.

the class StatisticsNavigatorNodeRenderer method getDetailsTipText.

private String getDetailsTipText(DBNNode element, Tree tree, Event event) {
    if (element instanceof DBNDatabaseNode) {
        if (element instanceof DBNDataSource) {
            if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_NODE_ACTIONS)) {
                // Detect active action
                INavigatorNodeActionHandler overActionButton = getActionButtonFor(element, tree, event);
                if (overActionButton != null) {
                    return overActionButton.getNodeActionToolTip(view, element);
                }
            }
            if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_CONNECTION_HOST_NAME)) {
                return DataSourceUtils.getDataSourceAddressText(((DBNDataSource) element).getDataSourceContainer());
            }
            return null;
        }
        if (DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_SHOW_STATISTICS_INFO)) {
            if (event.x > getTreeWidth(tree) - PERCENT_FILL_WIDTH) {
                DBSObject object = ((DBNDatabaseNode) element).getObject();
                if (object instanceof DBPObjectStatistics && ((DBPObjectStatistics) object).hasStatistics()) {
                    long statObjectSize = ((DBPObjectStatistics) object).getStatObjectSize();
                    if (statObjectSize > 0) {
                        String formattedSize;
                        try {
                            DBDDataFormatter formatter = object.getDataSource().getContainer().getDataFormatterProfile().createFormatter(DBDDataFormatter.TYPE_NAME_NUMBER, null);
                            formattedSize = formatter.formatValue(statObjectSize);
                        } catch (Exception e) {
                            formattedSize = String.valueOf(statObjectSize);
                        }
                        return "Object size on disk: " + formattedSize + " bytes";
                    }
                }
            }
        // renderObjectStatistics((DBNDatabaseNode) element, tree, gc, event);
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBDDataFormatter(org.jkiss.dbeaver.model.data.DBDDataFormatter) INavigatorNodeActionHandler(org.jkiss.dbeaver.ui.navigator.INavigatorNodeActionHandler) DBNDataSource(org.jkiss.dbeaver.model.navigator.DBNDataSource) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBException(org.jkiss.dbeaver.DBException)

Aggregations

DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)59 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)26 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)23 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)17 DBException (org.jkiss.dbeaver.DBException)15 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)13 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)12 DBNProject (org.jkiss.dbeaver.model.navigator.DBNProject)10 ArrayList (java.util.ArrayList)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 DBNLocalFolder (org.jkiss.dbeaver.model.navigator.DBNLocalFolder)8 IFile (org.eclipse.core.resources.IFile)6 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)6 SQLScriptExecuteSettings (org.jkiss.dbeaver.tools.sql.SQLScriptExecuteSettings)6 GridData (org.eclipse.swt.layout.GridData)5 IResource (org.eclipse.core.resources.IResource)4 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)4 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4