Skip to content

Commit

Permalink
use listdatabases for sqlondemand (microsoft#10398)
Browse files Browse the repository at this point in the history
* use listdatabases for sqlondemand

* comments

* use enum
  • Loading branch information
alanrenmsft authored May 14, 2020
1 parent 8f7861d commit f934dea
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
12 changes: 1 addition & 11 deletions extensions/mssql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,17 +478,7 @@
{
"displayName": "%databasesListProperties.name%",
"value": "name",
"widthWeight": 60
},
{
"displayName": "%databasesListProperties.status%",
"value": "state",
"widthWeight": 20
},
{
"displayName": "%databasesListProperties.size%",
"value": "sizeInMB",
"widthWeight": 20
"widthWeight": 100
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -106,32 +108,53 @@ 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"));
}
);
}
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"));
}
)));
}
}
}

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"));
}
)));
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[]) {
Expand Down

0 comments on commit f934dea

Please sign in to comment.