14
14
use Doctrine \DBAL \Driver \Connection as ConnectionInterface ;
15
15
use Doctrine \DBAL \Driver \Middleware \AbstractConnectionMiddleware ;
16
16
use Doctrine \DBAL \Driver \Result ;
17
- use Doctrine \DBAL \Driver \Statement as DriverStatement ;
18
17
use Symfony \Component \Stopwatch \Stopwatch ;
19
18
20
19
/**
21
20
* @author Laurent VOULLEMIER <[email protected] >
21
+ * @author Alexander M. Turek <[email protected] >
22
22
*
23
23
* @internal
24
24
*/
25
25
final class Connection extends AbstractConnectionMiddleware
26
26
{
27
- private $ nestingLevel = 0 ;
28
- private $ debugDataHolder ;
29
- private $ stopwatch ;
30
- private $ connectionName ;
31
-
32
- public function __construct (ConnectionInterface $ connection , DebugDataHolder $ debugDataHolder , ?Stopwatch $ stopwatch , string $ connectionName )
33
- {
27
+ public function __construct (
28
+ ConnectionInterface $ connection ,
29
+ private DebugDataHolder $ debugDataHolder ,
30
+ private ?Stopwatch $ stopwatch ,
31
+ private string $ connectionName ,
32
+ ) {
34
33
parent ::__construct ($ connection );
35
-
36
- $ this ->debugDataHolder = $ debugDataHolder ;
37
- $ this ->stopwatch = $ stopwatch ;
38
- $ this ->connectionName = $ connectionName ;
39
34
}
40
35
41
- public function prepare (string $ sql ): DriverStatement
36
+ public function prepare (string $ sql ): Statement
42
37
{
43
38
return new Statement (
44
39
parent ::prepare ($ sql ),
@@ -53,135 +48,79 @@ public function query(string $sql): Result
53
48
{
54
49
$ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ($ sql ));
55
50
56
- if (null !== $ this ->stopwatch ) {
57
- $ this ->stopwatch ->start ('doctrine ' , 'doctrine ' );
58
- }
59
-
51
+ $ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
60
52
$ query ->start ();
61
53
62
54
try {
63
- $ result = parent ::query ($ sql );
55
+ return parent ::query ($ sql );
64
56
} finally {
65
57
$ query ->stop ();
66
-
67
- if (null !== $ this ->stopwatch ) {
68
- $ this ->stopwatch ->stop ('doctrine ' );
69
- }
58
+ $ this ->stopwatch ?->stop('doctrine ' );
70
59
}
71
-
72
- return $ result ;
73
60
}
74
61
75
62
public function exec (string $ sql ): int
76
63
{
77
64
$ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ($ sql ));
78
65
79
- if (null !== $ this ->stopwatch ) {
80
- $ this ->stopwatch ->start ('doctrine ' , 'doctrine ' );
81
- }
82
-
66
+ $ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
83
67
$ query ->start ();
84
68
85
69
try {
86
70
$ affectedRows = parent ::exec ($ sql );
87
71
} finally {
88
72
$ query ->stop ();
89
-
90
- if (null !== $ this ->stopwatch ) {
91
- $ this ->stopwatch ->stop ('doctrine ' );
92
- }
73
+ $ this ->stopwatch ?->stop('doctrine ' );
93
74
}
94
75
95
76
return $ affectedRows ;
96
77
}
97
78
98
- public function beginTransaction (): bool
79
+ public function beginTransaction (): void
99
80
{
100
- $ query = null ;
101
- if (1 === ++$ this ->nestingLevel ) {
102
- $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"START TRANSACTION" ' ));
103
- }
104
-
105
- if (null !== $ this ->stopwatch ) {
106
- $ this ->stopwatch ->start ('doctrine ' , 'doctrine ' );
107
- }
81
+ $ query = new Query ('"START TRANSACTION" ' );
82
+ $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query );
108
83
109
- if (null !== $ query ) {
110
- $ query ->start ();
111
- }
84
+ $ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
85
+ $ query ->start ();
112
86
113
87
try {
114
- $ ret = parent ::beginTransaction ();
88
+ parent ::beginTransaction ();
115
89
} finally {
116
- if (null !== $ query ) {
117
- $ query ->stop ();
118
- }
119
-
120
- if (null !== $ this ->stopwatch ) {
121
- $ this ->stopwatch ->stop ('doctrine ' );
122
- }
90
+ $ query ->stop ();
91
+ $ this ->stopwatch ?->stop('doctrine ' );
123
92
}
124
-
125
- return $ ret ;
126
93
}
127
94
128
- public function commit (): bool
95
+ public function commit (): void
129
96
{
130
- $ query = null ;
131
- if (1 === $ this ->nestingLevel --) {
132
- $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"COMMIT" ' ));
133
- }
97
+ $ query = new Query ('"COMMIT" ' );
98
+ $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query );
134
99
135
- if (null !== $ this ->stopwatch ) {
136
- $ this ->stopwatch ->start ('doctrine ' , 'doctrine ' );
137
- }
138
-
139
- if (null !== $ query ) {
140
- $ query ->start ();
141
- }
100
+ $ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
101
+ $ query ->start ();
142
102
143
103
try {
144
- $ ret = parent ::commit ();
104
+ parent ::commit ();
145
105
} finally {
146
- if (null !== $ query ) {
147
- $ query ->stop ();
148
- }
149
-
150
- if (null !== $ this ->stopwatch ) {
151
- $ this ->stopwatch ->stop ('doctrine ' );
152
- }
106
+ $ query ->stop ();
107
+ $ this ->stopwatch ?->stop('doctrine ' );
153
108
}
154
-
155
- return $ ret ;
156
109
}
157
110
158
- public function rollBack (): bool
111
+ public function rollBack (): void
159
112
{
160
- $ query = null ;
161
- if (1 === $ this ->nestingLevel --) {
162
- $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"ROLLBACK" ' ));
163
- }
164
-
165
- if (null !== $ this ->stopwatch ) {
166
- $ this ->stopwatch ->start ('doctrine ' , 'doctrine ' );
167
- }
113
+ $ query = new Query ('"ROLLBACK" ' );
114
+ $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query );
168
115
169
- if (null !== $ query ) {
170
- $ query ->start ();
171
- }
116
+ $ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
117
+ $ query ->start ();
172
118
173
119
try {
174
- $ ret = parent ::rollBack ();
120
+ parent ::rollBack ();
175
121
} finally {
176
- if (null !== $ query ) {
177
- $ query ->stop ();
178
- }
179
-
180
- if (null !== $ this ->stopwatch ) {
181
- $ this ->stopwatch ->stop ('doctrine ' );
182
- }
122
+ $ query ->stop ();
123
+ $ this ->stopwatch ?->stop('doctrine ' );
183
124
}
184
-
185
- return $ ret ;
186
125
}
187
126
}
0 commit comments