improving OE tables expand (#555)

* improving OE tables expand for dw database
This commit is contained in:
Leila Lali
2017-12-01 14:49:42 -08:00
committed by GitHub
parent ab332cba9b
commit 1ec297efe2
11 changed files with 84 additions and 43 deletions

View File

@@ -45,12 +45,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
/// <summary> /// <summary>
/// Returns the node sub type if the object can have sub types otehr wise returns empty string /// Returns the node sub type if the object can have sub types otehr wise returns empty string
/// </summary> /// </summary>
public abstract string GetNodeSubType(object context); public abstract string GetNodeSubType(object smoObject, SmoQueryContext smoContext);
/// <summary> /// <summary>
/// Returns the status of the object assigned to node. If the object doesn't spport status returns empty string /// Returns the status of the object assigned to node. If the object doesn't spport status returns empty string
/// </summary> /// </summary>
public abstract string GetNodeStatus(object context); public abstract string GetNodeStatus(object smoObject, SmoQueryContext smoContext);
/// <summary> /// <summary>
/// Returns the custom name of the object assigned to the node. If the object doesn't have custom name, returns empty string /// Returns the custom name of the object assigned to the node. If the object doesn't have custom name, returns empty string

View File

@@ -3,6 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -29,6 +30,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
get { return numInits.HasValue && numInits != 0; } get { return numInits.HasValue && numInits != 0; }
} }
public bool IsSorted
{
get
{
// SMO objects are already sorted so no need to sort them again
return this.FirstOrDefault() is SmoTreeNode;
}
}
public void BeginInit() public void BeginInit()
{ {
if (!numInits.HasValue) if (!numInits.HasValue)
@@ -53,8 +63,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
numInits.Value == 1) numInits.Value == 1)
{ {
try try
{
if (!IsSorted)
{ {
DoSort(); DoSort();
}
if (deferredChildren != null) if (deferredChildren != null)
{ {

View File

@@ -17,6 +17,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
public class SmoChildFactoryBase : ChildFactory public class SmoChildFactoryBase : ChildFactory
{ {
private IEnumerable<NodeSmoProperty> smoProperties;
public override IEnumerable<string> ApplicableParents() public override IEnumerable<string> ApplicableParents()
{ {
return null; return null;
@@ -230,6 +231,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
} }
else else
{ {
smoProperties = SmoProperties;
SmoTreeNode childAsMeItem = (SmoTreeNode)child; SmoTreeNode childAsMeItem = (SmoTreeNode)child;
childAsMeItem.CacheInfoFromModel(smoObj); childAsMeItem.CacheInfoFromModel(smoObj);
SmoQueryContext smoContext = parent.GetContextAs<SmoQueryContext>(); SmoQueryContext smoContext = parent.GetContextAs<SmoQueryContext>();
@@ -241,8 +243,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
childAsMeItem.NodeValue = customizedName; childAsMeItem.NodeValue = customizedName;
} }
childAsMeItem.NodeSubType = GetNodeSubType(context); childAsMeItem.NodeSubType = GetNodeSubType(context, smoContext);
childAsMeItem.NodeStatus = GetNodeStatus(context); childAsMeItem.NodeStatus = GetNodeStatus(context, smoContext);
} }
} }
@@ -270,6 +272,14 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
} }
} }
internal IEnumerable<NodeSmoProperty> CachedSmoProperties
{
get
{
return smoProperties == null ? SmoProperties : smoProperties;
}
}
/// <summary> /// <summary>
/// Returns true if any final validation of the object to be added passes, and false /// Returns true if any final validation of the object to be added passes, and false
/// if validation fails. This provides a chance to filter specific items out of a list /// if validation fails. This provides a chance to filter specific items out of a list
@@ -282,16 +292,31 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return true; return true;
} }
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
return string.Empty; return string.Empty;
} }
public override string GetNodeStatus(object context) public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
{ {
return string.Empty; return string.Empty;
} }
public static bool IsPropertySupported(string propertyName, SmoQueryContext context, NamedSmoObject smoObj, IEnumerable<NodeSmoProperty> supportedProperties)
{
var property = supportedProperties.FirstOrDefault(x => string.Compare(x.Name, propertyName, StringComparison.InvariantCultureIgnoreCase) == 0);
if (property != null)
{
return ServerVersionHelper.IsValidFor(context.ValidFor, property.ValidFor);
}
else
{
// Return true if cannot find the proeprty, SMO still tries to get that property but adding the property to supported list can make loading the nodes faster
Logger.Write(LogLevel.Verbose, $"Smo property name {propertyName} for Smo type {smoObj.GetType()} is not added as supported properties. This can cause the performance of loading the OE nodes");
return true;
}
}
public override string GetNodeCustomName(object smoObject, SmoQueryContext smoContext) public override string GetNodeCustomName(object smoObject, SmoQueryContext smoContext)
{ {
return string.Empty; return string.Empty;

View File

@@ -4,6 +4,8 @@
// //
using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using System.Collections.Generic;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
@@ -12,21 +14,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
/// </summary> /// </summary>
internal partial class DatabasesChildFactory : SmoChildFactoryBase internal partial class DatabasesChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeStatus(object context) public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
{ {
return DatabasesCustomNodeHelper.GetStatus(context); return DatabasesCustomNodeHelper.GetStatus(smoObject, smoContext, CachedSmoProperties);
} }
} }
internal static class DatabasesCustomNodeHelper internal static class DatabasesCustomNodeHelper
{ {
internal static string GetStatus(object context) internal static string GetStatus(object smoObject, SmoQueryContext smoContext, IEnumerable<NodeSmoProperty> supportedProperties)
{ {
Database db = context as Database; Database db = smoObject as Database;
if (db != null) if (db != null && SmoChildFactoryBase.IsPropertySupported("Status", smoContext, db, supportedProperties))
{ {
DatabaseStatus status; DatabaseStatus status;
try { try
{
status = db.Status; status = db.Status;
} }
catch (SqlServer.Management.Common.ConnectionFailureException) catch (SqlServer.Management.Common.ConnectionFailureException)

View File

@@ -12,9 +12,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
/// </summary> /// </summary>
internal partial class KeysChildFactory : SmoChildFactoryBase internal partial class KeysChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
return IndexCustomeNodeHelper.GetSubType(context); return IndexCustomeNodeHelper.GetSubType(smoObject);
} }
} }
@@ -23,9 +23,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
/// </summary> /// </summary>
internal partial class IndexesChildFactory : SmoChildFactoryBase internal partial class IndexesChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
return IndexCustomeNodeHelper.GetSubType(context); return IndexCustomeNodeHelper.GetSubType(smoObject);
} }
public override string GetNodeCustomName(object smoObject, SmoQueryContext smoContext) public override string GetNodeCustomName(object smoObject, SmoQueryContext smoContext)
@@ -39,9 +39,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
/// </summary> /// </summary>
internal partial class UserDefinedTableTypeKeysChildFactory : SmoChildFactoryBase internal partial class UserDefinedTableTypeKeysChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
return IndexCustomeNodeHelper.GetSubType(context); return IndexCustomeNodeHelper.GetSubType(smoObject);
} }
} }

