Skip to content

Commit b098883

Browse files
authored
Merge pull request #395 from bgrainger/reorganise
Improve internal code organisation. Fixes #376
2 parents fbc0608 + 17aaa8e commit b098883

File tree

119 files changed

+902
-856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+902
-856
lines changed

src/MySqlConnector/MySqlClient/Caches/CachedParameter.cs renamed to src/MySqlConnector/Core/CachedParameter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System.Data;
22
using System.Linq;
3-
using MySql.Data.MySqlClient.Types;
43

5-
namespace MySql.Data.MySqlClient.Caches
4+
namespace MySqlConnector.Core
65
{
7-
internal class CachedParameter
6+
internal sealed class CachedParameter
87
{
98
public CachedParameter(int ordinalPosition, string mode, string name, string dataType, bool unsigned)
109
{

src/MySqlConnector/MySqlClient/Caches/CachedProcedure.cs renamed to src/MySqlConnector/Core/CachedProcedure.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
using System.Linq;
66
using System.Threading;
77
using System.Threading.Tasks;
8-
using MySql.Data.Protocol.Serialization;
8+
using MySql.Data.MySqlClient;
9+
using MySqlConnector.Protocol.Serialization;
910

10-
namespace MySql.Data.MySqlClient.Caches
11+
namespace MySqlConnector.Core
1112
{
12-
internal class CachedProcedure
13+
internal sealed class CachedProcedure
1314
{
1415
internal static async Task<CachedProcedure> FillAsync(IOBehavior ioBehavior, MySqlConnection connection, string schema, string component, CancellationToken cancellationToken)
1516
{
@@ -50,7 +51,7 @@ FROM information_schema.parameters
5051
return new CachedProcedure(schema, component, parameters.AsReadOnly());
5152
}
5253

53-
protected CachedProcedure(string schema, string component, ReadOnlyCollection<CachedParameter> parameters)
54+
private CachedProcedure(string schema, string component, ReadOnlyCollection<CachedParameter> parameters)
5455
{
5556
m_schema = schema;
5657
m_component = component;

src/MySqlConnector/MySqlClient/Types/ColumnTypeMetadata.cs renamed to src/MySqlConnector/Core/ColumnTypeMetadata.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace MySql.Data.MySqlClient.Types
1+
using MySql.Data.MySqlClient;
2+
3+
namespace MySqlConnector.Core
24
{
35
internal sealed class ColumnTypeMetadata
46
{

src/MySqlConnector/MySqlClient/ConnectionPool.cs renamed to src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
using System.Linq;
55
using System.Threading;
66
using System.Threading.Tasks;
7-
using MySql.Data.Protocol.Serialization;
8-
using MySql.Data.Serialization;
7+
using MySql.Data.MySqlClient;
8+
using MySqlConnector.Protocol.Serialization;
99

10-
namespace MySql.Data.MySqlClient
10+
namespace MySqlConnector.Core
1111
{
1212
internal sealed class ConnectionPool
1313
{
14-
public async Task<MySqlSession> GetSessionAsync(MySqlConnection connection, IOBehavior ioBehavior, CancellationToken cancellationToken)
14+
public async Task<ServerSession> GetSessionAsync(MySqlConnection connection, IOBehavior ioBehavior, CancellationToken cancellationToken)
1515
{
1616
cancellationToken.ThrowIfCancellationRequested();
1717

@@ -33,7 +33,7 @@ public async Task<MySqlSession> GetSessionAsync(MySqlConnection connection, IOBe
3333
try
3434
{
3535
// check for a waiting session
36-
MySqlSession session = null;
36+
ServerSession session = null;
3737
lock (m_sessions)
3838
{
3939
if (m_sessions.Count > 0)
@@ -79,7 +79,7 @@ public async Task<MySqlSession> GetSessionAsync(MySqlConnection connection, IOBe
7979
}
8080

8181
// create a new session
82-
session = new MySqlSession(this, m_generation, Interlocked.Increment(ref m_lastId));
82+
session = new ServerSession(this, m_generation, Interlocked.Increment(ref m_lastId));
8383
await session.ConnectAsync(m_connectionSettings, m_loadBalancer, ioBehavior, cancellationToken).ConfigureAwait(false);
8484
AdjustHostConnectionCount(session, 1);
8585
session.OwningConnection = new WeakReference<MySqlConnection>(connection);
@@ -94,7 +94,7 @@ public async Task<MySqlSession> GetSessionAsync(MySqlConnection connection, IOBe
9494
}
9595
}
9696

97-
private bool SessionIsHealthy(MySqlSession session)
97+
private bool SessionIsHealthy(ServerSession session)
9898
{
9999
if (!session.IsConnected)
100100
return false;
@@ -109,7 +109,7 @@ private bool SessionIsHealthy(MySqlSession session)
109109
return true;
110110
}
111111

112-
public void Return(MySqlSession session)
112+
public void Return(ServerSession session)
113113
{
114114
try
115115
{
@@ -150,13 +150,13 @@ public async Task ReapAsync(IOBehavior ioBehavior, CancellationToken cancellatio
150150
}
151151

152152
/// <summary>
153-
/// Examines all the <see cref="MySqlSession"/> objects in <see cref="m_leasedSessions"/> to determine if any
153+
/// Examines all the <see cref="ServerSession"/> objects in <see cref="m_leasedSessions"/> to determine if any
154154
/// have an owning <see cref="MySqlConnection"/> that has been garbage-collected. If so, assumes that the connection
155155
/// was not properly disposed and returns the session to the pool.
156156
/// </summary>
157157
private void RecoverLeakedSessions()
158158
{
159-
var recoveredSessions = new List<MySqlSession>();
159+
var recoveredSessions = new List<ServerSession>();
160160
lock (m_leasedSessions)
161161
{
162162
m_lastRecoveryTime = unchecked((uint) Environment.TickCount);
@@ -170,7 +170,7 @@ private void RecoverLeakedSessions()
170170
session.ReturnToPool();
171171
}
172172

173-
private async Task CleanPoolAsync(IOBehavior ioBehavior, Func<MySqlSession, bool> shouldCleanFn, bool respectMinPoolSize, CancellationToken cancellationToken)
173+
private async Task CleanPoolAsync(IOBehavior ioBehavior, Func<ServerSession, bool> shouldCleanFn, bool respectMinPoolSize, CancellationToken cancellationToken)
174174
{
175175
// synchronize access to this method as only one clean routine should be run at a time
176176
if (ioBehavior == IOBehavior.Asynchronous)
@@ -204,7 +204,7 @@ private async Task CleanPoolAsync(IOBehavior ioBehavior, Func<MySqlSession, bool
204204
try
205205
{
206206
// check for a waiting session
207-
MySqlSession session = null;
207+
ServerSession session = null;
208208
lock (m_sessions)
209209
{
210210
if (m_sessions.Count > 0)
@@ -267,7 +267,7 @@ private async Task CreateMinimumPooledSessions(IOBehavior ioBehavior, Cancellati
267267

268268
try
269269
{
270-
var session = new MySqlSession(this, m_generation, Interlocked.Increment(ref m_lastId));
270+
var session = new ServerSession(this, m_generation, Interlocked.Increment(ref m_lastId));
271271
await session.ConnectAsync(m_connectionSettings, m_loadBalancer, ioBehavior, cancellationToken).ConfigureAwait(false);
272272
AdjustHostConnectionCount(session, 1);
273273
lock (m_sessions)
@@ -313,8 +313,8 @@ private ConnectionPool(ConnectionSettings cs)
313313
m_generation = 0;
314314
m_cleanSemaphore = new SemaphoreSlim(1);
315315
m_sessionSemaphore = new SemaphoreSlim(cs.MaximumPoolSize);
316-
m_sessions = new LinkedList<MySqlSession>();
317-
m_leasedSessions = new Dictionary<int, MySqlSession>();
316+
m_sessions = new LinkedList<ServerSession>();
317+
m_leasedSessions = new Dictionary<int, ServerSession>();
318318
if (cs.LoadBalance == MySqlLoadBalance.FewestConnections)
319319
{
320320
m_hostSessions = new Dictionary<string, int>();
@@ -328,7 +328,7 @@ private ConnectionPool(ConnectionSettings cs)
328328
(ILoadBalancer) new RoundRobinLoadBalancer();
329329
}
330330

331-
private void AdjustHostConnectionCount(MySqlSession session, int delta)
331+
private void AdjustHostConnectionCount(ServerSession session, int delta)
332332
{
333333
if (m_hostSessions != null)
334334
{
@@ -375,9 +375,9 @@ public IEnumerable<string> LoadBalance(IReadOnlyList<string> hosts)
375375
int m_generation;
376376
readonly SemaphoreSlim m_cleanSemaphore;
377377
readonly SemaphoreSlim m_sessionSemaphore;
378-
readonly LinkedList<MySqlSession> m_sessions;
378+
readonly LinkedList<ServerSession> m_sessions;
379379
readonly ConnectionSettings m_connectionSettings;
380-
readonly Dictionary<int, MySqlSession> m_leasedSessions;
380+
readonly Dictionary<int, ServerSession> m_leasedSessions;
381381
readonly ILoadBalancer m_loadBalancer;
382382
readonly Dictionary<string, int> m_hostSessions;
383383
int m_lastId;

src/MySqlConnector/Serialization/ConnectionSettings.cs renamed to src/MySqlConnector/Core/ConnectionSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using MySql.Data.MySqlClient;
5+
using MySqlConnector.Utilities;
56

6-
namespace MySql.Data.Serialization
7+
namespace MySqlConnector.Core
78
{
89
internal sealed class ConnectionSettings
910
{

src/MySqlConnector/Serialization/ConnectionType.cs renamed to src/MySqlConnector/Core/ConnectionType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MySql.Data.Serialization
1+
namespace MySqlConnector.Core
22
{
33
/// <summary>
44
/// Specifies whether to perform synchronous or asynchronous I/O.

src/MySqlConnector/MySqlClient/Types/DbTypeMapping.cs renamed to src/MySqlConnector/Core/DbTypeMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Data;
33

4-
namespace MySql.Data.MySqlClient.Types
4+
namespace MySqlConnector.Core
55
{
66
internal sealed class DbTypeMapping
77
{

src/MySqlConnector/MySqlClient/CommandExecutors/ICommandExecutor.cs renamed to src/MySqlConnector/Core/ICommandExecutor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using System.Data;
1+
using System.Data;
22
using System.Data.Common;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using MySql.Data.Protocol.Serialization;
5+
using MySql.Data.MySqlClient;
6+
using MySqlConnector.Protocol.Serialization;
67

7-
namespace MySql.Data.MySqlClient.CommandExecutors
8+
namespace MySqlConnector.Core
89
{
910
internal interface ICommandExecutor
1011
{

src/MySqlConnector/Serialization/ILoadBalancer.cs renamed to src/MySqlConnector/Core/ILoadBalancer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33

4-
namespace MySql.Data.Serialization
4+
namespace MySqlConnector.Core
55
{
66
internal interface ILoadBalancer
77
{

src/MySqlConnector/MySqlClient/MySqlXaTransaction.cs renamed to src/MySqlConnector/Core/MySqlXaTransaction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
using System.Globalization;
44
using System.Threading;
55
using System.Transactions;
6+
using MySql.Data.MySqlClient;
67

7-
namespace MySql.Data.MySqlClient
8+
namespace MySqlConnector.Core
89
{
910
internal sealed class MySqlXaTransaction : IEnlistmentNotification
1011
{

src/MySqlConnector/MySqlClient/Caches/NormalizedSchema.cs renamed to src/MySqlConnector/Core/NormalizedSchema.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
1+
using System;
22
using System.Text.RegularExpressions;
33

4-
namespace MySql.Data.MySqlClient.Caches
4+
namespace MySqlConnector.Core
55
{
6-
internal class NormalizedSchema
6+
internal sealed class NormalizedSchema
77
{
88
private const string ReQuoted = @"`((?:[^`]|``)+)`";
99
private const string ReUnQuoted = @"([^\.`]+)";

src/MySqlConnector/MySqlClient/Results/ResultSet.cs renamed to src/MySqlConnector/Core/ResultSet.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
using System.IO;
55
using System.Threading;
66
using System.Threading.Tasks;
7-
using MySql.Data.MySqlClient.Types;
8-
using MySql.Data.Protocol.Serialization;
9-
using MySql.Data.Serialization;
7+
using MySql.Data.MySqlClient;
8+
using MySqlConnector.Protocol;
9+
using MySqlConnector.Protocol.Payloads;
10+
using MySqlConnector.Protocol.Serialization;
11+
using MySqlConnector.Utilities;
1012

11-
namespace MySql.Data.MySqlClient.Results
13+
namespace MySqlConnector.Core
1214
{
13-
internal class ResultSet
15+
internal sealed class ResultSet
1416
{
1517
public ResultSet(MySqlDataReader dataReader)
1618
{
@@ -277,7 +279,7 @@ public string GetDataTypeName(int ordinal)
277279

278280
var mySqlDbType = ColumnTypes[ordinal];
279281
if (mySqlDbType == MySqlDbType.String)
280-
return string.Format(CultureInfo.InvariantCulture, "CHAR({0})", ColumnDefinitions[ordinal].ColumnLength / SerializationUtility.GetBytesPerCharacter(ColumnDefinitions[ordinal].CharacterSet));
282+
return string.Format(CultureInfo.InvariantCulture, "CHAR({0})", ColumnDefinitions[ordinal].ColumnLength / ProtocolUtility.GetBytesPerCharacter(ColumnDefinitions[ordinal].CharacterSet));
281283
return TypeMapper.Instance.GetColumnTypeMetadata(mySqlDbType).SimpleDataTypeName;
282284
}
283285

@@ -326,7 +328,7 @@ public Row GetCurrentRow()
326328
public Exception ReadResultSetHeaderException { get; private set; }
327329
public MySqlCommand Command => DataReader.Command;
328330
public MySqlConnection Connection => DataReader.Connection;
329-
public MySqlSession Session => DataReader.Session;
331+
public ServerSession Session => DataReader.Session;
330332

331333
public ResultSetState BufferState { get; private set; }
332334
public ColumnDefinitionPayload[] ColumnDefinitions { get; private set; }
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MySql.Data.MySqlClient.Results
1+
namespace MySqlConnector.Core
22
{
33
internal enum ResultSetState
44
{
@@ -8,4 +8,4 @@ internal enum ResultSetState
88
HasMoreData,
99
NoMoreData,
1010
}
11-
}
11+
}

src/MySqlConnector/MySqlClient/Results/Row.cs renamed to src/MySqlConnector/Core/Row.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using System;
1+
using System;
22
using System.Globalization;
33
using System.Text;
4-
using MySql.Data.Serialization;
4+
using MySql.Data.MySqlClient;
5+
using MySqlConnector.Protocol;
6+
using MySqlConnector.Protocol.Serialization;
7+
using MySqlConnector.Utilities;
58

6-
namespace MySql.Data.MySqlClient.Results
9+
namespace MySqlConnector.Core
710
{
8-
internal class Row : IDisposable
11+
internal sealed class Row : IDisposable
912
{
1013
public Row(ResultSet resultSet) => ResultSet = resultSet;
1114

@@ -269,7 +272,7 @@ public object GetValue(int ordinal)
269272
return bitValue;
270273

271274
case ColumnType.String:
272-
if (!Connection.OldGuids && columnDefinition.ColumnLength / SerializationUtility.GetBytesPerCharacter(columnDefinition.CharacterSet) == 36)
275+
if (!Connection.OldGuids && columnDefinition.ColumnLength / ProtocolUtility.GetBytesPerCharacter(columnDefinition.CharacterSet) == 36)
273276
return Guid.Parse(Encoding.UTF8.GetString(data));
274277
goto case ColumnType.VarString;
275278

src/MySqlConnector/MySqlClient/SchemaProvider.cs renamed to src/MySqlConnector/Core/SchemaProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
using System.Collections.Generic;
44
using System.Data;
55
using System.Linq;
6-
using MySql.Data.MySqlClient.Types;
6+
using MySql.Data.MySqlClient;
77

8-
namespace MySql.Data.MySqlClient
8+
namespace MySqlConnector.Core
99
{
10-
internal sealed class SchemaProvider
11-
{
10+
internal sealed class SchemaProvider
11+
{
1212
public SchemaProvider(MySqlConnection connection)
1313
{
1414
m_connection = connection;

0 commit comments

Comments
 (0)