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 + ";"));
}
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;
}
};
}
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());
}
}
Aggregations