Search in sources :

Example 1 with SQLQueryListener

use of org.jkiss.dbeaver.runtime.sql.SQLQueryListener in project dbeaver by dbeaver.

the class SQLEditor method processQueries.

private void processQueries(@NotNull final List<SQLScriptElement> queries, final boolean newTab, final boolean export, final boolean checkSession, @Nullable final SQLQueryListener queryListener) {
    if (queries.isEmpty()) {
        // Nothing to process
        return;
    }
    final DBPDataSourceContainer container = getDataSourceContainer();
    if (checkSession) {
        try {
            DBRProgressListener connectListener = status -> {
                if (!status.isOK() || container == null || !container.isConnected()) {
                    DBUserInterface.getInstance().showError(CoreMessages.editors_sql_error_cant_obtain_session, null, status);
                    return;
                }
                updateExecutionContext(new Runnable() {

                    @Override
                    public void run() {
                        DBeaverUI.syncExec(() -> processQueries(queries, newTab, export, false, queryListener));
                    }
                });
            };
            if (!checkSession(connectListener)) {
                return;
            }
        } catch (DBException ex) {
            ResultSetViewer viewer = getActiveResultSetViewer();
            if (viewer != null) {
                viewer.setStatus(ex.getMessage(), DBPMessageType.ERROR);
            }
            DBUserInterface.getInstance().showError(CoreMessages.editors_sql_error_cant_obtain_session, ex.getMessage());
            return;
        }
    }
    if (dataSourceContainer == null) {
        return;
    }
    final boolean isSingleQuery = (queries.size() == 1);
    if (isSingleQuery && queries.get(0) instanceof SQLQuery) {
        SQLQuery query = (SQLQuery) queries.get(0);
        if (query.isDeleteUpdateDangerous()) {
            String targetName = "multiple tables";
            if (query.getSingleSource() != null) {
                targetName = query.getSingleSource().getEntityName();
            }
            if (ConfirmationDialog.showConfirmDialogEx(getSite().getShell(), DBeaverPreferences.CONFIRM_DANGER_SQL, ConfirmationDialog.CONFIRM, ConfirmationDialog.WARNING, query.getType().name(), targetName) != IDialogConstants.OK_ID) {
                return;
            }
        }
    } else if (newTab && queries.size() > MAX_PARALLEL_QUERIES_NO_WARN) {
        if (ConfirmationDialog.showConfirmDialogEx(getSite().getShell(), DBeaverPreferences.CONFIRM_MASS_PARALLEL_SQL, ConfirmationDialog.CONFIRM, ConfirmationDialog.WARNING, queries.size()) != IDialogConstants.OK_ID) {
            return;
        }
    }
    if (sashForm.getMaximizedControl() != null) {
        sashForm.setMaximizedControl(null);
    }
    // Save editor
    if (getActivePreferenceStore().getBoolean(SQLPreferenceConstants.AUTO_SAVE_ON_EXECUTE) && isDirty()) {
        doSave(new NullProgressMonitor());
    }
    if (!newTab || !isSingleQuery) {
        // We don't need new tab or we are executing a script - so close all extra tabs
        closeExtraResultTabs(null);
    }
    if (newTab) {
        // Execute each query in a new tab
        for (int i = 0; i < queries.size(); i++) {
            SQLScriptElement query = queries.get(i);
            QueryProcessor queryProcessor = (i == 0 && !isSingleQuery ? curQueryProcessor : createQueryProcessor(queries.size() == 1));
            queryProcessor.processQueries(Collections.singletonList(query), true, export, getActivePreferenceStore().getBoolean(SQLPreferenceConstants.RESULT_SET_CLOSE_ON_ERROR), queryListener);
        }
    } else {
        // Use current tab.
        // If current tab was pinned then use first tab
        final QueryResultsContainer firstResults = curQueryProcessor.getFirstResults();
        if (firstResults.isPinned()) {
            curQueryProcessor = queryProcessors.get(0);
        }
        closeExtraResultTabs(curQueryProcessor);
        if (firstResults.tabItem != null) {
            // Do not switch tab if Output tab is active
            CTabItem selectedTab = resultTabs.getSelection();
            if (selectedTab == null || selectedTab.getData() != outputViewer) {
                resultTabs.setSelection(firstResults.tabItem);
            }
        }
        curQueryProcessor.processQueries(queries, false, export, false, queryListener);
    }
}
Also used : StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) IResultSetListener(org.jkiss.dbeaver.ui.controls.resultset.IResultSetListener) org.eclipse.jface.action(org.eclipse.jface.action) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) SashForm(org.eclipse.swt.custom.SashForm) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) StyledText(org.eclipse.swt.custom.StyledText) DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) SQLQueryListener(org.jkiss.dbeaver.runtime.sql.SQLQueryListener) SQLQueryJob(org.jkiss.dbeaver.runtime.sql.SQLQueryJob) SQLResultsView(org.jkiss.dbeaver.ui.views.SQLResultsView) org.eclipse.jface.text(org.eclipse.jface.text) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) Point(org.eclipse.swt.graphics.Point) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) IOUtils(org.jkiss.utils.IOUtils) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) ScriptPositionColumn(org.jkiss.dbeaver.ui.editors.text.ScriptPositionColumn) URI(java.net.URI) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) SQLResultsConsumer(org.jkiss.dbeaver.runtime.sql.SQLResultsConsumer) EFS(org.eclipse.core.filesystem.EFS) ExplainPlanViewer(org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) IFileState(org.eclipse.core.resources.IFileState) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBeaverPreferences(org.jkiss.dbeaver.DBeaverPreferences) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) ITextEditorActionConstants(org.eclipse.ui.texteditor.ITextEditorActionConstants) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) PrefUtils(org.jkiss.dbeaver.utils.PrefUtils) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) java.util(java.util) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) DBUserInterface(org.jkiss.dbeaver.runtime.ui.DBUserInterface) Image(org.eclipse.swt.graphics.Image) Nullable(org.jkiss.code.Nullable) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotNull(org.jkiss.code.NotNull) EditorUtils(org.jkiss.dbeaver.ui.editors.EditorUtils) DataSourceHandler(org.jkiss.dbeaver.ui.actions.datasource.DataSourceHandler) IProject(org.eclipse.core.resources.IProject) INonPersistentEditorInput(org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IResultSetContainer(org.jkiss.dbeaver.ui.controls.resultset.IResultSetContainer) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) IFileStore(org.eclipse.core.filesystem.IFileStore) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) Job(org.eclipse.core.runtime.jobs.Job) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) org.eclipse.swt.widgets(org.eclipse.swt.widgets) ArrayUtils(org.jkiss.utils.ArrayUtils) CTabItem(org.eclipse.swt.custom.CTabItem) org.eclipse.ui(org.eclipse.ui) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) org.jkiss.dbeaver.core(org.jkiss.dbeaver.core) org.eclipse.core.runtime(org.eclipse.core.runtime) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) java.io(java.io) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) ConfirmationDialog(org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog) org.jkiss.dbeaver.model.sql(org.jkiss.dbeaver.model.sql) DBException(org.jkiss.dbeaver.DBException) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Aggregations

java.io (java.io)1 URI (java.net.URI)1 java.util (java.util)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EFS (org.eclipse.core.filesystem.EFS)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IFile (org.eclipse.core.resources.IFile)1 IFileState (org.eclipse.core.resources.IFileState)1 IProject (org.eclipse.core.resources.IProject)1 org.eclipse.core.runtime (org.eclipse.core.runtime)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 org.eclipse.jface.action (org.eclipse.jface.action)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 org.eclipse.jface.text (org.eclipse.jface.text)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1