Skip to content

Commit 1058566

Browse files
authored
Fix | PoolGroupProviderInfo Typing (#3417)
* Revert mistake in SqlConnectionFactory * Make pool provider info creation methods abstract Make pool provider info arguments in *ConnectionFactory methods strongly typed
1 parent 2385ca7 commit 1058566

File tree

4 files changed

+69
-24
lines changed

4 files changed

+69
-24
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,30 @@ override public DbProviderFactory ProviderFactory
3333
}
3434
}
3535

36-
override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection)
36+
protected override DbConnectionInternal CreateConnection(
37+
DbConnectionOptions options,
38+
DbConnectionPoolKey poolKey,
39+
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo,
40+
IDbConnectionPool pool,
41+
DbConnection owningConnection)
3742
{
3843
return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection, userOptions: null);
3944
}
4045

41-
override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
46+
protected override DbConnectionInternal CreateConnection(
47+
DbConnectionOptions options,
48+
DbConnectionPoolKey poolKey,
49+
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo,
50+
IDbConnectionPool pool,
51+
DbConnection owningConnection,
52+
DbConnectionOptions userOptions)
4253
{
4354
SqlConnectionString opt = (SqlConnectionString)options;
4455
SqlConnectionPoolKey key = (SqlConnectionPoolKey)poolKey;
4556
SessionData recoverySessionData = null;
4657

4758
SqlConnection sqlOwningConnection = (SqlConnection)owningConnection;
48-
bool applyTransientFaultHandling = sqlOwningConnection != null ? sqlOwningConnection._applyTransientFaultHandling : false;
59+
bool applyTransientFaultHandling = sqlOwningConnection?._applyTransientFaultHandling ?? false;
4960

5061
SqlConnectionString userOpt = null;
5162
if (userOptions != null)
@@ -137,7 +148,20 @@ override protected DbConnectionInternal CreateConnection(DbConnectionOptions opt
137148
opt = new SqlConnectionString(opt, instanceName, userInstance: false, setEnlistValue: null);
138149
poolGroupProviderInfo = null; // null so we do not pass to constructor below...
139150
}
140-
return new SqlInternalConnectionTds(identity, opt, key.Credential, poolGroupProviderInfo, "", null, redirectedUserInstance, userOpt, recoverySessionData, applyTransientFaultHandling, key.AccessToken, pool, key.AccessTokenCallback);
151+
return new SqlInternalConnectionTds(
152+
identity,
153+
opt,
154+
key.Credential,
155+
poolGroupProviderInfo,
156+
newPassword: string.Empty,
157+
newSecurePassword: null,
158+
redirectedUserInstance,
159+
userOpt,
160+
recoverySessionData,
161+
applyTransientFaultHandling,
162+
key.AccessToken,
163+
pool,
164+
key.AccessTokenCallback);
141165
}
142166

143167
protected override DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous)

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,30 @@ override public DbProviderFactory ProviderFactory
3131
}
3232
}
3333

34-
override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection)
34+
protected override DbConnectionInternal CreateConnection(
35+
DbConnectionOptions options,
36+
DbConnectionPoolKey poolKey,
37+
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo,
38+
IDbConnectionPool pool,
39+
DbConnection owningConnection)
3540
{
3641
return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection, userOptions: null);
3742
}
3843

39-
override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
44+
protected override DbConnectionInternal CreateConnection(
45+
DbConnectionOptions options,
46+
DbConnectionPoolKey poolKey,
47+
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo,
48+
IDbConnectionPool pool,
49+
DbConnection owningConnection,
50+
DbConnectionOptions userOptions)
4051
{
4152
SqlConnectionString opt = (SqlConnectionString)options;
4253
SqlConnectionPoolKey key = (SqlConnectionPoolKey)poolKey;
4354
SessionData recoverySessionData = null;
55+
4456
SqlConnection sqlOwningConnection = owningConnection as SqlConnection;
45-
bool applyTransientFaultHandling = sqlOwningConnection != null ? sqlOwningConnection._applyTransientFaultHandling : false;
57+
bool applyTransientFaultHandling = sqlOwningConnection?._applyTransientFaultHandling ?? false;
4658

4759
SqlConnectionString userOpt = null;
4860
if (userOptions != null)
@@ -51,7 +63,7 @@ override protected DbConnectionInternal CreateConnection(DbConnectionOptions opt
5163
}
5264
else if (sqlOwningConnection != null)
5365
{
54-
userOpt = (SqlConnectionString)(sqlOwningConnection.UserConnectionOptions);
66+
userOpt = (SqlConnectionString)sqlOwningConnection.UserConnectionOptions;
5567
}
5668

5769
if (sqlOwningConnection != null)
@@ -138,13 +150,14 @@ override protected DbConnectionInternal CreateConnection(DbConnectionOptions opt
138150
instanceName,
139151
userInstance: false,
140152
setEnlistValue: null); // Do not modify the enlist value
153+
poolGroupProviderInfo = null;
141154
}
142155

