Search in sources :

Example 6 with DBSInstance

use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by serge-rider.

the class InvalidateJob method invalidateTransaction.

public static void invalidateTransaction(DBRProgressMonitor monitor, DBPDataSource dataSource, DBCExecutionContext executionContext) {
    // Invalidate transactions
    if (executionContext != null) {
        monitor.subTask("Invalidate context [" + executionContext.getDataSource().getContainer().getName() + "/" + executionContext.getContextName() + "] transactions");
        invalidateTransaction(monitor, executionContext);
    } else {
        monitor.subTask("Invalidate datasource [" + dataSource.getContainer().getName() + "] transactions");
        for (DBSInstance instance : dataSource.getAvailableInstances()) {
            for (DBCExecutionContext context : instance.getAllContexts()) {
                invalidateTransaction(monitor, context);
            }
        }
    }
}
Also used : DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance)

Example 7 with DBSInstance

use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by serge-rider.

the class DashboardListViewer method openSeparateContext.

private void openSeparateContext() {
    DBPDataSource dataSource = dataSourceContainer.getDataSource();
    if (dataSource == null) {
        return;
    }
    new AbstractJob("Open connection for dashboard") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            DBSInstance instance = DBUtils.getObjectOwnerInstance(dataSource);
            if (instance != null) {
                try {
                    isolatedContext = instance.openIsolatedContext(monitor, "Dashboard connection", null);
                } catch (DBException e) {
                    return GeneralUtils.makeExceptionStatus(e);
                }
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 8 with DBSInstance

use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by serge-rider.

the class NavigatorHandlerLinkEditor method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor == null) {
        return null;
    }
    NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (navigatorView == null) {
        return null;
    }
    if (navigatorView instanceof ProjectExplorerView || (navigatorView instanceof ProjectNavigatorView && activeEditor instanceof ITextEditor)) {
        IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
        if (file != null) {
            showResourceInNavigator(navigatorView, file);
        }
    } else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
        IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
        DBNNode dbnNode = editorInput.getNavigatorNode();
        if (dbnNode != null) {
            navigatorView.showNode(dbnNode);
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        @NotNull DBSObject activeObject = null;
        if (dsContainer != null) {
            if (activeEditor instanceof DBPContextProvider) {
                DBCExecutionContext executionContext = ((DBPContextProvider) activeEditor).getExecutionContext();
                if (executionContext != null) {
                    DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
                    if (contextDefaults != null) {
                        activeObject = contextDefaults.getDefaultSchema();
                        if (activeObject == null) {
                            activeObject = contextDefaults.getDefaultCatalog();
                        }
                    }
                }
            }
            if (activeObject == null) {
                DBPDataSource dataSource = dsContainer.getDataSource();
                if (dataSource != null) {
                    activeObject = DBUtils.getDefaultOrActiveObject(dataSource.getDefaultInstance());
                } else {
                    activeObject = dsContainer;
                }
            }
            DBSObject objectToSelect = activeObject;
            final NavigatorViewBase view = navigatorView;
            UIUtils.runInUI(activePage.getWorkbenchWindow(), monitor -> {
                DBSObject showObject = objectToSelect;
                if (showObject instanceof DBSInstance && !(showObject instanceof DBPDataSourceContainer)) {
                    showObject = objectToSelect.getParentObject();
                }
                if (showObject instanceof DBPDataSource) {
                    showObject = ((DBPDataSource) showObject).getContainer();
                }
                DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
                if (objectNode != null) {
                    view.showNode(objectNode);
                }
            });
        }
    }
    activePage.activate(navigatorView);
    return null;
}
Also used : DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) IEditorPart(org.eclipse.ui.IEditorPart) NotNull(org.jkiss.code.NotNull) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ProjectNavigatorView(org.jkiss.dbeaver.ui.navigator.project.ProjectNavigatorView) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 9 with DBSInstance

use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by serge-rider.

the class SQLEditor method initSeparateConnection.

