1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ez\DbLinker\Driver\Connection; |
4
|
|
|
|
5
|
|
|
use IteratorAggregate; |
6
|
|
|
use Doctrine\DBAL\Driver\Statement; |
7
|
|
|
use Ez\DbLinker\Driver\Connection\RetryConnection; |
8
|
|
|
use Ez\DbLinker\RetryStrategy; |
9
|
|
|
|
10
|
|
|
class RetryStatement implements IteratorAggregate, Statement |
11
|
|
|
{ |
12
|
|
|
private $statement; |
13
|
|
|
private $retryConnection; |
14
|
|
|
private $retryStrategy; |
15
|
|
|
|
16
|
|
|
use CallAndRetry; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param Statement $statement |
20
|
|
|
*/ |
21
|
|
|
public function __construct(Statement $statement, RetryConnection $retryConnection, RetryStrategy $retryStrategy) |
22
|
|
|
{ |
23
|
|
|
$this->statement = $statement; |
24
|
|
|
$this->retryConnection = $retryConnection; |
25
|
|
|
$this->retryStrategy = $retryStrategy; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function execute($params = NULL) |
32
|
|
|
{ |
33
|
|
|
return (bool)$this->callAndRetry(function () use ($params) { |
34
|
|
|
return $this->statement->execute($params); |
35
|
|
|
}, $this->retryStrategy); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function bindParam($column, &$variable, $type = null, $length = null) |
42
|
|
|
{ |
43
|
|
|
return $this->statement->bindParam($column, $variable, $type, $length); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function bindValue($param, $value, $type = null) |
50
|
|
|
{ |
51
|
|
|
return $this->statement->bindValue($param, $value, $type); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function fetch($fetchMode = null) |
58
|
|
|
{ |
59
|
|
|
return $this->statement->fetch($fetchMode); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function fetchAll($fetchMode = null) |
66
|
|
|
{ |
67
|
|
|
return $this->statement->fetchAll($fetchMode); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function fetchColumn($columnIndex = 0) |
74
|
|
|
{ |
75
|
|
|
return $this->statement->fetchColumn($columnIndex); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function errorCode() |
82
|
|
|
{ |
83
|
|
|
return $this->statement->errorCode(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function errorInfo() |
90
|
|
|
{ |
91
|
|
|
return $this->statement->errorInfo(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function closeCursor() |
98
|
|
|
{ |
99
|
|
|
return $this->statement->closeCursor(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function rowCount() |
106
|
|
|
{ |
107
|
|
|
return $this->statement->rowCount(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
public function columnCount() |
114
|
|
|
{ |
115
|
|
|
return $this->statement->columnCount(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) |
122
|
|
|
{ |
123
|
|
|
return $this->statement->setFetchMode($fetchMode, $arg2, $arg3); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
|
|
public function getIterator() |
130
|
|
|
{ |
131
|
|
|
return $this->statement; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
private function context() |
135
|
|
|
{ |
136
|
|
|
return $this->retryConnection; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|