forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfiledDbConnection.cs
More file actions
80 lines (67 loc) · 3.33 KB
/
ProfiledDbConnection.cs
File metadata and controls
80 lines (67 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#if !NETSTANDARD2_0
using System;
using System.Data;
using System.Data.Common;
namespace ServiceStack.MiniProfiler.Data
{
/// <summary>
/// Wraps a database connection, allowing sql execution timings to be collected when a <see cref="ServiceStack.MiniProfiler"/> session is started.
/// </summary>
public class ProfiledDbConnection : ProfiledConnection, ICloneable
{
/// <summary>
/// Returns a new <see cref="ProfiledDbConnection"/> that wraps <paramref name="connection"/>,
/// providing query execution profiling. If profiler is null, no profiling will occur.
/// </summary>
/// <param name="connection">Your provider-specific flavor of connection, e.g. SqlConnection, OracleConnection</param>
/// <param name="profiler">The currently started <see cref="IDbProfiler"/> or null.</param>
/// <param name="autoDisposeConnection">Determines whether the ProfiledDbConnection will dispose the underlying connection.</param>
public ProfiledDbConnection(DbConnection connection, IDbProfiler profiler, bool autoDisposeConnection = true)
: base(connection, profiler, autoDisposeConnection) {}
public ProfiledDbConnection(IDbConnection connection, IDbProfiler profiler, bool autoDisposeConnection=true)
: base(connection, profiler, autoDisposeConnection) {}
public ProfiledDbConnection(DbConnection connection, IProfiler profiler, bool autoDisposeConnection = true)
: base(connection, GetDbProfiler(profiler), autoDisposeConnection) {}
public ProfiledDbConnection(IDbConnection connection, IProfiler profiler, bool autoDisposeConnection=true)
: base(connection, GetDbProfiler(profiler), autoDisposeConnection) {}
private static IDbProfiler GetDbProfiler(IProfiler profiler)
{
if (profiler is IDbProfiler dbProfiler)
return dbProfiler;
return profiler.GetMiniProfiler();
}
/// <summary>
/// This will be made private; use <see cref="ProfiledConnection.InnerConnection"/>
/// </summary>
protected DbConnection _conn // TODO: in MiniProfiler 2.0, make private
{
get { return InnerConnection; }
set { InnerConnection = value; }
}
/// <summary>
/// This will be made private; use <see cref="MiniProfiler"/>
/// </summary>
protected IDbProfiler _profiler // TODO: in MiniProfiler 2.0, make private
{
get { return Profiler; }
set { Profiler = value; }
}
protected bool autoDisposeConnection // Wrapper property for backwards compatibility
{
get { return AutoDisposeConnection; }
set { AutoDisposeConnection = value; }
}
protected override DbCommand CreateDbCommand()
{
return new ProfiledDbCommand(_conn.CreateCommand(), this, _profiler);
}
public ProfiledDbConnection Clone()
{
ICloneable tail = _conn as ICloneable;
if (tail == null) throw new NotSupportedException("Underlying " + _conn.GetType().FullName + " is not cloneable");
return new ProfiledDbConnection((DbConnection)tail.Clone(), _profiler, AutoDisposeConnection);
}
object ICloneable.Clone() { return Clone(); }
}
}
#endif