Skip to content

Commit 45a4937

Browse files
authored
Flatten | DbMetaDataFactory -> SqlMetaDataFactory (#3818)
* Remove unnecessary references to DbMetaDataFactory * Remove unnecessary cacheMetaDataFactory parameter and logic * Remove unused capability to provide normalized server version SqlConnectionFactory always passed the same value to both parameters * Convert CollectionDataSet property to auto-property * Cleanup of SqlMetaDataFactory prior to merge Convert the list of unsupported engines to a static variable. Make the UDT/TVP processing methods static. Change name of constants and ServerVersion parameter to fit naming conventions. Introduce constant for EngineEdition query. Reuse SqlCommand where possible. Remove layer of indentation for using block. Remove redundant client-side checks for null on fields which are declared as non-nullable within SQL Server. Slightly simplify building of assembly qualified names. Convert checks whether columns exist in a DataTable (and DataTables in a DataSet) to debug assertions, since these are statically built now. * Cleanup of DbMetaDataFactory prior to merge Move constants which were only used in one method to that method. Replace an unnecessary string[] allocation with a stack-allocated ReadOnlySpan<string>. Where appropriate, use ?.. Replace == null and != null with pattern matching. Convert checks whether columns exist in a DataTable (and DataTables in a DataSet) to debug assertions, since these are statically built now. Replace use of GetSchemaTable with GetColumnSchema to reduce allocations. Where appropriate, make methods private and/or static. Remove unnecessary ADP.CompareInsensitiveInvariant helper. Simplify IncludeThisColumn to make use of Contains or IndexOf where necessary. * Merge logic to create CollectionDataSet * Merge Dispose logic Also implement IDisposable on SqlMetaDataFactory * Merge DataTable population method * Merge ExecuteCommand population method * Merge top-level GetSchema method * Merge SupportedByCurrentVersion and properties, remove now-unused base class methods * Replace unnecessary private properties with variables * Remove DbMetaDataFactory
1 parent 6b047ab commit 45a4937

File tree

8 files changed

+785
-966
lines changed

8 files changed

+785
-966
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@
209209
<Compile Include="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbConnectionInternal.cs">
210210
<Link>Microsoft\Data\ProviderBase\DbConnectionInternal.cs</Link>
211211
</Compile>
212-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbMetaDataFactory.cs">
213-
<Link>Microsoft\Data\ProviderBase\DbMetaDataFactory.cs</Link>
214-
</Compile>
215212
<Compile Include="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbReferenceCollection.cs">
216213
<Link>Microsoft\Data\ProviderBase\DbReferenceCollection.cs</Link>
217214
</Compile>

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@
282282
<Compile Include="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbConnectionInternal.cs">
283283
<Link>Microsoft\Data\ProviderBase\DbConnectionInternal.cs</Link>
284284
</Compile>
285-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbMetaDataFactory.cs">
286-
<Link>Microsoft\Data\ProviderBase\DbMetaDataFactory.cs</Link>
287-
</Compile>
288285
<Compile Include="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbReferenceCollection.cs">
289286
<Link>Microsoft\Data\ProviderBase\DbReferenceCollection.cs</Link>
290287
</Compile>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,6 @@ internal static IndexOutOfRangeException InvalidBufferSizeOrIndex(int numBytes,
11291129
internal static Exception InvalidDataLength(long length)
11301130
=> IndexOutOfRange(StringsHelper.GetString(Strings.SQL_InvalidDataLength, length.ToString(CultureInfo.InvariantCulture)));
11311131

1132-
internal static bool CompareInsensitiveInvariant(string strvalue, string strconst)
1133-
=> 0 == CultureInfo.InvariantCulture.CompareInfo.Compare(strvalue, strconst, CompareOptions.IgnoreCase);
1134-
11351132
internal static void SetCurrentTransaction(Transaction transaction) => Transaction.Current = transaction;
11361133

11371134
internal static Exception NonSeqByteAccess(long badIndex, long currIndex, string method)
@@ -1142,9 +1139,6 @@ internal static Exception NonSeqByteAccess(long badIndex, long currIndex, string
11421139

11431140
internal static Exception NegativeParameter(string parameterName) => InvalidOperation(StringsHelper.GetString(Strings.ADP_NegativeParameter, parameterName));
11441141

1145-
internal static Exception InvalidXmlMissingColumn(string collectionName, string columnName)
1146-
=> Argument(StringsHelper.GetString(Strings.MDF_InvalidXmlMissingColumn, collectionName, columnName));
1147-
11481142
internal static InvalidOperationException AsyncOperationPending() => InvalidOperation(StringsHelper.GetString(Strings.ADP_PendingAsyncOperation));
11491143
#endregion
11501144

@@ -1231,7 +1225,7 @@ internal static Exception InvalidCommandTimeout(int value, [CallerMemberName] st
12311225
=> Argument(StringsHelper.GetString(Strings.ADP_InvalidCommandTimeout, value.ToString(CultureInfo.InvariantCulture)), property);
12321226
#endregion
12331227

1234-
#region DbMetaDataFactory
1228+
#region SqlMetaDataFactory
12351229
internal static Exception DataTableDoesNotExist(string collectionName)
12361230
=> Argument(StringsHelper.GetString(Strings.MDF_DataTableDoesNotExist, collectionName));
12371231

@@ -1268,8 +1262,6 @@ internal static InvalidOperationException OpenConnectionRequired(string method,
12681262
internal static Exception OpenReaderExists(Exception e, bool marsOn)
12691263
=> InvalidOperation(StringsHelper.GetString(Strings.ADP_OpenReaderExists, marsOn ? ADP.Command : ADP.Connection), e);
12701264

1271-
internal static Exception InvalidXml() => Argument(StringsHelper.GetString(Strings.MDF_InvalidXml));
1272-
12731265
internal static Exception InvalidXmlInvalidValue(string collectionName, string columnName)
12741266
=> Argument(StringsHelper.GetString(Strings.MDF_InvalidXmlInvalidValue, collectionName, columnName));
12751267

@@ -1287,8 +1279,6 @@ internal static Exception UndefinedCollection(string collectionName)
12871279
internal static Exception AmbiguousCollectionName(string collectionName)
12881280
=> Argument(StringsHelper.GetString(Strings.MDF_AmbiguousCollectionName, collectionName));
12891281

1290-
internal static Exception MissingRestrictionColumn() => Argument(StringsHelper.GetString(Strings.MDF_MissingRestrictionColumn));
1291-
12921282
internal static Exception MissingRestrictionRow() => Argument(StringsHelper.GetString(Strings.MDF_MissingRestrictionRow));
12931283

12941284
internal static Exception UndefinedPopulationMechanism(string populationMechanism)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ protected internal virtual DataTable GetSchema(
860860
{
861861
Debug.Assert(outerConnection is not null, "outerConnection may not be null.");
862862

863-
DbMetaDataFactory metaDataFactory = factory.GetMetaDataFactory(poolGroup, this);
863+
SqlMetaDataFactory metaDataFactory = factory.GetMetaDataFactory(poolGroup, this);
864864
Debug.Assert(metaDataFactory is not null, "metaDataFactory may not be null.");
865865

866866
return metaDataFactory.GetSchema(outerConnection, collectionName, restrictions);

0 commit comments

Comments
 (0)