diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQuerier.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQuerier.cs index aececc7a..2f0f0023 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQuerier.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQuerier.cs @@ -65,6 +65,14 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel return reader; } + /// + /// Mthod used to do custom filtering on smo objects if cannot be implemented using the filters + /// + protected virtual bool PassesFinalFilters(SqlSmoObject parent, SqlSmoObject smoObject) + { + return true; + } + /// /// Gets the urn from the enumResult /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.cs index c117ede7..2f2a58f6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.cs @@ -42,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -82,7 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -122,7 +122,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -162,7 +162,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -202,7 +202,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -242,7 +242,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -282,7 +282,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -322,7 +322,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -362,7 +362,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -402,7 +402,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -442,7 +442,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -482,7 +482,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServer, c) && urns.Contains(c.Urn)); } else { @@ -522,7 +522,47 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper
(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); + } + else + { + return new SmoCollectionWrapper
(retValue); + } + } + } + return Enumerable.Empty(); + } + } + + [Export(typeof(SmoQuerier))] + internal partial class SqlHistoryTableQuerier: SmoQuerier + { + Type[] supportedTypes = new Type[] { typeof(Table) }; + + public override Type[] SupportedObjectTypes { get { return supportedTypes; } } + + public override IEnumerable Query(SmoQueryContext context, string filter) + { + Table parentTable = context.Parent as Table; + if (parentTable != null) + { + bool hasFilter = !string.IsNullOrEmpty(filter); + var retValue = parentTable.Parent.Tables; + if (retValue != null) + { + HashSet urns = null; + if (hasFilter) + { + string urn = $"{parentTable.Parent.Urn.ToString()}/Table" + filter; + Enumerator en = new Enumerator(); + Request request = new Request(new Urn(urn)); + ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject); + EnumResult result = en.Process(serverConnection, request); + urns = GetUrns(result); + } + if (hasFilter && urns != null) + { + return new SmoCollectionWrapper
(retValue).Where(c => PassesFinalFilters(parentTable, c) && urns.Contains(c.Urn)); } else { @@ -562,7 +602,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -602,7 +642,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -642,7 +682,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentTableViewTableTypeBase, c) && urns.Contains(c.Urn)); } else { @@ -682,7 +722,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentTableViewTableTypeBase, c) && urns.Contains(c.Urn)); } else { @@ -722,7 +762,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentTable, c) && urns.Contains(c.Urn)); } else { @@ -762,7 +802,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentTable, c) && urns.Contains(c.Urn)); } else { @@ -825,7 +865,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentTable, c) && urns.Contains(c.Urn)); } else { @@ -888,7 +928,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentTableViewBase, c) && urns.Contains(c.Urn)); } else { @@ -928,7 +968,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -968,7 +1008,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1008,7 +1048,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1048,7 +1088,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1088,7 +1128,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1128,7 +1168,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1168,7 +1208,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1208,7 +1248,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1248,7 +1288,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1288,7 +1328,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1328,7 +1368,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1368,7 +1408,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1408,7 +1448,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentFileGroup, c) && urns.Contains(c.Urn)); } else { @@ -1448,7 +1488,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1488,7 +1528,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1528,7 +1568,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1568,7 +1608,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1608,7 +1648,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1648,7 +1688,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1688,7 +1728,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1728,7 +1768,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1768,7 +1808,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1808,7 +1848,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1894,7 +1934,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1934,7 +1974,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -1974,7 +2014,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2014,7 +2054,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2054,7 +2094,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2094,7 +2134,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2134,7 +2174,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2197,7 +2237,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServiceBroker, c) && urns.Contains(c.Urn)); } else { @@ -2237,7 +2277,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServiceBroker, c) && urns.Contains(c.Urn)); } else { @@ -2277,7 +2317,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServiceBroker, c) && urns.Contains(c.Urn)); } else { @@ -2317,7 +2357,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServiceBroker, c) && urns.Contains(c.Urn)); } else { @@ -2357,7 +2397,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServiceBroker, c) && urns.Contains(c.Urn)); } else { @@ -2397,7 +2437,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentServiceBroker, c) && urns.Contains(c.Urn)); } else { @@ -2437,7 +2477,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2477,7 +2517,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2517,7 +2557,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2557,7 +2597,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { @@ -2597,7 +2637,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentStoredProcedure, c) && urns.Contains(c.Urn)); } else { @@ -2624,7 +2664,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentUserDefinedAggregate, c) && urns.Contains(c.Urn)); } else { @@ -2651,7 +2691,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentUserDefinedFunction, c) && urns.Contains(c.Urn)); } else { @@ -2691,7 +2731,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentPartitionFunction, c) && urns.Contains(c.Urn)); } else { @@ -2722,7 +2762,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel HashSet urns = null; if (hasFilter) { - string urn = $"{parentDatabase.Urn.ToString()}/SystemDataType" + filter; + string urn = $"{parentDatabase.Parent.Urn.ToString()}/SystemDataType" + filter; Enumerator en = new Enumerator(); Request request = new Request(new Urn(urn)); ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject); @@ -2731,7 +2771,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel } if (hasFilter && urns != null) { - return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn)); + return new SmoCollectionWrapper(retValue).Where(c => PassesFinalFilters(parentDatabase, c) && urns.Contains(c.Urn)); } else { diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.tt b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.tt index 6243c4f6..b295c12a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.tt +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.tt @@ -75,13 +75,21 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel if (IsCollection(nodeElement)) { - + string fieldForUrn = GetNavPathFieldForUrn(xmlFile, nodeName, parentType); + if (!string.IsNullOrEmpty(fieldForUrn)) + { + fieldForUrn = string.Format("{0}.{1}", parentVar, fieldForUrn); + } + else + { + fieldForUrn = parentVar; + } WriteLine("HashSet urns = null;"); WriteLine("if (hasFilter)"); WriteLine("{"); PushIndent(indent); - WriteLine(string.Format("string urn = $\"{{{0}.Urn.ToString()}}/{1}\" + filter;", parentVar, nodeType)); + WriteLine(string.Format("string urn = $\"{{{0}.Urn.ToString()}}/{1}\" + filter;", fieldForUrn, nodeType)); WriteLine("Enumerator en = new Enumerator();"); WriteLine("Request request = new Request(new Urn(urn));"); WriteLine("ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);"); @@ -92,7 +100,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel WriteLine("if (hasFilter && urns != null)"); WriteLine("{"); PushIndent(indent); - WriteLine(string.Format("return new SmoCollectionWrapper<{0}>(retValue).Where(c => urns.Contains(c.Urn));", nodeType)); + WriteLine(string.Format("return new SmoCollectionWrapper<{0}>(retValue).Where(c => PassesFinalFilters({1}, c) && urns.Contains(c.Urn));", nodeType, parentVar)); PopIndent(); WriteLine("}"); WriteLine("else"); @@ -162,6 +170,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel return navPathElement == null ? null : navPathElement.GetAttribute("Field"); } + public static string GetNavPathFieldForUrn(string xmlFile, string nodeName, string parent) + { + XmlDocument doc = new XmlDocument(); + doc.Load(xmlFile); + XmlElement navPathElement = (XmlElement)doc.SelectSingleNode(string.Format("/SmoQueryModel/Node[@Name='{0}']/NavigationPath[@Parent='{1}']", nodeName, parent)); + + return navPathElement == null ? null : navPathElement.GetAttribute("FieldForUrn"); + } + public static string GetNavigationPath(XmlElement nodeElement, string xmlFile, string nodeName, string parentName) { string navPathField = GetNavPathField(xmlFile, nodeName, parentName); diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModelDefinition.xml b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModelDefinition.xml index f8d14777..9722214a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModelDefinition.xml +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModelDefinition.xml @@ -36,6 +36,10 @@ + + + + @@ -131,7 +135,7 @@ - + - + TableTemporalType.HistoryTable @@ -166,8 +166,10 @@ - + + + diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/TreeNodeGenerator.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/TreeNodeGenerator.cs index e74c1407..c4d906b3 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/TreeNodeGenerator.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/TreeNodeGenerator.cs @@ -1271,6 +1271,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel { Property = "TemporalType", Type = typeof(Enum), + TypeToReverse = typeof(SqlHistoryTableQuerier), ValidFor = ValidForFlag.Sql2016|ValidForFlag.AzureV12, Values = new List { @@ -1325,7 +1326,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel { get { - return new [] { typeof(SqlTableQuerier), }; + return new [] { typeof(SqlTableQuerier), typeof(SqlHistoryTableQuerier), }; } } @@ -1351,6 +1352,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel NodeTypeId = NodeTypes.Columns, SortPriority = SmoTreeNode.NextSortPriority, }); + currentChildren.Add(new FolderNode { + NodeValue = SR.SchemaHierarchy_Constraints, + NodeType = "Folder", + NodeTypeId = NodeTypes.Constraints, + SortPriority = SmoTreeNode.NextSortPriority, + }); currentChildren.Add(new FolderNode { NodeValue = SR.SchemaHierarchy_Indexes, NodeType = "Folder", @@ -1369,8 +1376,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel { get { - return new [] { typeof(SqlTableQuerier), }; - } + return new Type[0]; } } public override TreeNode CreateChild(TreeNode parent, object context) diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestData/ObjectExplorer/Baselines/AllSqlObjects.txt b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestData/ObjectExplorer/Baselines/AllSqlObjects.txt index 7c1a8e58..cdbf63e4 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestData/ObjectExplorer/Baselines/AllSqlObjects.txt +++ b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestData/ObjectExplorer/Baselines/AllSqlObjects.txt @@ -43,6 +43,21 @@ NodeType: Column Label: ValidFrom NodeType: Column Label: ValidTo NodeType: Key Label: PK_Employee_History_BusinessEntityID NodeType: Statistic Label: PK_Employee_History_BusinessEntityID +NodeType: HistoryTable Label: HumanResources.Employee_Temporal_History +NodeType: Column Label: BusinessEntityID +NodeType: Column Label: NationalIDNumber +NodeType: Column Label: LoginID +NodeType: Column Label: OrganizationNode +NodeType: Column Label: OrganizationLevel +NodeType: Column Label: JobTitle +NodeType: Column Label: BirthDate +NodeType: Column Label: MaritalStatus +NodeType: Column Label: Gender +NodeType: Column Label: HireDate +NodeType: Column Label: VacationHours +NodeType: Column Label: SickLeaveHours +NodeType: Column Label: ValidFrom +NodeType: Column Label: ValidTo NodeType: Table Label: Person.Person NodeType: Column Label: BusinessEntityID NodeType: Column Label: PersonType