Completed
Branch master (4de667)
by
unknown
26:16
created

DBConnRef::serverIsReadOnly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Helper class to handle automatically marking connections as reusable (via RAII pattern)
4
 * as well handling deferring the actual network connection until the handle is used
5
 *
6
 * @note: proxy methods are defined explicity to avoid interface errors
7
 * @ingroup Database
8
 * @since 1.22
9
 */
10
class DBConnRef implements IDatabase {
11
	/** @var LoadBalancer */
12
	private $lb;
13
14
	/** @var DatabaseBase|null */
15
	private $conn;
16
17
	/** @var array|null */
18
	private $params;
19
20
	/**
21
	 * @param LoadBalancer $lb
22
	 * @param DatabaseBase|array $conn Connection or (server index, group, wiki ID) array
23
	 */
24
	public function __construct( LoadBalancer $lb, $conn ) {
25
		$this->lb = $lb;
26
		if ( $conn instanceof DatabaseBase ) {
27
			$this->conn = $conn;
28
		} else {
29
			$this->params = $conn;
30
		}
31
	}
32
33
	function __call( $name, array $arguments ) {
34
		if ( $this->conn === null ) {
35
			list( $db, $groups, $wiki ) = $this->params;
36
			$this->conn = $this->lb->getConnection( $db, $groups, $wiki );
37
		}
38
39
		return call_user_func_array( [ $this->conn, $name ], $arguments );
40
	}
41
42
	public function getServerInfo() {
43
		return $this->__call( __FUNCTION__, func_get_args() );
44
	}
45
46
	public function bufferResults( $buffer = null ) {
47
		return $this->__call( __FUNCTION__, func_get_args() );
48
	}
49
50
	public function trxLevel() {
51
		return $this->__call( __FUNCTION__, func_get_args() );
52
	}
53
54
	public function trxTimestamp() {
55
		return $this->__call( __FUNCTION__, func_get_args() );
56
	}
57
58
	public function tablePrefix( $prefix = null ) {
59
		return $this->__call( __FUNCTION__, func_get_args() );
60
	}
61
62
	public function dbSchema( $schema = null ) {
63
		return $this->__call( __FUNCTION__, func_get_args() );
64
	}
65
66
	public function getLBInfo( $name = null ) {
67
		return $this->__call( __FUNCTION__, func_get_args() );
68
	}
69
70
	public function setLBInfo( $name, $value = null ) {
71
		return $this->__call( __FUNCTION__, func_get_args() );
72
	}
73
74
	public function implicitGroupby() {
75
		return $this->__call( __FUNCTION__, func_get_args() );
76
	}
77
78
	public function implicitOrderby() {
79
		return $this->__call( __FUNCTION__, func_get_args() );
80
	}
81
82
	public function lastQuery() {
83
		return $this->__call( __FUNCTION__, func_get_args() );
84
	}
85
86
	public function doneWrites() {
87
		return $this->__call( __FUNCTION__, func_get_args() );
88
	}
89
90
	public function lastDoneWrites() {
91
		return $this->__call( __FUNCTION__, func_get_args() );
92
	}
93
94
	public function writesPending() {
95
		return $this->__call( __FUNCTION__, func_get_args() );
96
	}
97
98
	public function writesOrCallbacksPending() {
99
		return $this->__call( __FUNCTION__, func_get_args() );
100
	}
101
102
	public function pendingWriteQueryDuration() {
103
		return $this->__call( __FUNCTION__, func_get_args() );
104
	}
105
106
	public function pendingWriteCallers() {
107
		return $this->__call( __FUNCTION__, func_get_args() );
108
	}
109
110
	public function isOpen() {
111
		return $this->__call( __FUNCTION__, func_get_args() );
112
	}
113
114
	public function setFlag( $flag ) {
115
		return $this->__call( __FUNCTION__, func_get_args() );
116
	}
117
118
	public function clearFlag( $flag ) {
119
		return $this->__call( __FUNCTION__, func_get_args() );
120
	}
121
122
	public function getFlag( $flag ) {
123
		return $this->__call( __FUNCTION__, func_get_args() );
124
	}
125
126
	public function getProperty( $name ) {
127
		return $this->__call( __FUNCTION__, func_get_args() );
128
	}
129
130
	public function getWikiID() {
131
		return $this->__call( __FUNCTION__, func_get_args() );
132
	}
133
134
	public function getType() {
135
		return $this->__call( __FUNCTION__, func_get_args() );
136
	}
137
138
	public function open( $server, $user, $password, $dbName ) {
139
		return $this->__call( __FUNCTION__, func_get_args() );
140
	}
141
142
	public function fetchObject( $res ) {
143
		return $this->__call( __FUNCTION__, func_get_args() );
144
	}
145
146
	public function fetchRow( $res ) {
147
		return $this->__call( __FUNCTION__, func_get_args() );
148
	}
149
150
	public function numRows( $res ) {
151
		return $this->__call( __FUNCTION__, func_get_args() );
152
	}
153
154
	public function numFields( $res ) {
155
		return $this->__call( __FUNCTION__, func_get_args() );
156
	}
157
158
	public function fieldName( $res, $n ) {
159
		return $this->__call( __FUNCTION__, func_get_args() );
160
	}
161
162
	public function insertId() {
163
		return $this->__call( __FUNCTION__, func_get_args() );
164
	}
165
166
	public function dataSeek( $res, $row ) {
167
		return $this->__call( __FUNCTION__, func_get_args() );
168
	}
169
170
	public function lastErrno() {
171
		return $this->__call( __FUNCTION__, func_get_args() );
172
	}
173
174
	public function lastError() {
175
		return $this->__call( __FUNCTION__, func_get_args() );
176
	}
177
178
	public function fieldInfo( $table, $field ) {
179
		return $this->__call( __FUNCTION__, func_get_args() );
180
	}
181
182
	public function affectedRows() {
183
		return $this->__call( __FUNCTION__, func_get_args() );
184
	}
185
186
	public function getSoftwareLink() {
187
		return $this->__call( __FUNCTION__, func_get_args() );
188
	}
189
190
	public function getServerVersion() {
191
		return $this->__call( __FUNCTION__, func_get_args() );
192
	}
193
194
	public function close() {
195
		return $this->__call( __FUNCTION__, func_get_args() );
196
	}
197
198
	public function reportConnectionError( $error = 'Unknown error' ) {
199
		return $this->__call( __FUNCTION__, func_get_args() );
200
	}
201
202
	public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) {
203
		return $this->__call( __FUNCTION__, func_get_args() );
204
	}
