Search in sources :

Example 16 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class ObjectEditorPageControl method isObjectEditable.

public boolean isObjectEditable() {
    DBCExecutionContext context = getEditorPart().getEditorInput().getExecutionContext();
    if (context == null) {
        return false;
    }
    if (context.getDataSource().getInfo().isReadOnlyMetaData()) {
        return false;
    }
    DBSObject databaseObject = getEditorPart().getEditorInput().getDatabaseObject();
    return databaseObject != null && EntityEditorsRegistry.getInstance().getObjectManager(databaseObject.getClass(), DBEObjectManager.class) != null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext)

Example 17 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class DataSourceAutoCommitHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DBCExecutionContext context = getExecutionContext(event, true);
    if (context != null) {
        DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
        if (txnManager != null) {
            try {
                final DBPDataSourceContainer container = context.getDataSource().getContainer();
                boolean newAutocommit = !container.isDefaultAutoCommit();
                if (context.isConnected()) {
                    // Get flag from connection
                    newAutocommit = !txnManager.isAutoCommit();
                }
                container.setDefaultAutoCommit(newAutocommit, context, true, new Runnable() {

                    @Override
                    public void run() {
                        // Save config
                        container.persistConfiguration();
                    }
                });
            } catch (DBException e) {
                UIUtils.showErrorDialog(null, "Auto-Commit", "Error while toggle auto-commit", e);
            }
        }
    }
    return null;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBCTransactionManager(org.jkiss.dbeaver.model.exec.DBCTransactionManager)

Example 18 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class DatabaseEditorUtils method setPartBackground.

public static void setPartBackground(IEditorPart editor, Composite composite) {
    CTabFolder tabFolder = null;
    Composite rootComposite = null;
    for (Composite c = composite; c != null; c = c.getParent()) {
        if (c.getParent() instanceof CTabFolder) {
            tabFolder = (CTabFolder) c.getParent();
            rootComposite = c;
            break;
        }
    }
    if (tabFolder == null) {
        return;
    }
    tabFolder.setBorderVisible(false);
    Color bgColor = null;
    if (editor instanceof IDataSourceContainerProvider) {
        DBPDataSourceContainer container = ((IDataSourceContainerProvider) editor).getDataSourceContainer();
        if (container != null) {
            bgColor = UIUtils.getConnectionColor(container.getConnectionConfiguration());
        }
    } else if (editor instanceof DBPContextProvider) {
        DBCExecutionContext context = ((DBPContextProvider) editor).getExecutionContext();
        if (context != null) {
            bgColor = UIUtils.getConnectionColor(context.getDataSource().getContainer().getConnectionConfiguration());
        }
    }
    if (bgColor == null) {
        rootComposite.setBackground(null);
    } else {
        rootComposite.setBackground(bgColor);
    }
}
Also used : IDataSourceContainerProvider(org.jkiss.dbeaver.model.IDataSourceContainerProvider) CTabFolder(org.eclipse.swt.custom.CTabFolder) Composite(org.eclipse.swt.widgets.Composite) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) Color(org.eclipse.swt.graphics.Color) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 19 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class BaseSQLDialog method createSQLPanel.

protected Composite createSQLPanel(Composite parent) {
    Composite panel = UIUtils.createPlaceholder(parent, 1);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (isLabelVisible()) {
        UIUtils.createControlLabel(panel, "SQL Preview");
    }
    //        new Label(panel, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Composite editorPH = new Composite(panel, SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.verticalIndent = 3;
    gd.horizontalSpan = 1;
    gd.minimumHeight = 100;
    gd.minimumWidth = 100;
    editorPH.setLayoutData(gd);
    editorPH.setLayout(new FillLayout());
    sqlViewer = new SQLEditorBase() {

        @NotNull
        @Override
        protected SQLDialect getSQLDialect() {
            return BaseSQLDialog.this.getSQLDialect();
        }

        @Override
        public DBCExecutionContext getExecutionContext() {
            return BaseSQLDialog.this.getExecutionContext();
        }
    };
    updateSQL();
    sqlViewer.createPartControl(editorPH);
    if (isWordWrap()) {
        Object text = sqlViewer.getAdapter(Control.class);
        if (text instanceof StyledText) {
            ((StyledText) text).setWordWrap(true);
        }
    }
    sqlViewer.reloadSyntaxRules();
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            sqlViewer.dispose();
        }
    });
    return panel;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) SQLDialect(org.jkiss.dbeaver.model.sql.SQLDialect) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent) NotNull(org.jkiss.code.NotNull)

