Search in sources :

Example 6 with DBSObjectSelector

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

the class SQLEntityResolver method resolveTables.

static void resolveTables(DBRProgressMonitor monitor, DBCExecutionContext executionContext, TemplateContext context, List<DBSEntity> entities) throws DBException {
    TemplateVariable schemaVariable = ((SQLContext) context).getTemplateVariable(SQLContainerResolver.VAR_NAME_SCHEMA);
    TemplateVariable catalogVariable = ((SQLContext) context).getTemplateVariable(SQLContainerResolver.VAR_NAME_CATALOG);
    String catalogName = catalogVariable == null ? null : catalogVariable.getDefaultValue();
    String schemaName = schemaVariable == null ? null : schemaVariable.getDefaultValue();
    DBSObjectContainer objectContainer = DBUtils.getAdapter(DBSObjectContainer.class, executionContext.getDataSource());
    if (objectContainer == null) {
        return;
    }
    if (!CommonUtils.isEmpty(catalogName) || !CommonUtils.isEmpty(schemaName)) {
        // Find container for specified schema/catalog
        objectContainer = (DBSObjectContainer) DBUtils.getObjectByPath(monitor, objectContainer, catalogName, schemaName, null);
    } else {
        DBSObjectSelector objectSelector = DBUtils.getAdapter(DBSObjectSelector.class, executionContext.getDataSource());
        if (objectSelector != null) {
            objectContainer = DBUtils.getAdapter(DBSObjectContainer.class, objectSelector.getDefaultObject());
        }
    }
    if (objectContainer != null) {
        makeProposalsFromChildren(monitor, objectContainer, entities);
    }
}
Also used : DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector)

Example 7 with DBSObjectSelector

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

the class SQLEditor method runPostExecuteActions.

private void runPostExecuteActions(@Nullable SQLQueryResult result) {
    final DBCExecutionContext executionContext = getExecutionContext();
    if (executionContext != null) {
        final DBPDataSource dataSource = executionContext.getDataSource();
        // Dump server output
        DBCServerOutputReader outputReader = DBUtils.getAdapter(DBCServerOutputReader.class, dataSource);
        if (outputReader == null && result != null) {
            outputReader = new DefaultServerOutputReader(result);
        }
        if (outputReader != null && outputReader.isServerOutputEnabled()) {
            dumpServerOutput(executionContext, outputReader);
        }
        // Refresh active object
        if (result == null || !result.hasError() && getActivePreferenceStore().getBoolean(SQLPreferenceConstants.REFRESH_DEFAULTS_AFTER_EXECUTE)) {
            final DBSObjectSelector objectSelector = DBUtils.getAdapter(DBSObjectSelector.class, dataSource);
            if (objectSelector != null) {
                new AbstractJob("Refresh default object") {

                    @Override
                    protected IStatus run(DBRProgressMonitor monitor) {
                        try (DBCSession session = executionContext.openSession(monitor, DBCExecutionPurpose.UTIL, "Refresh default object")) {
                            objectSelector.refreshDefaultObject(session);
                        } catch (Exception e) {
                            log.error(e);
                        }
                        return Status.OK_STATUS;
                    }
                }.schedule();
            }
        }
    }
}
Also used : AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Aggregations

DBSObjectSelector (org.jkiss.dbeaver.model.struct.DBSObjectSelector)7 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 DBException (org.jkiss.dbeaver.DBException)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)2 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)2 IStatus (org.eclipse.core.runtime.IStatus)1 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 MenuEvent (org.eclipse.swt.events.MenuEvent)1 MenuListener (org.eclipse.swt.events.MenuListener)1 Control (org.eclipse.swt.widgets.Control)1 Menu (org.eclipse.swt.widgets.Menu)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1 DefaultServerOutputReader (org.jkiss.dbeaver.model.impl.DefaultServerOutputReader)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1