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 int $ nestingLevel = 0 ;
28
-
29
27
public function __construct (
30
28
ConnectionInterface $ connection ,
31
29
private DebugDataHolder $ debugDataHolder ,
@@ -35,7 +33,7 @@ public function __construct(
35
33
parent ::__construct ($ connection );
36
34
}
37
35
38
- public function prepare (string $ sql ): DriverStatement
36
+ public function prepare (string $ sql ): Statement
39
37
{
40
38
return new Statement (
41
39
parent ::prepare ($ sql ),
@@ -54,13 +52,11 @@ public function query(string $sql): Result
54
52
$ query ->start ();
55
53
56
54
try {
57
- $ result = parent ::query ($ sql );
55
+ return parent ::query ($ sql );
58
56
} finally {
59
57
$ query ->stop ();
60
58
$ this ->stopwatch ?->stop('doctrine ' );
61
59
}
62
-
63
- return $ result ;
64
60
}
65
61
66
62
public function exec (string $ sql ): int
@@ -80,63 +76,51 @@ public function exec(string $sql): int
80
76
return $ affectedRows ;
81
77
}
82
78
83
- public function beginTransaction (): bool
79
+ public function beginTransaction (): void
84
80
{
85
- $ query = null ;
86
- if (1 === ++$ this ->nestingLevel ) {
87
- $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"START TRANSACTION" ' ));
88
- }
81
+ $ query = new Query ('"START TRANSACTION" ' );
82
+ $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query );
89
83
90
84
$ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
91
- $ query? ->start();
85
+ $ query ->start ();
92
86
93
87
try {
94
- $ ret = parent ::beginTransaction ();
88
+ parent ::beginTransaction ();
95
89
} finally {
96
- $ query? ->stop();
90
+ $ query ->stop ();
97
91
$ this ->stopwatch ?->stop('doctrine ' );
98
92
}
99
-
100
- return $ ret ;
101
93
}
102
94
103
- public function commit (): bool
95
+ public function commit (): void
104
96
{
105
- $ query = null ;
106
- if (1 === $ this ->nestingLevel --) {
107
- $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"COMMIT" ' ));
108
- }
97
+ $ query = new Query ('"COMMIT" ' );
98
+ $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query );
109
99
110
100
$ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
111
- $ query? ->start();
101
+ $ query ->start ();
112
102
113
103
try {
114
- $ ret = parent ::commit ();
104
+ parent ::commit ();
115
105
} finally {
116
- $ query? ->stop();
106
+ $ query ->stop ();
117
107
$ this ->stopwatch ?->stop('doctrine ' );
118
108
}
119
-
120
- return $ ret ;
121
109
}
122
110
123
- public function rollBack (): bool
111
+ public function rollBack (): void
124
112
{
125
- $ query = null ;
126
- if (1 === $ this ->nestingLevel --) {
127
- $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"ROLLBACK" ' ));
128
- }
113
+ $ query = new Query ('"ROLLBACK" ' );
114
+ $ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query );
129
115
130
116
$ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
131
- $ query? ->start();
117
+ $ query ->start ();
132
118
133
119
try {
134
- $ ret = parent ::rollBack ();
120
+ parent ::rollBack ();
135
121
} finally {
136
- $ query? ->stop();
122
+ $ query ->stop ();
137
123
$ this ->stopwatch ?->stop('doctrine ' );
138
124
}
139
-
140
- return $ ret ;
141
125
}
142
126
}
0 commit comments