143156
return new SqlInternalConnectionTds(
144157
identity,
145158
opt,
146159
key.Credential,
147-
providerInfo: null,
160+
poolGroupProviderInfo,
148161
newPassword: string.Empty,
149162
newSecurePassword: null,
150163
redirectedUserInstance,
@@ -163,7 +176,7 @@ protected override DbConnectionOptions CreateConnectionOptions(string connection
163176
return result;
164177
}
165178

166-
override internal DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(DbConnectionOptions connectionOptions)
179+
internal override DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(DbConnectionOptions connectionOptions)
167180
{
168181
DbConnectionPoolProviderInfo providerInfo = null;
169182

@@ -233,12 +246,12 @@ override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal
233246
internalConnection.ServerVersion); //internalConnection.ServerVersionNormalized);
234247
}
235248

236-
override internal DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo(DbConnectionOptions connectionOptions)
249+
internal override DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo(
250+
DbConnectionOptions connectionOptions)
237251
{
238252
return new SqlConnectionPoolGroupProviderInfo((SqlConnectionString)connectionOptions);
239253
}
240254

241-
242255
internal static SqlConnectionString FindSqlConnectionOptions(SqlConnectionPoolKey key)
243256
{
244257
SqlConnectionString connectionOptions = (SqlConnectionString)SingletonInstance.FindConnectionOptions(key);

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ internal SqlInternalConnectionTds(
457457
DbConnectionPoolIdentity identity,
458458
SqlConnectionString connectionOptions,
459459
SqlCredential credential,
460-
object providerInfo,
460+
DbConnectionPoolGroupProviderInfo providerInfo,
461461
string newPassword,
462462
SecureString newSecurePassword,
463463
bool redirectedUserInstance,
@@ -467,7 +467,8 @@ internal SqlInternalConnectionTds(
467467
string accessToken = null,
468468
IDbConnectionPool pool = null,
469469
Func<SqlAuthenticationParameters, CancellationToken,
470-
Task<SqlAuthenticationToken>> accessTokenCallback = null) : base(connectionOptions)
470+
Task<SqlAuthenticationToken>> accessTokenCallback = null)
471+
: base(connectionOptions)
471472
{
472473
#if DEBUG
473474
if (reconnectSessionData != null)

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ public void ClearPool(DbConnectionPoolKey key)
9191
}
9292
}
9393

94-
internal virtual DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(DbConnectionOptions connectionOptions)
95-
{
96-
return null;
97-
}
94+
internal abstract DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(
95+
DbConnectionOptions connectionOptions);
9896

9997
protected virtual DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory)
10098
{
@@ -139,10 +137,8 @@ internal DbConnectionInternal CreatePooledConnection(IDbConnectionPool pool, DbC
139137
return newConnection;
140138
}
141139

142-
internal virtual DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo(DbConnectionOptions connectionOptions)
143-
{
144-
return null;
145-
}
140+
internal abstract DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo(
141+
DbConnectionOptions connectionOptions);
146142

147143
private Timer CreatePruningTimer() =>
148144
ADP.UnsafeCreateTimer(
@@ -646,12 +642,23 @@ internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup)
646642
SqlClientEventSource.Metrics.ExitActiveConnectionPoolGroup();
647643
}
648644

649-
virtual protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
645+
protected virtual DbConnectionInternal CreateConnection(
646+
DbConnectionOptions options,
647+
DbConnectionPoolKey poolKey,
648+
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo,
649+
IDbConnectionPool pool,
650+
DbConnection owningConnection,
651+
DbConnectionOptions userOptions)
650652
{
651653
return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection);
652654
}
653655

654-
abstract protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection);
656+
protected abstract DbConnectionInternal CreateConnection(
657+
DbConnectionOptions options,
658+
DbConnectionPoolKey poolKey,
659+
DbConnectionPoolGroupProviderInfo poolGroupProviderInfo,
660+
IDbConnectionPool pool,
661+
DbConnection owningConnection);
655662

656663
abstract protected DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous);
657664

0 commit comments

Comments
 (0)