8
8
9
9
namespace NBi . Core . Query . Execution
10
10
{
11
- /// <summary>
12
- /// Engine wrapping the System.Data.SqlClient namespace for execution of NBi tests
13
- /// <remarks>Instances of this class are built by the means of the <see>QueryEngineFactory</see></remarks>
14
- /// </summary>
15
11
internal abstract class DbCommandExecutionEngine : IExecutionEngine
16
12
{
17
- protected readonly IDbCommand command ;
13
+ protected IDbCommand Command { get ; }
18
14
private readonly Stopwatch stopWatch = new Stopwatch ( ) ;
19
- protected internal TimeSpan CommandTimeout { get ; internal set ; }
15
+ public TimeSpan CommandTimeout
16
+ {
17
+ get => new TimeSpan ( 0 , 0 , Command . CommandTimeout ) ;
18
+ set => Command . CommandTimeout = Convert . ToInt32 ( Math . Ceiling ( value . TotalSeconds ) ) ;
19
+ }
20
20
protected internal string ConnectionString { get ; private set ; }
21
21
22
22
protected DbCommandExecutionEngine ( IDbConnection connection , IDbCommand command )
23
23
{
24
- this . command = command ;
25
- this . CommandTimeout = new TimeSpan ( 0 , 0 , command . CommandTimeout ) ;
26
- this . ConnectionString = connection . ConnectionString ;
24
+ Command = command ;
25
+ ConnectionString = connection . ConnectionString ;
27
26
}
28
27
29
28
[ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Security" , "CA2100:Review SQL queries for security vulnerabilities" ) ]
@@ -32,9 +31,9 @@ public DataSet Execute()
32
31
using ( var connection = NewConnection ( ) )
33
32
{
34
33
OpenConnection ( connection ) ;
35
- InitializeCommand ( command , CommandTimeout , command . Parameters , connection ) ;
34
+ InitializeCommand ( Command , CommandTimeout , Command . Parameters , connection ) ;
36
35
StartWatch ( ) ;
37
- var ds = OnExecuteDataSet ( command ) ;
36
+ var ds = OnExecuteDataSet ( Command ) ;
38
37
StopWatch ( ) ;
39
38
return ds ;
40
39
}
@@ -59,9 +58,9 @@ public object ExecuteScalar()
59
58
using ( var connection = NewConnection ( ) )
60
59
{
61
60
OpenConnection ( connection ) ;
62
- InitializeCommand ( command , CommandTimeout , command . Parameters , connection ) ;
61
+ InitializeCommand ( Command , CommandTimeout , Command . Parameters , connection ) ;
63
62
StartWatch ( ) ;
64
- var value = OnExecuteScalar ( command ) ;
63
+ var value = OnExecuteScalar ( Command ) ;
65
64
StopWatch ( ) ;
66
65
return value ;
67
66
}
@@ -83,9 +82,9 @@ public IEnumerable<T> ExecuteList<T>()
83
82
using ( var connection = NewConnection ( ) )
84
83
{
85
84
OpenConnection ( connection ) ;
86
- InitializeCommand ( command , CommandTimeout , command . Parameters , connection ) ;
85
+ InitializeCommand ( Command , CommandTimeout , Command . Parameters , connection ) ;
87
86
StartWatch ( ) ;
88
- var list = OnExecuteList < T > ( command ) ;
87
+ var list = OnExecuteList < T > ( Command ) ;
89
88
StopWatch ( ) ;
90
89
return list ;
91
90
}
@@ -112,8 +111,9 @@ protected void InitializeCommand(IDbCommand command, TimeSpan commandTimeout, ID
112
111
Trace . WriteLineIf ( Extensibility . NBiTraceSwitch . TraceVerbose , command . CommandText ) ;
113
112
command . Connection = connection ;
114
113
foreach ( IDataParameter param in parameters )
115
- Trace . WriteLineIf ( Extensibility . NBiTraceSwitch . TraceVerbose , string . Format ( "{0 } => {1}" , param . ParameterName , param . Value ) ) ;
114
+ Trace . WriteLineIf ( Extensibility . NBiTraceSwitch . TraceVerbose , $ " { param . ParameterName } => { param . Value } " ) ;
116
115
command . CommandTimeout = Convert . ToInt32 ( commandTimeout . TotalSeconds ) ;
116
+ Trace . WriteLineIf ( Extensibility . NBiTraceSwitch . TraceVerbose , $ "Command timeout set to { command . CommandTimeout } second{ ( command . CommandTimeout > 1 ? "s" : string . Empty ) } ") ;
117
117
}
118
118
119
119
protected abstract void HandleException ( Exception ex , IDbCommand command ) ;
@@ -122,10 +122,7 @@ protected void InitializeCommand(IDbCommand command, TimeSpan commandTimeout, ID
122
122
protected internal abstract IDbConnection NewConnection ( ) ;
123
123
protected abstract IDataAdapter NewDataAdapter ( IDbCommand command ) ;
124
124
125
- protected void StartWatch ( )
126
- {
127
- stopWatch . Restart ( ) ;
128
- }
125
+ protected void StartWatch ( ) => stopWatch . Restart ( ) ;
129
126
130
127
protected void StopWatch ( )
131
128
{
@@ -134,6 +131,6 @@ protected void StopWatch()
134
131
}
135
132
136
133
protected internal TimeSpan Elapsed { get => stopWatch . Elapsed ; }
137
-
134
+
138
135
}
139
136
}
0 commit comments