Skip to content

Commit a0cc7a9

Browse files
committed
Interface of connection handler
will be extended later on with async variants if needed
1 parent 3263519 commit a0cc7a9

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Data.Common;
3+
using Xtensive.Core;
4+
5+
namespace Xtensive.Orm
6+
{
7+
/// <summary>
8+
/// Extended <see cref="ConnectionEventData"/> with error happend during connection opening, restoration or initialization.
9+
/// </summary>
10+
public class ConnectionErrorEventData : ConnectionEventData
11+
{
12+
/// <summary>
13+
/// The exception appeared.
14+
/// </summary>
15+
public Exception Exception { get; }
16+
17+
public ConnectionErrorEventData(Exception exception, DbConnection connection, bool reconnect = false)
18+
: base(connection, reconnect)
19+
{
20+
ArgumentValidator.EnsureArgumentNotNull(exception, nameof(exception));
21+
Exception = exception;
22+
}
23+
}
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Data.Common;
2+
using Xtensive.Core;
3+
4+
namespace Xtensive.Orm
5+
{
6+
/// <summary>
7+
/// Contains general data for <see cref="IConnectionHandler"/> methods.
8+
/// </summary>
9+
public class ConnectionEventData
10+
{
11+
/// <summary>
12+
/// The connection for which event triggered.
13+
/// </summary>
14+
public DbConnection Connection { get; }
15+
16+
/// <summary>
17+
/// Indicates whether event happened during an attempt to restore connection.
18+
/// </summary>
19+
public bool Reconnect { get; }
20+
21+
public ConnectionEventData(DbConnection connection, bool reconnect = false)
22+
{
23+
ArgumentValidator.EnsureArgumentNotNull(connection, nameof(connection));
24+
Connection = connection;
25+
Reconnect = reconnect;
26+
}
27+
}
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Data.Common;
2+
using Xtensive.Core;
3+
4+
namespace Xtensive.Orm
5+
{
6+
/// <summary>
7+
/// Extended <see cref="ConnectionEventData"/> with connection initialization script
8+
/// </summary>
9+
public class ConnectionInitEventData : ConnectionEventData
10+
{
11+
/// <summary>
12+
/// Gets the script which will be used for connection initializatin
13+
/// </summary>
14+
public string InitializationScript { get; }
15+
16+
public ConnectionInitEventData(string initializationScript, DbConnection connection, bool reconnect = false)
17+
: base(connection, reconnect)
18+
{
19+
ArgumentValidator.EnsureArgumentNotNullOrEmpty(initializationScript, nameof(initializationScript));
20+
InitializationScript = initializationScript;
21+
}
22+
}
23+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace Xtensive.Orm
2+
{
3+
/// <summary>
4+
/// Offers event-like methods to access native database connection on different stages
5+
/// </summary>
6+
public interface IConnectionHandler
7+
{
8+
/// <summary>
9+
/// Executes before connection opening.
10+
/// </summary>
11+
/// <param name="eventData">Information connected with this event.</param>
12+
void ConnectionOpening(ConnectionEventData eventData) { }
13+
14+
/// <summary>
15+
/// Executes when connection is already opened but initialization script
16+
/// hasn't been executed yet.
17+
/// </summary>
18+
/// <param name="eventData">Information connected with this event.</param>
19+
void ConnectionInitialization(ConnectionInitEventData eventData) { }
20+
21+
/// <summary>
22+
/// Executes when connection is successfully opened and initialized
23+
/// </summary>
24+
/// <param name="eventData">Information connected with this event</param>
25+
void ConnectionOpened(ConnectionEventData eventData) { }
26+
27+
/// <summary>
28+
/// Executes if an error appeared on either connection opening or connection initialization.
29+
/// </summary>
30+
/// <param name="eventData">Information connected with this event</param>
31+
void ConnectionOpeningFailed(ConnectionErrorEventData eventData) { }
32+
}
33+
}

0 commit comments

Comments
 (0)