Example 20 with DBCExecutionContext

use of org.jkiss.dbeaver.model.exec.DBCExecutionContext in project dbeaver by serge-rider.

the class InvalidateJob method invalidateDataSource.

public static List<ContextInvalidateResult> invalidateDataSource(DBRProgressMonitor monitor, DBPDataSource dataSource) {
    long timeSpent = 0;
    List<ContextInvalidateResult> invalidateResults = new ArrayList<>();
    DBPDataSourceContainer container = dataSource.getContainer();
    DBWNetworkHandler[] activeHandlers = container.getActiveNetworkHandlers();
    boolean networkOK = true;
    boolean hasGoodContexts = false;
    if (activeHandlers != null && activeHandlers.length > 0) {
        for (DBWNetworkHandler nh : activeHandlers) {
            monitor.subTask("Invalidate network [" + container.getName() + "]");
            try {
                nh.invalidateHandler(monitor);
            } catch (Exception e) {
                invalidateResults.add(new ContextInvalidateResult(DBCExecutionContext.InvalidateResult.ERROR, e));
                networkOK = false;
                break;
            }
        }
    }
    if (networkOK) {
        // Invalidate datasource
        monitor.subTask("Invalidate connections of [" + container.getName() + "]");
        DBCExecutionContext[] allContexts = dataSource.getAllContexts();
        for (DBCExecutionContext context : allContexts) {
            long startTime = System.currentTimeMillis();
            try {
                final DBCExecutionContext.InvalidateResult result = context.invalidateContext(monitor);
                if (result != DBCExecutionContext.InvalidateResult.ERROR) {
                    hasGoodContexts = true;
                }
                invalidateResults.add(new ContextInvalidateResult(result, null));
            } catch (Exception e) {
                invalidateResults.add(new ContextInvalidateResult(DBCExecutionContext.InvalidateResult.ERROR, e));
            } finally {
                timeSpent += (System.currentTimeMillis() - startTime);
            }
        }
    }
    if (!hasGoodContexts) {
        // Close whole datasource. Target host seems to be unavailable
        try {
            container.disconnect(monitor);
        } catch (Exception e) {
            log.error("Error closing unaccessible datasource", e);
        }
        StringBuilder msg = new StringBuilder();
        for (ContextInvalidateResult result : invalidateResults) {
            if (result.error != null) {
                if (msg.length() > 0)
                    msg.append("\n");
                msg.append(result.error.getMessage());
            }
        }
        UIUtils.showErrorDialog(null, "Forced disconnect", "Datasource '" + container.getName() + "' was disconnected: destination database unreachable.\n" + msg);
    }
    return invalidateResults;
}
Also used : DBWNetworkHandler(org.jkiss.dbeaver.model.net.DBWNetworkHandler) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) ArrayList(java.util.ArrayList) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)23 DBPContextProvider (org.jkiss.dbeaver.model.DBPContextProvider)7 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)5 ArrayList (java.util.ArrayList)3 DBException (org.jkiss.dbeaver.DBException)3 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 NotNull (org.jkiss.code.NotNull)2 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)2 DBCTransactionManager (org.jkiss.dbeaver.model.exec.DBCTransactionManager)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 QMEventFilter (org.jkiss.dbeaver.model.qm.QMEventFilter)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)2 IDocument (org.eclipse.jface.text.IDocument)1