205
206
	public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
207
		return $this->__call( __FUNCTION__, func_get_args() );
208
	}
209
210
	public function freeResult( $res ) {
211
		return $this->__call( __FUNCTION__, func_get_args() );
212
	}
213
214
	public function selectField(
215
		$table, $var, $cond = '', $fname = __METHOD__, $options = []
216
	) {
217
		return $this->__call( __FUNCTION__, func_get_args() );
218
	}
219
220
	public function selectFieldValues(
221
		$table, $var, $cond = '', $fname = __METHOD__, $options = []
222
	) {
223
		return $this->__call( __FUNCTION__, func_get_args() );
224
	}
225
226
	public function select(
227
		$table, $vars, $conds = '', $fname = __METHOD__,
228
		$options = [], $join_conds = []
229
	) {
230
		return $this->__call( __FUNCTION__, func_get_args() );
231
	}
232
233
	public function selectSQLText(
234
		$table, $vars, $conds = '', $fname = __METHOD__,
235
		$options = [], $join_conds = []
236
	) {
237
		return $this->__call( __FUNCTION__, func_get_args() );
238
	}
239
240
	public function selectRow(
241
		$table, $vars, $conds, $fname = __METHOD__,
242
		$options = [], $join_conds = []
243
	) {
244
		return $this->__call( __FUNCTION__, func_get_args() );
245
	}
246
247
	public function estimateRowCount(
248
		$table, $vars = '*', $conds = '', $fname = __METHOD__, $options = []
249
	) {
250
		return $this->__call( __FUNCTION__, func_get_args() );
251
	}
252
253
	public function selectRowCount(
254
		$tables, $vars = '*', $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
255
	) {
256
		return $this->__call( __FUNCTION__, func_get_args() );
257
	}
258
259
	public function fieldExists( $table, $field, $fname = __METHOD__ ) {
260
		return $this->__call( __FUNCTION__, func_get_args() );
261
	}
262
263
	public function indexExists( $table, $index, $fname = __METHOD__ ) {
264
		return $this->__call( __FUNCTION__, func_get_args() );
265
	}
266
267
	public function tableExists( $table, $fname = __METHOD__ ) {
268
		return $this->__call( __FUNCTION__, func_get_args() );
269
	}
270
271
	public function indexUnique( $table, $index ) {
272
		return $this->__call( __FUNCTION__, func_get_args() );
273
	}
274
275
	public function insert( $table, $a, $fname = __METHOD__, $options = [] ) {
276
		return $this->__call( __FUNCTION__, func_get_args() );
277
	}
