3 use Wikimedia\Rdbms\LoadBalancer
;
6 * Base class for objects that allow access to other wiki's databases using
7 * the foreign database access mechanism implemented by LBFactoryMulti.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
29 * @licence GNU GPL v2+
30 * @author Daniel Kinzler
32 abstract class DBAccessBase
implements IDBAccessObject
{
34 * @var string|bool $wiki The target wiki's name. This must be an ID
35 * that LBFactory can understand.
37 protected $wiki = false;
40 * @param string|bool $wiki The target wiki's name. This must be an ID
41 * that LBFactory can understand.
43 public function __construct( $wiki = false ) {
48 * Returns a database connection.
51 * @see LoadBalancer::getConnection()
55 * @param int $id Which connection to use
56 * @param array $groups Query groups
60 protected function getConnection( $id, $groups = [] ) {
61 $loadBalancer = wfGetLB( $this->wiki
);
63 return $loadBalancer->getConnection( $id, $groups, $this->wiki
);
67 * Releases a database connection and makes it available for recycling.
69 * @see LoadBalancer::reuseConnection()
73 * @param Database $db The database connection to release.
75 protected function releaseConnection( Database
$db ) {
76 if ( $this->wiki
!== false ) {
77 $loadBalancer = $this->getLoadBalancer();
78 $loadBalancer->reuseConnection( $db );
83 * Get the database type used for read operations.
89 * @return LoadBalancer The database load balancer object
91 public function getLoadBalancer() {
92 return wfGetLB( $this->wiki
);