Search in sources :

Example 1 with SQLServerDataSource

use of org.jkiss.dbeaver.ext.mssql.model.SQLServerDataSource in project dbeaver by serge-rider.

the class SQLServerDatabaseManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectRenameCommand command, Map<String, Object> options) {
    final SQLServerDataSource source = command.getObject().getDataSource();
    final String oldName = DBUtils.getQuotedIdentifier(source, command.getOldName());
    final String newName = DBUtils.getQuotedIdentifier(source, command.getNewName());
    actions.add(new SQLDatabasePersistAction("Rename database", "ALTER DATABASE " + oldName + " MODIFY NAME = " + newName + ";"));
}
Also used : SQLServerDataSource(org.jkiss.dbeaver.ext.mssql.model.SQLServerDataSource) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 2 with SQLServerDataSource

use of org.jkiss.dbeaver.ext.mssql.model.SQLServerDataSource in project dbeaver by serge-rider.

the class SQLServerSessionEditor method createSessionViewer.

@Override
protected SessionManagerViewer createSessionViewer(DBCExecutionContext executionContext, Composite parent) {
    return new SessionManagerViewer<SQLServerSession>(this, parent, new SQLServerSessionManager((SQLServerDataSource) executionContext.getDataSource())) {

        @Override
        protected void contributeToToolbar(DBAServerSessionManager sessionManager, IContributionManager contributionManager) {
            contributionManager.add(ActionUtils.makeActionContribution(new Action("Only connections", Action.AS_CHECK_BOX) {

                {
                    setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.CONFIGURATION));
                    setToolTipText("Show only physical connections");
                    setChecked(showOnlyConnections);
                }

                @Override
                public void run() {
                    showOnlyConnections = isChecked();
                    refreshPart(SQLServerSessionEditor.this, true);
                }
            }, true));
            contributionManager.add(new Separator());
            contributionManager.add(terminateQueryAction);
            contributionManager.add(new Separator());
        }

        @Override
        protected void onSessionSelect(DBAServerSession session) {
            super.onSessionSelect(session);
            terminateQueryAction.setEnabled(session != null);
        }

        @Override
        protected void loadSettings(IDialogSettings settings) {
            showOnlyConnections = CommonUtils.getBoolean(settings.get("showOnlyConnections"), true);
            super.loadSettings(settings);
        }

        @Override
        protected void saveSettings(IDialogSettings settings) {
            super.saveSettings(settings);
            settings.put("showOnlyConnections", showOnlyConnections);
        }

        @Override
        public Map<String, Object> getSessionOptions() {
            Map<String, Object> options = new HashMap<>();
            if (showOnlyConnections) {
                options.put(SQLServerSessionManager.OPTION_SHOW_ONLY_CONNECTIONS, true);
            }
            return options;
        }
    };
}
Also used : Action(org.eclipse.jface.action.Action) DBAServerSession(org.jkiss.dbeaver.model.admin.sessions.DBAServerSession) HashMap(java.util.HashMap) SQLServerDataSource(org.jkiss.dbeaver.ext.mssql.model.SQLServerDataSource) SessionManagerViewer(org.jkiss.dbeaver.ui.views.session.SessionManagerViewer) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) DBAServerSessionManager(org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager) SQLServerSessionManager(org.jkiss.dbeaver.ext.mssql.model.session.SQLServerSessionManager) IContributionManager(org.eclipse.jface.action.IContributionManager) Separator(org.eclipse.jface.action.Separator)

Example 3 with SQLServerDataSource

use of org.jkiss.dbeaver.ext.mssql.model.SQLServerDataSource in project dbeaver by serge-rider.

the class SQLServerSessionManager method getSessions.

@Override
public Collection<SQLServerSession> getSessions(DBCSession session, Map<String, Object> options) throws DBException {
    try {
        boolean onlyConnections = CommonUtils.getOption(options, OPTION_SHOW_ONLY_CONNECTIONS);
        boolean supportsDatabaseInfo = ((SQLServerDataSource) session.getDataSource()).isServerVersionAtLeast(SQLServerConstants.SQL_SERVER_2012_VERSION_MAJOR, 0);
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT s.*,");
        if (supportsDatabaseInfo) {
            sql.append("db.name as database_name,");
        } else {
            sql.append("NULL as database_name,");
        }
        sql.append("c.connection_id,(select text from sys.dm_exec_sql_text(c.most_recent_sql_handle)) as sql_text\n").append("FROM sys.dm_exec_sessions s\n");
        if (onlyConnections) {
            sql.append("LEFT OUTER ");
        }
        sql.append("JOIN sys.dm_exec_connections c ON c.session_id=s.session_id\n");
        if (supportsDatabaseInfo) {
            sql.append("LEFT OUTER JOIN sys.sysdatabases db on db.dbid=s.database_id\n");
        }
        sql.append("ORDER BY s.session_id DESC");
        try (JDBCPreparedStatement dbStat = ((JDBCSession) session).prepareStatement(sql.toString())) {
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                List<SQLServerSession> sessions = new ArrayList<>();
                while (dbResult.next()) {
                    sessions.add(new SQLServerSession(dbResult));
                }
                return sessions;
            }
        }
    } catch (SQLException e) {
        throw new DBException(e, session.getDataSource());
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) DBException(org.jkiss.dbeaver.DBException) SQLException(java.sql.SQLException) SQLServerDataSource(org.jkiss.dbeaver.ext.mssql.model.SQLServerDataSource) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) ArrayList(java.util.ArrayList)

Aggregations

SQLServerDataSource (org.jkiss.dbeaver.ext.mssql.model.SQLServerDataSource)3 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Action (org.eclipse.jface.action.Action)1 IContributionManager (org.eclipse.jface.action.IContributionManager)1 Separator (org.eclipse.jface.action.Separator)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 DBException (org.jkiss.dbeaver.DBException)1 SQLServerSessionManager (org.jkiss.dbeaver.ext.mssql.model.session.SQLServerSessionManager)1 DBAServerSession (org.jkiss.dbeaver.model.admin.sessions.DBAServerSession)1 DBAServerSessionManager (org.jkiss.dbeaver.model.admin.sessions.DBAServerSessionManager)1 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)1 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)1 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)1 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)1 SessionManagerViewer (org.jkiss.dbeaver.ui.views.session.SessionManagerViewer)1