View File

@@ -12,9 +12,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
/// </summary> /// </summary>
internal partial class ServerLevelLoginsChildFactory : SmoChildFactoryBase internal partial class ServerLevelLoginsChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeStatus(object context) public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
{ {
return LoginCustomNodeHelper.GetStatus(context); return LoginCustomNodeHelper.GetStatus(smoObject);
} }
} }

View File

@@ -18,9 +18,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext); return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext);
} }
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
return ParameterCustomeNodeHelper.GetSubType(context); return ParameterCustomeNodeHelper.GetSubType(smoObject);
} }
} }
@@ -33,9 +33,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext); return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext);
} }
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
return ParameterCustomeNodeHelper.GetSubType(context); return ParameterCustomeNodeHelper.GetSubType(smoObject);
} }
} }
@@ -48,9 +48,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext); return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext);
} }
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
return ParameterCustomeNodeHelper.GetSubType(context); return ParameterCustomeNodeHelper.GetSubType(smoObject);
} }
} }
@@ -63,9 +63,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext); return ParameterCustomeNodeHelper.GetCustomLabel(smoObject, smoContext);
} }
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
return ParameterCustomeNodeHelper.GetSubType(context); return ParameterCustomeNodeHelper.GetSubType(smoObject);
} }
} }

View File

@@ -17,7 +17,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
try try
{ {
Table table = smoObject as Table; Table table = smoObject as Table;
if (table != null && table.IsSystemVersioned) if (table != null && IsPropertySupported("IsSystemVersioned", smoContext, table, CachedSmoProperties) && table.IsSystemVersioned)
{ {
return $"{table.Schema}.{table.Name} ({SR.SystemVersioned_LabelPart})"; return $"{table.Schema}.{table.Name} ({SR.SystemVersioned_LabelPart})";
} }
@@ -30,12 +30,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return string.Empty; return string.Empty;
} }
public override string GetNodeSubType(object context) public override string GetNodeSubType(object smoObject, SmoQueryContext smoContext)
{ {
try try
{ {
Table table = context as Table; Table table = smoObject as Table;
if (table != null && table.TemporalType != TableTemporalType.None) if (table != null && IsPropertySupported("TemporalType", smoContext, table, CachedSmoProperties) && table.TemporalType != TableTemporalType.None)
{ {
return "Temporal"; return "Temporal";
} }

View File

@@ -12,25 +12,25 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
/// </summary> /// </summary>
internal partial class TriggersChildFactory : SmoChildFactoryBase internal partial class TriggersChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeStatus(object context) public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
{ {
return TriggersCustomeNodeHelper.GetStatus(context); return TriggersCustomeNodeHelper.GetStatus(smoObject);
} }
} }
internal partial class ServerLevelServerTriggersChildFactory : SmoChildFactoryBase internal partial class ServerLevelServerTriggersChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeStatus(object context) public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
{ {
return TriggersCustomeNodeHelper.GetStatus(context); return TriggersCustomeNodeHelper.GetStatus(smoObject);
} }
} }
internal partial class DatabaseTriggersChildFactory : SmoChildFactoryBase internal partial class DatabaseTriggersChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeStatus(object context) public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
{ {
return TriggersCustomeNodeHelper.GetStatus(context); return TriggersCustomeNodeHelper.GetStatus(smoObject);
} }
} }

