Search in sources :

Example 21 with DBCExecutionContext

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

the class GlobalProxySelector method select.

@Override
public List<Proxy> select(URI uri) {
    String scheme = uri.getScheme();
    if (CommonUtils.isEmpty(scheme)) {
        return parent.select(uri);
    }
    if (scheme.startsWith("http")) {
    // 1. Check for drivers download proxy
    }
    if (SocksConstants.SOCKET_SCHEME.equals(scheme)) {
        // 2. Check for connections' proxy config
        DBCExecutionContext activeContext = DBExecUtils.findConnectionContext(uri.getHost(), uri.getPort(), uri.getPath());
        if (activeContext != null) {
            List<Proxy> proxies = null;
            DBPDataSourceContainer container = activeContext.getDataSource().getContainer();
            for (DBWHandlerConfiguration networkHandler : container.getConnectionConfiguration().getDeclaredHandlers()) {
                if (networkHandler.isEnabled() && networkHandler.getType() == DBWHandlerType.PROXY) {
                    Map<String, String> proxyProps = networkHandler.getProperties();
                    String proxyHost = proxyProps.get(SocksConstants.PROP_HOST);
                    String proxyPort = proxyProps.get(SocksConstants.PROP_PORT);
                    if (!CommonUtils.isEmpty(proxyHost)) {
                        int portNumber = SocksConstants.DEFAULT_SOCKS_PORT;
                        if (!CommonUtils.isEmpty(proxyPort)) {
                            try {
                                portNumber = Integer.parseInt(proxyPort);
                            } catch (NumberFormatException e) {
                                log.warn("Bad proxy port number", e);
                            }
                        }
                        InetSocketAddress proxyAddr = new InetSocketAddress(proxyHost, portNumber);
                        Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr);
                        if (proxies == null) {
                            proxies = new ArrayList<>();
                        }
                        proxies.add(proxy);
                        log.debug("Use SOCKS proxy [" + proxyAddr + "]");
                    }
                }
            }
            if (proxies != null) {
                return proxies;
            }
        }
    }
    return parent.select(uri);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 22 with DBCExecutionContext

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

the class PropertySourceAbstract method collectProperties.

public boolean collectProperties() {
    lazyValues.clear();
    props.clear();
    propValues.clear();
    final Object editableValue = getEditableValue();
    IPropertyFilter filter;
    if (editableValue instanceof DBSObject) {
        filter = new DataSourcePropertyFilter(((DBSObject) editableValue).getDataSource());
    } else if (editableValue instanceof DBPContextProvider) {
        DBCExecutionContext context = ((DBPContextProvider) editableValue).getExecutionContext();
        filter = context == null ? new DataSourcePropertyFilter() : new DataSourcePropertyFilter(context.getDataSource());
    } else {
        filter = new DataSourcePropertyFilter();
    }
    List<ObjectPropertyDescriptor> annoProps = ObjectAttributeDescriptor.extractAnnotations(this, editableValue.getClass(), filter);
    for (final ObjectPropertyDescriptor desc : annoProps) {
        addProperty(desc);
    }
    if (editableValue instanceof DBPPropertySource) {
        DBPPropertySource ownPropSource = (DBPPropertySource) editableValue;
        DBPPropertyDescriptor[] ownProperties = ownPropSource.getPropertyDescriptors2();
        if (!ArrayUtils.isEmpty(ownProperties)) {
            for (DBPPropertyDescriptor prop : ownProperties) {
                props.add(prop);
                propValues.put(prop.getId(), ownPropSource.getPropertyValue(null, prop.getId()));
            }
        }
    }
    return !props.isEmpty();
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) DBPPropertySource(org.jkiss.dbeaver.model.preferences.DBPPropertySource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Example 23 with DBCExecutionContext

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

the class SQLLogFilter method belongsToEditor.

private boolean belongsToEditor(QMMSessionInfo session) {
    String containerId = session.getContainerId();
    String contextName = session.getContextName();
    DBCExecutionContext executionContext = editor.getExecutionContext();
    return executionContext != null && Objects.equals(executionContext.getDataSource().getContainer().getId(), containerId) && Objects.equals(executionContext.getContextName(), contextName);
}
Also used : DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext)

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