278
279
	public function update( $table, $values, $conds, $fname = __METHOD__, $options = [] ) {
280
		return $this->__call( __FUNCTION__, func_get_args() );
281
	}
282
283
	public function makeList( $a, $mode = LIST_COMMA ) {
284
		return $this->__call( __FUNCTION__, func_get_args() );
285
	}
286
287
	public function makeWhereFrom2d( $data, $baseKey, $subKey ) {
288
		return $this->__call( __FUNCTION__, func_get_args() );
289
	}
290
291
	public function bitNot( $field ) {
292
		return $this->__call( __FUNCTION__, func_get_args() );
293
	}
294
295
	public function bitAnd( $fieldLeft, $fieldRight ) {
296
		return $this->__call( __FUNCTION__, func_get_args() );
297
	}
298
299
	public function bitOr( $fieldLeft, $fieldRight ) {
300
		return $this->__call( __FUNCTION__, func_get_args() );
301
	}
302
303
	public function buildConcat( $stringList ) {
304
		return $this->__call( __FUNCTION__, func_get_args() );
305
	}
306
307
	public function buildGroupConcatField(
308
		$delim, $table, $field, $conds = '', $join_conds = []
309
	) {
310
		return $this->__call( __FUNCTION__, func_get_args() );
311
	}
312
313
	public function selectDB( $db ) {
314
		return $this->__call( __FUNCTION__, func_get_args() );
315
	}
316
317
	public function getDBname() {
318
		return $this->__call( __FUNCTION__, func_get_args() );
319
	}
320
321
	public function getServer() {
322
		return $this->__call( __FUNCTION__, func_get_args() );
323
	}
324
325
	public function addQuotes( $s ) {
326
		return $this->__call( __FUNCTION__, func_get_args() );
327
	}
328
329
	public function buildLike() {
330
		return $this->__call( __FUNCTION__, func_get_args() );
331
	}
332
333
	public function anyChar() {
334
		return $this->__call( __FUNCTION__, func_get_args() );
335
	}
336
337
	public function anyString() {
338
		return $this->__call( __FUNCTION__, func_get_args() );
339
	}
340
341
	public function nextSequenceValue( $seqName ) {
342
		return $this->__call( __FUNCTION__, func_get_args() );
343
	}
344
345
	public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
346
		return $this->__call( __FUNCTION__, func_get_args() );
347
	}
348
349
	public function upsert(
350
		$table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
351
	) {
352
		return $this->__call( __FUNCTION__, func_get_args() );
353
	}
354
355
	public function deleteJoin(
356
		$delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
357
	) {
358
		return $this->__call( __FUNCTION__, func_get_args() );
359
	}
360
361
	public function delete( $table, $conds, $fname = __METHOD__ ) {
362
		return $this->__call( __FUNCTION__, func_get_args() );
363
	}
364
365
	public function insertSelect(
366
		$destTable, $srcTable, $varMap, $conds,
367
		$fname = __METHOD__, $insertOptions = [], $selectOptions = []
368
	) {
369
		return $this->__call( __FUNCTION__, func_get_args() );
370
	}
371
372
	public function unionSupportsOrderAndLimit() {
373
		return $this->__call( __FUNCTION__, func_get_args() );
374
	}
375
376
	public function unionQueries( $sqls, $all ) {
377
		return $this->__call( __FUNCTION__, func_get_args() );
378
	}
379
380
	public function conditional( $cond, $trueVal, $falseVal ) {
381
		return $this->__call( __FUNCTION__, func_get_args() );
382
	}
383
384
	public function strreplace( $orig, $old, $new ) {
385
		return $this->__call( __FUNCTION__, func_get_args() );
386
	}
387
388
	public function getServerUptime() {
389
		return $this->__call( __FUNCTION__, func_get_args() );
390
	}
391
392
	public function wasDeadlock() {
393
		return $this->__call( __FUNCTION__, func_get_args() );
394
	}
395
396
	public function wasLockTimeout() {
397
		return $this->__call( __FUNCTION__, func_get_args() );
398
	}
399
400
	public function wasErrorReissuable() {
401
		return $this->__call( __FUNCTION__, func_get_args() );
402
	}
403
404
	public function wasReadOnlyError() {
405
		return $this->__call( __FUNCTION__, func_get_args() );
406
	}
407
408
	public function masterPosWait( DBMasterPos $pos, $timeout ) {
409
		return $this->__call( __FUNCTION__, func_get_args() );
410
	}
411
412
	public function getSlavePos() {
413
		return $this->__call( __FUNCTION__, func_get_args() );
414
	}
415
416
	public function getMasterPos() {
417
		return $this->__call( __FUNCTION__, func_get_args() );
418
	}