private void initSeparateConnection(@NotNull DBPDataSource dataSource, Runnable onSuccess) {
    DBSInstance dsInstance = dataSource.getDefaultInstance();
    String[] contextDefaults = isRestoreActiveSchemaFromScript() ? EditorUtils.getInputContextDefaults(dataSource.getContainer(), getEditorInput()) : null;
    if (!ArrayUtils.isEmpty(contextDefaults) && contextDefaults[0] != null) {
        DBSInstance selectedInstance = DBUtils.findObject(dataSource.getAvailableInstances(), contextDefaults[0]);
        if (selectedInstance != null) {
            dsInstance = selectedInstance;
        }
    }
    if (dsInstance != null) {
        final OpenContextJob job = new OpenContextJob(dsInstance, onSuccess);
        job.schedule();
    }
}
Also used : DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance)

Example 10 with DBSInstance

use of org.jkiss.dbeaver.model.struct.DBSInstance in project dbeaver by dbeaver.

the class NavigatorHandlerLinkEditor method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor == null) {
        return null;
    }
    NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
    if (navigatorView == null) {
        return null;
    }
    if (navigatorView instanceof ProjectExplorerView || (navigatorView instanceof ProjectNavigatorView && activeEditor instanceof ITextEditor)) {
        IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
        if (file != null) {
            showResourceInNavigator(navigatorView, file);
        }
    } else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
        IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
        DBNNode dbnNode = editorInput.getNavigatorNode();
        if (dbnNode != null) {
            navigatorView.showNode(dbnNode);
        }
    } else if (activeEditor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
        @NotNull DBSObject activeObject = null;
        if (dsContainer != null) {
            if (activeEditor instanceof DBPContextProvider) {
                DBCExecutionContext executionContext = ((DBPContextProvider) activeEditor).getExecutionContext();
                if (executionContext != null) {
                    DBCExecutionContextDefaults contextDefaults = executionContext.getContextDefaults();
                    if (contextDefaults != null) {
                        activeObject = contextDefaults.getDefaultSchema();
                        if (activeObject == null) {
                            activeObject = contextDefaults.getDefaultCatalog();
                        }
                    }
                }
            }
            if (activeObject == null) {
                DBPDataSource dataSource = dsContainer.getDataSource();
                if (dataSource != null) {
                    activeObject = DBUtils.getDefaultOrActiveObject(dataSource.getDefaultInstance());
                } else {
                    activeObject = dsContainer;
                }
            }
            DBSObject objectToSelect = activeObject;
            final NavigatorViewBase view = navigatorView;
            UIUtils.runInUI(activePage.getWorkbenchWindow(), monitor -> {
                DBSObject showObject = objectToSelect;
                if (showObject instanceof DBSInstance && !(showObject instanceof DBPDataSourceContainer)) {
                    showObject = objectToSelect.getParentObject();
                }
                if (showObject instanceof DBPDataSource) {
                    showObject = ((DBPDataSource) showObject).getContainer();
                }
                DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
                if (objectNode != null) {
                    view.showNode(objectNode);
                }
            });
        }
    }
    activePage.activate(navigatorView);
    return null;
}
Also used : DBCExecutionContextDefaults(org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults) ProjectExplorerView(org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) IEditorPart(org.eclipse.ui.IEditorPart) NotNull(org.jkiss.code.NotNull) IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ProjectNavigatorView(org.jkiss.dbeaver.ui.navigator.project.ProjectNavigatorView) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) NavigatorViewBase(org.jkiss.dbeaver.ui.navigator.database.NavigatorViewBase) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Aggregations

DBSInstance (org.jkiss.dbeaver.model.struct.DBSInstance)14 ArrayList (java.util.ArrayList)4 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)4 IFile (org.eclipse.core.resources.IFile)2 IStatus (org.eclipse.core.runtime.IStatus)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 NotNull (org.jkiss.code.NotNull)2 DBException (org.jkiss.dbeaver.DBException)2 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)2 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 DBCExecutionContextDefaults (org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)2 DBWNetworkHandler (org.jkiss.dbeaver.model.net.DBWNetworkHandler)2 QMTransactionState (org.jkiss.dbeaver.model.qm.QMTransactionState)2 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2