View File

@@ -12,9 +12,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
/// </summary> /// </summary>
internal partial class UsersChildFactory : SmoChildFactoryBase internal partial class UsersChildFactory : SmoChildFactoryBase
{ {
public override string GetNodeStatus(object context) public override string GetNodeStatus(object smoObject, SmoQueryContext smoContext)
{ {
return UserCustomeNodeHelper.GetStatus(context); return UserCustomeNodeHelper.GetStatus(smoObject);
} }
} }

View File

@@ -33,8 +33,8 @@ NodeType: Column Label: SickLeaveHours (smallint, not null) SubType: Status:
NodeType: Column Label: CurrentFlag (Flag(bit), not null) SubType: Status: NodeType: Column Label: CurrentFlag (Flag(bit), not null) SubType: Status:
NodeType: Column Label: rowguid (uniqueidentifier, not null) SubType: Status: NodeType: Column Label: rowguid (uniqueidentifier, not null) SubType: Status:
NodeType: Column Label: ModifiedDate (datetime, not null) SubType: Status: NodeType: Column Label: ModifiedDate (datetime, not null) SubType: Status:
NodeType: Key Label: FK_Employee_Person_BusinessEntityID SubType:ForeignKey Status:
NodeType: Key Label: PK_Employee_BusinessEntityID SubType:PrimaryKey Status: NodeType: Key Label: PK_Employee_BusinessEntityID SubType:PrimaryKey Status:
NodeType: Key Label: FK_Employee_Person_BusinessEntityID SubType:ForeignKey Status:
NodeType: Constraint Label: CK_Employee_BirthDate SubType: Status: NodeType: Constraint Label: CK_Employee_BirthDate SubType: Status:
NodeType: Constraint Label: CK_Employee_Gender SubType: Status: NodeType: Constraint Label: CK_Employee_Gender SubType: Status:
NodeType: Constraint Label: CK_Employee_HireDate SubType: Status: NodeType: Constraint Label: CK_Employee_HireDate SubType: Status:
@@ -156,7 +156,6 @@ NodeType: DatabaseRole Label: db_securityadmin SubType: Status:
NodeType: DatabaseRole Label: public SubType: Status: NodeType: DatabaseRole Label: public SubType: Status:
NodeType: DatabaseRole Label: SalesManagers SubType: Status: NodeType: DatabaseRole Label: SalesManagers SubType: Status:
NodeType: DatabaseRole Label: SalesPersons SubType: Status: NodeType: DatabaseRole Label: SalesPersons SubType: Status:
NodeType: Schema Label: dbo SubType: Status:
NodeType: Schema Label: db_accessadmin SubType: Status: NodeType: Schema Label: db_accessadmin SubType: Status:
NodeType: Schema Label: db_backupoperator SubType: Status: NodeType: Schema Label: db_backupoperator SubType: Status:
NodeType: Schema Label: db_datareader SubType: Status: NodeType: Schema Label: db_datareader SubType: Status:
@@ -166,6 +165,7 @@ NodeType: Schema Label: db_denydatareader SubType: Status:
NodeType: Schema Label: db_denydatawriter SubType: Status: NodeType: Schema Label: db_denydatawriter SubType: Status:
NodeType: Schema Label: db_owner SubType: Status: NodeType: Schema Label: db_owner SubType: Status:
NodeType: Schema Label: db_securityadmin SubType: Status: NodeType: Schema Label: db_securityadmin SubType: Status:
NodeType: Schema Label: dbo SubType: Status:
NodeType: Schema Label: Demo SubType: Status: NodeType: Schema Label: Demo SubType: Status:
NodeType: Schema Label: guest SubType: Status: NodeType: Schema Label: guest SubType: Status:
NodeType: Schema Label: HumanResources SubType: Status: NodeType: Schema Label: HumanResources SubType: Status: