mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
* Fixed #4772 create unique connection for each notebook by using notebook path as uri Disconnect sqlConnection from SqlKernel to ensure no connection left after the notebook is closed. * SqlSessionManager is ADS level manager * Moved path to SqlKernel constructor
This commit is contained in:
@@ -12,7 +12,6 @@ import QueryRunner, { EventType } from 'sql/platform/query/common/queryRunner';
|
|||||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import Severity from 'vs/base/common/severity';
|
import Severity from 'vs/base/common/severity';
|
||||||
import * as Utils from 'sql/platform/connection/common/utils';
|
|
||||||
import { Deferred } from 'sql/base/common/promise';
|
import { Deferred } from 'sql/base/common/promise';
|
||||||
import { Disposable } from 'vs/base/common/lifecycle';
|
import { Disposable } from 'vs/base/common/lifecycle';
|
||||||
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
|
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
|
||||||
@@ -46,6 +45,8 @@ export interface SQLData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SqlSessionManager implements nb.SessionManager {
|
export class SqlSessionManager implements nb.SessionManager {
|
||||||
|
private static _sessions: nb.ISession[] = [];
|
||||||
|
|
||||||
constructor(private _instantiationService: IInstantiationService) { }
|
constructor(private _instantiationService: IInstantiationService) { }
|
||||||
|
|
||||||
public get isReady(): boolean {
|
public get isReady(): boolean {
|
||||||
@@ -65,11 +66,25 @@ export class SqlSessionManager implements nb.SessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startNew(options: nb.ISessionOptions): Thenable<nb.ISession> {
|
startNew(options: nb.ISessionOptions): Thenable<nb.ISession> {
|
||||||
let session = new SqlSession(options, this._instantiationService);
|
let sqlSession = new SqlSession(options, this._instantiationService);
|
||||||
return Promise.resolve(session);
|
let index = SqlSessionManager._sessions.findIndex(session => session.path === options.path);
|
||||||
|
if (index > -1) {
|
||||||
|
SqlSessionManager._sessions.splice(index);
|
||||||
|
}
|
||||||
|
SqlSessionManager._sessions.push(sqlSession);
|
||||||
|
return Promise.resolve(sqlSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown(id: string): Thenable<void> {
|
shutdown(id: string): Thenable<void> {
|
||||||
|
let index = SqlSessionManager._sessions.findIndex(session => session.id === id);
|
||||||
|
if (index > -1) {
|
||||||
|
let sessionManager = SqlSessionManager._sessions[index];
|
||||||
|
SqlSessionManager._sessions.splice(index);
|
||||||
|
if (sessionManager && sessionManager.kernel) {
|
||||||
|
let sqlKernel = sessionManager.kernel as SqlKernel;
|
||||||
|
return sqlKernel.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +103,7 @@ export class SqlSession implements nb.ISession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(private options: nb.ISessionOptions, private _instantiationService: IInstantiationService) {
|
constructor(private options: nb.ISessionOptions, private _instantiationService: IInstantiationService) {
|
||||||
this._kernel = this._instantiationService.createInstance(SqlKernel);
|
this._kernel = this._instantiationService.createInstance(SqlKernel, options.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get canChangeKernels(): boolean {
|
public get canChangeKernels(): boolean {
|
||||||
@@ -96,7 +111,7 @@ export class SqlSession implements nb.ISession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get id(): string {
|
public get id(): string {
|
||||||
return this.options.kernelId || '';
|
return this.options.kernelId || this.kernel ? this._kernel.id : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public get path(): string {
|
public get path(): string {
|
||||||
@@ -146,7 +161,8 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
|||||||
private _executionCount: number = 0;
|
private _executionCount: number = 0;
|
||||||
private _magicToExecutorMap = new Map<string, ExternalScriptMagic>();
|
private _magicToExecutorMap = new Map<string, ExternalScriptMagic>();
|
||||||
|
|
||||||
constructor(@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
constructor(private _path: string,
|
||||||
|
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||||
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
|
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
|
||||||
@IInstantiationService private _instantiationService: IInstantiationService,
|
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||||
@IErrorMessageService private _errorMessageService: IErrorMessageService,
|
@IErrorMessageService private _errorMessageService: IErrorMessageService,
|
||||||
@@ -232,9 +248,8 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
|||||||
}
|
}
|
||||||
this._queryRunner.runQuery(code);
|
this._queryRunner.runQuery(code);
|
||||||
} else if (this._currentConnection && this._currentConnectionProfile) {
|
} else if (this._currentConnection && this._currentConnectionProfile) {
|
||||||
let connectionUri = Utils.generateUri(this._currentConnectionProfile, 'notebook');
|
this._queryRunner = this._instantiationService.createInstance(QueryRunner, this._path);
|
||||||
this._queryRunner = this._instantiationService.createInstance(QueryRunner, connectionUri);
|
this._connectionManagementService.connect(this._currentConnectionProfile, this._path).then((result) => {
|
||||||
this._connectionManagementService.connect(this._currentConnectionProfile, connectionUri).then((result) => {
|
|
||||||
this.addQueryEventListeners(this._queryRunner);
|
this.addQueryEventListeners(this._queryRunner);
|
||||||
this._queryRunner.runQuery(code);
|
this._queryRunner.runQuery(code);
|
||||||
});
|
});
|
||||||
@@ -311,6 +326,13 @@ class SqlKernel extends Disposable implements nb.IKernel {
|
|||||||
}
|
}
|
||||||
// TODO issue #2746 should ideally show a warning inside the dialog if have no data
|
// TODO issue #2746 should ideally show a warning inside the dialog if have no data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async disconnect(): Promise<void> {
|
||||||
|
if (this._path) {
|
||||||
|
await this._connectionManagementService.disconnect(this._path);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SQLFuture extends Disposable implements FutureInternal {
|
export class SQLFuture extends Disposable implements FutureInternal {
|
||||||
|
|||||||
Reference in New Issue
Block a user