419
420
	public function serverIsReadOnly() {
421
		return $this->__call( __FUNCTION__, func_get_args() );
422
	}
423
424
	public function onTransactionResolution( callable $callback ) {
425
		return $this->__call( __FUNCTION__, func_get_args() );
426
	}
427
428
	public function onTransactionIdle( callable $callback ) {
429
		return $this->__call( __FUNCTION__, func_get_args() );
430
	}
431
432
	public function onTransactionPreCommitOrIdle( callable $callback ) {
433
		return $this->__call( __FUNCTION__, func_get_args() );
434
	}
435
436
	public function startAtomic( $fname = __METHOD__ ) {
437
		return $this->__call( __FUNCTION__, func_get_args() );
438
	}
439
440
	public function endAtomic( $fname = __METHOD__ ) {
441
		return $this->__call( __FUNCTION__, func_get_args() );
442
	}
443
444
	public function doAtomicSection( $fname, callable $callback ) {
445
		return $this->__call( __FUNCTION__, func_get_args() );
446
	}
447
448
	public function begin( $fname = __METHOD__ ) {
449
		return $this->__call( __FUNCTION__, func_get_args() );
450
	}
451
452
	public function commit( $fname = __METHOD__, $flush = '' ) {
453
		return $this->__call( __FUNCTION__, func_get_args() );
454
	}
455
456
	public function rollback( $fname = __METHOD__, $flush = '' ) {
457
		return $this->__call( __FUNCTION__, func_get_args() );
458
	}
459
460
	public function listTables( $prefix = null, $fname = __METHOD__ ) {
461
		return $this->__call( __FUNCTION__, func_get_args() );
462
	}
463
464
	public function timestamp( $ts = 0 ) {
465
		return $this->__call( __FUNCTION__, func_get_args() );
466
	}
467
468
	public function timestampOrNull( $ts = null ) {
469
		return $this->__call( __FUNCTION__, func_get_args() );
470
	}
471
472
	public function ping() {
473
		return $this->__call( __FUNCTION__, func_get_args() );
474
	}
475
476
	public function getLag() {
477
		return $this->__call( __FUNCTION__, func_get_args() );
478
	}
479
480
	public function getSessionLagStatus() {
481
		return $this->__call( __FUNCTION__, func_get_args() );
482
	}
483
484
	public function maxListLen() {
485
		return $this->__call( __FUNCTION__, func_get_args() );
486
	}
487
488
	public function encodeBlob( $b ) {
489
		return $this->__call( __FUNCTION__, func_get_args() );
490
	}
491
492
	public function decodeBlob( $b ) {
493
		return $this->__call( __FUNCTION__, func_get_args() );
494
	}
495
496
	public function setSessionOptions( array $options ) {
497
		return $this->__call( __FUNCTION__, func_get_args() );
498
	}
499
500
	public function setSchemaVars( $vars ) {
501
		return $this->__call( __FUNCTION__, func_get_args() );
502
	}
503
504
	public function lockIsFree( $lockName, $method ) {
505
		return $this->__call( __FUNCTION__, func_get_args() );
506
	}
507
508
	public function lock( $lockName, $method, $timeout = 5 ) {
509
		return $this->__call( __FUNCTION__, func_get_args() );
510
	}
511
512
	public function unlock( $lockName, $method ) {
513
		return $this->__call( __FUNCTION__, func_get_args() );
514
	}
515
516
	public function getScopedLockAndFlush( $lockKey, $fname, $timeout ) {
517
		return $this->__call( __FUNCTION__, func_get_args() );
518
	}
519
520
	public function namedLocksEnqueue() {
521
		return $this->__call( __FUNCTION__, func_get_args() );
522
	}
523
524
	public function getInfinity() {
525
		return $this->__call( __FUNCTION__, func_get_args() );
526
	}
527
528
	public function encodeExpiry( $expiry ) {
529
		return $this->__call( __FUNCTION__, func_get_args() );
530
	}
531
532
	public function decodeExpiry( $expiry, $format = TS_MW ) {
533
		return $this->__call( __FUNCTION__, func_get_args() );
534
	}
535
536
	public function setBigSelects( $value = true ) {
537
		return $this->__call( __FUNCTION__, func_get_args() );
538
	}
539
540
	public function isReadOnly() {
541
		return $this->__call( __FUNCTION__, func_get_args() );
542
	}
543
544
	/**
545
	 * Clean up the connection when out of scope
546
	 */
547
	function __destruct() {
548
		if ( $this->conn !== null ) {
549
			$this->lb->reuseConnection( $this->conn );
550
		}
551
	}
552
}
553