use listdatabases for sqlondemand (#10398)

* use listdatabases for sqlondemand

* comments

* use enum
This commit is contained in:
Alan Ren
2020-05-14 14:25:29 -07:00
committed by GitHub
parent 8f7861deac
commit f934dea6ea
2 changed files with 49 additions and 36 deletions

View File

@@ -26,6 +26,8 @@ import { ILogService } from 'vs/platform/log/common/log';
import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { attachInputBoxStyler } from 'vs/platform/theme/common/styler';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { DatabaseEngineEdition } from 'sql/workbench/api/common/sqlExtHostTypes';
@Component({
selector: 'explorer-widget',
@@ -51,6 +53,7 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
@Inject(IMenuService) private readonly menuService: IMenuService,
@Inject(IContextKeyService) private readonly contextKeyService: IContextKeyService,
@Inject(IEditorProgressService) private readonly progressService: IEditorProgressService,
@Inject(IConnectionManagementService) private readonly connectionManagementService: IConnectionManagementService,
@Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef
) {
super(changeRef);
@@ -95,7 +98,6 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
this._register(subscriptionToDisposable(this._bootstrap.metadataService.metadata.subscribe(
data => {
if (data) {
const objectData = ObjectMetadataWrapper.createFromObjectMetadata(data.objectMetadata);
objectData.sort(ObjectMetadataWrapper.sort);
this.updateTable(objectData);
@@ -106,34 +108,55 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
}
)));
} else {
this._register(subscriptionToDisposable(this._bootstrap.metadataService.databases.subscribe(
data => {
// Handle the case where there is no metadata service
data = data || [];
if (isStringArray(data)) {
data = data.map(item => {
const dbInfo: DatabaseInfo = { options: {} };
dbInfo.options[NameProperty] = item;
return dbInfo;
});
// TODO: remove this ADS side workaround for SQL On-Demand and handle it in SQL Tools Service
if (this._bootstrap.connectionManagementService.connectionInfo.serverInfo.engineEditionId === DatabaseEngineEdition.SqlOnDemand) {
this.connectionManagementService.listDatabases(this._bootstrap.connectionManagementService.connectionInfo.ownerUri).then(
result => {
// Sort the databases: system databases first and then the sorted list of other databases
const sysDatabases = ['master', 'model', 'msdb', 'tempdb'];
const databaseNames = result.databaseNames.filter(db => sysDatabases.indexOf(db) !== -1).
concat(result.databaseNames.filter(db => sysDatabases.indexOf(db) === -1).sort());
this.handleServerContextResults(databaseNames);
},
error => {
this.showErrorMessage(nls.localize('dashboard.explorer.databaseError', "Unable to load databases"));
}
const currentProfile = this._bootstrap.connectionManagementService.connectionInfo.connectionProfile;
this.updateTable(data.map(d => {
const item = assign({}, d.options);
const profile = currentProfile.toIConnectionProfile();
profile.databaseName = d.options[NameProperty];
item[ConnectionProfilePropertyName] = profile;
return item;
}));
},
error => {
this.showErrorMessage(nls.localize('dashboard.explorer.databaseError', "Unable to load databases"));
}
)));
);
}
else {
this._register(subscriptionToDisposable(this._bootstrap.metadataService.databases.subscribe(
data => {
this.handleServerContextResults(data);
},
error => {
this.showErrorMessage(nls.localize('dashboard.explorer.databaseError', "Unable to load databases"));
}
)));
}
}
}
private handleServerContextResults(data: string[] | DatabaseInfo[]): void {
// Handle the case where there is no metadata service
data = data || [];
if (isStringArray(data)) {
data = data.map(item => {
const dbInfo: DatabaseInfo = { options: {} };
dbInfo.options[NameProperty] = item;
return dbInfo;
});
}
const currentProfile = this._bootstrap.connectionManagementService.connectionInfo.connectionProfile;
this.updateTable(data.map(d => {
const item = assign({}, d.options);
const profile = currentProfile.toIConnectionProfile();
profile.databaseName = d.options[NameProperty];
item[ConnectionProfilePropertyName] = profile;
return item;
}));
}
private updateTable(data: Slick.SlickData[]) {
this._table.setData(data);
this.setLoadingStatus(false);